using Newtonsoft.Json; using Support.Crypto; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Support.Models { public class Appsettings { public string DatabaseConnectionString { get; set; } public string ServiceInsideURL { get; set; } public string ServiceOutsideURL { get; set; } public string PrivateDirectory { get; set; } public string PublicDirectory { get; set; } public string SupportPassword { get; set; } public static Appsettings Load() { Appsettings result = null; try { if(!string.IsNullOrEmpty(GetConfigPath) && File.Exists(GetConfigPath)) { string json = File.ReadAllText(GetConfigPath); if(!string.IsNullOrEmpty(json)) { result = JsonConvert.DeserializeObject(json); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { if(result != null) { if(string.IsNullOrEmpty(result.SupportPassword)) { result.SupportPassword = "M+WPC5BMtIH0NK4YL87bjpBKFZLiTVUSoT7UQVOXI9Wd6n9+CvaANWhH9ZeY6e40Sib5yw=="; result.Save(); } } } return result; } public bool Save() { bool result = false; try { string json = JsonConvert.SerializeObject(this); if (!string.IsNullOrEmpty(json)) { File.WriteAllText(GetConfigPath, json); } result = File.Exists(GetConfigPath); } catch (Exception ex) { MessageBox.Show(ex.Message); } return result; } public static string GetConfigPath { get { string app = Path.GetDirectoryName(Application.ExecutablePath); return Path.Combine(app, "config.json"); } } } }