/// <summary> /// Load settings, if load failed or file not exist, initialize instead /// </summary> public void LoadSettings() { ConfigFile configFile = new ConfigFile(); if (configFile.SetConfigFile(System.Text.RegularExpressions.Regex.Replace(Application.ExecutablePath, @"\..+?$", @".xml")) == ConfigFile.OperateConfigResult.Succeed) { //settings cache string Base64BoxFontName = configFile.ReadConfig("General", "Base64BoxFontName"); string Base64BoxFontSize = configFile.ReadConfig("General", "Base64BoxFontSize"); string Base64BoxFontBold = configFile.ReadConfig("General", "Base64BoxFontBold"); string Base64BoxFontItalic = configFile.ReadConfig("General", "Base64BoxFontItalic"); string TextBoxFontName = configFile.ReadConfig("General", "TextBoxFontName"); string TextBoxFontSize = configFile.ReadConfig("General", "TextBoxFontSize"); string TextBoxFontBold = configFile.ReadConfig("General", "TextBoxFontBold"); string TextBoxFontItalic = configFile.ReadConfig("General", "TextBoxFontItalic"); string ImageBase64StyleSet = configFile.ReadConfig("General", "ImageBase64Style"); string ExtMonitor = configFile.ReadConfig("General", "ExtMonitor"); string ImageBase64StyleBefore = configFile.ReadConfig("General", "ImageBase64StyleBefore"); string ImageBase64StyleAfter = configFile.ReadConfig("General", "ImageBase64StyleAfter"); string ImageAutoDetectEnabled = configFile.ReadConfig("General", "ImageAutoDetectEnabled"); string AutoCopy = configFile.ReadConfig("General", "AutoCopy"); string RealtimeConvert = configFile.ReadConfig("General", "RealtimeConvert"); string RealtimeConvertThreshold = configFile.ReadConfig("General", "RealtimeConvertThreshold"); //apply settings //general //font if (Base64BoxFontName.Length == 0) { if (Base64BoxFontSize.Length > 0) base64Box.Font = new Font("Georgia", Convert.ToSingle(Base64BoxFontSize)); else base64Box.Font = new Font("Georgia", 9F); } else //found name area { try { if (Base64BoxFontSize.Length > 0) base64Box.Font = new Font(Base64BoxFontName, Convert.ToSingle(Base64BoxFontSize)); else base64Box.Font = new Font(Base64BoxFontName, 9F); } catch { if (Base64BoxFontSize.Length > 0) base64Box.Font = new Font("Georgia", Convert.ToSingle(Base64BoxFontSize)); else base64Box.Font = new Font("Georgia", 9F); } } //apply style if (Base64BoxFontItalic.Length > 0 && Base64BoxFontBold.Length > 0) // bold & italic { base64Box.Font = new Font(base64Box.Font, FontStyle.Bold | FontStyle.Italic); } else if (Base64BoxFontBold.Length > 0)// bold { base64Box.Font = new Font(base64Box.Font, FontStyle.Bold); } else if (Base64BoxFontItalic.Length > 0) //italic { base64Box.Font = new Font(base64Box.Font, FontStyle.Italic); }//else no changing if (TextBoxFontName.Length == 0) { if (TextBoxFontSize.Length > 0) textBox.Font = new Font("Georgia", Convert.ToSingle(TextBoxFontSize)); else textBox.Font = new Font("Georgia", 9F); } else //found name area { try { if (TextBoxFontSize.Length > 0) textBox.Font = new Font(TextBoxFontName, Convert.ToSingle(TextBoxFontSize)); else textBox.Font = new Font(TextBoxFontName, 9F); } catch { if (TextBoxFontSize.Length > 0) textBox.Font = new Font("Georgia", Convert.ToSingle(TextBoxFontSize)); else textBox.Font = new Font("Georgia", 9F); } } //apply style if (TextBoxFontItalic.Length > 0 && TextBoxFontBold.Length > 0) // bold & italic { textBox.Font = new Font(textBox.Font, FontStyle.Bold | FontStyle.Italic); } else if (TextBoxFontBold.Length > 0)// bold { textBox.Font = new Font(textBox.Font, FontStyle.Bold); } else if (TextBoxFontItalic.Length > 0) //italic { textBox.Font = new Font(textBox.Font, FontStyle.Italic); }//else no changing //apply image base64 style //DIY style string if (ImageBase64StyleBefore.Length > 0) imageBase64StyleBefore = ImageBase64StyleBefore; else imageBase64StyleBefore = ""; if (ImageBase64StyleAfter.Length > 0) imageBase64StyleAfter = ImageBase64StyleAfter; else imageBase64StyleAfter = ""; if (ExtMonitor.Length > 0) extMonitor = ExtMonitor; else extMonitor = @"apng | bmp | gif | iff | j2c | j2k | jp2 | jpc | jpe | jpeg | jpf | jpg | jpx | pcx | png | psd | ras | raw | rsb | sgi | tga | tiff | tif | wbmp"; if (ImageAutoDetectEnabled.Length > 0) imageAutoDetectEnabled = false; else imageAutoDetectEnabled = true; //style chioce if (ImageBase64StyleSet.Length > 0) { switch (ImageBase64StyleSet) { case "None": imageBase64Style = ImageBase64Style.None; break; case "Header": imageBase64Style = ImageBase64Style.Header; break; case "Style": imageBase64Style = ImageBase64Style.Style; break; case "DIY": imageBase64Style = ImageBase64Style.DIY; break; default: imageBase64Style = ImageBase64Style.None; break; } } //auto copy if (AutoCopy.Length > 0) autoCopy = false; else autoCopy = true; //realtime convert if (RealtimeConvert.Length > 0) realtimeConvert = false; else realtimeConvert = true; if (RealtimeConvertThreshold.Length > 0) { try { realtimeConvertThreshold = Convert.ToInt32(RealtimeConvertThreshold); } catch { realtimeConvertThreshold = 50000; } } else realtimeConvertThreshold = 50000; } else { //initialize textBox.Font = new System.Drawing.Font("Georgia", 9F); base64Box.Font = new System.Drawing.Font("Georgia", 9F); imageBase64Style = ImageBase64Style.None; extMonitor = @"apng | bmp | gif | iff | j2c | j2k | jp2 | jpc | jpe | jpeg | jpf | jpg | jpx | pcx | png | psd | ras | raw | rsb | sgi | tga | tiff | tif | wbmp"; imageBase64StyleBefore = ""; imageBase64StyleAfter = ""; imageAutoDetectEnabled = true; autoCopy = true; realtimeConvert = true; realtimeConvertThreshold = 50000; } }
/// <summary> /// Load settings, if load failed or file not exist, initialize instead /// </summary> private void LoadSettings() { ConfigFile configFile = new ConfigFile(); if (configFile.SetConfigFile(System.Text.RegularExpressions.Regex.Replace(Application.ExecutablePath, @"\..+?$", @".xml")) == ConfigFile.OperateConfigResult.Succeed) { //loading config cache strings string Base64BoxFontName = configFile.ReadConfig("General", "Base64BoxFontName"); string Base64BoxFontSize = configFile.ReadConfig("General", "Base64BoxFontSize"); string Base64BoxFontBold = configFile.ReadConfig("General", "Base64BoxFontBold"); string Base64BoxFontItalic = configFile.ReadConfig("General", "Base64BoxFontItalic"); string TextBoxFontName = configFile.ReadConfig("General", "TextBoxFontName"); string TextBoxFontSize = configFile.ReadConfig("General", "TextBoxFontSize"); string TextBoxFontBold = configFile.ReadConfig("General", "TextBoxFontBold"); string TextBoxFontItalic = configFile.ReadConfig("General", "TextBoxFontItalic"); string Language = configFile.ReadConfig("General", "Language"); string ImageBase64StyleSet = configFile.ReadConfig("General", "ImageBase64Style"); string ExtMonitor = configFile.ReadConfig("General", "ExtMonitor"); string ImageBase64StyleBefore = configFile.ReadConfig("General", "ImageBase64StyleBefore"); string ImageBase64StyleAfter = configFile.ReadConfig("General", "ImageBase64StyleAfter"); string ImageAutoDetectEnabled = configFile.ReadConfig("General", "ImageAutoDetectEnabled"); string AutoCopy = configFile.ReadConfig("General", "AutoCopy"); string RealtimeConvert = configFile.ReadConfig("General", "RealtimeConvert"); string RealtimeConvertThreshold = configFile.ReadConfig("General", "RealtimeConvertThreshold"); //apply config //base64 box font setting //no name found if (Base64BoxFontName.Length == 0) { //no name, found size area if (Base64BoxFontSize.Length > 0) { textBoxBase64BoxFont.Font = new Font("Georgia", 9f); textBoxBase64BoxFont.Tag = Convert.ToSingle(Base64BoxFontSize); } else // no size and no name { textBoxBase64BoxFont.Font = new Font("Georgia", 9F); textBoxBase64BoxFont.Tag = 9f; } } else //found name area { try { //found name, found size if (Base64BoxFontSize.Length > 0) { textBoxBase64BoxFont.Font = new Font(Base64BoxFontName, 9f); textBoxBase64BoxFont.Tag = Convert.ToSingle(Base64BoxFontSize); } else // found name, no size { textBoxBase64BoxFont.Font = new Font(Base64BoxFontName, 9F); textBoxBase64BoxFont.Tag = 9f; } } catch //invalid name, treat as no name { if (Base64BoxFontSize.Length > 0) { textBoxBase64BoxFont.Font = new Font("Georgia", 9f); textBoxBase64BoxFont.Tag = Convert.ToSingle(Base64BoxFontSize); } else { textBoxBase64BoxFont.Font = new Font("Georgia", 9F); textBoxBase64BoxFont.Tag = 9f; } } } //apply style if (Base64BoxFontItalic.Length > 0 && Base64BoxFontBold.Length > 0 ) // bold & italic { textBoxBase64BoxFont.Font = new Font(textBoxBase64BoxFont.Font, FontStyle.Bold | FontStyle.Italic); } else if(Base64BoxFontBold.Length > 0)// bold { textBoxBase64BoxFont.Font = new Font(textBoxBase64BoxFont.Font, FontStyle.Bold); } else if (Base64BoxFontItalic.Length > 0) //italic { textBoxBase64BoxFont.Font = new Font(textBoxBase64BoxFont.Font, FontStyle.Italic); }//else no changing textBoxBase64BoxFont.ShowFont(); //textbox font setting //no name found if (TextBoxFontName.Length == 0) { //no name, found size area if (TextBoxFontSize.Length > 0) { textBoxTextBoxFont.Font = new Font("Georgia", 9f); textBoxTextBoxFont.Tag = Convert.ToSingle(TextBoxFontSize); } else // no size and no name { textBoxTextBoxFont.Font = new Font("Georgia", 9F); textBoxTextBoxFont.Tag = 9f; } } else //found name area { try { //found name, found size if (TextBoxFontSize.Length > 0) { textBoxTextBoxFont.Font = new Font(TextBoxFontName, 9f); textBoxTextBoxFont.Tag = Convert.ToSingle(TextBoxFontSize); } else // found name, no size { textBoxTextBoxFont.Font = new Font(TextBoxFontName, 9F); textBoxTextBoxFont.Tag = 9f; } } catch //invalid name, treat as no name { if (TextBoxFontSize.Length > 0) { textBoxTextBoxFont.Font = new Font("Georgia", 9f); textBoxTextBoxFont.Tag = Convert.ToSingle(TextBoxFontSize); } else { textBoxTextBoxFont.Font = new Font("Georgia", 9F); textBoxTextBoxFont.Tag = 9f; } } } //apply style if (TextBoxFontItalic.Length > 0 && TextBoxFontBold.Length > 0) // bold & italic { textBoxTextBoxFont.Font = new Font(textBoxTextBoxFont.Font, FontStyle.Bold | FontStyle.Italic); } else if (TextBoxFontBold.Length > 0)// bold { textBoxTextBoxFont.Font = new Font(textBoxTextBoxFont.Font, FontStyle.Bold); } else if (TextBoxFontItalic.Length > 0) //italic { textBoxTextBoxFont.Font = new Font(textBoxTextBoxFont.Font, FontStyle.Italic); }//else no changing textBoxTextBoxFont.ShowFont(); //apply language if (Language.Length > 0) { switch (Language) { case "en-US": comboBoxLanguageChoice.SelectedIndex = 0; break; case "zh-CN": comboBoxLanguageChoice.SelectedIndex = 1; break; default: comboBoxLanguageChoice.Text = Language; break; } } else { switch (currentLanguage) { case "en-US": comboBoxLanguageChoice.SelectedIndex = 0; break; case "zh-CN": comboBoxLanguageChoice.SelectedIndex = 1; break; default: comboBoxLanguageChoice.SelectedIndex = 0; break; } } //apply image base64 style //DIY style string if (ImageBase64StyleBefore.Length > 0) imageBase64StyleBefor = ImageBase64StyleBefore; else imageBase64StyleBefor = ""; if (ImageBase64StyleAfter.Length > 0) imageBase64StyleAfter = ImageBase64StyleAfter; else imageBase64StyleAfter = ""; if (ExtMonitor.Length > 0) extMonitorTextBox.Text = ExtMonitor; else extMonitorTextBox.Text = @"apng | bmp | gif | iff | j2c | j2k | jp2 | jpc | jpe | jpeg | jpf | jpg | jpx | pcx | png | psd | ras | raw | rsb | sgi | tga | tiff | tif | wbmp"; if (ImageAutoDetectEnabled.Length > 0) imageAutoDetectCheckBox.Checked = false; else imageAutoDetectCheckBox.Checked = true; //style chioce if (ImageBase64StyleSet.Length > 0) { switch (ImageBase64StyleSet) { case "None": radioButtonImageBase64StyleNone.Checked = true; break; case "Header": radioButtonImageBase64StyleHeader.Checked = true; break; case "Style": radioButtonImageBase64StyleStyle.Checked = true; break; case "DIY": radioButtonImageBase64StyleDIY.Checked = true; break; default: radioButtonImageBase64StyleNone.Checked = true; break; } } else { radioButtonImageBase64StyleNone.Checked = true; } //auto copy if (AutoCopy.Length > 0) checkBoxAutoCopy.Checked = false; else checkBoxAutoCopy.Checked = true; //realtime convert if (RealtimeConvert.Length > 0) checkBoxRealtimeConvert.Checked = false; else checkBoxRealtimeConvert.Checked = true; if (RealtimeConvertThreshold.Length > 0) textBoxAutoConvertThreshold.Text = RealtimeConvertThreshold; else textBoxAutoConvertThreshold.Text = "50000"; //finished isOptionChanged = false; } else//Initialize { SetToDefault(); isOptionChanged = false; } }
private void saveButton_Click(object sender, EventArgs e) { ConfigFile configFile = new ConfigFile(); //save settings #if DEBUG MessageBox.Show(System.Text.RegularExpressions.Regex.Replace(Application.ExecutablePath, @"\..+?$", @".xml")); #endif if (configFile.SetConfigFile(System.Text.RegularExpressions.Regex.Replace(Application.ExecutablePath, @"\..+?$", @".xml")) != ConfigFile.OperateConfigResult.IOError) { //saving configs if (textBoxBase64BoxFont.Font.Name != "Georgia") configFile.SaveConfig("General", "Base64BoxFontName", textBoxBase64BoxFont.Font.Name); else configFile.DeleteConfig("General", "Base64BoxFontName"); if (textBoxBase64BoxFont.Tag.ToString() != "9") configFile.SaveConfig("General", "Base64BoxFontSize", textBoxBase64BoxFont.Tag.ToString()); else configFile.DeleteConfig("General", "Base64BoxFontSize"); if (textBoxBase64BoxFont.Font.Bold) configFile.SaveConfig("General", "Base64BoxFontBold", textBoxBase64BoxFont.Font.Bold.ToString()); else configFile.DeleteConfig("General", "Base64BoxFontBold"); if (textBoxBase64BoxFont.Font.Italic) configFile.SaveConfig("General", "Base64BoxFontItalic", textBoxBase64BoxFont.Font.Italic.ToString()); else configFile.DeleteConfig("General", "Base64BoxFontItalic"); if (textBoxTextBoxFont.Font.Name != "Georgia") configFile.SaveConfig("General", "TextBoxFontName", textBoxTextBoxFont.Font.Name); else configFile.DeleteConfig("General", "TextBoxFontName"); if (textBoxTextBoxFont.Tag.ToString() != "9") configFile.SaveConfig("General", "TextBoxFontSize", textBoxTextBoxFont.Tag.ToString()); else configFile.DeleteConfig("General", "TextBoxFontSize"); if(textBoxTextBoxFont.Font.Bold)configFile.SaveConfig("General", "TextBoxFontBold", textBoxTextBoxFont.Font.Bold.ToString()); else configFile.DeleteConfig("General", "TextBoxFontBold"); if (textBoxTextBoxFont.Font.Italic) configFile.SaveConfig("General", "TextBoxFontItalic", textBoxTextBoxFont.Font.Italic.ToString()); else configFile.DeleteConfig("General", "TextBoxFontItalic"); if (comboBoxLanguageChoice.Text.Length != 0) configFile.SaveConfig("General", "Language", comboBoxLanguageChoice.Text); else configFile.ReadConfig("General", "Language"); switch (imageBase64Style) { case MainForm.ImageBase64Style.None: configFile.DeleteConfig("General", "ImageBase64Style"); break; case MainForm.ImageBase64Style.Header: configFile.SaveConfig("General", "ImageBase64Style", "Header"); break; case MainForm.ImageBase64Style.Style: configFile.SaveConfig("General", "ImageBase64Style", "Style"); break; case MainForm.ImageBase64Style.DIY: configFile.SaveConfig("General", "ImageBase64Style", "DIY"); configFile.SaveConfig("General", "ImageBase64StyleBefore", textBoxStyleBefore.Text); configFile.SaveConfig("General", "ImageBase64StyleAfter", textBoxStyleAfter.Text); break; default: break; } if (extMonitorTextBox.Text != @"apng | bmp | gif | iff | j2c | j2k | jp2 | jpc | jpe | jpeg | jpf | jpg | jpx | pcx | png | psd | ras | raw | rsb | sgi | tga | tiff | tif | wbmp") { configFile.SaveConfig("General", "ExtMonitor", extMonitorTextBox.Text); } else configFile.DeleteConfig("General", "ExtMonitor"); if (!imageAutoDetectCheckBox.Checked) configFile.SaveConfig("General", "ImageAutoDetectEnabled", imageAutoDetectCheckBox.Checked.ToString()); else configFile.DeleteConfig("General", "ImageAutoDetectEnabled"); if (!checkBoxAutoCopy.Checked) configFile.SaveConfig("General", "AutoCopy", checkBoxAutoCopy.Checked.ToString()); else configFile.DeleteConfig("General", "AutoCopy"); if (!checkBoxRealtimeConvert.Checked) configFile.SaveConfig("General", "RealtimeConvert", checkBoxRealtimeConvert.Checked.ToString()); else configFile.DeleteConfig("General", "RealtimeConvert"); if (textBoxAutoConvertThreshold.Text != "50000") configFile.SaveConfig("General", "RealtimeConvertThreshold", textBoxAutoConvertThreshold.Text); else configFile.DeleteConfig("General", "RealtimeConvertThreshold"); configFile.SaveConfigFile(); isOptionChanged = false; //update settings event UpdateButtonClick(DialogResult.OK); if(sender != applyButton) this.Close(); } else { MessageBox.Show(Properties.Resources.Option_saveFailMessage); } }
public static string LoadLanguage() { string CurrentLanguage = System.Threading.Thread.CurrentThread.CurrentUICulture.ToString(); ConfigFile configFile = new ConfigFile(); if (configFile.SetConfigFile(System.Text.RegularExpressions.Regex.Replace(Application.ExecutablePath, @"\..+?$", @".xml")) == ConfigFile.OperateConfigResult.Succeed) { string Language = configFile.ReadConfig("General", "Language"); //apply language try { if (Language.Length != 0) { System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(Language); System.Threading.Thread.CurrentThread.CurrentCulture = System.Threading.Thread.CurrentThread.CurrentUICulture; } } catch { return CurrentLanguage; } return CurrentLanguage; } return CurrentLanguage; }