Skip to content

Commit

Permalink
Fixed restore not working if original game directory was not empty or…
Browse files Browse the repository at this point in the history
… did not exist.
  • Loading branch information
Mgamerz committed Dec 12, 2017
1 parent ebdbca8 commit 81f7e40
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
14 changes: 12 additions & 2 deletions AlotAddOnGUI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ private async void InstallCompleted(object sender, RunWorkerCompletedEventArgs e
// colored until user focuses the main window
helper.FlashApplicationWindow();

HeaderLabel.Text = "Addon Created.\nThe MEM package for the addon have been placed into the " + MEM_OUTPUT_DISPLAY_DIR + " directory.";
HeaderLabel.Text = "Addon created.\nThe MEM packages for the addon have been placed into the " + MEM_OUTPUT_DISPLAY_DIR + " directory.";
AddonFilesLabel.Text = "MEM Packages placed in the " + MEM_OUTPUT_DISPLAY_DIR + " folder";
MetroDialogSettings mds = new MetroDialogSettings();
mds.AffirmativeButtonText = "Open MEM";
Expand Down Expand Up @@ -1510,7 +1510,17 @@ private void RestoreGame(object sender, DoWorkEventArgs e)
string backupPath = Utilities.GetGameBackupPath(BACKUP_THREAD_GAME);
BackupWorker.ReportProgress(completed, new ThreadCommand(UPDATE_PROGRESSBAR_INDETERMINATE, true));
BackupWorker.ReportProgress(completed, new ThreadCommand(UPDATE_OPERATION_LABEL, "Deleting exist game installation"));
Directory.Delete(gamePath, true);
if (Directory.Exists(gamePath))
{
Log.Information("Deleting existing game directory: " + gamePath);
try
{
Utilities.DeleteFilesAndFoldersRecursively(gamePath);
} catch (Exception ex)
{
Log.Error("Exception deleting game directory: " + gamePath+ ": "+ex.Message);
}
}
Directory.CreateDirectory(gamePath);
BackupWorker.ReportProgress(completed, new ThreadCommand(UPDATE_PROGRESSBAR_INDETERMINATE, false));
BackupWorker.ReportProgress(completed, new ThreadCommand(UPDATE_OPERATION_LABEL, "Restoring game from backup "));
Expand Down
4 changes: 2 additions & 2 deletions AlotAddOnGUI/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
[assembly: AssemblyCulture("")]

// Version informationr(
[assembly: AssemblyVersion("2.0.60.427")]
[assembly: AssemblyFileVersion("2.0.60.427")]
[assembly: AssemblyVersion("2.0.61.428")]
[assembly: AssemblyFileVersion("2.0.61.428")]
[assembly: NeutralResourcesLanguageAttribute( "en-US" )]

18 changes: 18 additions & 0 deletions AlotAddOnGUI/Utilites.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.IO;
using AlotAddOnGUI.classes;
using System.Runtime.InteropServices;
using System.Threading;

namespace AlotAddOnGUI
{
Expand Down Expand Up @@ -225,5 +226,22 @@ public static bool DriveFreeBytes(string folderName, out ulong freespace)
return false;
}
}


public static void DeleteFilesAndFoldersRecursively(string target_dir)
{
foreach (string file in Directory.GetFiles(target_dir))
{
File.Delete(file);
}

foreach (string subDir in Directory.GetDirectories(target_dir))
{
DeleteFilesAndFoldersRecursively(subDir);
}

Thread.Sleep(1); // This makes the difference between whether it works or not. Sleep(0) is not enough.
Directory.Delete(target_dir);
}
}
}

0 comments on commit 81f7e40

Please sign in to comment.