@@ -32,10 +32,9 @@ public void DisablePortableMode()
32
32
try
33
33
{
34
34
MoveUserDataFolder ( DataLocation . PortableDataPath , DataLocation . RoamingDataPath ) ;
35
- #if DEBUG
35
+ #if ! DEBUG
36
36
// Create shortcuts and uninstaller are not required in debug mode,
37
37
// otherwise will repoint the path of the actual installed production version to the debug version
38
- #else
39
38
CreateShortcuts ( ) ;
40
39
CreateUninstallerEntry ( ) ;
41
40
#endif
@@ -60,10 +59,9 @@ public void EnablePortableMode()
60
59
try
61
60
{
62
61
MoveUserDataFolder ( DataLocation . RoamingDataPath , DataLocation . PortableDataPath ) ;
63
- #if DEBUG
62
+ #if ! DEBUG
64
63
// Remove shortcuts and uninstaller are not required in debug mode,
65
64
// otherwise will delete the actual installed production version
66
- #else
67
65
RemoveShortcuts ( ) ;
68
66
RemoveUninstallerEntry ( ) ;
69
67
#endif
@@ -126,13 +124,16 @@ public void CreateUninstallerEntry()
126
124
{
127
125
var uninstallRegSubKey = @"Software\Microsoft\Windows\CurrentVersion\Uninstall" ;
128
126
// NB: Sometimes the Uninstall key doesn't exist
129
- using ( var parentKey =
130
- RegistryKey . OpenBaseKey ( RegistryHive . CurrentUser , RegistryView . Default )
131
- . CreateSubKey ( "Uninstall" , RegistryKeyPermissionCheck . ReadWriteSubTree ) ) { ; }
127
+ RegistryKey
128
+ . OpenBaseKey ( RegistryHive . CurrentUser , RegistryView . Default )
129
+ . CreateSubKey ( "Uninstall" , RegistryKeyPermissionCheck . ReadWriteSubTree )
130
+ . Dispose ( ) ;
132
131
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 ) ;
132
+ var key = RegistryKey
133
+ . OpenBaseKey ( RegistryHive . CurrentUser , RegistryView . Default )
134
+ . CreateSubKey ( $@ "{ uninstallRegSubKey } \{ Constant . FlowLauncher } ", RegistryKeyPermissionCheck . ReadWriteSubTree ) ;
135
+
136
+ key . SetValue ( "DisplayIcon" , Path . Combine ( Constant . ApplicationDirectory , "app.ico" ) , RegistryValueKind . String ) ;
136
137
137
138
using ( var portabilityUpdater = NewUpdateManager ( ) )
138
139
{
@@ -142,7 +143,8 @@ public void CreateUninstallerEntry()
142
143
143
144
internal void IndicateDeletion ( string filePathTodelete )
144
145
{
145
- using ( StreamWriter sw = File . CreateText ( filePathTodelete + "\\ " + DataLocation . DeletionIndicatorFile ) ) { }
146
+ var deleteFilePath = Path . Combine ( filePathTodelete , DataLocation . DeletionIndicatorFile ) ;
147
+ File . CreateText ( deleteFilePath ) . Close ( ) ;
146
148
}
147
149
148
150
///<summary>
@@ -152,21 +154,17 @@ internal void IndicateDeletion(string filePathTodelete)
152
154
public void PreStartCleanUpAfterPortabilityUpdate ( )
153
155
{
154
156
// 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 ;
157
+ var portableDataDir = Path . Combine ( Directory . GetParent ( Assembly . GetExecutingAssembly ( ) . Location . NonNull ( ) ) . ToString ( ) , "UserData" ) ;
158
+ var roamingDataDir = Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . ApplicationData ) , "FlowLauncher" ) ;
160
159
161
- if ( ( roamingDataPath + "\\ " + DataLocation . DeletionIndicatorFile ) . FileExits ( ) )
162
- DataLocationRoamingDeleteRequired = true ;
160
+ // Get full path to the .dead files for each case
161
+ var portableDataDeleteFilePath = Path . Combine ( portableDataDir , DataLocation . DeletionIndicatorFile ) ;
162
+ var roamingDataDeleteFilePath = Path . Combine ( roamingDataDir , DataLocation . DeletionIndicatorFile ) ;
163
163
164
- if ( ( portableDataPath + "\\ " + DataLocation . DeletionIndicatorFile ) . FileExits ( ) )
165
- DataLocationPortableDeleteRequired = true ;
166
-
167
- if ( DataLocationRoamingDeleteRequired )
164
+ // Should we switch from %AppData% to portable mode?
165
+ if ( File . Exists ( roamingDataDeleteFilePath ) )
168
166
{
169
- FilesFolders . RemoveFolderIfExists ( roamingDataPath ) ;
167
+ FilesFolders . RemoveFolderIfExists ( roamingDataDir ) ;
170
168
171
169
if ( MessageBox . Show ( "Flow Launcher has detected you enabled portable mode, " +
172
170
"would you like to move it to a different location?" , string . Empty ,
@@ -176,18 +174,14 @@ public void PreStartCleanUpAfterPortabilityUpdate()
176
174
177
175
Environment . Exit ( 0 ) ;
178
176
}
179
-
180
- return ;
181
177
}
182
-
183
- if ( DataLocationPortableDeleteRequired )
178
+ // Should we switch from portable mode to %AppData%?
179
+ else if ( File . Exists ( portableDataDeleteFilePath ) )
184
180
{
185
- FilesFolders . RemoveFolderIfExists ( portableDataPath ) ;
181
+ FilesFolders . RemoveFolderIfExists ( portableDataDir ) ;
186
182
187
183
MessageBox . Show ( "Flow Launcher has detected you disabled portable mode, " +
188
184
"the relevant shortcuts and uninstaller entry have been created" ) ;
189
-
190
- return ;
191
185
}
192
186
}
193
187
@@ -196,7 +190,7 @@ public bool CanUpdatePortability()
196
190
var roamingLocationExists = DataLocation . RoamingDataPath . LocationExists ( ) ;
197
191
var portableLocationExists = DataLocation . PortableDataPath . LocationExists ( ) ;
198
192
199
- if ( roamingLocationExists && portableLocationExists )
193
+ if ( roamingLocationExists && portableLocationExists )
200
194
{
201
195
MessageBox . Show ( string . Format ( "Flow Launcher detected your user data exists both in {0} and " +
202
196
"{1}. {2}{2}Please delete {1} in order to proceed. No changes have occured." ,
0 commit comments