Ejemplo n.º 1
0
        public ConfigManager()
        {
            // app settings
            _settingsHandler = new SettingsHandler();
            CommonSettings   = _settingsHandler.Load(AppDomain.CurrentDomain.BaseDirectory + "settings.cfg");
            if (CommonSettings == null)
            {
                CommonSettings = _settingsHandler.GetDefault();
                _settingsHandler.Save(CommonSettings, AppDomain.CurrentDomain.BaseDirectory + "settings.cfg");
            }

            // profile
            _profileHandler = new ProfileHandler();
            ProfileList     = new Dictionary <String, Profile>();
            if (!LoadProfiles())
            {
                CurrentProfile = _profileHandler.GetDefault();
                ProfileList.Add(CurrentProfile.Name, CurrentProfile);
                SaveProfile();
            }
            else
            {
                if (ProfileList.TryGetValue(CommonSettings.DefaultProfile, out Profile profile))
                {
                    CurrentProfile = profile;
                }
                else
                {
                    CurrentProfile = ProfileList.Values.OrderBy(p => p.Name).ToList().ElementAt(0);
                    CommonSettings.DefaultProfile = CurrentProfile.Name;
                    SaveSettings();
                }
            }

            // app language
            _languageHandler = new LanguageHandler();
            Languages        = _languageHandler.Load(AppDomain.CurrentDomain.BaseDirectory + "locale\\");
            CurrentLanguage  = Languages.GetLocalizations().TryGetValue(CommonSettings.Language, out var loc)
                    ? loc
                    : Languages.GetLocalizations()["English"];

            EventOnLanguageChange = (name) =>
            {
                CurrentLanguage = Languages.GetLocalizations().TryGetValue(name, out loc)
                    ? loc
                    : Languages.GetLocalizations()["English"];
                CommonSettings.Language = CurrentLanguage["Locale"];
            };
        }
Ejemplo n.º 2
0
        public bool AddProfile(string name)
        {
            Profile profile = _profileHandler.GetDefault();

            profile.Name = name;

            if (ProfileList.ContainsKey(profile.Name))
            {
                return(false);
            }

            ProfileList.Add(profile.Name, profile);

            if (!_profileHandler.Save(profile, AppDomain.CurrentDomain.BaseDirectory + "profiles\\" + profile.Name))
            {
                EventOnIOProfileFail.Invoke("Cannot save profile file: <" + profile.Name + ">",
                                            "Load profile exception");
                return(false);
            }

            return(true);
        }