Exemple #1
0
        private void CreateEmptySettingsFile()
        {
            var obj  = new SettingsValues();
            var json = JsonConvert.SerializeObject(obj);
            var dir  = Path.GetDirectoryName(filePath);

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            File.WriteAllText(filePath, json);
        }
Exemple #2
0
        private void Load()
        {
            if (string.IsNullOrEmpty(filePath))
            {
                throw new Exception("The filePath must be set.");
            }

            if (!File.Exists(filePath))
            {
                CreateEmptySettingsFile();
            }

            try
            {
                var json = File.ReadAllText(filePath);
                Values = JsonConvert.DeserializeObject <SettingsValues>(json);
            }
            catch (Exception)
            {
                Values = new SettingsValues();
            }
        }