コード例 #1
0
ファイル: GameManager.cs プロジェクト: CarJem/BedrockLauncher
        private async void InvokeConvert()
        {
            await Task.Run(() =>
            {
                IsBackingUp                       = true;
                Model.StateChangeInfo             = new VersionStateChangeInfo();
                Model.StateChangeInfo.IsBackingUp = true;
                Application.Current.Dispatcher.Invoke(() => { OnGameStateChanged(GameStateArgs.Empty); });

                try
                {
                    var data = ApplicationDataManager.CreateForPackageFamily(MINECRAFT_PACKAGE_FAMILY);

                    string recoveryPath = Path.Combine(Filepaths.GetInstallationsFolderPath(ConfigManager.CurrentProfile, "Recovery_Data"), "LocalState");

                    if (!Directory.Exists(recoveryPath))
                    {
                        Directory.CreateDirectory(recoveryPath);
                    }

                    Program.Log("Moving backup Minecraft data to: " + recoveryPath);
                    RestoreCopy(data.LocalFolder.Path, recoveryPath);
                    ConfigManager.CreateInstallation("Recovery_Data", null, "Recovery_Data");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }

                IsBackingUp           = false;
                Model.StateChangeInfo = null;
                Application.Current.Dispatcher.Invoke(() => { OnGameStateChanged(GameStateArgs.Empty); });
            });
        }
コード例 #2
0
        public static void SaveProfiles()
        {
            string json = JsonConvert.SerializeObject(CleanProfiles(), Formatting.Indented);

            File.WriteAllText(Filepaths.GetProfilesFilePath(), json);
            Init(true);
        }
コード例 #3
0
        public void OpenFolder(MCInstallation i)
        {
            string Directory = Filepaths.GetInstallationsFolderPath(ConfigManager.CurrentProfile, i.DirectoryName_Full);

            if (!System.IO.Directory.Exists(Directory))
            {
                System.IO.Directory.CreateDirectory(Directory);
            }
            Process.Start("explorer.exe", Directory);
        }
コード例 #4
0
ファイル: GameManager.cs プロジェクト: CarJem/BedrockLauncher
        private void SetInstallationDataPath()
        {
            if (Properties.LauncherSettings.Default.SaveRedirection)
            {
                string PackageFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Packages", MINECRAFT_PACKAGE_FAMILY);
                string ProfileFolder = Path.GetFullPath(Filepaths.GetInstallationsFolderPath(ConfigManager.CurrentProfile, ConfigManager.CurrentInstallation.DirectoryName));

                if (Directory.Exists(PackageFolder))
                {
                    DirectoryInfo PackageDirectory = new DirectoryInfo(PackageFolder);
                    System.IO.Directory.Delete(PackageFolder, true);
                }

                SetFolderPermisions(ProfileFolder);
                Methods.SymLinkHelper.CreateSymbolicLink(PackageFolder, ProfileFolder, SymLinkHelper.SymbolicLinkType.Directory);
                SetLinkPermisions(PackageFolder);
            }
        }
コード例 #5
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());
            }
        }
コード例 #6
0
        private async void InvokeConvert()
        {
            await Task.Run(() =>
            {
                Application.Current.Dispatcher.Invoke(() => { OnGameStateChanged(GameStateArgs.Empty); });

                try
                {
                    var data      = ApplicationDataManager.CreateForPackageFamily(MINECRAFT_PACKAGE_FAMILY);
                    string tmpDir = GetBackupMinecraftDataDir();
                    if (!Directory.Exists(tmpDir))
                    {
                        Debug.WriteLine("Moving Minecraft data to: " + tmpDir);
                        Directory.Move(data.LocalFolder.Path, tmpDir);
                    }

                    string recoveryPath = Filepaths.GetInstallationsFolderPath(ConfigManager.CurrentProfile, "Recovery_Data");

                    if (!Directory.Exists(recoveryPath))
                    {
                        Directory.CreateDirectory(recoveryPath);
                    }

                    Debug.WriteLine("Moving backup Minecraft data to: " + recoveryPath);
                    RestoreMove(tmpDir, recoveryPath);
                    Directory.Delete(tmpDir, true);

                    ConfigManager.CreateInstallation("Recovery_Data", null, "Recovery_Data");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }

                Application.Current.Dispatcher.Invoke(() => { OnGameStateChanged(GameStateArgs.Empty); });
            });
        }
