public void download(string url, string outputPath, string filename) { this.url = url; this.outputPath = outputPath; this.filename = filename; setDownloaderEvents(); downloadAssistant.download(url); }
// Actual updater section private void DownloadRemoteResourcesJson() { //Text = OnlineResource.LyreUpdaterLocation; DownloaderAsync daResourcesList = new DownloaderAsync(new List <string> { Path.Combine(OnlineResource.LyreUpdaterLocation, Shared.tempDirectory, "remoteResources.json") }); daResourcesList.MyDownloadCompleted += DaResourcesList_MyDownloadCompleted; daResourcesList.MyDownloadChanged += DaResourcesList_MyDownloadChanged; daResourcesList.download(OnlineResource.resourcesWebsiteURL + "resources.json"); }
private void DaResourcesList_MyDownloadCompleted(DownloaderAsync sender, DownloadDataCompletedEventArgs e) { // write the file File.Create(Path.Combine(OnlineResource.LyreUpdaterLocation, Shared.tempDirectory, "remoteResources.json")).Close(); File.WriteAllBytes(Path.Combine(OnlineResource.LyreUpdaterLocation, Shared.tempDirectory, "remoteResources.json"), sender.data); SharedFunctions.loadJSON(sender.outputPaths[0], ref remoteResourcesList); // this could be improved by matching version/iteration numbers of // local files where there is more than one file of the same resource instance int hits = 0; foreach (OnlineResource onR in remoteResourcesList) { foreach (string path in onR.paths) { if (File.Exists(path) == false || newerAvailable(onR)) { hits++; lock (resourcesMissingCountLock) { resourcesMissingCount++; // NAH download the file to a temporary folder and replace the older one only after // NAH a successful download DownloaderAsync newDA = new DownloaderAsync(onR.paths); //Shared.tempDirectory + Path.GetFileName(path)); setDownloaderEvents(newDA); newDA.download(onR.url); } break; } } } if (hits == 0) { ccMainLog.SelectionColor = Shared.preferences.colorAccent2; ccMainLog.AppendText("No new updates found..." + Environment.NewLine + Environment.NewLine); ccMainLog.SelectionColor = Shared.preferences.colorFontDefault; addLastMessage(); } }