@@ -32,10 +32,9 @@ public void DisablePortableMode()
3232 try
3333 {
3434 MoveUserDataFolder ( DataLocation . PortableDataPath , DataLocation . RoamingDataPath ) ;
35- #if DEBUG
35+ #if ! DEBUG
3636 // Create shortcuts and uninstaller are not required in debug mode,
3737 // otherwise will repoint the path of the actual installed production version to the debug version
38- #else
3938 CreateShortcuts ( ) ;
4039 CreateUninstallerEntry ( ) ;
4140#endif
@@ -48,10 +47,7 @@ public void DisablePortableMode()
4847 }
4948 catch ( Exception e )
5049 {
51- #if ! DEBUG
52- Log . Exception ( "Portable" , "Error occured while disabling portable mode" , e ) ;
53- #endif
54- throw ;
50+ Log . Exception ( "|Portable.DisablePortableMode|Error occured while disabling portable mode" , e ) ;
5551 }
5652 }
5753
@@ -60,10 +56,9 @@ public void EnablePortableMode()
6056 try
6157 {
6258 MoveUserDataFolder ( DataLocation . RoamingDataPath , DataLocation . PortableDataPath ) ;
63- #if DEBUG
59+ #if ! DEBUG
6460 // Remove shortcuts and uninstaller are not required in debug mode,
6561 // otherwise will delete the actual installed production version
66- #else
6762 RemoveShortcuts ( ) ;
6863 RemoveUninstallerEntry ( ) ;
6964#endif
@@ -76,10 +71,7 @@ public void EnablePortableMode()
7671 }
7772 catch ( Exception e )
7873 {
79- #if ! DEBUG
80- Log . Exception ( "Portable" , "Error occured while enabling portable mode" , e ) ;
81- #endif
82- throw ;
74+ Log . Exception ( "|Portable.EnablePortableMode|Error occured while enabling portable mode" , e ) ;
8375 }
8476 }
8577
@@ -125,14 +117,13 @@ public void CreateShortcuts()
125117 public void CreateUninstallerEntry ( )
126118 {
127119 var uninstallRegSubKey = @"Software\Microsoft\Windows\CurrentVersion\Uninstall" ;
128- // NB: Sometimes the Uninstall key doesn't exist
129- using ( var parentKey =
130- RegistryKey . OpenBaseKey ( RegistryHive . CurrentUser , RegistryView . Default )
131- . CreateSubKey ( "Uninstall" , RegistryKeyPermissionCheck . ReadWriteSubTree ) ) { ; }
132120
133- var key = RegistryKey . OpenBaseKey ( RegistryHive . CurrentUser , RegistryView . Default )
134- . CreateSubKey ( uninstallRegSubKey + "\\ " + Constant . FlowLauncher , RegistryKeyPermissionCheck . ReadWriteSubTree ) ;
135- key . SetValue ( "DisplayIcon" , Constant . ApplicationDirectory + "\\ app.ico" , RegistryValueKind . String ) ;
121+ using ( var baseKey = RegistryKey . OpenBaseKey ( RegistryHive . CurrentUser , RegistryView . Default ) )
122+ using ( var subKey1 = baseKey . CreateSubKey ( uninstallRegSubKey , RegistryKeyPermissionCheck . ReadWriteSubTree ) )
123+ using ( var subKey2 = subKey1 . CreateSubKey ( Constant . FlowLauncher , RegistryKeyPermissionCheck . ReadWriteSubTree ) )
124+ {
125+ subKey2 . SetValue ( "DisplayIcon" , Path . Combine ( Constant . ApplicationDirectory , "app.ico" ) , RegistryValueKind . String ) ;
126+ }
136127
137128 using ( var portabilityUpdater = NewUpdateManager ( ) )
138129 {
@@ -142,7 +133,10 @@ public void CreateUninstallerEntry()
142133
143134 internal void IndicateDeletion ( string filePathTodelete )
144135 {
145- using ( StreamWriter sw = File . CreateText ( filePathTodelete + "\\ " + DataLocation . DeletionIndicatorFile ) ) { }
136+ var deleteFilePath = Path . Combine ( filePathTodelete , DataLocation . DeletionIndicatorFile ) ;
137+ using ( var _ = File . CreateText ( deleteFilePath ) )
138+ {
139+ }
146140 }
147141
148142 ///<summary>
@@ -152,21 +146,18 @@ internal void IndicateDeletion(string filePathTodelete)
152146 public void PreStartCleanUpAfterPortabilityUpdate ( )
153147 {
154148 // Specify here so this method does not rely on other environment variables to initialise
155- var portableDataPath = Path . Combine ( Directory . GetParent ( Assembly . GetExecutingAssembly ( ) . Location . NonNull ( ) ) . ToString ( ) , "UserData" ) ;
156- var roamingDataPath = Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . ApplicationData ) , "FlowLauncher" ) ;
157-
158- bool DataLocationPortableDeleteRequired = false ;
159- bool DataLocationRoamingDeleteRequired = false ;
160-
161- if ( ( roamingDataPath + "\\ " + DataLocation . DeletionIndicatorFile ) . FileExits ( ) )
162- DataLocationRoamingDeleteRequired = true ;
149+ var portableDataDir = Path . Combine ( Directory . GetParent ( Assembly . GetExecutingAssembly ( ) . Location . NonNull ( ) ) . ToString ( ) , "UserData" ) ;
150+ var roamingDataDir = Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . ApplicationData ) , "FlowLauncher" ) ;
163151
164- if ( ( portableDataPath + "\\ " + DataLocation . DeletionIndicatorFile ) . FileExits ( ) )
165- DataLocationPortableDeleteRequired = true ;
152+ // Get full path to the .dead files for each case
153+ var portableDataDeleteFilePath = Path . Combine ( portableDataDir , DataLocation . DeletionIndicatorFile ) ;
154+ var roamingDataDeleteFilePath = Path . Combine ( roamingDataDir , DataLocation . DeletionIndicatorFile ) ;
166155
167- if ( DataLocationRoamingDeleteRequired )
156+ // If the data folder in %appdata% is marked for deletion,
157+ // delete it and prompt the user to pick the portable data location
158+ if ( File . Exists ( roamingDataDeleteFilePath ) )
168159 {
169- FilesFolders . RemoveFolderIfExists ( roamingDataPath ) ;
160+ FilesFolders . RemoveFolderIfExists ( roamingDataDir ) ;
170161
171162 if ( MessageBox . Show ( "Flow Launcher has detected you enabled portable mode, " +
172163 "would you like to move it to a different location?" , string . Empty ,
@@ -176,18 +167,15 @@ public void PreStartCleanUpAfterPortabilityUpdate()
176167
177168 Environment . Exit ( 0 ) ;
178169 }
179-
180- return ;
181170 }
182-
183- if ( DataLocationPortableDeleteRequired )
171+ // Otherwise, if the portable data folder is marked for deletion,
172+ // delete it and notify the user about it.
173+ else if ( File . Exists ( portableDataDeleteFilePath ) )
184174 {
185- FilesFolders . RemoveFolderIfExists ( portableDataPath ) ;
175+ FilesFolders . RemoveFolderIfExists ( portableDataDir ) ;
186176
187177 MessageBox . Show ( "Flow Launcher has detected you disabled portable mode, " +
188178 "the relevant shortcuts and uninstaller entry have been created" ) ;
189-
190- return ;
191179 }
192180 }
193181
@@ -196,7 +184,7 @@ public bool CanUpdatePortability()
196184 var roamingLocationExists = DataLocation . RoamingDataPath . LocationExists ( ) ;
197185 var portableLocationExists = DataLocation . PortableDataPath . LocationExists ( ) ;
198186
199- if ( roamingLocationExists && portableLocationExists )
187+ if ( roamingLocationExists && portableLocationExists )
200188 {
201189 MessageBox . Show ( string . Format ( "Flow Launcher detected your user data exists both in {0} and " +
202190 "{1}. {2}{2}Please delete {1} in order to proceed. No changes have occured." ,
0 commit comments