@@ -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
@@ -48,10 +47,7 @@ public void DisablePortableMode()
48
47
}
49
48
catch ( Exception e )
50
49
{
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 ) ;
55
51
}
56
52
}
57
53
@@ -60,10 +56,9 @@ public void EnablePortableMode()
60
56
try
61
57
{
62
58
MoveUserDataFolder ( DataLocation . RoamingDataPath , DataLocation . PortableDataPath ) ;
63
- #if DEBUG
59
+ #if ! DEBUG
64
60
// Remove shortcuts and uninstaller are not required in debug mode,
65
61
// otherwise will delete the actual installed production version
66
- #else
67
62
RemoveShortcuts ( ) ;
68
63
RemoveUninstallerEntry ( ) ;
69
64
#endif
@@ -76,10 +71,7 @@ public void EnablePortableMode()
76
71
}
77
72
catch ( Exception e )
78
73
{
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 ) ;
83
75
}
84
76
}
85
77
@@ -125,14 +117,13 @@ public void CreateShortcuts()
125
117
public void CreateUninstallerEntry ( )
126
118
{
127
119
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 ) ) { ; }
132
120
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
+ }
136
127
137
128
using ( var portabilityUpdater = NewUpdateManager ( ) )
138
129
{
@@ -142,7 +133,10 @@ public void CreateUninstallerEntry()
142
133
143
134
internal void IndicateDeletion ( string filePathTodelete )
144
135
{
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
+ }
146
140
}
147
141
148
142
///<summary>
@@ -152,21 +146,18 @@ internal void IndicateDeletion(string filePathTodelete)
152
146
public void PreStartCleanUpAfterPortabilityUpdate ( )
153
147
{
154
148
// 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" ) ;
163
151
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 ) ;
166
155
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 ) )
168
159
{
169
- FilesFolders . RemoveFolderIfExists ( roamingDataPath ) ;
160
+ FilesFolders . RemoveFolderIfExists ( roamingDataDir ) ;
170
161
171
162
if ( MessageBox . Show ( "Flow Launcher has detected you enabled portable mode, " +
172
163
"would you like to move it to a different location?" , string . Empty ,
@@ -176,18 +167,15 @@ public void PreStartCleanUpAfterPortabilityUpdate()
176
167
177
168
Environment . Exit ( 0 ) ;
178
169
}
179
-
180
- return ;
181
170
}
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 ) )
184
174
{
185
- FilesFolders . RemoveFolderIfExists ( portableDataPath ) ;
175
+ FilesFolders . RemoveFolderIfExists ( portableDataDir ) ;
186
176
187
177
MessageBox . Show ( "Flow Launcher has detected you disabled portable mode, " +
188
178
"the relevant shortcuts and uninstaller entry have been created" ) ;
189
-
190
- return ;
191
179
}
192
180
}
193
181
@@ -196,7 +184,7 @@ public bool CanUpdatePortability()
196
184
var roamingLocationExists = DataLocation . RoamingDataPath . LocationExists ( ) ;
197
185
var portableLocationExists = DataLocation . PortableDataPath . LocationExists ( ) ;
198
186
199
- if ( roamingLocationExists && portableLocationExists )
187
+ if ( roamingLocationExists && portableLocationExists )
200
188
{
201
189
MessageBox . Show ( string . Format ( "Flow Launcher detected your user data exists both in {0} and " +
202
190
"{1}. {2}{2}Please delete {1} in order to proceed. No changes have occured." ,
0 commit comments