コード例 #1
0
        public static bool CreateProfile(string profile)
        {
            MCProfile profileSettings = new MCProfile();

            if (ProfileList == null)
            {
                ProfileList = new MCProfilesList();
            }

            if (ProfileList.profiles.ContainsKey(profile))
            {
                return(false);
            }
            else
            {
                // default settings
                profileSettings.Name          = profile;
                profileSettings.ProfilePath   = ValidatePathName(profile);
                profileSettings.Installations = new List <MCInstallation>();

                ProfileList.profiles.Add(profile, profileSettings);

                Properties.LauncherSettings.Default.CurrentProfile = profile;
                Properties.LauncherSettings.Default.Save();

                SaveProfiles();
                return(true);
            }

            string ValidatePathName(string pathName)
            {
                char[] invalidFileNameChars = Path.GetInvalidFileNameChars();
                return(new string(pathName.Where(ch => !invalidFileNameChars.Contains(ch)).ToArray()));
            }
        }
コード例 #2
0
        public static MCProfilesList CleanProfiles()
        {
            MCProfilesList cleaned_list = ProfileList;

            foreach (var profile in cleaned_list.profiles)
            {
                profile.Value.Installations.RemoveAll(x => x.ReadOnly);
            }
            return(cleaned_list);
        }
コード例 #3
0
        public static void LoadProfiles()
        {
            string         json;
            MCProfilesList profileList;

            if (File.Exists(Filepaths.GetProfilesFilePath()))
            {
                json = File.ReadAllText(Filepaths.GetProfilesFilePath());
                try { profileList = JsonConvert.DeserializeObject <MCProfilesList>(json, JsonSerializerSettings); }
                catch { profileList = new MCProfilesList(); }
            }
            else
            {
                profileList = new MCProfilesList();
            }

            if (profileList.profiles == null)
            {
                profileList.profiles = new Dictionary <string, MCProfile>();
            }

            System.Diagnostics.Debug.WriteLine("Profile count: " + profileList.profiles.Count);
            foreach (MCProfile setting in profileList.profiles.Values)
            {
                System.Diagnostics.Debug.WriteLine("\nProfile found!: ");
                System.Diagnostics.Debug.WriteLine("Name: " + setting.Name);
                System.Diagnostics.Debug.WriteLine("Path: " + setting.ProfilePath);

                if (setting.Installations == null)
                {
                    setting.Installations = new List <MCInstallation>();
                }
                System.Diagnostics.Debug.WriteLine("Installations: " + setting.Installations.Count);
            }

            ProfileList = profileList;

            if (ProfileList.profiles.Count() == 0)
            {
                ViewModels.LauncherModel.Default.SetOverlayFrame(new Pages.FirstLaunch.WelcomePage());
            }
        }
コード例 #4
0
 private void LoadConfig()
 {
     Config.PropertyChanged -= (sender, e) => OnConfigUpdated(e);
     Config = MCProfilesList.Load(LauncherModel.Default.FilepathManager.GetProfilesFilePath(), Properties.LauncherSettings.Default.CurrentProfile, Properties.LauncherSettings.Default.CurrentProfile);
     Config.PropertyChanged += (sender, e) => OnConfigUpdated(e);
 }