From e6b988d227ddc03556f0571b440fd7e08939fcf8 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Thu, 5 Mar 2020 23:13:06 +1100 Subject: [PATCH] Add code to enable portable mode --- Wox.Core/Configuration/IPortable.cs | 1 + Wox.Core/Configuration/Portable.cs | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Wox.Core/Configuration/IPortable.cs b/Wox.Core/Configuration/IPortable.cs index 95c1b345b..86a355b2b 100644 --- a/Wox.Core/Configuration/IPortable.cs +++ b/Wox.Core/Configuration/IPortable.cs @@ -12,5 +12,6 @@ namespace Wox.Core.Configuration bool IsPortableModeEnabled(); void MoveUserDataFolder(string fromLocation, string toLocation); void VerifyUserDataAfterMove(string fromLocation, string toLocation); + void CleanUpFolderAfterPortabilityUpdate(); } } \ No newline at end of file diff --git a/Wox.Core/Configuration/Portable.cs b/Wox.Core/Configuration/Portable.cs index 5cb746f54..458c8a96c 100644 --- a/Wox.Core/Configuration/Portable.cs +++ b/Wox.Core/Configuration/Portable.cs @@ -52,20 +52,30 @@ namespace Wox.Core.Configuration public void EnablePortableMode() { + portabilityUpdater = new UpdateManager(string.Empty, Constant.Wox, Constant.RootDirectory); + try { - MoveUserDataFolder(roamingDataPath, portableDataPath); + MoveUserDataFolder(DataLocation.RoamingDataPath, DataLocation.PortableDataPath); RemoveShortcuts(); RemoveUninstallerEntry(); + IndicateDeletion(DataLocation.RoamingDataPath); - // always dispose UpdateManager??????????? + MessageBox.Show("Wox needs to restart to finish enabling portable mode, " + + "after the restart your roaming data profile will be deleted and portable data profile kept"); + + portabilityUpdater.Dispose(); + + UpdateManager.RestartApp(); } catch (Exception e) { //log and update error message to output above locations where shortcuts may not have been removed #if DEBUG + portabilityUpdater.Dispose(); throw; #else + portabilityUpdater.Dispose(); throw;// PRODUCTION LOGGING AND CONTINUE #endif @@ -79,6 +89,7 @@ namespace Wox.Core.Configuration public void RemoveShortcuts() { + var exeName = Constant.Wox + ".exe"; portabilityUpdater.RemoveShortcutsForExecutable(exeName, ShortcutLocation.StartMenu); portabilityUpdater.RemoveShortcutsForExecutable(exeName, ShortcutLocation.Desktop); portabilityUpdater.RemoveShortcutsForExecutable(exeName, ShortcutLocation.Startup); @@ -93,7 +104,6 @@ namespace Wox.Core.Configuration { FilesFolders.Copy(fromLocation, toLocation); VerifyUserDataAfterMove(fromLocation, toLocation); - FilesFolders.RemoveFolder(fromLocation); } public void VerifyUserDataAfterMove(string fromLocation, string toLocation)