Skip to content

Commit

Permalink
修复bug, 优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
BluePointLilac committed Mar 10, 2021
1 parent 958d2a0 commit 480b5d6
Show file tree
Hide file tree
Showing 31 changed files with 404 additions and 307 deletions.
4 changes: 2 additions & 2 deletions ContextMenuManager/App.config
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>

<supportedRuntime version="v2.0.50727"/></startup>
<supportedRuntime version="v2.0.50727"/>
</startup>
<runtime>
<legacyCorruptedStateExceptionsPolicy enabled="true"/>
<EnableWindowsFormsHighDpiAutoResizing enabled="true"/>
Expand Down
41 changes: 21 additions & 20 deletions ContextMenuManager/AppConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,15 @@ static AppConfig()
};

private static readonly IniWriter ConfigWriter = new IniWriter(ConfigIni);
private static string GetGeneralValue(string key) => ConfigWriter.GetValue("General", key);
private static void SetGeneralValue(string key, object value) => ConfigWriter.SetValue("General", key, value);

public static string LanguageIniPath => $@"{LangsDir}\{Language}.ini";

public static string Language
{
get
{
string language = ConfigWriter.GetValue("General", "Language");
string language = GetGeneralValue("Language");
if(language == string.Empty)
{
language = new CultureInfo(GetUserDefaultUILanguage()).Name;
Expand All @@ -75,13 +76,13 @@ public static string Language
}
return language;
}
set => ConfigWriter.SetValue("General", "Language", value);
set => SetGeneralValue("Language", value);
}

public static bool AutoBackup
{
get => ConfigWriter.GetValue("General", "AutoBackup") != "0";
set => ConfigWriter.SetValue("General", "AutoBackup", value ? 1 : 0);
get => GetGeneralValue("AutoBackup") != "0";
set => SetGeneralValue("AutoBackup", value ? 1 : 0);
}

public static DateTime LastCheckUpdateTime
Expand All @@ -90,7 +91,7 @@ public static DateTime LastCheckUpdateTime
{
try
{
string time = ConfigWriter.GetValue("General", "LastCheckUpdateTime");
string time = GetGeneralValue("LastCheckUpdateTime");
//二进制数据时间不会受系统时间格式影响
return DateTime.FromBinary(Convert.ToInt64(time));
}
Expand All @@ -102,60 +103,60 @@ public static DateTime LastCheckUpdateTime
}
set
{
ConfigWriter.SetValue("General", "LastCheckUpdateTime", value.ToBinary());
SetGeneralValue("LastCheckUpdateTime", value.ToBinary());
}
}

public static bool ProtectOpenItem
{
get => ConfigWriter.GetValue("General", "ProtectOpenItem") != "0";
set => ConfigWriter.SetValue("General", "ProtectOpenItem", value ? 1 : 0);
get => GetGeneralValue("ProtectOpenItem") != "0";
set => SetGeneralValue("ProtectOpenItem", value ? 1 : 0);
}

public static string EngineUrl
{
get
{
string url = ConfigWriter.GetValue("General", "EngineUrl");
string url = GetGeneralValue("EngineUrl");
if(url.IsNullOrWhiteSpace()) url = EngineUrls[0];
return url;
}
set
{
ConfigWriter.SetValue("General", "EngineUrl", value);
SetGeneralValue("EngineUrl", value);
}
}

public static bool ShowFilePath
{
get => ConfigWriter.GetValue("General", "ShowFilePath") == "1";
set => ConfigWriter.SetValue("General", "ShowFilePath", value ? 1 : 0);
get => GetGeneralValue("ShowFilePath") == "1";
set => SetGeneralValue("ShowFilePath", value ? 1 : 0);
}

public static bool WinXSortable
{
get => ConfigWriter.GetValue("General", "WinXSortable") == "1";
set => ConfigWriter.SetValue("General", "WinXSortable", value ? 1 : 0);
get => GetGeneralValue("WinXSortable") == "1";
set => SetGeneralValue("WinXSortable", value ? 1 : 0);
}

