mirror of
https://github.com/BluePointLilac/ContextMenuManager.git
synced 2026-01-14 06:04:00 +08:00
添加快速单次读取ini键值方法
This commit is contained in:
@@ -50,7 +50,6 @@ namespace ContextMenuManager
|
||||
"https://www.so.com/s?q=%s", //360搜索
|
||||
};
|
||||
|
||||
private static IniReader ConfigReader => new IniReader(ConfigIni);
|
||||
private static IniWriter ConfigWriter => new IniWriter(ConfigIni);
|
||||
|
||||
public static DateTime LastCheckUpdateTime
|
||||
@@ -59,7 +58,7 @@ namespace ContextMenuManager
|
||||
{
|
||||
try
|
||||
{
|
||||
string time = ConfigReader.GetValue("General", "LastCheckUpdateTime");
|
||||
string time = ConfigWriter.GetValue("General", "LastCheckUpdateTime");
|
||||
//二进制数据时间不会受系统时间格式影响
|
||||
return DateTime.FromBinary(Convert.ToInt64(time));
|
||||
}
|
||||
@@ -79,7 +78,7 @@ namespace ContextMenuManager
|
||||
{
|
||||
get
|
||||
{
|
||||
string language = ConfigReader.GetValue("General", "Language");
|
||||
string language = ConfigWriter.GetValue("General", "Language");
|
||||
DirectoryInfo di = new DirectoryInfo(LangsDir);
|
||||
if(language == string.Empty && di.Exists)
|
||||
{
|
||||
@@ -105,13 +104,13 @@ namespace ContextMenuManager
|
||||
|
||||
public static bool AutoBackup
|
||||
{
|
||||
get => ConfigReader.GetValue("General", "AutoBackup") != "0";
|
||||
get => ConfigWriter.GetValue("General", "AutoBackup") != "0";
|
||||
set => ConfigWriter.SetValue("General", "AutoBackup", (value ? 1 : 0).ToString());
|
||||
}
|
||||
|
||||
public static bool ProtectOpenItem
|
||||
{
|
||||
get => ConfigReader.GetValue("General", "ProtectOpenItem") != "0";
|
||||
get => ConfigWriter.GetValue("General", "ProtectOpenItem") != "0";
|
||||
set => ConfigWriter.SetValue("General", "ProtectOpenItem", (value ? 1 : 0).ToString());
|
||||
}
|
||||
|
||||
@@ -119,7 +118,7 @@ namespace ContextMenuManager
|
||||
{
|
||||
get
|
||||
{
|
||||
string url = ConfigReader.GetValue("General", "EngineUrl");
|
||||
string url = ConfigWriter.GetValue("General", "EngineUrl");
|
||||
if(url.IsNullOrWhiteSpace()) url = EngineUrls[0];
|
||||
return url;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,8 @@ namespace BulePointLilac.Methods
|
||||
return lines;
|
||||
}
|
||||
|
||||
public void SetValue(string section, string key, string value)
|
||||
/// <param name="isGetValue">是否是获取value值</param>
|
||||
private void SetValue(string section, string key, ref string value, bool isGetValue)
|
||||
{
|
||||
if(section == null) return;
|
||||
List<string> lines = GetLines();
|
||||
@@ -67,6 +68,11 @@ namespace BulePointLilac.Methods
|
||||
string str = lines[i].Substring(0, index).TrimEnd();
|
||||
if(str.Equals(key, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
if(isGetValue)//如果是获取Value值,直接返回
|
||||
{
|
||||
value = lines[i].Substring(index + 1).Trim();
|
||||
return;
|
||||
}
|
||||
keyRow = i; continue;//得到目标key行
|
||||
}
|
||||
}
|
||||
@@ -137,6 +143,19 @@ namespace BulePointLilac.Methods
|
||||
}
|
||||
}
|
||||
|
||||
public void SetValue(string section, string key, string value)
|
||||
{
|
||||
SetValue(section, key, ref value, false);
|
||||
}
|
||||
|
||||
/// <summary>一次读取只获取一个值,用此方法比IniReader.GetValue要快</summary>
|
||||
public string GetValue(string section, string key)
|
||||
{
|
||||
string value = string.Empty;
|
||||
SetValue(section, key, ref value, true);
|
||||
return value;
|
||||
}
|
||||
|
||||
public void DeleteKey(string section, string key)
|
||||
{
|
||||
SetValue(section, key, null);
|
||||
|
||||
Reference in New Issue
Block a user