56 lines
1.9 KiB
C#
56 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Click_to_Call_Tray
|
|
{
|
|
internal static class IniConfig
|
|
{
|
|
// Hotkey settings
|
|
private const string IniSection = "Settings";
|
|
private const string IniKey = "Hotkey";
|
|
private const string DefaultHotkey = "F11"; // Default key name
|
|
|
|
// Full path to the INI file, placed next to the executable
|
|
private static readonly string IniFilePath = Path.Combine(
|
|
Path.GetDirectoryName(Application.ExecutablePath), "Click-to-Call-Tray.ini");
|
|
|
|
// P/Invoke for INI file reading
|
|
[DllImport("kernel32", CharSet = CharSet.Unicode)]
|
|
private static extern int GetPrivateProfileString(
|
|
string lpAppName,
|
|
string lpKeyName,
|
|
string lpDefault,
|
|
StringBuilder lpReturnedString,
|
|
int nSize,
|
|
string lpFileName);
|
|
|
|
// P/Invoke for INI file writing
|
|
[DllImport("kernel32", CharSet = CharSet.Unicode, SetLastError = true)]
|
|
[return: MarshalAs(UnmanagedType.Bool)]
|
|
private static extern bool WritePrivateProfileString(
|
|
string lpAppName,
|
|
string lpKeyName,
|
|
string lpString,
|
|
string lpFileName);
|
|
|
|
// Reads the current hotkey from the INI file
|
|
public static string ReadHotkey()
|
|
{
|
|
var temp = new StringBuilder(255);
|
|
GetPrivateProfileString(IniSection, IniKey, DefaultHotkey, temp, temp.Capacity, IniFilePath);
|
|
return temp.ToString().Trim().ToUpper();
|
|
}
|
|
|
|
// Writes the new hotkey to the INI file
|
|
public static void WriteHotkey(string hotkeyName)
|
|
{
|
|
WritePrivateProfileString(IniSection, IniKey, hotkeyName, IniFilePath);
|
|
}
|
|
}
|
|
|
|
}
|