Exemplo n.º 1
0
        public static General ReadGeneralSettings()
        {
            string generalJsonFile = Path.Combine(Directory.GetCurrentDirectory(), GENERAL_FILE_NAME);

            var generalSettings = new General();

            if (!File.Exists(generalJsonFile))
            {
                generalSettings = GetDefaultGeneralSettings();
                WriteGeneralSettings(generalSettings);
            }
            else
            {
                try
                {
                    using (StreamReader file = File.OpenText(generalJsonFile))
                    using (JsonTextReader reader = new JsonTextReader(file))
                    {
                        while (reader.Read())
                        {
                            JObject o3 = (JObject) JToken.ReadFrom(reader);
                            foreach (var child in o3.Children())
                            {
                                AddPropertyToGeneralSettings(generalSettings, child.Path, child.First.ToString());
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show($"{Constants.GeneralMessages.ErrorWritingFile}{ex}",
                        Constants.GeneralMessages.ErrorWritingFileCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    throw;
                }
            }
            return generalSettings;
        }
Exemplo n.º 2
0
        public static void WriteGeneralSettings(General general)
        {
            string generalJsonFile = Path.Combine(Directory.GetCurrentDirectory(), GENERAL_FILE_NAME);

            try
            {
                using (StreamWriter file = File.CreateText(generalJsonFile))
                using (JsonTextWriter writer = new JsonTextWriter(file))
                {
                    var jsonGeneralSettings = JsonConvert.SerializeObject(general);
                    writer.WriteRaw(jsonGeneralSettings);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"{Constants.GeneralMessages.ErrorWritingFile}{ex}",
                    Constants.GeneralMessages.ErrorWritingFileCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                throw;
            }
        }
Exemplo n.º 3
0
 public static void PopulateIconProperties(General generalSettings, ComboBox fontComboBox, ComboBox colorComboBox, ComboBox textColorComboBox)
 {
     PopulateFontComboBox(generalSettings.IconFont, fontComboBox);
     ColorUtils.PopulateColorComboBox("Blue", colorComboBox);
     ColorUtils.PopulateColorComboBox("White", textColorComboBox);
 }
Exemplo n.º 4
0
 private static General AddPropertyToGeneralSettings(General general, string propertyName, string propertyValue)
 {
     switch (propertyName)
     {
         case FileConstants.General.ICON_FONT:
             general.IconFont = propertyValue;
             break;
         case FileConstants.General.ICON_FONT_SIZE:
             general.IconFontSize = propertyValue.ToFloat();
             break;
         case FileConstants.General.ICON_SHAPE:
             general.IconShape = propertyValue;
             break;
         case FileConstants.General.SHOW_BALLOON_TIPS:
             general.ShowBalloonTips = Convert.ToBoolean(propertyValue);
             break;
         case FileConstants.General.LOADED_GLOBAL_HOTKEY:
             general.LoadedGlobalHotkey = GlobalHotkeyParser.ConvertToLoadedGlobalHotkey(propertyValue);
             break;
     }
     return general;
 }