Skip to content

Commit 4ac1925

Browse files
committed
refactor Core.Configuration.Portable
1 parent 0ddd7f2 commit 4ac1925

File tree

1 file changed

+25
-31
lines changed

1 file changed

+25
-31
lines changed

Flow.Launcher.Core/Configuration/Portable.cs

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -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
@@ -60,10 +59,9 @@ public void EnablePortableMode()
6059
try
6160
{
6261
MoveUserDataFolder(DataLocation.RoamingDataPath, DataLocation.PortableDataPath);
63-
#if DEBUG
62+
#if !DEBUG
6463
// Remove shortcuts and uninstaller are not required in debug mode,
6564
// otherwise will delete the actual installed production version
66-
#else
6765
RemoveShortcuts();
6866
RemoveUninstallerEntry();
6967
#endif
@@ -126,13 +124,16 @@ public void CreateUninstallerEntry()
126124
{
127125
var uninstallRegSubKey = @"Software\Microsoft\Windows\CurrentVersion\Uninstall";
128126
// 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();
132131

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);
136137

137138
using (var portabilityUpdater = NewUpdateManager())
138139
{
@@ -142,7 +143,8 @@ public void CreateUninstallerEntry()
142143

143144
internal void IndicateDeletion(string filePathTodelete)
144145
{
145-
using (StreamWriter sw = File.CreateText(filePathTodelete + "\\" + DataLocation.DeletionIndicatorFile)){}
146+
var deleteFilePath = Path.Combine(filePathTodelete, DataLocation.DeletionIndicatorFile);
147+
File.CreateText(deleteFilePath).Close();
146148
}
147149

148150
///<summary>
@@ -152,21 +154,17 @@ internal void IndicateDeletion(string filePathTodelete)
152154
public void PreStartCleanUpAfterPortabilityUpdate()
153155
{
154156
// 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");
160159

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);
163163

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))
168166
{
169-
FilesFolders.RemoveFolderIfExists(roamingDataPath);
167+
FilesFolders.RemoveFolderIfExists(roamingDataDir);
170168

171169
if (MessageBox.Show("Flow Launcher has detected you enabled portable mode, " +
172170
"would you like to move it to a different location?", string.Empty,
@@ -176,18 +174,14 @@ public void PreStartCleanUpAfterPortabilityUpdate()
176174

177175
Environment.Exit(0);
178176
}
179-
180-
return;
181177
}
182-
183-
if(DataLocationPortableDeleteRequired)
178+
// Should we switch from portable mode to %AppData%?
179+
else if (File.Exists(portableDataDeleteFilePath))
184180
{
185-
FilesFolders.RemoveFolderIfExists(portableDataPath);
181+
FilesFolders.RemoveFolderIfExists(portableDataDir);
186182

187183
MessageBox.Show("Flow Launcher has detected you disabled portable mode, " +
188184
"the relevant shortcuts and uninstaller entry have been created");
189-
190-
return;
191185
}
192186
}
193187

@@ -196,7 +190,7 @@ public bool CanUpdatePortability()
196190
var roamingLocationExists = DataLocation.RoamingDataPath.LocationExists();
197191
var portableLocationExists = DataLocation.PortableDataPath.LocationExists();
198192

199-
if(roamingLocationExists && portableLocationExists)
193+
if (roamingLocationExists && portableLocationExists)
200194
{
201195
MessageBox.Show(string.Format("Flow Launcher detected your user data exists both in {0} and " +
202196
"{1}. {2}{2}Please delete {1} in order to proceed. No changes have occured.",

0 commit comments

Comments
 (0)