This repository was archived by the owner on Feb 12, 2021. It is now read-only.
forked from Wox-launcher/Wox
-
Notifications
You must be signed in to change notification settings - Fork 12
Enable/disable portable mode setting #143
Merged
Merged
Changes from 28 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
7385243
Add enable portable mode logic
jjw24 d55560e
Add UserData operations- Copy, verify, remove
jjw24 69f66b7
update
jjw24 ad4c9fb
Add possible exception path too long handling
jjw24 ba46ce0
Update with exception handling and continue
jjw24 61845dd
Add disable portable mode code
jjw24 2531f71
Add disable portable mode programatically
jjw24 dbc52f5
Merge branch 'dev' into add_enable_portablemode_setting
jjw24 39eac96
Change method name to make intention clearer. Add additional methods
jjw24 e6b988d
Add code to enable portable mode
jjw24 7ac69f9
Update disable portable mode code
jjw24 56b8b5f
After restart, clean up data folder locations so only one is used
jjw24 f6ae266
Add settings check box ui and viewmodel
jjw24 c2d7e65
Add settings saving to file
jjw24 fd4f0f6
Add method used to indicate deletion of data location
jjw24 be8da80
Remove Wait on create uninstaller reg entry call
jjw24 4fc3016
separate get data location code from constant file
jjw24 6134550
Include DataLocation.cs in project file
jjw24 d0976a9
Update all applicable files to use the new data location class
jjw24 ef1b521
Change PortableDataLocationInUse property to method
jjw24 930ceef
Change method name for cleaning up after portability update
jjw24 82a24c9
Add validation prior to update portability
jjw24 83df0b3
Remove unnecessary method implementation
jjw24 31dd774
Update add comments change to internal
jjw24 a70615d
Add production logging
jjw24 830378e
update
jjw24 f933f9d
cater for debug mode
jjw24 f939abb
Remove need for saving to settings file by getting status dynamically
jjw24 c5dc21d
Merge branch 'dev' into add_enable_portablemode_setting
jjw24 62c11a0
Make debug mode clearer during exception
jjw24 3e76b38
Per comment change filename to Constant
jjw24 b85f5a1
Remove unnecessary interface methods
jjw24 86903e5
Wrap UpdateManager in using statement + enable methods run as standalone
jjw24 733326b
Revert accidental removal of interface methods
jjw24 7a6edd0
Per comment, simplify code in Setter
jjw24 cb0a4de
Merge branch 'dev' into add_enable_portablemode_setting
jjw24 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| | ||
| namespace Wox.Core.Configuration | ||
| { | ||
| public interface IPortable | ||
| { | ||
| void EnablePortableMode(); | ||
| void DisablePortableMode(); | ||
| void RemoveShortcuts(); | ||
| void RemoveUninstallerEntry(); | ||
| void CreateShortcuts(); | ||
| void CreateUninstallerEntry(); | ||
| void MoveUserDataFolder(string fromLocation, string toLocation); | ||
| void VerifyUserDataAfterMove(string fromLocation, string toLocation); | ||
| bool CanUpdatePortability(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,200 @@ | ||
| using Microsoft.Win32; | ||
| using Squirrel; | ||
| using System; | ||
| using System.IO; | ||
| using System.Reflection; | ||
| using System.Windows; | ||
| using Wox.Infrastructure; | ||
| using Wox.Infrastructure.Logger; | ||
| using Wox.Infrastructure.UserSettings; | ||
| using Wox.Plugin.SharedCommands; | ||
|
|
||
| namespace Wox.Core.Configuration | ||
| { | ||
| public class Portable : IPortable | ||
| { | ||
| private UpdateManager portabilityUpdater; | ||
|
|
||
| public void DisablePortableMode() | ||
| { | ||
| portabilityUpdater = new UpdateManager(string.Empty, Constant.Wox, Constant.RootDirectory); | ||
theClueless marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| try | ||
| { | ||
| MoveUserDataFolder(DataLocation.PortableDataPath, DataLocation.RoamingDataPath); | ||
| #if DEBUG | ||
| // Create shortcuts and uninstaller are not required in debug mode, | ||
| // otherwise will repoint the path of the actual installed production version to the debug version | ||
| #else | ||
| CreateShortcuts(); | ||
| CreateUninstallerEntry(); | ||
| #endif | ||
| IndicateDeletion(DataLocation.PortableDataPath); | ||
|
|
||
| MessageBox.Show("Wox needs to restart to finish disabling portable mode, " + | ||
| "after the restart your portable data profile will be deleted and roaming data profile kept"); | ||
|
|
||
| portabilityUpdater.Dispose(); | ||
|
|
||
| UpdateManager.RestartApp(); | ||
| } | ||
| catch (Exception e) | ||
| { | ||
| #if DEBUG | ||
| portabilityUpdater.Dispose(); | ||
| throw; | ||
| #else | ||
| portabilityUpdater.Dispose(); | ||
| Log.Exception("Portable", "Error occured while disabling portable mode", e); | ||
jjw24 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| throw; | ||
| #endif | ||
| } | ||
| } | ||
|
|
||
| public void EnablePortableMode() | ||
| { | ||
| portabilityUpdater = new UpdateManager(string.Empty, Constant.Wox, Constant.RootDirectory); | ||
|
|
||
| try | ||
| { | ||
| MoveUserDataFolder(DataLocation.RoamingDataPath, DataLocation.PortableDataPath); | ||
| #if DEBUG | ||
| // Remove shortcuts and uninstaller are not required in debug mode, | ||
| // otherwise will delete the actual installed production version | ||
| #else | ||
| RemoveShortcuts(); | ||
| RemoveUninstallerEntry(); | ||
| #endif | ||
| IndicateDeletion(DataLocation.RoamingDataPath); | ||
|
|
||
| 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) | ||
| { | ||
| #if DEBUG | ||
| portabilityUpdater.Dispose(); | ||
| throw; | ||
| #else | ||
| portabilityUpdater.Dispose(); | ||
| Log.Exception("Portable", "Error occured while enabling portable mode", e); | ||
| throw; | ||
| #endif | ||
| } | ||
| } | ||
|
|
||
| public void RemoveShortcuts() | ||
| { | ||
| var exeName = Constant.Wox + ".exe"; | ||
| portabilityUpdater.RemoveShortcutsForExecutable(exeName, ShortcutLocation.StartMenu); | ||
theClueless marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| portabilityUpdater.RemoveShortcutsForExecutable(exeName, ShortcutLocation.Desktop); | ||
| portabilityUpdater.RemoveShortcutsForExecutable(exeName, ShortcutLocation.Startup); | ||
| } | ||
|
|
||
| public void RemoveUninstallerEntry() | ||
| { | ||
| portabilityUpdater.RemoveUninstallerRegistryEntry(); | ||
| } | ||
|
|
||
| public void MoveUserDataFolder(string fromLocation, string toLocation) | ||
| { | ||
| FilesFolders.Copy(fromLocation, toLocation); | ||
| VerifyUserDataAfterMove(fromLocation, toLocation); | ||
| } | ||
|
|
||
| public void VerifyUserDataAfterMove(string fromLocation, string toLocation) | ||
| { | ||
| FilesFolders.VerifyBothFolderFilesEqual(fromLocation, toLocation); | ||
| } | ||
|
|
||
| public void CreateShortcuts() | ||
| { | ||
| var exeName = Constant.Wox + ".exe"; | ||
| portabilityUpdater.CreateShortcutsForExecutable(exeName, ShortcutLocation.StartMenu, false); | ||
| portabilityUpdater.CreateShortcutsForExecutable(exeName, ShortcutLocation.Desktop, false); | ||
| portabilityUpdater.CreateShortcutsForExecutable(exeName, ShortcutLocation.Startup, false); | ||
| } | ||
|
|
||
| public void CreateUninstallerEntry() | ||
| { | ||
| var uninstallRegSubKey = @"Software\Microsoft\Windows\CurrentVersion\Uninstall"; | ||
| // NB: Sometimes the Uninstall key doesn't exist | ||
| using (var parentKey = | ||
| RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Default) | ||
| .CreateSubKey("Uninstall", RegistryKeyPermissionCheck.ReadWriteSubTree)) {; } | ||
|
|
||
| var key = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Default) | ||
| .CreateSubKey(uninstallRegSubKey + "\\" + Constant.Wox, RegistryKeyPermissionCheck.ReadWriteSubTree); | ||
| key.SetValue("DisplayIcon", Constant.ApplicationDirectory + "\\app.ico", RegistryValueKind.String); | ||
|
|
||
| portabilityUpdater.CreateUninstallerRegistryEntry(); | ||
| } | ||
|
|
||
| internal void IndicateDeletion(string filePathTodelete) | ||
| { | ||
| using (StreamWriter sw = File.CreateText(filePathTodelete + "\\" + DataLocation.DeletionIndicatorFile)){} | ||
| } | ||
|
|
||
| ///<summary> | ||
| ///This method should be run at first before all methods during start up and should be run before determining which data location | ||
| ///will be used for Wox. | ||
| ///</summary> | ||
| public void PreStartCleanUpAfterPortabilityUpdate() | ||
| { | ||
| // Specify here so this method does not rely on other environment variables to initialise | ||
| var portableDataPath = Path.Combine(Directory.GetParent(Assembly.GetExecutingAssembly().Location.NonNull()).ToString(), "UserData"); | ||
| var roamingDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Wox"); | ||
|
|
||
| bool DataLocationPortableDeleteRequired = false; | ||
| bool DataLocationRoamingDeleteRequired = false; | ||
|
|
||
| if ((roamingDataPath + "\\" + DataLocation.DeletionIndicatorFile).FileExits()) | ||
| DataLocationRoamingDeleteRequired = true; | ||
|
|
||
| if ((portableDataPath + "\\" + DataLocation.DeletionIndicatorFile).FileExits()) | ||
| DataLocationPortableDeleteRequired = true; | ||
|
|
||
| if (DataLocationRoamingDeleteRequired) | ||
| { | ||
| if(roamingDataPath.LocationExists()) | ||
| MessageBox.Show("Wox detected you restarted after enabling portable mode, " + | ||
| "your roaming data profile will now be deleted"); | ||
|
|
||
| FilesFolders.RemoveFolderIfExists(roamingDataPath); | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| if(DataLocationPortableDeleteRequired) | ||
| { | ||
| MessageBox.Show("Wox detected you restarted after disabling portable mode, " + | ||
| "your portable data profile will now be deleted"); | ||
|
|
||
| FilesFolders.RemoveFolderIfExists(portableDataPath); | ||
|
|
||
| return; | ||
| } | ||
| } | ||
|
|
||
| public bool CanUpdatePortability() | ||
| { | ||
| var roamingLocationExists = DataLocation.RoamingDataPath.LocationExists(); | ||
| var portableLocationExists = DataLocation.PortableDataPath.LocationExists(); | ||
|
|
||
| if(roamingLocationExists && portableLocationExists) | ||
| { | ||
| MessageBox.Show(string.Format("Wox detected your user data exists both in {0} and " + | ||
| "{1}. {2}{2}Please delete {1} in order to proceed. No changes have occured.", | ||
| DataLocation.PortableDataPath, DataLocation.RoamingDataPath, Environment.NewLine)); | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.