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); }); }); }
private void RestoreMinecraftDataFromReinstall(string packageFamily) { string tmpDir = GetBackupMinecraftDataDir(); if (!Directory.Exists(tmpDir)) { return; } var data = ApplicationDataManager.CreateForPackageFamily(packageFamily); Debug.WriteLine("Moving backup Minecraft data to: " + data.LocalFolder.Path); RestoreMove(tmpDir, data.LocalFolder.Path); Directory.Delete(tmpDir, true); }
private void BackupMinecraftDataForRemoval(string packageFamily) { var data = ApplicationDataManager.CreateForPackageFamily(packageFamily); string tmpDir = GetBackupMinecraftDataDir(); if (Directory.Exists(tmpDir)) { Debug.WriteLine("BackupMinecraftDataForRemoval error: " + tmpDir + " already exists"); Process.Start("explorer.exe", tmpDir); MessageBox.Show("The temporary directory for backing up MC data already exists. This probably means that we failed last time backing up the data. Please back the directory up manually."); throw new Exception("Temporary dir exists"); } Debug.WriteLine("Moving Minecraft data to: " + tmpDir); Directory.Move(data.LocalFolder.Path, tmpDir); }
private void InvokeConvert() { Task.Run(async() => { Application.Current.Dispatcher.Invoke(() => { ConfigManager.MainThread.ProgressBarGrid.Visibility = Visibility.Visible; }); 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 = Constants.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); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } Application.Current.Dispatcher.Invoke(() => { ConfigManager.MainThread.ProgressBarGrid.Visibility = Visibility.Collapsed; }); }); }
static private bool GetACInfo(string packageFamilyName, out string acSid, out string tempDir) { IntPtr acPSID; acSid = null; tempDir = null; if (DeriveAppContainerSidFromAppContainerName(packageFamilyName, out acPSID) < 0) { return(false); } if (ConvertSidToStringSid(acPSID, out acSid) == 0) { return(false); } ApplicationData appData = ApplicationDataManager.CreateForPackageFamily(packageFamilyName); tempDir = appData.TemporaryFolder.Path; return(true); }
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); }); }); }
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); } } }
public async void Backup() { 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 = Path.Combine(data.LocalFolder.Path, "games", "com.mojang"); } catch { dataPath = string.Empty; } if (dataPath != string.Empty) { var dirData = GenerateStrings(); if (!Directory.Exists(dirData.Item2)) Directory.CreateDirectory(dirData.Item2); System.Diagnostics.Debug.WriteLine("Moving backup Minecraft data to: " + dirData.Item2); RestoreCopy(dataPath, dirData.Item2); Application.Current.Dispatcher.Invoke(() => LauncherModel.Default.Config.Installation_Create(dirData.Item1, null, dirData.Item2)); } } catch (Exception ex) { ErrorScreenShow.exceptionmsg(ex); } ViewModels.LauncherModel.Default.ShowProgressBar = false; ViewModels.LauncherModel.Default.CurrentState = ViewModels.LauncherModel.StateChange.None; }); Tuple<string, string> GenerateStrings(string name = "Recovery Data", string dir = "RecoveryData") { string recoveryName = name; string recoveryDir = dir; string directoryPath = string.Empty; int i = 1; while (i < 100) { if (i != 1) { recoveryName = string.Format("{0} ({1})", name, i); recoveryDir = string.Format("{0}_{1}", dir, i); } directoryPath = Path.Combine(LauncherModel.Default.FilepathManager.GetInstallationsFolderPath(LauncherModel.Default.Config.CurrentProfileUUID, recoveryDir)); if (!Directory.Exists(directoryPath)) break; i++; } if (i >= 100) throw new Exception("Too many backups made"); return new Tuple<string, string>(recoveryName, directoryPath); } 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)); File.Copy(f, ft); ViewModels.LauncherModel.Default.CurrentProgress += 1; } foreach (var f in Directory.EnumerateDirectories(from)) { string tp = Path.Combine(to, Path.GetFileName(f)); Directory.CreateDirectory(tp); RestoreCopy_Step(f, tp); } } }