예제 #1
0
        public static bool PathIsEftServerBase(PEOptions options, string path = null)
        {
            if (string.IsNullOrEmpty(path))
            {
                path = options.EftServerPath;
            }
            if (string.IsNullOrEmpty(path))
            {
                return(false);
            }
            if (!Directory.Exists(path))
            {
                return(false);
            }
            if (options.FilesList.Any(x => !File.Exists(Path.Combine(path, x.Value))))
            {
                return(false);
            }
            if (options.DirsList.Any(x => !Directory.Exists(Path.Combine(path, x.Value))))
            {
                return(false);
            }

            return(true);
        }
예제 #2
0
 public static bool ServerHaveProfiles(PEOptions options)
 {
     if (string.IsNullOrEmpty(options.EftServerPath))
     {
         return(false);
     }
     if (!Directory.Exists(Path.Combine(options.EftServerPath, options.DirsList["dir_profiles"])))
     {
         return(false);
     }
     if (Directory.GetFiles(Path.Combine(options.EftServerPath, options.DirsList["dir_profiles"])).Count() < 1)
     {
         return(false);
     }
     return(true);
 }
예제 #3
0
        private static PEOptions CreateOptions()
        {
            if (!File.Exists(PeoPath))
            {
                return new PEOptions
                       {
                           DirsList = new Dictionary <string, string>
                           {
                               ["dir_globals"]  = "Aki_Data\\Server\\eft-database\\db\\locales\\global",
                               ["dir_traders"]  = "Aki_Data\\Server\\eft-database\\db\\traders",
                               ["dir_profiles"] = "user\\profiles"
                           },
                           FilesList = new Dictionary <string, string>
                           {
                               ["file_globals"]   = "Aki_Data\\Server\\eft-database\\db\\globals.json",
                               ["file_items"]     = "Aki_Data\\Server\\eft-database\\db\\templates\\items.json",
                               ["file_quests"]    = "Aki_Data\\Server\\eft-database\\db\\templates\\quests.json",
                               ["file_usec"]      = "Aki_Data\\Server\\eft-database\\db\\bots\\types\\usec.json",
                               ["file_bear"]      = "Aki_Data\\Server\\eft-database\\db\\bots\\types\\bear.json",
                               ["file_areas"]     = "Aki_Data\\Server\\eft-database\\db\\hideout\\areas.json",
                               ["file_serverexe"] = "Server.exe"
                           }
                       }
            }
            ;

            string    json = File.ReadAllText(PeoPath);
            PEOptions peo  = null;

            try
            {
                peo = JsonConvert.DeserializeObject <PEOptions>(json);
            }
            catch (Exception ex)
            {
                Debug.Print($"Error loading PEOptions.json: {ex.GetType().Name}: {ex.Message}{Environment.NewLine}{ex.StackTrace}");
                return(new PEOptions());
            }

            return(peo);
        }
        private static PEOptions CreateOptions()
        {
            if (!File.Exists(PeoPath))
            {
                return(new PEOptions());
            }

            string    json = File.ReadAllText(PeoPath);
            PEOptions peo  = null;

            try
            {
                peo = JsonConvert.DeserializeObject <PEOptions>(json);
            }
            catch (Exception ex)
            {
                Debug.Print($"Error loading PEOptions.json: {ex.GetType().Name}: {ex.Message}{Environment.NewLine}{ex.StackTrace}");
                return(new PEOptions());
            }

            return(peo);
        }
예제 #5
0
        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);
        }