private void SaveButton_Click(object sender, EventArgs e) { var settings = new SettingObject(); if (textBox1.TextLength > 0) { settings.payAddress = textBox1.Text; } if (textBox2.TextLength > 0) { var daysInCycle = 0; if (!int.TryParse(textBox2.Text, out daysInCycle)) { MessageBox.Show("Данный параметр принимает только цифры", "Кол-во дней в статистике"); } else { settings.daysInCycle = daysInCycle; } } settingService.UpdateSettings(settings); ((MainForm)Owner).InitProvider(); Close(); }
private async Task LoadConfig() { string json = null; bool ok = ApplicationData.Current.LocalSettings.Values.TryGetValue("config", out object temp); if (ok) { json = temp.ToString(); } if (string.IsNullOrEmpty(json)) { SettingObject setting = SettingObject.GetDefaultSetting(); json = await JsonHelper.JsonSerializeAsync(setting); } var config = await JsonHelper.JsonDeserializeAsync <SettingObject>(json); if (config.General == null) { config.General = new GeneralSetting(); } //UWP string descPath = Path.Combine(Windows.ApplicationModel.Package.Current.InstalledLocation.Path, "Res\\setting.desc.json"); var descConfig = await JsonHelper.JsonDeserializeFromFileAsync <dynamic>(descPath); JsonConfierViewModel = _jcrService.GetVM(JObject.FromObject(config), descConfig); }
public static async Task ApplySetting(SettingObject setting) { LocalWallpaperDir = Setting.General.WallpaperSaveDir; string cultureName = setting.General.CurrentLan; if (cultureName == null) { cultureName = Thread.CurrentThread.CurrentUICulture.Name; } Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(cultureName); await LanService.UpdateLanguage(); try { await _desktopBridgeStartupManager.Set(setting.General.StartWithWindows); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); } setting.General.StartWithWindows = await _desktopBridgeStartupManager.Check(); //WallpaperManager.VideoAspect = setting.Wallpaper.VideoAspect; LiveWallpaper.WallpaperManager.WallpaperManager.ApplyVideoAspect(setting.Wallpaper.VideoAspect); }
public void SaveSettings(SettingObject settings) { using (var fs = new FileStream("./settings.sdat", FileMode.OpenOrCreate)) { var bw = new BinaryWriter(fs); bw.Write(settings.payAddress); bw.Write(settings.daysInCycle); bw.Flush(); } }
public async Task <SettingObject> LoadConfig() { var config = await JsonHelper.JsonDeserializeFromFileAsync <SettingObject>(SettingPath); if (config == null) { config = SettingObject.GetDefaultSetting(); } config.CheckDefaultSetting(); Setting = config; return(config); }
public static async Task ApplySetting(SettingObject setting) { Setting = setting; Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(setting.General.CurrentLan); await LanService.UpdateLanguage(); await AutoStartupHelper.Instance.Set(setting.General.StartWithWindows); setting.General.StartWithWindows = await AutoStartupHelper.Instance.Check(); WallpaperManager.VideoAspect = setting.Wallpaper.VideoAspect; WallpaperManager.ApplyVideoAspect(); }
//检查是否有配置需要重新生成 private static async Task CheckDefaultSetting() { var tempSetting = await JsonHelper.JsonDeserializeFromFileAsync <SettingObject>(SettingPath); bool writeDefault = false; if (tempSetting == null) { //默认值 tempSetting = new SettingObject { General = GeneralSettting.GetDefaultGeneralSettting(), Wallpaper = WallpaperSetting.GetDefaultWallpaperSetting(), //Server = ServerSetting.GetDefaultServerSetting() }; writeDefault = true; } //默认值 if (tempSetting.General == null) { writeDefault = true; tempSetting.General = GeneralSettting.GetDefaultGeneralSettting(); } if (string.IsNullOrEmpty(tempSetting.General.WallpaperSaveDir)) { writeDefault = true; tempSetting.General.WallpaperSaveDir = GeneralSettting.GetDefaultSaveDir(); } if (tempSetting.Wallpaper == null) { writeDefault = true; tempSetting.Wallpaper = WallpaperSetting.GetDefaultWallpaperSetting(); } //if (tempSetting.Server == null) //{ // writeDefault = true; // tempSetting.Server = ServerSetting.GetDefaultServerSetting(); //} if (writeDefault) { //生成默认配置 await JsonHelper.JsonSerializeAsync(tempSetting, SettingPath); } await ApplySetting(tempSetting); }
public SettingObject GetSettings() { var settings = new SettingObject(); using (var fs = new FileStream("./settings.sdat", FileMode.OpenOrCreate)) { if (fs.Length > 0) { var br = new BinaryReader(fs); settings.payAddress = br.ReadString(); settings.daysInCycle = br.ReadInt32(); } } return(settings); }
/// <summary> /// Handles the finish of the work /// </summary> private void WorkerCompleted(Object sender, RunWorkerCompletedEventArgs e) { if (((Boolean)e.Result)) { if (!File.Exists(FileNameHelper.SettingData)) { SettingObject settings = SettingObject.GetDefaultSettings(); MainForm.Instance.AppSettings = settings; } Globals.Settings.LatestCommand = this.commands.LatestCommand; this.Close(); } else { this.infoLabel.Text = TextHelper.GetString("Info.InitFailed"); this.pictureBox.Click += new EventHandler(this.FirstRunDialogClick); this.progressBar.Click += new EventHandler(this.FirstRunDialogClick); this.infoLabel.Click += new EventHandler(this.FirstRunDialogClick); } }
public static async Task ApplySetting(SettingObject setting) { LocalWallpaperDir = Setting.General.WallpaperSaveDir; string cultureName = setting.General.CurrentLan; if (cultureName == null) { cultureName = Thread.CurrentThread.CurrentUICulture.Name; } Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(cultureName); await LanService.UpdateLanguage(); await AutoStartupHelper.Instance.Set(setting.General.StartWithWindows); setting.General.StartWithWindows = await AutoStartupHelper.Instance.Check(); //WallpaperManager.VideoAspect = setting.Wallpaper.VideoAspect; WallpaperManager.ApplyVideoAspect(setting.Wallpaper.VideoAspect); }
public async Task LoadConfig() { string json = null; bool ok = ApplicationData.Current.LocalSettings.Values.TryGetValue("config", out object temp); if (ok) { json = temp.ToString(); } if (string.IsNullOrEmpty(json)) { SettingObject setting = SettingObject.GetDefaultSetting(); json = await JsonHelper.JsonSerializeAsync(setting); } var config = await JsonHelper.JsonDeserializeAsync <SettingObject>(json); config.CheckDefaultSetting(); Setting = config; }
public static async Task ApplySetting(SettingObject setting) { LocalWallpaperDir = Setting.General.WallpaperSaveDir; string cultureName = setting.General.CurrentLan; if (cultureName == null) { cultureName = Thread.CurrentThread.CurrentUICulture.Name; } Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(cultureName); await LanService.UpdateLanguage(); try { await _startupManager.Set(setting.General.StartWithWindows); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); } setting.General.StartWithWindows = await _startupManager.Check(); var screenSetting = WallpaperManager.Instance.ScreenIndexs.Select((m) => new ScreenOption() { ScreenIndex = m, WhenAppMaximized = setting.Wallpaper.ActionWhenMaximized, }).ToList(); var liveWallpaperOptions = new LiveWallpaperOptions { AppMaximizedEffectAllScreen = true, AudioScreenIndex = setting.Wallpaper.AudioSource, ScreenOptions = screenSetting }; await WallpaperManager.Instance.SetOptions(liveWallpaperOptions); }
public void UpdateSettings(SettingObject settings) { settingRepository.SaveSettings(settings); }
public static void ApplyWallpaper(SettingObject setting) { WallpaperManager.InitMonitor(setting.Wallpaper.DisplayMonitor); WallpaperManager.PlayAudio(setting.Wallpaper.AudioSource); }
public static void LoadSettingJSON() { if (!File.Exists(Path.Combine(Loader.APPDIR, SettingFile))) { GenerateSettingJSON(DefaultSetting.GlobalSettingObject); GlobalSetting = DefaultSetting.GlobalSettingObject; LoadSettingJSON(); } else { var o = JObject.Parse(File.ReadAllText(Path.Combine(Loader.APPDIR, SettingFile))); if (GlobalSetting == null) { GlobalSetting = new GlobalSettingObject(); } foreach (FieldInfo fi in GlobalSetting.GetType().GetFields()) { foreach (JProperty p in o["PluginConfig"]) { if (fi.Name == p.Name) { if (fi.FieldType == typeof(string)) { GlobalSetting.GetType().GetField(fi.Name).SetValue(GlobalSetting, p.Value.ToString()); } else if (fi.FieldType == typeof(int)) { GlobalSetting.GetType().GetField(fi.Name).SetValue(GlobalSetting, int.Parse(p.Value.ToString())); } else if (fi.FieldType == typeof(bool)) { GlobalSetting.GetType().GetField(fi.Name).SetValue(GlobalSetting, p.Value.ToString() == "True" ? true : false); } } } } if (o["PluginConfig"]["Overlays"] != null) { foreach (JProperty p in o["PluginConfig"]["Overlays"]) { if (o["PluginConfig"]["Overlays"][p.Name] != null) { var so = new SettingObject(); foreach (FieldInfo fi in so.GetType().GetFields()) { foreach (JProperty jo in o["PluginConfig"]["Overlays"][p.Name]) { if (fi.Name == jo.Name) { if (fi.FieldType == typeof(string)) { so.GetType().GetField(fi.Name).SetValue(so, jo.Value.ToString()); } else if (fi.FieldType == typeof(int)) { so.GetType().GetField(fi.Name).SetValue(so, int.Parse(jo.Value.ToString())); } else if (fi.FieldType == typeof(bool)) { so.GetType().GetField(fi.Name).SetValue(so, jo.Value.ToString() == "True" ? true : false); } } } } so.Name = p.Name; OverlayController.OverlayConfigs.Add(p.Name, new OverlayTabPage(so.CreateOverlayConfig())); } } } } // LoadSettingJSON }