Files
mirror-processhacker/2.x/trunk/plugins/ProcessHacker.Api/ProcessHacker/PluginGlobal.cs
T
dmex 2df0834cd8 PH plugin API updated: Performance fixes, mem leak fix, ported PH1.x Heap/Memory classes with fixes
git-svn-id: svn://svn.code.sf.net/p/processhacker/code@4474 21ef857c-d57f-4fe0-8362-d861dc6d29cd
2011-08-19 07:16:50 +00:00

106 lines
3.2 KiB
C#

/*
* Process Hacker -
* Settings API
*
* Copyright (C) 2011 wj32
* Copyright (C) 2011 dmex
*
* This file is part of Process Hacker.
*
* Process Hacker 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 3 of the License, or
* (at your option) any later version.
*
* Process Hacker 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 Process Hacker. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Runtime.InteropServices;
using ProcessHacker.Native;
namespace ProcessHacker.Api
{
public static unsafe class PluginGlobal
{
public struct Setting
{
public PhSettingType Type;
public string Name;
public string DefaultValue;
}
public static void AddSettings(Setting[] settings)
{
PhSettingCreate* create = stackalloc PhSettingCreate[settings.Length];
for (int i = 0; i < settings.Length; i++)
{
create[i].Type = settings[i].Type;
create[i].Name = (void*)NativeApi.StringToNativeUni(settings[i].Name);
create[i].DefaultValue = (void*)NativeApi.StringToNativeUni(settings[i].DefaultValue);
}
NativeApi.PhAddSettings(create, settings.Length);
for (int i = 0; i < settings.Length; i++)
{
MemoryAlloc.PrivateHeap.Free((IntPtr)create[i].Name);
MemoryAlloc.PrivateHeap.Free((IntPtr)create[i].DefaultValue);
}
}
public static int GetIntegerSetting(string name)
{
return NativeApi.PhGetIntegerSetting(name);
}
public static PhIntegerPair GetIntegerPairSetting(string name)
{
return NativeApi.PhGetIntegerPairSetting(name);
}
public static string GetStringSetting(string name)
{
PhString* value = NativeApi.PhGetStringSetting(name);
string newValue = value->Text;
NativeApi.PhDereferenceObject(value);
return newValue;
}
public static void SetIntegerSetting(string name, int value)
{
NativeApi.PhSetIntegerSetting(name, value);
}
public static void SetIntegerPairSetting(string name, PhIntegerPair value)
{
NativeApi.PhSetIntegerPairSetting(name, value);
}
public static void SetStringSetting(string name, string value)
{
PhStringRef sr;
fixed (char* buffer = value)
{
sr.Buffer = buffer;
sr.Length = (ushort)(value.Length * 2);
NativeApi.PhSetStringSetting2(name, &sr);
}
// TODO: evaluate if sr needs to be disposed.
}
}
}