// private string config = @"./Resources/config.json"; public MainWindow() { string config = ApplicationUtility.GetUserAppDataPath() + @"\WinBoard\config.json"; //string ResourcesPath = @"./Resources"; InitializeComponent(); if (!File.Exists(config)) { return; } AppPath appPath = new AppPath(); using (var sr = new StreamReader(System.IO.Path.GetFullPath(config), System.Text.Encoding.UTF8)) { var json = sr.ReadToEnd(); appPath = JsonConvert.DeserializeObject <AppPath>(json); } if (appPath.r_SearchColor < 256 && appPath.r_SearchColor > 0) { DashboardParam.rSerachColor = appPath.r_SearchColor; } else { DashboardParam.rSerachColor = 0; } if (appPath.g_SearchColor < 256 && appPath.g_SearchColor > 0) { DashboardParam.gSearchColor = appPath.g_SearchColor; } else { DashboardParam.gSearchColor = 0; } if (appPath.b_SearchColor < 256 && appPath.b_SearchColor > 0) { DashboardParam.bSearchColor = appPath.b_SearchColor; } else { DashboardParam.bSearchColor = 0; } TextColorChange(SearchText, (byte)DashboardParam.rSerachColor, (byte)DashboardParam.gSearchColor, (byte)DashboardParam.bSearchColor); //背景画像が指定されていれば読み込む if (appPath.BackgroundPath != null && File.Exists(appPath.BackgroundPath)) { DashboardParam.BackgroundPath = appPath.BackgroundPath; ChangeBg(Path.GetFullPath(DashboardParam.BackgroundPath)); } if (appPath.ApplicationPath != null && Directory.Exists(appPath.ApplicationPath)) { DashboardParam.ApplicaitonPath = appPath.ApplicationPath; Reload(); } }
public Setting() { InitializeComponent(); Roaming = ApplicationUtility.GetUserAppDataPath(); winboard = Roaming + @"\WinBoard"; config = winboard + @"\config.json"; AppPath appPath = new AppPath(); //WinBoardフォルダがなかったら作る if (!Directory.Exists(winboard)) { MessageBox.Show("WinBoardフォルダが見つかりませんでした\n" + "ファルダを自動作成します"); Directory.CreateDirectory(winboard); } //Configがなかったら作る if (!File.Exists(config)) { MessageBox.Show("config.jsonファイルが見つかりませんでした\n" + "ファイルを自動作成します"); var fs = File.Create(config); //appPath.ApplicationPath = pathText.Text; //appPath.BackgroundPath = backgroundPath.Text; //var json = JsonConvert.SerializeObject(appPath); //using (var sw = new StreamWriter(@"./Resources/config.json", false, System.Text.Encoding.UTF8)) //{ // sw.Write(json); //} } else { using (var sr = new StreamReader(System.IO.Path.GetFullPath(config), System.Text.Encoding.UTF8)) { var json = sr.ReadToEnd(); appPath = JsonConvert.DeserializeObject <AppPath>(json); } if (appPath.ApplicationPath != null && Directory.Exists(appPath.ApplicationPath)) { pathText.Text = appPath.ApplicationPath; } if (appPath.BackgroundPath != null && File.Exists(appPath.BackgroundPath)) { backgroundPath.Text = appPath.BackgroundPath; } r_SearchColor.Text = appPath.r_SearchColor.ToString(); g_SearchColor.Text = appPath.g_SearchColor.ToString(); b_SearchColor.Text = appPath.b_SearchColor.ToString(); } }
void UpdateParam() { var newPath = pathText.Text; var bgPath = backgroundPath.Text; AppPath appPath = new AppPath(); appPath.ApplicationPath = newPath; if (File.Exists(bgPath) && (bgPath.EndsWith(".png") || bgPath.EndsWith(".jpg") || bgPath.EndsWith(".jpeg"))) { appPath.BackgroundPath = bgPath; } else { appPath.BackgroundPath = ""; } appPath.r_SearchColor = int.Parse(r_SearchColor.Text); appPath.g_SearchColor = int.Parse(g_SearchColor.Text); appPath.b_SearchColor = int.Parse(b_SearchColor.Text); var json = JsonConvert.SerializeObject(appPath); using (var sw = new StreamWriter(config, false, System.Text.Encoding.UTF8)) { sw.Write(json); } DashboardParam.ApplicaitonPath = appPath.ApplicationPath; DashboardParam.BackgroundPath = appPath.BackgroundPath; DashboardParam.rSerachColor = appPath.r_SearchColor; DashboardParam.gSearchColor = appPath.g_SearchColor; DashboardParam.bSearchColor = appPath.b_SearchColor; var observers = Application.Current.Windows.OfType <IObserver>(); foreach (var observer in observers) { observer.Update(); } }