A very basic edit server unit, it doesnt use EOF settings.
even tho it is usable i dont recomend it .
No encyption on settings in server, no error hadeling.
i coded this last night ,,,, learn from it dont use it (unless you dont mind your settings
stings unencrypted in he server)
///////////////////////////////////////////
////////// Edit Server v.1 Alpha //////////
////////////// By Bubzuru /////////////////
///////////////////////////////////////////
using System;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace Bubzuru
{
public class EditServer
{
//////////// DLL IMPORTS FOR API ////////////
//BeginUpdateResource
[DllImport("kernel32", CharSet = CharSet.Unicode)]
private static extern IntPtr BeginUpdateResource(String pFileName, bool bDeleteExistingResources);
//UpdateResource
[DllImport("kernel32", CharSet = CharSet.Unicode, SetLastError = true)]
private static extern int UpdateResource(IntPtr hUpdate, System.Text.StringBuilder lpType, System.Text.StringBuilder lpName, System.Int16 wLanguage, Byte[] lpData, int cbData);
//EndUpdateResource
[DllImport("kernel32", SetLastError = true)]
private static extern int EndUpdateResource(IntPtr hUpdate, bool fDiscard);
//FindResourceW
[DllImport("Kernel32.dll", EntryPoint = "FindResourceW", SetLastError = true, CharSet = CharSet.Unicode)]
private static extern IntPtr FindResource(IntPtr hModule, string pName, string pType);
//SizeofResource
[DllImport("Kernel32.dll", EntryPoint = "SizeofResource", SetLastError = true)]
private static extern uint SizeofResource(IntPtr hModule, IntPtr hResource);
//LoadResource
[DllImport("Kernel32.dll", EntryPoint = "LoadResource", SetLastError = true)]
private static extern IntPtr LoadResource(IntPtr hModule, IntPtr hResource);
//LockResource
[DllImport("Kernel32.dll", EntryPoint = "LockResource")]
private static extern IntPtr LockResource(IntPtr hGlobal);
/////////////////////////////////////////
private const string ID = "{{#}}";
private string _FindSettings()
{
IntPtr resH1 = FindResource(IntPtr.Zero, "SETTINGS.BUBZ", "FILE");
IntPtr resH2 = LoadResource(IntPtr.Zero, resH1);
IntPtr resH3 = LockResource(resH2);
uint resSize = SizeofResource(IntPtr.Zero, resH1);
//copey resorce to byte array in our memory
byte[] y = new byte[resSize];
Marshal.Copy(resH3, y, 0, (int)resSize);
//convert byte array to string
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
string settingtxt = encoding.GetString(y);
return settingtxt;
}
private void _UpdateSettings(string file, string settings)
{
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding(); //encode string so we can turn to byte array
System.Text.StringBuilder resType = new System.Text.StringBuilder("FILE");
System.Text.StringBuilder resName = new System.Text.StringBuilder("settings.bubz".ToUpper());
Byte[] someByteArray = encoding.GetBytes(settings);
IntPtr hResource = BeginUpdateResource(file, false);
UpdateResource(hResource, resType, resName, 1033, someByteArray, someByteArray.Length);
EndUpdateResource(hResource, false);
}
public ArrayList SettingsToAdd = new ArrayList();
public ArrayList LoadedSettings = new ArrayList();
public void LoadSettings()
{
string encsettings = _FindSettings();
string[] stringSeparators = new string[] { ID };
string[] settings = encsettings.Split(stringSeparators, StringSplitOptions.None);
foreach (string s in settings)
{
if (!s.Equals(null))
{
LoadedSettings.Add(s);
}
}
}
public void AddSettings(string file)
{
string final = "";
foreach (string word in SettingsToAdd)
{
if (!word.Equals(null))
{
final += word + ID;
}
}
_UpdateSettings(file, final);
}
}
}