From 9bbde49a5c3c555b7bd8c17635094e6014732dae Mon Sep 17 00:00:00 2001 From: Frank Skare Date: Tue, 15 Oct 2019 19:01:56 +0200 Subject: [PATCH] design improvement --- Clean.ps1 | 11 +++++++++++ mpv.net.sln | 20 ++++++------------- mpv.net/WPF/ConfWindow.xaml.cs | 36 ++++++++++++++++------------------ 3 files changed, 34 insertions(+), 33 deletions(-) create mode 100644 Clean.ps1 diff --git a/Clean.ps1 b/Clean.ps1 new file mode 100644 index 0000000..f6dfcc0 --- /dev/null +++ b/Clean.ps1 @@ -0,0 +1,11 @@ +function Remove($path) { + if (Test-Path $path) { + Remove-Item $path -Recurse -Force + } else { + Write-Host "Path don't exist: $path" + } +} + +Remove("obj") +Remove(".vs") +Remove("*.csproj.user") \ No newline at end of file diff --git a/mpv.net.sln b/mpv.net.sln index f87dffb..e58b54b 100644 --- a/mpv.net.sln +++ b/mpv.net.sln @@ -11,40 +11,32 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScriptingExtension", "exten EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU Debug|x64 = Debug|x64 Debug|x86 = Debug|x86 - Release|Any CPU = Release|Any CPU Release|x64 = Release|x64 Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {1751F378-8EDF-4B62-BE6D-304C7C287089}.Debug|Any CPU.ActiveCfg = Debug|x86 {1751F378-8EDF-4B62-BE6D-304C7C287089}.Debug|x64.ActiveCfg = Debug|x64 {1751F378-8EDF-4B62-BE6D-304C7C287089}.Debug|x64.Build.0 = Debug|x64 - {1751F378-8EDF-4B62-BE6D-304C7C287089}.Debug|x86.ActiveCfg = Debug|x86 - {1751F378-8EDF-4B62-BE6D-304C7C287089}.Debug|x86.Build.0 = Debug|x86 - {1751F378-8EDF-4B62-BE6D-304C7C287089}.Release|Any CPU.ActiveCfg = Release|x86 + {1751F378-8EDF-4B62-BE6D-304C7C287089}.Debug|x86.ActiveCfg = Debug|x64 + {1751F378-8EDF-4B62-BE6D-304C7C287089}.Debug|x86.Build.0 = Debug|x64 {1751F378-8EDF-4B62-BE6D-304C7C287089}.Release|x64.ActiveCfg = Release|x64 {1751F378-8EDF-4B62-BE6D-304C7C287089}.Release|x64.Build.0 = Release|x64 {1751F378-8EDF-4B62-BE6D-304C7C287089}.Release|x86.ActiveCfg = Release|x86 {1751F378-8EDF-4B62-BE6D-304C7C287089}.Release|x86.Build.0 = Release|x86 - {55C88710-539D-4402-84C8-31694841C731}.Debug|Any CPU.ActiveCfg = Debug|x86 {55C88710-539D-4402-84C8-31694841C731}.Debug|x64.ActiveCfg = Debug|x64 {55C88710-539D-4402-84C8-31694841C731}.Debug|x64.Build.0 = Debug|x64 - {55C88710-539D-4402-84C8-31694841C731}.Debug|x86.ActiveCfg = Debug|x86 - {55C88710-539D-4402-84C8-31694841C731}.Debug|x86.Build.0 = Debug|x86 - {55C88710-539D-4402-84C8-31694841C731}.Release|Any CPU.ActiveCfg = Release|x86 + {55C88710-539D-4402-84C8-31694841C731}.Debug|x86.ActiveCfg = Debug|x64 + {55C88710-539D-4402-84C8-31694841C731}.Debug|x86.Build.0 = Debug|x64 {55C88710-539D-4402-84C8-31694841C731}.Release|x64.ActiveCfg = Release|x64 {55C88710-539D-4402-84C8-31694841C731}.Release|x64.Build.0 = Release|x64 {55C88710-539D-4402-84C8-31694841C731}.Release|x86.ActiveCfg = Release|x86 {55C88710-539D-4402-84C8-31694841C731}.Release|x86.Build.0 = Release|x86 - {94255EF2-C823-4D82-9017-0E993CC0F5A1}.Debug|Any CPU.ActiveCfg = Debug|x86 {94255EF2-C823-4D82-9017-0E993CC0F5A1}.Debug|x64.ActiveCfg = Debug|x64 {94255EF2-C823-4D82-9017-0E993CC0F5A1}.Debug|x64.Build.0 = Debug|x64 - {94255EF2-C823-4D82-9017-0E993CC0F5A1}.Debug|x86.ActiveCfg = Debug|x86 - {94255EF2-C823-4D82-9017-0E993CC0F5A1}.Debug|x86.Build.0 = Debug|x86 - {94255EF2-C823-4D82-9017-0E993CC0F5A1}.Release|Any CPU.ActiveCfg = Release|x86 + {94255EF2-C823-4D82-9017-0E993CC0F5A1}.Debug|x86.ActiveCfg = Debug|x64 + {94255EF2-C823-4D82-9017-0E993CC0F5A1}.Debug|x86.Build.0 = Debug|x64 {94255EF2-C823-4D82-9017-0E993CC0F5A1}.Release|x64.ActiveCfg = Release|x64 {94255EF2-C823-4D82-9017-0E993CC0F5A1}.Release|x64.Build.0 = Release|x64 {94255EF2-C823-4D82-9017-0E993CC0F5A1}.Release|x86.ActiveCfg = Release|x86 diff --git a/mpv.net/WPF/ConfWindow.xaml.cs b/mpv.net/WPF/ConfWindow.xaml.cs index bd0f2a7..332cf91 100644 --- a/mpv.net/WPF/ConfWindow.xaml.cs +++ b/mpv.net/WPF/ConfWindow.xaml.cs @@ -100,8 +100,6 @@ namespace mpvnet return string.Join("", SettingsDefinitions.Select(item => item.Name + item.Value).ToArray()); } - Dictionary SectionComment = new Dictionary(); - void LoadConf(string file) { if (!File.Exists(file)) @@ -109,7 +107,7 @@ namespace mpvnet string comment = ""; string section = ""; - bool isSectionItem = false; ; + bool isSectionItem = false; foreach (string currentLine in File.ReadAllLines(file)) { @@ -125,11 +123,11 @@ namespace mpvnet } else if (line.StartsWith("[") && line.Contains("]")) { + if (!isSectionItem && comment != "" && comment != "\r\n") + ConfItems.Add(new ConfItem() { + Comment = comment, File = Path.GetFileNameWithoutExtension(file)}); + section = line.Substring(0, line.IndexOf("]") + 1); - - if (!SectionComment.ContainsKey(file)) - SectionComment[file] = comment; - comment = ""; isSectionItem = true; } @@ -166,14 +164,14 @@ namespace mpvnet } } - string GetContent(string name) + string GetContent(string filename) { StringBuilder sb = new StringBuilder(); List namesWritten = new List(); foreach (ConfItem item in ConfItems) { - if (name != item.File || item.Section != "" || item.IsSectionItem) + if (filename != item.File || item.Section != "" || item.IsSectionItem) continue; if (item.Comment != "") @@ -181,13 +179,16 @@ namespace mpvnet if (item.SettingBase == null) { - sb.Append(item.Name + " = " + item.Value); + if (item.Name != "") + { + sb.Append(item.Name + " = " + item.Value); - if (item.LineComment != "") - sb.Append(" " + item.LineComment); + if (item.LineComment != "") + sb.Append(" " + item.LineComment); - sb.AppendLine(); - namesWritten.Add(item.Name); + sb.AppendLine(); + namesWritten.Add(item.Name); + } } else if ((item.SettingBase.Value ?? "") != item.SettingBase.Default) { @@ -211,15 +212,12 @@ namespace mpvnet } } - if (SectionComment.ContainsKey(name) && SectionComment[name] != "\r\n") - sb.Append(SectionComment[name]); - if (!sb.ToString().Contains("# Editor")) sb.AppendLine("# Editor"); foreach (SettingBase setting in SettingsDefinitions) { - if (name != setting.File || namesWritten.Contains(setting.Name)) + if (filename != setting.File || namesWritten.Contains(setting.Name)) continue; if ((setting.Value ?? "") != setting.Default) @@ -240,7 +238,7 @@ namespace mpvnet foreach (ConfItem item in ConfItems) { - if (name != item.File || (item.Section == "" && !item.IsSectionItem)) + if (filename != item.File || (item.Section == "" && !item.IsSectionItem)) continue; if (item.Section != "")