Skip to content
This repository was archived by the owner on Dec 22, 2019. It is now read-only.

Commit d740080

Browse files
committed
Fixed bug in Updater that supresses the error from the user.
1 parent 51195d2 commit d740080

5 files changed

Lines changed: 33 additions & 26 deletions

File tree

UpdateLib/TestApp/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ static void Main()
2626

2727
private static void InitializeUpdater()
2828
{
29-
//Updater.Instance.Initialize();
29+
Updater.Instance.Initialize();
3030
Updater.Instance.UpdateURL = "https://raw.githubusercontent.com/MatthiWare/UpdateLib.TestApp.UpdateExample/master/Dev/updatefile.xml";
3131
//Updater.Instance.UpdateURL = "http://matthiware.dev/UpdateLib/Dev/updatefile.xml";
3232
}

UpdateLib/UpdateLib/Files/HashCacheFile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ private static string GetStoragePath()
2727
{
2828
string appdata = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
2929
string name = Assembly.GetEntryAssembly().GetName().Name;
30-
storagePath = $@"{appdata}\{name}\MatthiWare.UpdateLib\Cache\HashCacheFile.xml";
30+
storagePath = $@"{appdata}\{name}\UpdateLib\Cache\HashCacheFile.xml";
3131
}
3232

3333
return storagePath;

UpdateLib/UpdateLib/Logging/Writers/FileLogWriter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public FileLogWriter()
1919
{
2020
string appdata = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
2121
string name = Assembly.GetEntryAssembly().GetName().Name;
22-
logFile = new FileInfo($@"{appdata}\{name}\MatthiWare.UpdateLib\Log\log_{DateTime.Now.ToString("yyyyMMdd")}.log");
22+
logFile = new FileInfo($@"{appdata}\{name}\UpdateLib\Log\log_{DateTime.Now.ToString("yyyyMMdd")}.log");
2323

2424
if (!logFile.Directory.Exists)
2525
logFile.Directory.Create();

UpdateLib/UpdateLib/Tasks/CheckForUpdatedFilesTask.cs

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,39 @@ namespace MatthiWare.UpdateLib.Tasks
55
{
66
public class CheckForUpdatedFilesTask : AsyncTask<bool>
77
{
8-
private UpdateFile updateFile;
9-
private HashCacheFile cacheFile;
10-
private PathVariableConverter converter;
8+
private UpdateFile m_updateFile;
9+
private HashCacheFile m_cacheFile;
10+
private PathVariableConverter m_converter;
1111

1212
public CheckForUpdatedFilesTask(UpdateFile update, HashCacheFile cache, PathVariableConverter converter)
1313
{
14-
updateFile = update;
15-
cacheFile = cache;
16-
this.converter = converter;
14+
if (update == null) throw new ArgumentNullException(nameof(update));
15+
if (cache == null) throw new ArgumentNullException(nameof(cache));
16+
if (converter == null) throw new ArgumentNullException(nameof(converter));
17+
18+
m_updateFile = update;
19+
m_cacheFile = cache;
20+
m_converter = converter;
21+
}
22+
23+
protected override void DoWork()
24+
{
25+
Action<DirectoryEntry> call = new Action<DirectoryEntry>(RecursiveCheck);
26+
27+
foreach (DirectoryEntry dir in m_updateFile.Folders)
28+
Enqueue(call, dir);
29+
30+
AwaitWorkers();
31+
32+
Result = m_updateFile.Count > 0;
1733
}
1834

1935
private void RecursiveCheck(DirectoryEntry dir)
2036
{
2137
dir.Files.RemoveAll(fe =>
2238
{
23-
string convertedPath = converter.Replace(fe.DestinationLocation);
24-
HashCacheEntry cacheEntry = cacheFile.Items.Find(hash => hash.FilePath.Equals(convertedPath));
39+
string convertedPath = m_converter.Replace(fe.DestinationLocation);
40+
HashCacheEntry cacheEntry = m_cacheFile.Items.Find(hash => hash.FilePath.Equals(convertedPath));
2541

2642
if (cacheEntry == null)
2743
return false;
@@ -35,17 +51,5 @@ private void RecursiveCheck(DirectoryEntry dir)
3551
foreach (DirectoryEntry de in dir.Directories)
3652
Enqueue(call, de);
3753
}
38-
39-
protected override void DoWork()
40-
{
41-
Action<DirectoryEntry> call = new Action<DirectoryEntry>(RecursiveCheck);
42-
43-
foreach (DirectoryEntry dir in updateFile.Folders)
44-
Enqueue(call, dir);
45-
46-
AwaitWorkers();
47-
48-
Result = updateFile.Count > 0;
49-
}
5054
}
5155
}

UpdateLib/UpdateLib/Updater.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public void Initialize()
8383
CleanUpTask.ConfigureAwait(false).Start();
8484

8585
UpdateCacheTask = new UpdateCacheTask();
86-
UpdateCacheTask.Start();
86+
UpdateCacheTask.ConfigureAwait(false).Start();
8787

8888
initialized = true;
8989
}
@@ -130,10 +130,13 @@ public CheckForUpdatesTask CheckForUpdatesAsync(IWin32Window owner)
130130
throw new ArgumentException("You need to specifify an update url", nameof(UpdateURL));
131131

132132
CheckForUpdatesTask task = new CheckForUpdatesTask(UpdateURL);
133-
task.TaskCompleted += (o, e) =>
133+
task.TaskCompleted += (o, e) =>
134134
{
135-
if (!task.Result.UpdateAvailable) // no updates available
135+
if (!task.Result.UpdateAvailable || e.Cancelled || e.Error != null)
136+
{
137+
CheckForUpdatesCompleted?.Invoke(task, new CheckForUpdatesCompletedEventArgs(task.Result, e));
136138
return;
139+
}
137140

138141
DialogResult result = MessageDialog.Show(
139142
"Update available",

0 commit comments

Comments
 (0)