コード例 #7
0
        private async Task SetInstallationDataPath()
        {
            await Task.Run(() =>
            {
                if (Properties.LauncherSettings.Default.SaveRedirection)
                {
                    string LocalStateFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Packages", MINECRAFT_PACKAGE_FAMILY, "LocalState");
                    string PackageFolder    = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Packages", MINECRAFT_PACKAGE_FAMILY, "LocalState", "games", "com.mojang");
                    string PackageBakFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Packages", MINECRAFT_PACKAGE_FAMILY, "LocalState", "games", "com.mojang.default");
                    string ProfileFolder    = Path.GetFullPath(Filepaths.GetInstallationsFolderPath(ConfigManager.CurrentProfile, ConfigManager.CurrentInstallation.DirectoryName_Full));

                    if (Directory.Exists(PackageFolder))
                    {
                        var dir = new DirectoryInfo(PackageFolder);
                        if (!dir.IsSymbolicLink())
                        {
                            dir.MoveTo(PackageBakFolder);
                        }
                        else
                        {
                            dir.Delete(true);
                        }
                    }

                    DirectoryInfo profileDir = Directory.CreateDirectory(ProfileFolder);
                    SymLinkHelper.CreateSymbolicLink(PackageFolder, ProfileFolder, SymLinkHelper.SymbolicLinkType.Directory);
                    DirectoryInfo pkgDir = Directory.CreateDirectory(PackageFolder);
                    DirectoryInfo lsDir  = Directory.CreateDirectory(LocalStateFolder);

                    SecurityIdentifier owner = WindowsIdentity.GetCurrent().User;
                    SecurityIdentifier authenticated_users_identity = new SecurityIdentifier("S-1-5-11");

                    FileSystemAccessRule owner_access_rules = new FileSystemAccessRule(owner, FileSystemRights.FullControl, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, PropagationFlags.None, AccessControlType.Allow);
                    FileSystemAccessRule au_access_rules    = new FileSystemAccessRule(authenticated_users_identity, FileSystemRights.FullControl, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, PropagationFlags.None, AccessControlType.Allow);

                    var lsSecurity = lsDir.GetAccessControl();
                    AuthorizationRuleCollection rules        = lsSecurity.GetAccessRules(true, true, typeof(NTAccount));
                    List <FileSystemAccessRule> needed_rules = new List <FileSystemAccessRule>();
                    foreach (AccessRule rule in rules)
                    {
                        if (rule.IdentityReference is SecurityIdentifier)
                        {
                            var required_rule = new FileSystemAccessRule(rule.IdentityReference, FileSystemRights.FullControl, rule.InheritanceFlags, rule.PropagationFlags, rule.AccessControlType);
                            needed_rules.Add(required_rule);
                        }
                    }

                    var pkgSecurity = pkgDir.GetAccessControl();
                    pkgSecurity.SetOwner(owner);
                    pkgSecurity.AddAccessRule(au_access_rules);
                    pkgSecurity.AddAccessRule(owner_access_rules);
                    pkgDir.SetAccessControl(pkgSecurity);

                    var profileSecurity = profileDir.GetAccessControl();
                    profileSecurity.SetOwner(owner);
                    profileSecurity.AddAccessRule(au_access_rules);
                    profileSecurity.AddAccessRule(owner_access_rules);
                    needed_rules.ForEach(x => profileSecurity.AddAccessRule(x));
                    profileDir.SetAccessControl(profileSecurity);
                }
            });

            Thread.Sleep(1000);
        }
コード例 #8
0
        private async void InvokeBackup()
        {
            await Task.Run(() =>
            {
                ViewModels.LauncherModel.Default.ShowProgressBar = true;
                ViewModels.LauncherModel.Default.CurrentState    = ViewModels.LauncherModel.StateChange.isBackingUp;

                try
                {
                    var data = ApplicationDataManager.CreateForPackageFamily(MINECRAFT_PACKAGE_FAMILY);
                    string dataPath;

                    try { dataPath = data.LocalFolder.Path; }
                    catch { dataPath = string.Empty; }

                    if (dataPath != string.Empty)
                    {
                        string recoveryPath = Path.Combine(Filepaths.GetInstallationsFolderPath(ConfigManager.CurrentProfile, "Recovery_Data"), "LocalState");
                        if (!Directory.Exists(recoveryPath))
                        {
                            Directory.CreateDirectory(recoveryPath);
                        }
                        System.Diagnostics.Debug.WriteLine("Moving backup Minecraft data to: " + recoveryPath);
                        RestoreCopy(dataPath, recoveryPath);
                        ConfigManager.CreateInstallation("Recovery_Data", null, "Recovery_Data");
                    }
                }
                catch (Exception ex) { ErrorScreenShow.exceptionmsg(ex); }

                ViewModels.LauncherModel.Default.ShowProgressBar = false;
                ViewModels.LauncherModel.Default.CurrentState    = ViewModels.LauncherModel.StateChange.None;
            });

            ConfigManager.OnConfigStateChanged(this, Events.ConfigStateArgs.Empty);


            void RestoreCopy(string from, string to)
            {
                int Total = Directory.GetFiles(from, "*", SearchOption.AllDirectories).Length;

                ViewModels.LauncherModel.Default.TotalProgress   = Total;
                ViewModels.LauncherModel.Default.CurrentProgress = 0;

                RestoreCopy_Step(from, to);
            }

            void RestoreCopy_Step(string from, string to)
            {
                foreach (var f in Directory.EnumerateFiles(from))
                {
                    string ft = Path.Combine(to, Path.GetFileName(f));
                    if (File.Exists(ft))
                    {
                        if (MessageBox.Show(string.Format(Application.Current.FindResource("GameManager_RecoveringDataIssue_FileNotExistant_Text").ToString(), ft), Application.Current.FindResource("GameManager_RecoveringDataIssue_Title").ToString(), MessageBoxButton.YesNo) != MessageBoxResult.Yes)
                        {
                            continue;
                        }
                        File.Delete(ft);
                    }
                    File.Copy(f, ft);
                    ViewModels.LauncherModel.Default.CurrentProgress += 1;
                }
                foreach (var f in Directory.EnumerateDirectories(from))
                {
                    string tp = Path.Combine(to, Path.GetFileName(f));
                    if (!Directory.Exists(tp))
                    {
                        if (File.Exists(tp) && MessageBox.Show(string.Format(Application.Current.FindResource("GameManager_RecoveringDataIssue_NotaDirectory_Text").ToString(), tp), Application.Current.FindResource("GameManager_RecoveringDataIssue_Title").ToString(), MessageBoxButton.YesNo) != MessageBoxResult.Yes)
                        {
                            continue;
                        }
                        Directory.CreateDirectory(tp);
                    }
                    RestoreCopy_Step(f, tp);
                }
            }
        }
コード例 #9
0
 public static void LoadVersions()
 {
     Versions = new MCVersionList(Filepaths.GetVersionsFilePath(), GameManager);
     ReloadVersions();
 }