Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
NSTechBytes authored Nov 12, 2024
1 parent 5dc241b commit 445d9f0
Show file tree
Hide file tree
Showing 4 changed files with 177 additions and 0 deletions.
52 changes: 52 additions & 0 deletions SkinFound/Main.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[Rainmeter]
Update=1000
BackgroundMode=2
SolidColor=255,255,255,150

[Metadata]
Name=SkinFound
Author=NS Tech Bytes
Version=1.0
Description=Checks if specific skins exist in the Rainmeter skins folder using the SkinFound plugin.
License=Appache 2.0

[Variables]
SkinList=YourBar | Illustro | MiniSnap

[mSkinFoundWhole]
Measure=Plugin
Plugin=SkinFound.dll
SkinName=#SkinList#
Output=Whole
DynamicVariables=1
OnUpdateAction=[!Log "[mSkinFoundWhole]"]

[mSkinFoundNameOnly]
Measure=Plugin
Plugin=SkinFound.dll
SkinName=#SkinList#
Output=NameOnly
DynamicVariables=1
OnUpdateAction=[!Log "[mSkinFoundNameOnly]"]

[TextWhole]
Meter=String
MeasureName=mSkinFoundWhole
X=10
Y=10
FontColor=10,10,10
FontSize=12
Text="Full Status: #CRLF#[mSkinFoundWhole]"
DynamicVariables=1
Antialias=1

[TextNameOnly]
Meter=String
MeasureName=mSkinFoundNameOnly
X=10
Y=100
FontColor=10,10,10
FontSize=12
Text="Available Skins: #CRLF#[mSkinFoundNameOnly]"
DynamicVariables=1
Antialias=1
125 changes: 125 additions & 0 deletions SourceCode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
using System;
using System.IO;
using System.Runtime.InteropServices;
using Rainmeter;

namespace PluginSkinFound
{
public class Measure
{
private string[] skinNames;
private string skinsFolderPath;
private string outputFormat = "Whole";

public void Reload(API api)
{
string skinNamesSetting = api.ReadString("SkinName", "").Trim();
outputFormat = api.ReadString("Output", "Whole").Trim();

// Retrieve the Skins directory path from the #SKINSPATH# variable
skinsFolderPath = api.ReplaceVariables("#SKINSPATH#").Trim();

if (string.IsNullOrEmpty(skinNamesSetting))
{
api.Log(API.LogType.Error, "SkinFound.dll: No SkinName provided.");
skinNames = Array.Empty<string>();
}
else
{
// Split skin names and remove any extra spaces around them
skinNames = skinNamesSetting.Split('|');
for (int i = 0; i < skinNames.Length; i++)
{
skinNames[i] = skinNames[i].Trim();
}
}
}

public string CheckSkinsExist(API api)
{
if (skinNames == null || skinNames.Length == 0)
{
return "No skins specified.";
}

string result = "";
foreach (string skin in skinNames)
{
string skinPath = Path.Combine(skinsFolderPath, skin);
bool skinExists = Directory.Exists(skinPath);

if (outputFormat.Equals("NameOnly", StringComparison.OrdinalIgnoreCase))
{
if (skinExists)
{
result += $"{skin}\n";
api.Log(API.LogType.Debug, $"SkinFound.dll: {skin} is available.");
}
}
else // Whole format
{
result += $"{skin}: {(skinExists ? 1 : 0)}\n";
api.Log(API.LogType.Debug, $"SkinFound.dll: {skin} is {(skinExists ? "available" : "NOT available")}.");
}
}
return result.TrimEnd('\n');
}
}

public static class Plugin
{
static IntPtr stringBuffer = IntPtr.Zero;

[DllExport]
public static void Initialize(ref IntPtr data, IntPtr rm)
{
data = GCHandle.ToIntPtr(GCHandle.Alloc(new Measure()));
}

[DllExport]
public static void Finalize(IntPtr data)
{
if (data != IntPtr.Zero)
{
GCHandle.FromIntPtr(data).Free();
}

if (stringBuffer != IntPtr.Zero)
{
Marshal.FreeHGlobal(stringBuffer);
stringBuffer = IntPtr.Zero;
}
}

[DllExport]
public static void Reload(IntPtr data, IntPtr rm, ref double maxValue)
{
var measure = (Measure)GCHandle.FromIntPtr(data).Target;
var api = new API(rm);
measure.Reload(api);
}

[DllExport]
public static double Update(IntPtr data)
{
return 0.0;
}

[DllExport]
public static IntPtr GetString(IntPtr data)
{
var measure = (Measure)GCHandle.FromIntPtr(data).Target;
var api = new API(IntPtr.Zero); // Only used for logging purposes
string result = measure.CheckSkinsExist(api);

if (stringBuffer != IntPtr.Zero)
{
Marshal.FreeHGlobal(stringBuffer);
stringBuffer = IntPtr.Zero;
}

stringBuffer = Marshal.StringToHGlobalUni(result);
return stringBuffer;
}
}
}
Binary file added x32/SkinFound.dll
Binary file not shown.
Binary file added x64/SkinFound.dll
Binary file not shown.

0 comments on commit 445d9f0

Please sign in to comment.