mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-10-22 08:40:57 +00:00
Update the files related to settings.ini
This commit is contained in:
parent
d04e03200b
commit
f44f0b38b2
|
@ -31,7 +31,7 @@ using System.Runtime.InteropServices;
|
||||||
using MSScriptControl;
|
using MSScriptControl;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using WelsonJS.Service.TinyINIController;
|
||||||
|
|
||||||
namespace WelsonJS.Service
|
namespace WelsonJS.Service
|
||||||
{
|
{
|
||||||
|
@ -50,16 +50,11 @@ namespace WelsonJS.Service
|
||||||
private bool disabledFileMonitor = false;
|
private bool disabledFileMonitor = false;
|
||||||
private ScreenMatching screenMatcher;
|
private ScreenMatching screenMatcher;
|
||||||
private FileEventMonitor fileEventMonitor;
|
private FileEventMonitor fileEventMonitor;
|
||||||
|
private IniFile settingsController;
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll")]
|
||||||
private static extern int GetSystemMetrics(int nIndex);
|
private static extern int GetSystemMetrics(int nIndex);
|
||||||
|
|
||||||
[DllImport("kernel32.dll")]
|
|
||||||
private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
|
|
||||||
|
|
||||||
[DllImport("kernel32.dll")]
|
|
||||||
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
|
|
||||||
|
|
||||||
private static int SM_REMOTESESSION = 0x1000;
|
private static int SM_REMOTESESSION = 0x1000;
|
||||||
|
|
||||||
public ServiceMain(string[] args)
|
public ServiceMain(string[] args)
|
||||||
|
@ -110,6 +105,20 @@ namespace WelsonJS.Service
|
||||||
}
|
}
|
||||||
Directory.SetCurrentDirectory(workingDirectory);
|
Directory.SetCurrentDirectory(workingDirectory);
|
||||||
|
|
||||||
|
// read settings.ini
|
||||||
|
string settingsFilePath = Path.Combine(workingDirectory, "settings.ini");
|
||||||
|
if (File.Exists(settingsFilePath))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
settingsController = new IniFile(settingsFilePath);
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
settingsController = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// set script name
|
// set script name
|
||||||
if (string.IsNullOrEmpty(scriptName))
|
if (string.IsNullOrEmpty(scriptName))
|
||||||
{
|
{
|
||||||
|
|
|
@ -0,0 +1,72 @@
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
// https://github.com/niklyadov/tiny-ini-file-class
|
||||||
|
namespace WelsonJS.Service.TinyINIController
|
||||||
|
{
|
||||||
|
class IniFile
|
||||||
|
{
|
||||||
|
[DllImport("kernel32", CharSet = CharSet.Unicode)]
|
||||||
|
static extern long WritePrivateProfileString(string section, string key, string value, string FilePath);
|
||||||
|
|
||||||
|
[DllImport("kernel32", CharSet = CharSet.Unicode)]
|
||||||
|
static extern int GetPrivateProfileString(string section, string key, string Default, StringBuilder RetVal, int Size, string FilePath);
|
||||||
|
|
||||||
|
private readonly FileInfo FileInfo;
|
||||||
|
|
||||||
|
private readonly string exe = Assembly.GetExecutingAssembly().GetName().Name;
|
||||||
|
|
||||||
|
private readonly FileAccess fileAccess;
|
||||||
|
|
||||||
|
public IniFile(string path = null, FileAccess access = FileAccess.ReadWrite)
|
||||||
|
{
|
||||||
|
fileAccess = access;
|
||||||
|
FileInfo = new FileInfo(path ?? exe);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Read(string key, string section = null)
|
||||||
|
{
|
||||||
|
var RetVal = new StringBuilder(65025);
|
||||||
|
|
||||||
|
if (fileAccess != FileAccess.Write)
|
||||||
|
{
|
||||||
|
GetPrivateProfileString(section ?? exe, key, "", RetVal, 65025, FileInfo.FullName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception("Can`t read file! No access!");
|
||||||
|
}
|
||||||
|
|
||||||
|
return RetVal.ToString();
|
||||||
|
}
|
||||||
|
public void Write(string key, string value, string section = null)
|
||||||
|
{
|
||||||
|
if (fileAccess != FileAccess.Read)
|
||||||
|
{
|
||||||
|
WritePrivateProfileString(section ?? exe, key, value, FileInfo.FullName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception("Can`t write to file! No access!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DeleteKey(string key, string section = null)
|
||||||
|
{
|
||||||
|
Write(key, null, section ?? exe);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DeleteSection(string section = null)
|
||||||
|
{
|
||||||
|
Write(null, null, section ?? exe);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool KeyExists(string key, string section = null)
|
||||||
|
{
|
||||||
|
return Read(key, section).Length > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -144,6 +144,7 @@
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="ScreenMatching.cs" />
|
<Compile Include="ScreenMatching.cs" />
|
||||||
<Compile Include="ScreenMatchResult.cs" />
|
<Compile Include="ScreenMatchResult.cs" />
|
||||||
|
<Compile Include="TinyINIController\IniFile.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<COMReference Include="MSScriptControl">
|
<COMReference Include="MSScriptControl">
|
||||||
|
|
Loading…
Reference in New Issue
Block a user