/// <summary> /// Returen string with added style /// </summary> /// <param name="rawstring">Input string</param> /// <param name="style">What style to add</param> /// <param name="filepath">Used to check if it is a image</param> /// <returns>The string with added style</returns> private string ASAddStyle(string rawstring, ImageBase64Style style, string filepath) { string fileExt = ""; string imageFileExt = Regex.Replace(extMonitor, @"[ ]+", @""); fileExt = Regex.Replace(filepath, @".*\.([^.]+)$", @"$1"); #if DEBUG MessageBox.Show(fileExt + " find:" + Regex.IsMatch(fileExt, imageFileExt, RegexOptions.IgnoreCase).ToString()); #endif if (fileExt.Length > 0 && Regex.IsMatch(fileExt,imageFileExt,RegexOptions.IgnoreCase)) { switch (style) { case ImageBase64Style.None: return rawstring; case ImageBase64Style.Header: return @"data:image/png;base64," + rawstring; case ImageBase64Style.Style: return @"<img src=""data:image/png;base64," + rawstring + @""">"; case ImageBase64Style.DIY: return imageBase64StyleBefore + rawstring + imageBase64StyleAfter; default: return rawstring; } } else return rawstring; }
/// <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; } }