Options:
- Drive : The drive letter we want information of, e.g. C, D etc.
- Type : The information we want. Valid values are:
- DriveType
- FileSystem (NTFS, FAT32 etc)
- FreeSpace
- Label
- TotalSpace
Inline Functions:
- GetDriveType(driveletter) : [&MeasureName:GetDriveType(C)] = Fixed
- GetFileSystem(driveletter) : [&MeasureName:GetFileSystem(C)] = NTFS
- GetFreeSpace(driveletter) : [&MeasureName:GetFreeSpace(C)] = 110595407872
- GetLabel(driveletter) : [&MeasureName:GetLabel(D)] = OS
- GetTotalSpace(driveletter) : [&MeasureName:GetTotalSpace(C)] = 246960619520
Usage:
Code: Select all
[DriveInfo]
Measure=Plugin
Plugin=DriveInfo
Drive=D
Type=Label
Source(C#):
Code: Select all
using Rainmeter;
using System;
using System.Runtime.InteropServices;
namespace DriveInfo
{
class Measure
{
static public implicit operator Measure(IntPtr data)
{
return (Measure)GCHandle.FromIntPtr(data).Target;
}
public IntPtr buffer = IntPtr.Zero;
public API rmapi;
public string drive;
public string type;
public bool driveValid = false;
public System.IO.DriveInfo driveInfo;
}
public class Plugin
{
[DllExport]
public static void Initialize(ref IntPtr data, IntPtr rm)
{
data = GCHandle.ToIntPtr(GCHandle.Alloc(new Measure()));
Rainmeter.API api = (Rainmeter.API)rm;
}
[DllExport]
public static void Finalize(IntPtr data)
{
Measure measure = (Measure)data;
if (measure.buffer != IntPtr.Zero)
{
Marshal.FreeHGlobal(measure.buffer);
}
GCHandle.FromIntPtr(data).Free();
}
[DllExport]
public static void Reload(IntPtr data, IntPtr rm, ref double maxValue)
{
Measure measure = (Measure)data;
measure.rmapi = new Rainmeter.API(rm);
measure.drive = measure.rmapi.ReadString("Drive", "");
measure.type = measure.rmapi.ReadString("Type", "drivetype").ToLower();
if (String.IsNullOrEmpty(measure.drive)) return;
try
{
measure.driveInfo = new System.IO.DriveInfo(measure.drive.Substring(0, 1));
measure.driveValid = true;
}
catch
{
measure.rmapi.Log(API.LogType.Error, String.Format("Drive {0} doesn't exist.", measure.drive));
}
}
[DllExport]
public static double Update(IntPtr data)
{
Measure measure = (Measure)data;
if (!measure.driveValid)
return 0.0;
if (!measure.driveInfo.IsReady)
return 0.0;
if (measure.type == "freespace")
return Convert.ToDouble(GetDriveInfo(measure.driveInfo, measure.type));
if (measure.type == "totalspace")
return Convert.ToDouble(GetDriveInfo(measure.driveInfo, measure.type));
return 0.0;
}
[DllExport]
public static IntPtr GetString(IntPtr data)
{
Measure measure = (Measure)data;
if (measure.buffer != IntPtr.Zero)
{
Marshal.FreeHGlobal(measure.buffer);
measure.buffer = IntPtr.Zero;
}
if (measure.driveValid)
{
measure.buffer = Marshal.StringToHGlobalUni(GetDriveInfo(measure.driveInfo, measure.type));
}
return measure.buffer;
}
public static string GetDriveInfo(System.IO.DriveInfo drive, string infoType)
{
if (!drive.IsReady)
{
if (infoType.Equals("drivetype"))
{
return drive.DriveType.ToString();
}
else if (infoType.Equals("label"))
{
switch (drive.DriveType)
{
case System.IO.DriveType.CDRom:
return "CD Drive";
case System.IO.DriveType.Fixed:
return "Fixed Drive";
case System.IO.DriveType.Network:
return "Network Drive";
case System.IO.DriveType.Ram:
return "RAM Disk";
case System.IO.DriveType.Removable:
return "Removable Drive";
default:
return "Unknown";
}
}
else if (infoType.Equals("filesystem"))
{
return "Unidentified";
}
else
{
return null;
}
}
switch (infoType)
{
case "drivetype":
return drive.DriveType.ToString();
case "filesystem":
return drive.DriveFormat;
case "freespace":
return drive.AvailableFreeSpace.ToString();
case "label":
return drive.VolumeLabel;
case "totalspace":
return drive.TotalSize.ToString();
default:
return null;
}
}
public static string TrimQuotes(string rawString)
{
string outString = rawString;
if ((rawString.StartsWith("\"") && rawString.EndsWith("\"")) || (rawString.StartsWith("'") && rawString.EndsWith("'")))
{
outString = outString.Remove(0, 1);
outString = outString.Remove(outString.Length - 1, 1);
return outString;
}
return rawString;
}
[DllExport]
public static IntPtr GetLabel(IntPtr data, int argc, [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 1)] string[] argv)
{
Measure measure = (Measure)data;
if (argc <= 0)
{
return IntPtr.Zero;
}
System.IO.DriveInfo drive;
string output = null;
try
{
drive = new System.IO.DriveInfo(TrimQuotes(argv[0]).Substring(0, 1));
output = GetDriveInfo(drive, "label");
}
catch
{
return Marshal.StringToHGlobalUni(TrimQuotes(argv[0]));
}
if (!String.IsNullOrEmpty(output))
{
return Marshal.StringToHGlobalUni(output);
}
return Marshal.StringToHGlobalUni("Unidentified");
}
[DllExport]
public static IntPtr GetFileSystem(IntPtr data, int argc, [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 1)] string[] argv)
{
Measure measure = (Measure)data;
if (argc <= 0)
{
return IntPtr.Zero;
}
System.IO.DriveInfo drive;
string output;
try
{
drive = new System.IO.DriveInfo(TrimQuotes(argv[0]).Substring(0, 1));
if (!drive.IsReady)
{
return Marshal.StringToHGlobalUni("Unidentified");
}
else
{
output = GetDriveInfo(drive, "filesystem");
}
}
catch
{
return IntPtr.Zero;
}
if (!String.IsNullOrEmpty(output)) return Marshal.StringToHGlobalUni(output);
return Marshal.StringToHGlobalUni("Unidentified");
}
[DllExport]
public static IntPtr GetDriveType(IntPtr data, int argc, [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 1)] string[] argv)
{
Measure measure = (Measure)data;
if (argc <= 0)
{
return IntPtr.Zero;
}
System.IO.DriveInfo drive;
string output;
try
{
drive = new System.IO.DriveInfo(TrimQuotes(argv[0]));
output = drive.DriveType.ToString();
}
catch
{
return Marshal.StringToHGlobalUni("Unidentified");
}
if (!String.IsNullOrEmpty(output)) return Marshal.StringToHGlobalUni(output);
return Marshal.StringToHGlobalUni("Unidentified");
}
[DllExport]
public static IntPtr GetTotalSpace(IntPtr data, int argc, [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 1)] string[] argv)
{
Measure measure = (Measure)data;
if (argc <= 0)
{
return IntPtr.Zero;
}
System.IO.DriveInfo drive;
string output;
try
{
drive = new System.IO.DriveInfo(TrimQuotes(argv[0]));
if (!drive.IsReady)
{
return Marshal.StringToHGlobalUni("0");
}
else
{
output = GetDriveInfo(drive, "totalspace");
}
}
catch
{
return Marshal.StringToHGlobalUni("Unidentified");
}
if (!String.IsNullOrEmpty(output)) return Marshal.StringToHGlobalUni(output);
return Marshal.StringToHGlobalUni("Unidentified");
}
[DllExport]
public static IntPtr GetFreeSpace(IntPtr data, int argc, [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 1)] string[] argv)
{
Measure measure = (Measure)data;
if (argc <= 0)
{
return IntPtr.Zero;
}
System.IO.DriveInfo drive;
string output;
try
{
drive = new System.IO.DriveInfo(TrimQuotes(argv[0]));
if (!drive.IsReady)
{
return Marshal.StringToHGlobalUni("0");
}
else
{
output = GetDriveInfo(drive, "freespace");
}
}
catch
{
return Marshal.StringToHGlobalUni("Unidentified");
}
if (!String.IsNullOrEmpty(output)) return Marshal.StringToHGlobalUni(output);
return Marshal.StringToHGlobalUni("Unidentified");
}
}
}
Example Skin:
Example skin inspired from TitanDrives by CodeCode
Preview:
Redistributables: