public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value == null) { return(Visibility.Visible); } return((ExtMethods.PathIsEftServerBase((PEOptions)value) && ExtMethods.ServerHaveProfiles((PEOptions)value)) ? Visibility.Hidden : Visibility.Visible); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value == null) { return(false); } return(ExtMethods.PathIsEftServerBase(value.ToString()) && ExtMethods.ServerHaveProfiles(value.ToString())); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value == null) { return(Visibility.Visible); } if (!ExtMethods.ServerHaveProfiles((PEOptions)value)) { return(Visibility.Visible); } return(Visibility.Collapsed); }
public static MainData Load() { if (!Directory.Exists(LangPath)) { Directory.CreateDirectory(LangPath); } if (!File.Exists(Path.Combine(LangPath, "en.json"))) { File.WriteAllText(Path.Combine(LangPath, "en.json"), JsonConvert.SerializeObject(EN, Formatting.Indented)); } if (!File.Exists(Path.Combine(LangPath, "ru.json"))) { File.WriteAllText(Path.Combine(LangPath, "ru.json"), JsonConvert.SerializeObject(RU, Formatting.Indented)); } if (!File.Exists(Path.Combine(LangPath, "fr.json"))) { File.WriteAllText(Path.Combine(LangPath, "fr.json"), JsonConvert.SerializeObject(FR, Formatting.Indented)); } if (!File.Exists(Path.Combine(LangPath, "ge.json"))) { File.WriteAllText(Path.Combine(LangPath, "ge.json"), JsonConvert.SerializeObject(GE, Formatting.Indented)); } PEOptions eOptions = CreateOptions(); if (string.IsNullOrEmpty(eOptions.Language)) { eOptions.Language = ExtMethods.GetWindowsCulture(); } Dictionary <string, string> Locale = JsonConvert.DeserializeObject <Dictionary <string, string> >(File.ReadAllText(Path.Combine(LangPath, eOptions.Language + ".json"))); Dictionary <string, string> Eth = new Dictionary <string, string>(); switch (eOptions.Language) { case "en": Eth = EN; break; case "ge": Eth = GE; break; case "ru": Eth = RU; break; case "fr": Eth = FR; break; } bool needReSave = false; foreach (var lc in Eth) { if (!Locale.ContainsKey(lc.Key)) { Locale.Add(lc.Key, lc.Value); needReSave = true; } } if (needReSave) { File.WriteAllText(Path.Combine(LangPath, $"{eOptions.Language}.json"), JsonConvert.SerializeObject(Locale, Formatting.Indented)); } MainData lang = new MainData { locale = Locale, options = eOptions, characterInventory = new CharacterInventory { Rubles = 0, Euros = 0, Dollars = 0 } }; try { if (!string.IsNullOrEmpty(eOptions.EftServerPath) && !ExtMethods.PathIsEftServerBase(eOptions)) { eOptions.EftServerPath = null; } if (!string.IsNullOrEmpty(eOptions.DefaultProfile) && !string.IsNullOrEmpty(eOptions.EftServerPath) && !File.Exists(Path.Combine(eOptions.EftServerPath, eOptions.DirsList["dir_profiles"], eOptions.DefaultProfile + ".json"))) { eOptions.DefaultProfile = null; } if (!string.IsNullOrEmpty(eOptions.EftServerPath) && ExtMethods.ServerHaveProfiles(eOptions)) { lang.Profiles = Directory.GetFiles(Path.Combine(eOptions.EftServerPath, eOptions.DirsList["dir_profiles"])).Select(x => Path.GetFileNameWithoutExtension(x)).ToList(); if (lang.Profiles.Count > 0 && (string.IsNullOrEmpty(eOptions.DefaultProfile) || !lang.Profiles.Contains(eOptions.DefaultProfile))) { eOptions.DefaultProfile = lang.Profiles.FirstOrDefault(); } } if (!string.IsNullOrEmpty(eOptions.EftServerPath) && !string.IsNullOrEmpty(eOptions.DefaultProfile)) { var Pr = JsonConvert.DeserializeObject <Profile>(File.ReadAllText(Path.Combine(eOptions.EftServerPath, eOptions.DirsList["dir_profiles"], eOptions.DefaultProfile + ".json"))); lang.Character = Pr.characters?.pmc; if (lang.Character == null) { lang.Character = new Character(); } lang.Character.Suits = Pr.suits?.ToList(); lang.Character.WeaponPresets = Pr.weaponbuilds; } if (lang.Character != null && lang.Character.Info != null && lang.Character.Inventory != null && lang.Character.TraderStandings != null && lang.Character.Skills != null) { lang.ProfileHash = JsonConvert.SerializeObject(lang.Character).ToString().GetHashCode(); } } catch (Exception ex) { DialogManager.ShowMessageAsync(Application.Current.MainWindow as MetroWindow, lang.locale["invalid_server_location_caption"], $"{ex.GetType().Name}: {ex.Message}", MessageDialogStyle.Affirmative, new MetroDialogSettings { AffirmativeButtonText = lang.locale["saveprofiledialog_ok"], AnimateShow = true, AnimateHide = true }); ExtMethods.Log($"Error loading profile: {ex.GetType().Name}: {ex.Message}{Environment.NewLine}{ex.StackTrace}"); } return(lang); }
public static MainData Load() { if (!Directory.Exists(LangPath)) { Directory.CreateDirectory(LangPath); } if (!File.Exists(Path.Combine(LangPath, "en.json"))) { File.WriteAllText(Path.Combine(LangPath, "en.json"), JsonConvert.SerializeObject(EN, Formatting.Indented)); } if (!File.Exists(Path.Combine(LangPath, "ru.json"))) { File.WriteAllText(Path.Combine(LangPath, "ru.json"), JsonConvert.SerializeObject(RU, Formatting.Indented)); } if (!File.Exists(Path.Combine(LangPath, "fr.json"))) { File.WriteAllText(Path.Combine(LangPath, "fr.json"), JsonConvert.SerializeObject(FR, Formatting.Indented)); } if (!File.Exists(Path.Combine(LangPath, "ge.json"))) { File.WriteAllText(Path.Combine(LangPath, "ge.json"), JsonConvert.SerializeObject(GE, Formatting.Indented)); } PEOptions eOptions = CreateOptions(); if (string.IsNullOrEmpty(eOptions.Language)) { eOptions.Language = "en"; } Dictionary <string, string> Locale = JsonConvert.DeserializeObject <Dictionary <string, string> >(File.ReadAllText(Path.Combine(LangPath, eOptions.Language + ".json"))); Dictionary <string, string> Eth = new Dictionary <string, string>(); switch (eOptions.Language) { case "en": Eth = EN; break; case "ge": Eth = GE; break; case "ru": Eth = RU; break; case "fr": Eth = FR; break; } bool needReSave = false; foreach (var lc in Eth) { if (!Locale.ContainsKey(lc.Key)) { Locale.Add(lc.Key, lc.Value); needReSave = true; } } if (needReSave) { File.WriteAllText(Path.Combine(LangPath, $"{eOptions.Language}.json"), JsonConvert.SerializeObject(Locale, Formatting.Indented)); } MainData lang = new MainData { locale = Locale, options = eOptions, characterInventory = new CharacterInventory { Rubles = 0, Euros = 0, Dollars = 0 } }; if (!string.IsNullOrEmpty(eOptions.EftServerPath) && !ExtMethods.PathIsEftServerBase(eOptions.EftServerPath)) { eOptions.EftServerPath = null; } if (!string.IsNullOrEmpty(eOptions.DefaultProfile) && !string.IsNullOrEmpty(eOptions.EftServerPath) && !File.Exists(Path.Combine(eOptions.EftServerPath, "user\\profiles", eOptions.DefaultProfile + ".json"))) { eOptions.DefaultProfile = null; } if (!string.IsNullOrEmpty(eOptions.EftServerPath) && ExtMethods.ServerHaveProfiles(eOptions.EftServerPath)) { lang.Profiles = Directory.GetFiles(eOptions.EftServerPath + "\\user\\profiles").Select(x => Path.GetFileNameWithoutExtension(x)).ToList(); if (lang.Profiles.Count > 0 && (string.IsNullOrEmpty(eOptions.DefaultProfile) || !lang.Profiles.Contains(eOptions.DefaultProfile))) { eOptions.DefaultProfile = lang.Profiles.FirstOrDefault(); } } if (!string.IsNullOrEmpty(eOptions.EftServerPath) && !string.IsNullOrEmpty(eOptions.DefaultProfile)) { var Pr = JsonConvert.DeserializeObject <Profile>(File.ReadAllText(Path.Combine(eOptions.EftServerPath, "user\\profiles", eOptions.DefaultProfile + ".json"))); lang.Character = Pr.characters.pmc; if (Pr.suits != null && Pr.suits.Count() > 0) { lang.Character.Suits = Pr.suits.ToList(); } } if (lang.Character != null && lang.Character.Info != null && lang.Character.Inventory != null && lang.Character.TraderStandings != null && lang.Character.Skills != null) { lang.ProfileHash = JsonConvert.SerializeObject(lang.Character).ToString().GetHashCode(); } return(lang); }