From 30fb612bda8fccb620a3c5c08787ad1573464e5f Mon Sep 17 00:00:00 2001 From: syneffort Date: Wed, 14 Dec 2022 10:52:14 +0900 Subject: [PATCH] add config --- WoL/Waker/App.config | 9 +++++ WoL/Waker/MainForm.cs | 37 +++++++++-------- WoL/Waker/Settings.Designer.cs | 74 ---------------------------------- WoL/Waker/Settings.settings | 18 --------- WoL/Waker/Waker.csproj | 14 +------ 5 files changed, 28 insertions(+), 124 deletions(-) create mode 100644 WoL/Waker/App.config delete mode 100644 WoL/Waker/Settings.Designer.cs delete mode 100644 WoL/Waker/Settings.settings diff --git a/WoL/Waker/App.config b/WoL/Waker/App.config new file mode 100644 index 0000000..2a87526 --- /dev/null +++ b/WoL/Waker/App.config @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/WoL/Waker/MainForm.cs b/WoL/Waker/MainForm.cs index 9db2ee3..920c11e 100644 --- a/WoL/Waker/MainForm.cs +++ b/WoL/Waker/MainForm.cs @@ -19,6 +19,8 @@ namespace Waker { public partial class MainForm : Form { + private Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); + private readonly Color PING_SUCCESS = Color.Green; private readonly Color PING_FAIL = Color.Red; private readonly Color PING_UNKNOWN = Color.Gray; @@ -38,19 +40,17 @@ namespace Waker private void InitInstance() { - string path = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath; - - if (!string.IsNullOrEmpty(Settings.Default.ip)) - ip = Settings.Default.ip; + if (!string.IsNullOrEmpty(config.AppSettings.Settings["ip"].Value)) + ip = config.AppSettings.Settings["ip"].Value; - if (!string.IsNullOrEmpty(Settings.Default.mac)) - mac = Settings.Default.mac; + if (!string.IsNullOrEmpty(config.AppSettings.Settings["mac"].Value)) + mac = config.AppSettings.Settings["mac"].Value; - if (!string.IsNullOrEmpty(Settings.Default.ports)) - ports = Settings.Default.ports; + if (!string.IsNullOrEmpty(config.AppSettings.Settings["ports"].Value)) + ports = config.AppSettings.Settings["ports"].Value; - if (!string.IsNullOrEmpty(Settings.Default.pingPort)) - pingPort = Settings.Default.pingPort; + if (!string.IsNullOrEmpty(config.AppSettings.Settings["pingPort"].Value)) + pingPort = config.AppSettings.Settings["pingPort"].Value; FillInformation(); @@ -73,8 +73,8 @@ namespace Waker return false; AddressTextBox.Text = ip; - Settings.Default.ip = ip; - Settings.Default.Save(); + config.AppSettings.Settings["ip"].Value = ip; + config.Save(ConfigurationSaveMode.Modified); return true; } @@ -92,11 +92,10 @@ namespace Waker MacTextBox.Text = mac; PortTextBox.Text = ports; - Settings.Default.ip = ip; - Settings.Default.mac = mac; - Settings.Default.ports = ports; - - Settings.Default.Save(); + config.AppSettings.Settings["ip"].Value = ip; + config.AppSettings.Settings["mac"].Value = mac; + config.AppSettings.Settings["ports"].Value = ports; + config.Save(ConfigurationSaveMode.Modified); return true; } @@ -197,8 +196,8 @@ namespace Waker if (string.IsNullOrEmpty(ip)) return; - Settings.Default.pingPort = pingPort; - Settings.Default.Save(); + config.AppSettings.Settings["pingPort"].Value = pingPort; + config.Save(ConfigurationSaveMode.Modified); object[] parameters = new object[2] { ip, targetPort }; pingThread = new Thread(new ParameterizedThreadStart(SendPing)); diff --git a/WoL/Waker/Settings.Designer.cs b/WoL/Waker/Settings.Designer.cs deleted file mode 100644 index 7d04a7a..0000000 --- a/WoL/Waker/Settings.Designer.cs +++ /dev/null @@ -1,74 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 이 코드는 도구를 사용하여 생성되었습니다. -// 런타임 버전:4.0.30319.42000 -// -// 파일 내용을 변경하면 잘못된 동작이 발생할 수 있으며, 코드를 다시 생성하면 -// 이러한 변경 내용이 손실됩니다. -// -//------------------------------------------------------------------------------ - -namespace Waker { - - - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.10.0.0")] - internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { - - private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); - - public static Settings Default { - get { - return defaultInstance; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("")] - public string ip { - get { - return ((string)(this["ip"])); - } - set { - this["ip"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("")] - public string mac { - get { - return ((string)(this["mac"])); - } - set { - this["mac"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("7, 9")] - public string ports { - get { - return ((string)(this["ports"])); - } - set { - this["ports"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("")] - public string pingPort { - get { - return ((string)(this["pingPort"])); - } - set { - this["pingPort"] = value; - } - } - } -} diff --git a/WoL/Waker/Settings.settings b/WoL/Waker/Settings.settings deleted file mode 100644 index 0f49671..0000000 --- a/WoL/Waker/Settings.settings +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - 7, 9 - - - - - - \ No newline at end of file diff --git a/WoL/Waker/Waker.csproj b/WoL/Waker/Waker.csproj index da69189..c1d7cef 100644 --- a/WoL/Waker/Waker.csproj +++ b/WoL/Waker/Waker.csproj @@ -2,7 +2,7 @@ WinExe - netcoreapp3.1 + net6.0-windows true False 1.0.0.1 @@ -27,18 +27,6 @@ - - True - True - Settings.settings - - - - - - SettingsSingleFileGenerator - Settings.Designer.cs - True