diff --git a/AlotAddOnGUI/MainWindow.xaml.cs b/AlotAddOnGUI/MainWindow.xaml.cs index 34f6b832..9e29d3d3 100644 --- a/AlotAddOnGUI/MainWindow.xaml.cs +++ b/AlotAddOnGUI/MainWindow.xaml.cs @@ -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"; @@ -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 ")); diff --git a/AlotAddOnGUI/Properties/AssemblyInfo.cs b/AlotAddOnGUI/Properties/AssemblyInfo.cs index 5923874f..7d6945fd 100644 --- a/AlotAddOnGUI/Properties/AssemblyInfo.cs +++ b/AlotAddOnGUI/Properties/AssemblyInfo.cs @@ -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" )] diff --git a/AlotAddOnGUI/Utilites.cs b/AlotAddOnGUI/Utilites.cs index 40311c7f..375724f5 100644 --- a/AlotAddOnGUI/Utilites.cs +++ b/AlotAddOnGUI/Utilites.cs @@ -7,6 +7,7 @@ using System.IO; using AlotAddOnGUI.classes; using System.Runtime.InteropServices; +using System.Threading; namespace AlotAddOnGUI { @@ -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); + } } } \ No newline at end of file