From c40d54ff997f52fda418171f9524794f13bfb40e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9=20=D0=A5=D1=83?= =?UTF-8?q?=D0=B4=D1=8F=D0=BA=D0=BE=D0=B2?= Date: Sun, 4 Oct 2020 14:42:34 +0700 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BE=D1=85=D1=80=D0=B0=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BF=D1=80=D0=BE=D1=84=D0=B8=D0=BB=D1=8F?= =?UTF-8?q?=20=D0=B2=20=D0=BE=D1=82=D0=B4=D0=B5=D0=BB=D1=8C=D0=BD=D0=BE?= =?UTF-8?q?=D0=BC=20=D0=BF=D0=BE=D1=82=D0=BE=D0=BA=D0=B5.=20=D0=98=D0=B7?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D1=81=D0=B8=D0=B8=20=D0=BF=D1=80=D0=BE=D0=B3=D1=80=D0=B0=D0=BC?= =?UTF-8?q?=D0=BC=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SP-EFT-ProfileEditor/MainWindow.xaml.cs | 161 ++++++++++-------- .../Properties/AssemblyInfo.cs | 4 +- 2 files changed, 88 insertions(+), 77 deletions(-) diff --git a/SP-EFT-ProfileEditor/MainWindow.xaml.cs b/SP-EFT-ProfileEditor/MainWindow.xaml.cs index 74cac14..b0458d2 100644 --- a/SP-EFT-ProfileEditor/MainWindow.xaml.cs +++ b/SP-EFT-ProfileEditor/MainWindow.xaml.cs @@ -38,6 +38,7 @@ public partial class MainWindow : MetroWindow private GlobalLang globalLang; private Dictionary itemsDB; private List examinedItems; + private BackgroundWorker SaveProfileWorker; private static string moneyRub = "5449016a4bdc2d6f028b456f"; private static string moneyDol = "5696686a4bdc2da3298b456a"; @@ -61,6 +62,9 @@ public MainWindow() LoadDataWorker = new BackgroundWorker(); LoadDataWorker.DoWork += LoadDataWorker_DoWork; LoadDataWorker.RunWorkerCompleted += LoadDataWorker_RunWorkerCompleted; + SaveProfileWorker = new BackgroundWorker(); + SaveProfileWorker.DoWork += SaveProfileWorker_DoWork; + SaveProfileWorker.RunWorkerCompleted += SaveProfileWorker_RunWorkerCompleted; } private void LoadDataWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) @@ -394,96 +398,103 @@ private void MerchantsMaximumButton_Click(object sender, RoutedEventArgs e) LoadData(); } - private async void SaveProfileButton_Click(object sender, RoutedEventArgs e) + private async void SaveProfileWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { - JsonSerializerSettings seriSettings = new JsonSerializerSettings + progressDialog.CloseAsync(); + if (e.Error != null) { - Formatting = Formatting.Indented, - }; - try - { - string profilepath = Path.Combine(Lang.options.EftServerPath, "user", "profiles", Lang.options.DefaultProfile + ".json"); - JObject jobject = JObject.Parse(File.ReadAllText(profilepath)); - jobject.SelectToken("characters")["pmc"].SelectToken("Info")["Nickname"] = Lang.Character.Info.Nickname; - jobject.SelectToken("characters")["pmc"].SelectToken("Info")["LowerNickname"] = Lang.Character.Info.Nickname.ToLower(); - jobject.SelectToken("characters")["pmc"].SelectToken("Info")["Side"] = Lang.Character.Info.Side; - jobject.SelectToken("characters")["pmc"].SelectToken("Info")["Voice"] = Lang.Character.Info.Voice; - jobject.SelectToken("characters")["pmc"].SelectToken("Info")["Level"] = Lang.Character.Info.Level; - jobject.SelectToken("characters")["pmc"].SelectToken("Info")["Experience"] = Lang.Character.Info.Experience; - for (int index = 0; index < Lang.Character.Inventory.Items.Count(); ++index) - { - if (index < jobject.SelectToken("characters")["pmc"].SelectToken("Inventory").SelectToken("items").ToObject().Count()) - { - var probe = jobject.SelectToken("characters")["pmc"].SelectToken("Inventory").SelectToken("items")[index].ToObject(); - if (probe.Tpl == "557ffd194bdc2d28148b457f" || probe.Tpl == "5af99e9186f7747c447120b8") - { - jobject.SelectToken("characters")["pmc"].SelectToken("Inventory").SelectToken("items")[index]["_tpl"] = BigPocketsSwitcher.IsOn ? "5af99e9186f7747c447120b8" : "557ffd194bdc2d28148b457f"; - } - } - else - jobject.SelectToken("characters")["pmc"].SelectToken("Inventory").SelectToken("items").Last().AddAfterSelf(ExtMethods.RemoveNullAndEmptyProperties(JObject.FromObject(Lang.Character.Inventory.Items[index]))); - } - if (Lang.ItemsForDelete != null && Lang.ItemsForDelete.Count > 0) + await this.ShowMessageAsync(Lang.locale["invalid_server_location_caption"], e.Error.Message, MessageDialogStyle.Affirmative, new MetroDialogSettings { AffirmativeButtonText = Lang.locale["saveprofiledialog_ok"] }); + ExtMethods.Log($"SaveProfileButton_Click | {e.Error.Message}"); + } + else + await this.ShowMessageAsync(Lang.locale["saveprofiledialog_title"], Lang.locale["saveprofiledialog_caption"], MessageDialogStyle.Affirmative, new MetroDialogSettings { AffirmativeButtonText = Lang.locale["saveprofiledialog_ok"] }); + LoadBackups(); + } + + private void SaveProfileWorker_DoWork(object sender, DoWorkEventArgs e) + { + JsonSerializerSettings seriSettings = new JsonSerializerSettings { Formatting = Formatting.Indented }; + string profilepath = Path.Combine(Lang.options.EftServerPath, "user", "profiles", Lang.options.DefaultProfile + ".json"); + JObject jobject = JObject.Parse(File.ReadAllText(profilepath)); + jobject.SelectToken("characters")["pmc"].SelectToken("Info")["Nickname"] = Lang.Character.Info.Nickname; + jobject.SelectToken("characters")["pmc"].SelectToken("Info")["LowerNickname"] = Lang.Character.Info.Nickname.ToLower(); + jobject.SelectToken("characters")["pmc"].SelectToken("Info")["Side"] = Lang.Character.Info.Side; + jobject.SelectToken("characters")["pmc"].SelectToken("Info")["Voice"] = Lang.Character.Info.Voice; + jobject.SelectToken("characters")["pmc"].SelectToken("Info")["Level"] = Lang.Character.Info.Level; + jobject.SelectToken("characters")["pmc"].SelectToken("Info")["Experience"] = Lang.Character.Info.Experience; + for (int index = 0; index < Lang.Character.Inventory.Items.Count(); ++index) + { + if (index < jobject.SelectToken("characters")["pmc"].SelectToken("Inventory").SelectToken("items").ToObject().Count()) { - foreach (var del in jobject.SelectToken("characters")["pmc"].SelectToken("Inventory").SelectToken("items").ToList()) + var probe = jobject.SelectToken("characters")["pmc"].SelectToken("Inventory").SelectToken("items")[index].ToObject(); + if (probe.Tpl == "557ffd194bdc2d28148b457f" || probe.Tpl == "5af99e9186f7747c447120b8") { - string id = del.ToObject().Id; - if (Lang.ItemsForDelete.Contains(id)) - { - del.Remove(); - Lang.ItemsForDelete.Remove(id); - } + Dispatcher.Invoke(() => jobject.SelectToken("characters")["pmc"].SelectToken("Inventory").SelectToken("items")[index]["_tpl"] = BigPocketsSwitcher.IsOn ? "5af99e9186f7747c447120b8" : "557ffd194bdc2d28148b457f"); } } - for (int index = 0; index < Lang.Character.Skills.Common.Count(); ++index) - { - var probe = jobject.SelectToken("characters")["pmc"].SelectToken("Skills").SelectToken("Common")[index].ToObject(); - jobject.SelectToken("characters")["pmc"].SelectToken("Skills").SelectToken("Common")[index]["Progress"] = Lang.Character.Skills.Common.Where(x => x.Id == probe.Id).FirstOrDefault().Progress; - } - for (int index = 0; index < Lang.Character.Hideout.Areas.Count(); ++index) - { - var probe = jobject.SelectToken("characters")["pmc"].SelectToken("Hideout").SelectToken("Areas")[index].ToObject(); - jobject.SelectToken("characters")["pmc"].SelectToken("Hideout").SelectToken("Areas")[index]["level"] = Lang.Character.Hideout.Areas.Where(x => x.Type == probe.Type).FirstOrDefault().Level; - } - foreach (var tr in Lang.Character.TraderStandings) - { - jobject.SelectToken("characters")["pmc"].SelectToken("TraderStandings").SelectToken(tr.Key)["currentLevel"] = Lang.Character.TraderStandings[tr.Key].CurrentLevel; - jobject.SelectToken("characters")["pmc"].SelectToken("TraderStandings").SelectToken(tr.Key)["currentSalesSum"] = Lang.Character.TraderStandings[tr.Key].CurrentSalesSum; - jobject.SelectToken("characters")["pmc"].SelectToken("TraderStandings").SelectToken(tr.Key)["currentStanding"] = Lang.Character.TraderStandings[tr.Key].CurrentStanding; - if (Lang.Character.TraderStandings[tr.Key].CurrentLevel > 1) - jobject.SelectToken("characters")["pmc"].SelectToken("TraderStandings").SelectToken(tr.Key)["display"] = true; - } - if (Lang.Character.Quests.Count() > 0) + else + jobject.SelectToken("characters")["pmc"].SelectToken("Inventory").SelectToken("items").Last().AddAfterSelf(ExtMethods.RemoveNullAndEmptyProperties(JObject.FromObject(Lang.Character.Inventory.Items[index]))); + } + if (Lang.ItemsForDelete != null && Lang.ItemsForDelete.Count > 0) + { + foreach (var del in jobject.SelectToken("characters")["pmc"].SelectToken("Inventory").SelectToken("items").ToList()) { - for (int index = 0; index < Lang.Character.Quests.Count(); ++index) + string id = del.ToObject().Id; + if (Lang.ItemsForDelete.Contains(id)) { - var probe = jobject.SelectToken("characters")["pmc"].SelectToken("Quests")[index].ToObject(); - jobject.SelectToken("characters")["pmc"].SelectToken("Quests")[index]["status"] = Lang.Character.Quests.Where(x => x.Qid == probe.Qid).FirstOrDefault().Status; + del.Remove(); + Lang.ItemsForDelete.Remove(id); } } - for (int index = 0; index < Lang.Character.Skills.Mastering.Count(); ++index) + } + for (int index = 0; index < Lang.Character.Skills.Common.Count(); ++index) + { + var probe = jobject.SelectToken("characters")["pmc"].SelectToken("Skills").SelectToken("Common")[index].ToObject(); + jobject.SelectToken("characters")["pmc"].SelectToken("Skills").SelectToken("Common")[index]["Progress"] = Lang.Character.Skills.Common.Where(x => x.Id == probe.Id).FirstOrDefault().Progress; + } + for (int index = 0; index < Lang.Character.Hideout.Areas.Count(); ++index) + { + var probe = jobject.SelectToken("characters")["pmc"].SelectToken("Hideout").SelectToken("Areas")[index].ToObject(); + jobject.SelectToken("characters")["pmc"].SelectToken("Hideout").SelectToken("Areas")[index]["level"] = Lang.Character.Hideout.Areas.Where(x => x.Type == probe.Type).FirstOrDefault().Level; + } + foreach (var tr in Lang.Character.TraderStandings) + { + jobject.SelectToken("characters")["pmc"].SelectToken("TraderStandings").SelectToken(tr.Key)["currentLevel"] = Lang.Character.TraderStandings[tr.Key].CurrentLevel; + jobject.SelectToken("characters")["pmc"].SelectToken("TraderStandings").SelectToken(tr.Key)["currentSalesSum"] = Lang.Character.TraderStandings[tr.Key].CurrentSalesSum; + jobject.SelectToken("characters")["pmc"].SelectToken("TraderStandings").SelectToken(tr.Key)["currentStanding"] = Lang.Character.TraderStandings[tr.Key].CurrentStanding; + if (Lang.Character.TraderStandings[tr.Key].CurrentLevel > 1) + jobject.SelectToken("characters")["pmc"].SelectToken("TraderStandings").SelectToken(tr.Key)["display"] = true; + } + if (Lang.Character.Quests.Count() > 0) + { + for (int index = 0; index < Lang.Character.Quests.Count(); ++index) { - var probe = jobject.SelectToken("characters")["pmc"].SelectToken("Skills").SelectToken("Mastering")[index].ToObject(); - jobject.SelectToken("characters")["pmc"].SelectToken("Skills").SelectToken("Mastering")[index]["Progress"] = Lang.Character.Skills.Mastering.Where(x => x.Id == probe.Id).FirstOrDefault().Progress; + var probe = jobject.SelectToken("characters")["pmc"].SelectToken("Quests")[index].ToObject(); + jobject.SelectToken("characters")["pmc"].SelectToken("Quests")[index]["status"] = Lang.Character.Quests.Where(x => x.Qid == probe.Qid).FirstOrDefault().Status; } - jobject.SelectToken("characters")["pmc"].SelectToken("Encyclopedia").Replace(JToken.FromObject(Lang.Character.Encyclopedia)); - DateTime now = DateTime.Now; - if (!Directory.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Backups"))) - Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Backups")); - if (!Directory.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Backups", Lang.options.DefaultProfile))) - Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Backups", Lang.options.DefaultProfile)); - string backupfile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Backups", Lang.options.DefaultProfile, $"{Lang.options.DefaultProfile}-backup-{now:dd-MM-yyyy-HH-mm-ss}.json"); - File.Copy(profilepath, backupfile, true); - string json = JsonConvert.SerializeObject(jobject, seriSettings); - File.WriteAllText(profilepath, json); - await this.ShowMessageAsync(Lang.locale["saveprofiledialog_title"], Lang.locale["saveprofiledialog_caption"], MessageDialogStyle.Affirmative, new MetroDialogSettings { AffirmativeButtonText = Lang.locale["saveprofiledialog_ok"] }); } - catch (Exception ex) + for (int index = 0; index < Lang.Character.Skills.Mastering.Count(); ++index) { - ExtMethods.Log($"SaveProfileButton_Click | {ex.GetType().Name}: {ex.Message}"); - await this.ShowMessageAsync(Lang.locale["invalid_server_location_caption"], $"{ex.GetType().Name}: {ex.Message}", MessageDialogStyle.Affirmative, new MetroDialogSettings { AffirmativeButtonText = Lang.locale["saveprofiledialog_ok"] }); + var probe = jobject.SelectToken("characters")["pmc"].SelectToken("Skills").SelectToken("Mastering")[index].ToObject(); + jobject.SelectToken("characters")["pmc"].SelectToken("Skills").SelectToken("Mastering")[index]["Progress"] = Lang.Character.Skills.Mastering.Where(x => x.Id == probe.Id).FirstOrDefault().Progress; } - LoadBackups(); + jobject.SelectToken("characters")["pmc"].SelectToken("Encyclopedia").Replace(JToken.FromObject(Lang.Character.Encyclopedia)); + DateTime now = DateTime.Now; + if (!Directory.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Backups"))) + Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Backups")); + if (!Directory.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Backups", Lang.options.DefaultProfile))) + Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Backups", Lang.options.DefaultProfile)); + string backupfile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Backups", Lang.options.DefaultProfile, $"{Lang.options.DefaultProfile}-backup-{now:dd-MM-yyyy-HH-mm-ss}.json"); + File.Copy(profilepath, backupfile, true); + string json = JsonConvert.SerializeObject(jobject, seriSettings); + File.WriteAllText(profilepath, json); + } + + private async void SaveProfileButton_Click(object sender, RoutedEventArgs e) + { + progressDialog = await this.ShowProgressAsync(Lang.locale["progressdialog_title"], Lang.locale["saveprofiledialog_title"]); + progressDialog.SetIndeterminate(); + SaveProfileWorker.RunWorkerAsync(); } private void LoadBackups() diff --git a/SP-EFT-ProfileEditor/Properties/AssemblyInfo.cs b/SP-EFT-ProfileEditor/Properties/AssemblyInfo.cs index 0005897..520695d 100644 --- a/SP-EFT-ProfileEditor/Properties/AssemblyInfo.cs +++ b/SP-EFT-ProfileEditor/Properties/AssemblyInfo.cs @@ -51,5 +51,5 @@ // Можно задать все значения или принять номера сборки и редакции по умолчанию // используя "*", как показано ниже: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyVersion("1.1.0.0")] +[assembly: AssemblyFileVersion("1.1.0.0")]