Skip to content

Commit cbfa3f3

Browse files
committed
Inform user when checking update fail or update fail, and wrap all code in one try catch instead of catch each exception seperately since they are all same kind of exception.
Use using instead of manually dispose.
1 parent f61a727 commit cbfa3f3

File tree

1 file changed

+45
-65
lines changed

1 file changed

+45
-65
lines changed

Flow.Launcher.Core/Updater.cs

Lines changed: 45 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -29,89 +29,69 @@ public Updater(string gitHubRepository)
2929
GitHubRepository = gitHubRepository;
3030
}
3131

32-
public async Task UpdateApp(IPublicAPI api , bool silentUpdate = true)
32+
public async Task UpdateApp(IPublicAPI api, bool silentUpdate = true)
3333
{
34-
UpdateManager updateManager;
35-
UpdateInfo newUpdateInfo;
36-
37-
if (!silentUpdate)
38-
api.ShowMsg("Please wait...", "Checking for new update");
39-
4034
try
4135
{
42-
updateManager = await GitHubUpdateManager(GitHubRepository);
43-
}
44-
catch (Exception e) when (e is HttpRequestException || e is WebException || e is SocketException)
45-
{
46-
Log.Exception($"|Updater.UpdateApp|Please check your connection and proxy settings to api.github.com.", e);
47-
return;
48-
}
36+
UpdateInfo newUpdateInfo;
37+
38+
if (!silentUpdate)
39+
api.ShowMsg("Please wait...", "Checking for new update");
40+
41+
using var updateManager = await GitHubUpdateManager(GitHubRepository);
42+
4943

50-
try
51-
{
5244
// UpdateApp CheckForUpdate will return value only if the app is squirrel installed
5345
newUpdateInfo = await updateManager.CheckForUpdate().NonNull();
54-
}
55-
catch (Exception e) when (e is HttpRequestException || e is WebException || e is SocketException)
56-
{
57-
Log.Exception($"|Updater.UpdateApp|Check your connection and proxy settings to api.github.com.", e);
58-
updateManager.Dispose();
59-
return;
60-
}
6146

62-
var newReleaseVersion = Version.Parse(newUpdateInfo.FutureReleaseEntry.Version.ToString());
63-
var currentVersion = Version.Parse(Constant.Version);
47+
var newReleaseVersion = Version.Parse(newUpdateInfo.FutureReleaseEntry.Version.ToString());
48+
var currentVersion = Version.Parse(Constant.Version);
6449

65-
Log.Info($"|Updater.UpdateApp|Future Release <{newUpdateInfo.FutureReleaseEntry.Formatted()}>");
50+
Log.Info($"|Updater.UpdateApp|Future Release <{newUpdateInfo.FutureReleaseEntry.Formatted()}>");
6651

67-
if (newReleaseVersion <= currentVersion)
68-
{
69-
if (!silentUpdate)
70-
MessageBox.Show("You already have the latest Flow Launcher version");
71-
updateManager.Dispose();
72-
return;
73-
}
52+
if (newReleaseVersion <= currentVersion)
53+
{
54+
if (!silentUpdate)
55+
MessageBox.Show("You already have the latest Flow Launcher version");
56+
updateManager.Dispose();
57+
return;
58+
}
7459

75-
if (!silentUpdate)
76-
api.ShowMsg("Update found", "Updating...");
60+
if (!silentUpdate)
61+
api.ShowMsg("Update found", "Updating...");
7762

78-
try
79-
{
8063
await updateManager.DownloadReleases(newUpdateInfo.ReleasesToApply);
64+
65+
await updateManager.ApplyReleases(newUpdateInfo);
66+
67+
if (DataLocation.PortableDataLocationInUse())
68+
{
69+
var targetDestination = updateManager.RootAppDirectory + $"\\app-{newReleaseVersion.ToString()}\\{DataLocation.PortableFolderName}";
70+
FilesFolders.CopyAll(DataLocation.PortableDataPath, targetDestination);
71+
if (!FilesFolders.VerifyBothFolderFilesEqual(DataLocation.PortableDataPath, targetDestination))
72+
MessageBox.Show("Flow Launcher was not able to move your user profile data to the new update version. Please manually " +
73+
$"move your profile data folder from {DataLocation.PortableDataPath} to {targetDestination}");
74+
}
75+
else
76+
{
77+
await updateManager.CreateUninstallerRegistryEntry();
78+
}
79+
80+
var newVersionTips = NewVersinoTips(newReleaseVersion.ToString());
81+
82+
Log.Info($"|Updater.UpdateApp|Update success:{newVersionTips}");
83+
84+
if (MessageBox.Show(newVersionTips, "New Update", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
85+
{
86+
UpdateManager.RestartApp(Constant.ApplicationFileName);
87+
}
8188
}
8289
catch (Exception e) when (e is HttpRequestException || e is WebException || e is SocketException)
8390
{
8491
Log.Exception($"|Updater.UpdateApp|Check your connection and proxy settings to github-cloud.s3.amazonaws.com.", e);
85-
updateManager.Dispose();
92+
api.ShowMsg("Update Fail!", "Check your connection and proxy settings to github-cloud.s3.amazonaws.com.");
8693
return;
8794
}
88-
89-
await updateManager.ApplyReleases(newUpdateInfo);
90-
91-
if (DataLocation.PortableDataLocationInUse())
92-
{
93-
var targetDestination = updateManager.RootAppDirectory + $"\\app-{newReleaseVersion.ToString()}\\{DataLocation.PortableFolderName}";
94-
FilesFolders.CopyAll(DataLocation.PortableDataPath, targetDestination);
95-
if (!FilesFolders.VerifyBothFolderFilesEqual(DataLocation.PortableDataPath, targetDestination))
96-
MessageBox.Show("Flow Launcher was not able to move your user profile data to the new update version. Please manually " +
97-
$"move your profile data folder from {DataLocation.PortableDataPath} to {targetDestination}");
98-
}
99-
else
100-
{
101-
await updateManager.CreateUninstallerRegistryEntry();
102-
}
103-
104-
var newVersionTips = NewVersinoTips(newReleaseVersion.ToString());
105-
106-
Log.Info($"|Updater.UpdateApp|Update success:{newVersionTips}");
107-
108-
// always dispose UpdateManager
109-
updateManager.Dispose();
110-
111-
if (MessageBox.Show(newVersionTips, "New Update", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
112-
{
113-
UpdateManager.RestartApp(Constant.ApplicationFileName);
114-
}
11595
}
11696

11797
[UsedImplicitly]

0 commit comments

Comments
 (0)