public static bool OpenMoreRegedit
{
get => ConfigWriter.GetValue("General", "OpenMoreRegedit") == "1";
set => ConfigWriter.SetValue("General", "OpenMoreRegedit", value ? 1 : 0);
get => GetGeneralValue("OpenMoreRegedit") == "1";
set => SetGeneralValue("OpenMoreRegedit", value ? 1 : 0);
}

public static Version Version
{
get
{
Version version = new Version();
try { version = new Version(ConfigWriter.GetValue("General", "Version")); }
Version version = new Version(0, 0, 0, 0);
try { version = new Version(GetGeneralValue("Version")); }
catch { }
return version;
}
set
{
ConfigWriter.SetValue("General", "Version", value);
SetGeneralValue("Version", value);
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions ContextMenuManager/AppImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public static class AppImage
public static readonly Image AddSeparator = Resources.AddSeparator.ResizeImage(Scale);
///<summary>打开图标</summary>
public static readonly Image Open = Resources.Open.ResizeImage(Scale);
///<summary>下载图标</summary>
public static readonly Image DownLoad = Resources.DownLoad.ResizeImage(Scale);
///<summary>翻译图标</summary>
public static readonly Image Translate = Resources.Translate.ResizeImage(Scale);
///<summary>上图标</summary>
public static readonly Image Up = Resources.Up.ResizeImage(Scale);
///<summary>下图标</summary>
Expand Down
72 changes: 34 additions & 38 deletions ContextMenuManager/AppString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace ContextMenuManager
public static class AppString
{
public static readonly IniReader UserLanguage = new IniReader(AppConfig.LanguageIniPath);
private static readonly IniReader DefaultLanguage = new IniReader(new StringBuilder(Properties.Resources.AppLanguageDic));
public static readonly IniReader DefaultLanguage = new IniReader(new StringBuilder(Properties.Resources.AppLanguageDic));

private static string GetStringValue(string section, string key)
{
Expand Down Expand Up @@ -61,6 +61,7 @@ public static class SideBar
public static string DirectoryType => GetValue("DirectoryType");
public static string EnhanceMenu => GetValue("EnhanceMenu");
public static string ThirdRules => GetValue("ThirdRules");
public static string OtherAccounts => GetValue("OtherAccounts");
public static string GuidBlocked => GetValue("GuidBlocked");
public static string DragDrop => GetValue("DragDrop");
public static string PublicReferences => GetValue("PublicReferences");
Expand Down Expand Up @@ -99,6 +100,7 @@ public static class StatusBar
public static string DirectoryType => GetValue("DirectoryType");
public static string EnhanceMenu => GetValue("EnhanceMenu");
public static string ThirdRules => GetValue("ThirdRules");
public static string OtherAccounts => GetValue("OtherAccounts");
public static string GuidBlocked => GetValue("GuidBlocked");
public static string DragDrop => GetValue("DragDrop");
public static string PublicReferences => GetValue("PublicReferences");
Expand Down Expand Up @@ -147,42 +149,6 @@ public static class Menu
public static string Save => GetValue("Save");
}

/// <summary>特殊项目文本</summary>
public static class Item
{
private static string GetValue(string key) => GetStringValue("Item", key);
public static string Open => GetValue("Open");
public static string Edit => GetValue("Edit");
public static string Explore => GetValue("Explore");
public static string ExploreOld => GetValue("ExploreOld");
public static string Play => GetValue("Play");
public static string Print => GetValue("Print");
public static string Find => GetValue("Find");
public static string Runas => GetValue("Runas");
public static string CustomFolder => GetValue("CustomFolder");
public static string MapNetworkDrive => GetValue("MapNetworkDrive");
public static string DisconnectNetworkDrive => GetValue("DisconnectNetworkDrive");
public static string RecycleBinProperties => GetValue("RecycleBinProperties");
public static string RemovableDrive => GetValue("RemovableDrive");
public static string BuildSendtoMenu => GetValue("BuildSendtoMenu");
public static string UseStoreOpenWith => GetValue("UseStoreOpenWith");
public static string NewItem => GetValue("NewItem");
public static string AddGuidBlockedItem => GetValue("AddGuidBlockedItem");
public static string SelectExtension => GetValue("SelectExtension");
public static string SelectPerceivedType => GetValue("SelectPerceivedType");
public static string SelectDirectoryType => GetValue("SelectDirectoryType");
public static string CurrentExtension => GetValue("CurrentExtension");
public static string CurrentPerceivedType => GetValue("CurrentPerceivedType");
public static string CurrentDirectoryType => GetValue("CurrentDirectoryType");
public static string EditSubItems => GetValue("EditSubItems");
public static string InvalidItem => GetValue("InvalidItem");
public static string Separator => GetValue("Separator");
public static string LockNewMenu => GetValue("LockNewMenu");
public static string WinXSortable => GetValue("WinXSortable");
public static string ShowFilePath => GetValue("ShowFilePath");
public static string OpenMoreRegedit => GetValue("OpenMoreRegedit");
}

public static class Dialog
{
private static string GetValue(string key) => GetStringValue("Dialog", key);
Expand Down Expand Up @@ -215,6 +181,9 @@ public static class Dialog
public static string AudioDirectory => GetValue("AudioDirectory");
public static string CheckReference => GetValue("CheckReference");
public static string CheckCopy => GetValue("CheckCopy");
public static string SelectExtension => GetValue("SelectExtension");
public static string SelectPerceivedType => GetValue("SelectPerceivedType");
public static string SelectDirectoryType => GetValue("SelectDirectoryType");
public static string SelectSubMenuMode => GetValue("SelectSubMenuMode");
public static string SelectNewItemType => GetValue("SelectNewItemType");
public static string RegistryFile => GetValue("RegistryFile");
Expand Down Expand Up @@ -260,11 +229,34 @@ public static class MessageBox
public static class Other
{
private static string GetValue(string key) => GetStringValue("Other", key);
public static string Open => GetValue("Open");
public static string Edit => GetValue("Edit");
public static string Explore => GetValue("Explore");
public static string ExploreOld => GetValue("ExploreOld");
public static string Play => GetValue("Play");
public static string Print => GetValue("Print");
public static string Find => GetValue("Find");
public static string Runas => GetValue("Runas");
public static string CustomFolder => GetValue("CustomFolder");
public static string MapNetworkDrive => GetValue("MapNetworkDrive");
public static string DisconnectNetworkDrive => GetValue("DisconnectNetworkDrive");
public static string RecycleBinProperties => GetValue("RecycleBinProperties");
public static string RemovableDrive => GetValue("RemovableDrive");
public static string BuildSendtoMenu => GetValue("BuildSendtoMenu");
public static string UseStoreOpenWith => GetValue("UseStoreOpenWith");
public static string NewItem => GetValue("NewItem");
public static string AddGuidBlockedItem => GetValue("AddGuidBlockedItem");
public static string CurrentExtension => GetValue("CurrentExtension");
public static string CurrentPerceivedType => GetValue("CurrentPerceivedType");
public static string CurrentDirectoryType => GetValue("CurrentDirectoryType");
public static string EditSubItems => GetValue("EditSubItems");
public static string InvalidItem => GetValue("InvalidItem");
public static string Separator => GetValue("Separator");
public static string LockNewMenu => GetValue("LockNewMenu");
public static string RestartExplorer => GetValue("RestartExplorer");
public static string DictionaryDescription => GetValue("DictionaryDescription");
public static string GuidInfosDictionary => GetValue("GuidInfosDictionary");
public static string Translators => GetValue("Translators");
public static string OtherLanguages => GetValue("OtherLanguages");
public static string AboutApp => GetValue("AboutApp");
public static string Dictionaries => GetValue("Dictionaries");
public static string Donate => GetValue("Donate");
Expand All @@ -281,6 +273,9 @@ public static class Other
public static string WebSearchEngine => GetValue("WebSearchEngine");
public static string CustomEngine => GetValue("CustomEngine");
public static string SetCustomEngine => GetValue("SetCustomEngine");
public static string WinXSortable => GetValue("WinXSortable");
public static string ShowFilePath => GetValue("ShowFilePath");
public static string OpenMoreRegedit => GetValue("OpenMoreRegedit");
}

/// <summary>提示文本</summary>
Expand All @@ -301,6 +296,7 @@ public static class Tip
public static string CheckUpdate => GetValue("CheckUpdate");
public static string LastCheckUpdateTime => GetValue("LastCheckUpdateTime");
public static string OpenLanguagesDir => GetValue("OpenLanguagesDir");
public static string OtherLanguages => GetValue("OtherLanguages");
public static string OpenDictionariesDir => GetValue("OpenDictionariesDir");
public static string ConfigPath => GetValue("ConfigPath");
public static string CommandFiles => GetValue("CommandFiles");
Expand Down
2 changes: 2 additions & 0 deletions ContextMenuManager/BluePointLilac.Methods/HighDpi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public static class HighDpi

public static RectangleF DpiZoom(this RectangleF r) => new RectangleF(DpiZoom(r.Location), DpiZoom(r.Size));

public static Padding DpiZoom(this Padding p) => new Padding(DpiZoom(p.Left), DpiZoom(p.Top), DpiZoom(p.Right), DpiZoom(p.Bottom));

public static int DpiZoom(this int num) => (int)(num * DpiScale);

public static float DpiZoom(this float num) => (float)(num * DpiScale);
Expand Down
4 changes: 3 additions & 1 deletion ContextMenuManager/BluePointLilac.Methods/SingleInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ public static bool IsRunning()
}
}

public static void Restart()
public static void Restart(bool isElevated = false, string[] args = null)
{
using(Process process = new Process())
{
process.StartInfo.FileName = Application.ExecutablePath;
process.StartInfo.Arguments = "Restart";
if(args != null) process.StartInfo.Arguments += string.Join(" ", args);
if(isElevated) process.StartInfo.Verb = "Runas";
process.Start();
}
Application.Exit();
Expand Down
13 changes: 12 additions & 1 deletion ContextMenuManager/ContextMenuManager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>true</Optimize>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
Expand Down Expand Up @@ -93,6 +93,9 @@
<PropertyGroup />
<PropertyGroup />
<PropertyGroup />
<PropertyGroup />
<PropertyGroup />
<PropertyGroup />
<PropertyGroup>
<ApplicationManifest>Properties\App.manifest</ApplicationManifest>
</PropertyGroup>
Expand Down Expand Up @@ -138,6 +141,9 @@
<Compile Include="Controls\AddGuidDicDialog.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Controls\FileExtensionDialog.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Controls\EnhanceMenusItem.cs">
<SubType>Component</SubType>
</Compile>
Expand Down Expand Up @@ -267,6 +273,9 @@
<Compile Include="Controls\ThirdRulesList.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Controls\TranslateDialog.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Controls\UwpModeItem.cs">
<SubType>Component</SubType>
</Compile>
Expand Down Expand Up @@ -338,6 +347,8 @@
<None Include="Properties\App.manifest" />
<None Include="Properties\Resources\Texts\AppLanguageDic.ini" />
<None Include="Properties\Resources\Texts\GuidInfosDic.ini" />
<Content Include="Properties\Resources\Images\DownLoad.png" />
<Content Include="Properties\Resources\Images\Translate.png" />
<Content Include="Properties\Resources\Texts\UwpModeItemsDic.xml" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
Expand Down
Loading

0 comments on commit 480b5d6

Please sign in to comment.