mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
InputText.dll: Updated to new API
This commit is contained in:
@ -1,173 +1,148 @@
|
||||
using System;
|
||||
/*
|
||||
Copyright (C) 2013 Rainmeter Team
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using Rainmeter;
|
||||
|
||||
namespace InputText
|
||||
{
|
||||
public class Main
|
||||
internal partial class Measure
|
||||
{
|
||||
/// <summary>
|
||||
/// Your name (author) and the version of the plugin go here. The code will
|
||||
/// automatically format the values and send them back when a call to GetAuthor()
|
||||
/// or GetVersion() is made.
|
||||
///
|
||||
/// Optionally, you may also provide an e-mail address and additional comments
|
||||
/// </summary>
|
||||
private static Rainmeter.Settings Plugin = new Rainmeter.Settings
|
||||
(
|
||||
// Author name
|
||||
"Peter Souza IV",
|
||||
private Rainmeter.API rm;
|
||||
|
||||
// Version
|
||||
1.06,
|
||||
private string LastInput = string.Empty;
|
||||
private bool IsExecuteBangRunning = false;
|
||||
|
||||
// E-mail
|
||||
"psouza4@gmail.com",
|
||||
private object locker = new object();
|
||||
|
||||
// Comments (try to keep it under 50 characters)
|
||||
"Please visit the forums for support."
|
||||
);
|
||||
|
||||
#region GetAuthor() and GetVersion() exports -- no need to modify
|
||||
|
||||
[DllExport]
|
||||
public static UInt32 GetPluginVersion()
|
||||
internal Measure(Rainmeter.API rm)
|
||||
{
|
||||
return Rainmeter.Version(Plugin.Version);
|
||||
this.rm = rm;
|
||||
}
|
||||
|
||||
[DllExport]
|
||||
public unsafe static char* GetPluginAuthor()
|
||||
internal void Reload(Rainmeter.API rm, ref double maxValue)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(Plugin.Email) && !string.IsNullOrEmpty(Plugin.Comments))
|
||||
return Rainmeter.String(Plugin.Author + " (" + Plugin.Email + "): " + Plugin.Comments);
|
||||
if (!string.IsNullOrEmpty(Plugin.Email))
|
||||
return Rainmeter.String(Plugin.Author + " (" + Plugin.Email + ")");
|
||||
if (!string.IsNullOrEmpty(Plugin.Comments))
|
||||
return Rainmeter.String(Plugin.Author + ": " + Plugin.Comments);
|
||||
return Rainmeter.String(Plugin.Author);
|
||||
// Do nothing here.
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Initialize() and Finalize() -- you may add to these functions if necessary
|
||||
|
||||
[DllExport]
|
||||
public unsafe static UInt32 Initialize(IntPtr instance, char* iniFile, char* section, UInt32 id)
|
||||
internal double Update()
|
||||
{
|
||||
Plugin.AddInstance(iniFile, section, id); // required: do not remove
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// You may add code here, if necessary
|
||||
//
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
return 0;
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
[DllExport]
|
||||
public static void Finalize(IntPtr instance, UInt32 id)
|
||||
internal string GetString()
|
||||
{
|
||||
Plugin.RemoveInstance(id); // required: do not remove
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// You may add code here, if necessary
|
||||
//
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
return;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Update(), Update2(), and GetString() exports -- please read notes
|
||||
|
||||
// *** WARNING / NOTES ***
|
||||
//
|
||||
// Do not add to this code: change your code in PluginCode.cs instead
|
||||
//
|
||||
// However, due to the way Rainmeter works, you will probably want to
|
||||
// comment-out either 'Update' or 'Update2' if your plugin will be returning
|
||||
// numeric values.
|
||||
//
|
||||
// Rainmeter will look for 'Update' for positive integers. If you want to
|
||||
// allow negative numbers or floating-point numbers, use 'Update2' instead.
|
||||
//
|
||||
// You *MUST* comment-out whichever function you don't want to use for this
|
||||
// to work.
|
||||
//
|
||||
// If you don't care, such as a plugin that either doesn't return data or
|
||||
// only returns string/text data, then you can leave them both here (it won't
|
||||
// hurt anything).
|
||||
//
|
||||
// *** WARNING / NOTES ***
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Rainmeter's request for numeric data from the plugin. This version can only
|
||||
/// return positive integers ranging from 0 to 4,294,967,296. Comment this member
|
||||
/// out and use 'Update2' if you want to return negative or floating-point values.
|
||||
/// </summary>
|
||||
/// <param name="id">The unique instance ID of this request.</param>
|
||||
/// <returns>Current value for this meter.</returns>
|
||||
[DllExport]
|
||||
public static UInt32 Update(UInt32 id)
|
||||
{
|
||||
// Do not modify this member (although you can comment it out). Instead, update
|
||||
// your code in 'PluginCode.cs'.
|
||||
return new YourPlugin().Update(Plugin, id);
|
||||
lock (this.locker)
|
||||
{
|
||||
return this.LastInput;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Rainmeter's request for numeric data from the plugin. This version can return
|
||||
/// positive or negative floating-point numbers (32-bit precision). Comment this
|
||||
/// member out and use 'Update' if you want to only return positive integers.
|
||||
/// </summary>
|
||||
/// <param name="id">The unique instance ID of this request.</param>
|
||||
/// <returns>Current value for this meter.</returns>
|
||||
//[DllExport]
|
||||
//public static double Update2(UInt32 id)
|
||||
//{
|
||||
// // Do not modify this member (although you can comment it out). Instead, update
|
||||
// // your code in 'PluginCode.cs'.
|
||||
// return new YourPlugin().Update2(Plugin, id);
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// Rainmeter's request for text data from the plugin.
|
||||
/// </summary>
|
||||
/// <param name="id">The unique instance ID of this request.</param>
|
||||
/// <param name="flags">Unused still as of Dec 2nd, 2010.</param>
|
||||
/// <returns></returns>
|
||||
[DllExport]
|
||||
public unsafe static char* GetString(UInt32 id, UInt32 flags)
|
||||
internal void ExecuteBang(string args)
|
||||
{
|
||||
// Do not modify this member. Instead, update your code in 'PluginCode.cs'.
|
||||
return Rainmeter.String(new YourPlugin().GetString(Plugin, id));
|
||||
bool go = false;
|
||||
|
||||
lock (this.locker)
|
||||
{
|
||||
if (!this.IsExecuteBangRunning)
|
||||
{
|
||||
this.IsExecuteBangRunning = true;
|
||||
go = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (go)
|
||||
{
|
||||
ThreadPool.QueueUserWorkItem(ExecuteBangThread, args);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ExecuteBang() export -- no need to modify (change code in PluginCode.cs)
|
||||
|
||||
[DllExport]
|
||||
public static unsafe void ExecuteBang(char* args, UInt32 id)
|
||||
private void ExecuteBangThread(object state)
|
||||
{
|
||||
new YourPlugin().ExecuteBang(Plugin, id, new string(args));
|
||||
return;
|
||||
}
|
||||
string command = (string)state;
|
||||
|
||||
#endregion
|
||||
try
|
||||
{
|
||||
ExecuteCommands(command);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
API.Log(API.LogType.Error, "C# plugin in ExecuteBang(), " + ex.GetType().ToString() + ": " + ex.Message);
|
||||
}
|
||||
|
||||
lock (this.locker)
|
||||
{
|
||||
this.IsExecuteBangRunning = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dummy attribute to mark method as exported for DllExporter.exe.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Method)]
|
||||
public class DllExport : Attribute
|
||||
#region Plugin
|
||||
|
||||
public static class Plugin
|
||||
{
|
||||
public DllExport()
|
||||
internal static Dictionary<uint, Measure> Measures = new Dictionary<uint, Measure>();
|
||||
|
||||
[DllExport]
|
||||
public unsafe static void Initialize(void** data, void* rm)
|
||||
{
|
||||
uint id = (uint)((void*)*data);
|
||||
Measures.Add(id, new Measure(new Rainmeter.API((IntPtr)rm)));
|
||||
}
|
||||
|
||||
[DllExport]
|
||||
public unsafe static void Finalize(void* data)
|
||||
{
|
||||
uint id = (uint)data;
|
||||
Measures.Remove(id);
|
||||
}
|
||||
|
||||
[DllExport]
|
||||
public unsafe static void Reload(void* data, void* rm, double* maxValue)
|
||||
{
|
||||
uint id = (uint)data;
|
||||
Measures[id].Reload(new Rainmeter.API((IntPtr)rm), ref *maxValue);
|
||||
}
|
||||
|
||||
[DllExport]
|
||||
public unsafe static double Update(void* data)
|
||||
{
|
||||
uint id = (uint)data;
|
||||
return Measures[id].Update();
|
||||
}
|
||||
|
||||
[DllExport]
|
||||
public unsafe static char* GetString(void* data)
|
||||
{
|
||||
uint id = (uint)data;
|
||||
fixed (char* s = Measures[id].GetString()) return s;
|
||||
}
|
||||
|
||||
[DllExport]
|
||||
public unsafe static void ExecuteBang(void* data, char* args)
|
||||
{
|
||||
uint id = (uint)data;
|
||||
Measures[id].ExecuteBang(new string(args));
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
Reference in New Issue
Block a user