rainmeter-studio/Plugins/API/RainmeterAPI.cs

141 lines
4.4 KiB
C#
Raw Normal View History

2012-01-08 17:35:29 +00:00
/*
Copyright (C) 2011 Birunthan Mohanathas
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2012-01-08 17:35:29 +00:00
*/
using System;
using System.Runtime.InteropServices;
namespace Rainmeter
{
/// <summary>
/// Wrapper around the Rainmeter C API.
/// </summary>
public class API
{
private IntPtr m_Rm;
public API(IntPtr rm)
{
m_Rm = rm;
}
[DllImport("Rainmeter.dll", CharSet = CharSet.Unicode)]
private extern static IntPtr RmReadString(IntPtr rm, string option, string defValue, bool replaceMeasures);
2012-01-08 17:35:29 +00:00
[DllImport("Rainmeter.dll", CharSet = CharSet.Unicode)]
private extern static double RmReadFormula(IntPtr rm, string option, double defValue);
2012-01-08 17:35:29 +00:00
[DllImport("Rainmeter.dll", CharSet = CharSet.Unicode)]
private extern static IntPtr RmReplaceVariables(IntPtr rm, string str);
2012-01-08 17:35:29 +00:00
[DllImport("Rainmeter.dll", CharSet = CharSet.Unicode)]
private extern static IntPtr RmPathToAbsolute(IntPtr rm, string relativePath);
[DllImport("Rainmeter.dll", EntryPoint = "RmExecute", CharSet = CharSet.Unicode)]
public extern static void Execute(IntPtr skin, string command);
2012-01-08 17:35:29 +00:00
[DllImport("Rainmeter.dll")]
private extern static IntPtr RmGet(IntPtr rm, RmGetType type);
2012-01-08 17:35:29 +00:00
[DllImport("Rainmeter.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
private extern static int LSLog(LogType type, string unused, string message);
2012-01-08 17:35:29 +00:00
private enum RmGetType
{
MeasureName = 0,
Skin = 1,
SettingsFile = 2,
SkinName = 3,
SkinWindowHandle = 4
}
2012-01-08 17:35:29 +00:00
public enum LogType
{
Error = 1,
Warning = 2,
Notice = 3,
Debug = 4
}
public string ReadString(string option, string defValue, bool replaceMeasures = true)
2012-01-08 17:35:29 +00:00
{
return Marshal.PtrToStringUni(RmReadString(m_Rm, option, defValue, replaceMeasures));
2012-01-08 17:35:29 +00:00
}
public string ReadPath(string option, string defValue)
2012-01-08 17:35:29 +00:00
{
return Marshal.PtrToStringUni(RmPathToAbsolute(m_Rm, ReadString(option, defValue)));
2012-01-08 17:35:29 +00:00
}
public double ReadDouble(string option, double defValue)
2012-01-08 17:35:29 +00:00
{
return RmReadFormula(m_Rm, option, defValue);
2012-01-08 17:35:29 +00:00
}
public int ReadInt(string option, int defValue)
{
return (int)RmReadFormula(m_Rm, option, defValue);
}
public string ReplaceVariables(string str)
2012-01-08 17:35:29 +00:00
{
return Marshal.PtrToStringUni(RmReplaceVariables(m_Rm, str));
2012-01-08 17:35:29 +00:00
}
public string GetMeasureName()
2012-01-08 17:35:29 +00:00
{
return Marshal.PtrToStringUni(RmGet(m_Rm, RmGetType.MeasureName));
2012-01-08 17:35:29 +00:00
}
public IntPtr GetSkin()
{
return RmGet(m_Rm, RmGetType.Skin);
}
public string GetSettingsFile()
{
return Marshal.PtrToStringUni(RmGet(m_Rm, RmGetType.SettingsFile));
}
public string GetSkinName()
{
return Marshal.PtrToStringUni(RmGet(m_Rm, RmGetType.SkinName));
}
public IntPtr GetSkinWindow()
2012-01-08 17:35:29 +00:00
{
return RmGet(m_Rm, RmGetType.SkinWindowHandle);
2012-01-08 17:35:29 +00:00
}
public static void Log(LogType type, string message)
2012-01-08 17:35:29 +00:00
{
LSLog(type, null, message);
2012-01-08 17:35:29 +00:00
}
}
/// <summary>
/// Dummy attribute to mark method as exported for DllExporter.exe.
/// </summary>
[AttributeUsage(AttributeTargets.Method)]
public class DllExport : Attribute
{
public DllExport()
{
}
}
}