예제 #1
0
 private void DA_MyDownloadChanged(DownloaderAsync sender, DownloadProgressChangedEventArgs e)
 {
     progress = (double)e.BytesReceived / (double)e.TotalBytesToReceive;
     try
     {
         logBuilder.Append("[PROGRESS] " + (progress * 100).ToString("0.000") + " % " + Environment.NewLine);
     }
     catch (Exception ex) { }
 }
예제 #2
0
        private void DA_MyDownloadChanged(DownloaderAsync sender, DownloadProgressChangedEventArgs e)
        {
            double progress = (double)e.BytesReceived / (double)e.TotalBytesToReceive;

            try
            {
                ccMainLog.AppendText(sender.filename + " : [PROGRESS] " + (progress * 100).ToString("0.000") + " % " + Environment.NewLine);
                ccMainLog.ScrollToCaret();
            }
            catch (Exception ex) { }
        }
예제 #3
0
        // 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");
        }
예제 #4
0
 private void DA_MyDownloadCompleted(DownloaderAsync sender, DownloadDataCompletedEventArgs e)
 {
     logBuilder.Append("[PROGRESS] Done");
     logBuilder.Append(sender.url.ToString() + ":" + Environment.NewLine);
     logBuilder.Append("[BYTES SIZE] " + sender.totalBytesToReceive.ToString() + Environment.NewLine);
     logBuilder.Append("[TIME NEEDED] (ms): " + sender.timeNeeded.TotalMilliseconds + Environment.NewLine + Environment.NewLine);
     try
     {
         Directory.CreateDirectory(outputPath);
         File.Create(Path.Combine(outputPath, filename)).Close();
         File.WriteAllBytes(Path.Combine(outputPath, filename), sender.data);
     }
     catch (Exception ex)
     {
         logBuilder.Append(ex.ToString() + Environment.NewLine + Environment.NewLine);
     }
 }
예제 #5
0
        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();
            }
        }
예제 #6
0
 public void setDownloaderEvents()
 {
     downloadAssistant = new DownloaderAsync();
     downloadAssistant.MyDownloadCompleted += DA_MyDownloadCompleted;
     downloadAssistant.MyDownloadChanged   += DA_MyDownloadChanged;
 }
예제 #7
0
 private void OnDownloadChanged(DownloaderAsync sender, DownloadProgressChangedEventArgs e)
 {
     MyDownloadChanged?.Invoke(this, e);
 }
예제 #8
0
 private void OnDownloadCompleted(DownloaderAsync sender, DownloadDataCompletedEventArgs e)
 {
     MyDownloadCompleted?.Invoke(this, e);
 }
예제 #9
0
        private void DA_MyDownloadCompleted(DownloaderAsync sender, DownloadDataCompletedEventArgs e)
        {
            ccMainLog.AppendText(sender.filename + " : [PROGRESS] Done" + Environment.NewLine);
            ccMainLog.AppendText(sender.filename + " : " + sender.url.ToString() + ":" + Environment.NewLine);
            ccMainLog.AppendText(sender.filename + " : [BYTES SIZE] " + sender.totalBytesToReceive.ToString() + Environment.NewLine);
            ccMainLog.AppendText(sender.filename + " : [TIME NEEDED] (ms): " + Math.Round(sender.timeNeeded.TotalMilliseconds) + Environment.NewLine);
            ccMainLog.ScrollToCaret();

            try
            {
                lock (resourcesMissingCountLock)
                {
                    resourcesMissingCount--;
                }

                foreach (string outputPath in sender.outputPaths)
                {
                    string path       = "";
                    string senderPath = outputPath;

                    if (senderPath.Contains("\\"))
                    {
                        path = senderPath.Substring(0, senderPath.LastIndexOf("\\"));
                    }

                    if (path.Length > 0)
                    {
                        Directory.CreateDirectory(path);
                    }

                    // write the file
                    ccMainLog.AppendText(sender.filename + " : " + outputPath + Environment.NewLine);
                    File.Create(outputPath).Close();
                    File.WriteAllBytes(outputPath, sender.data);
                }
            }
            catch (Exception ex)
            {
                ccMainLog.AppendText(sender.filename + Environment.NewLine + ex.ToString() + Environment.NewLine + Environment.NewLine);
            }

            ccMainLog.AppendText(Environment.NewLine);

            lock (resourcesMissingCountLock)
            {
                if (resourcesMissingCount == 0)
                {
                    ccMainLog.AppendText("All resources downloaded..." + Environment.NewLine);
                    ccMainLog.AppendText("Saving update log..." + Environment.NewLine);
                    ccMainLog.AppendText("Replacing resources.json..." + Environment.NewLine + Environment.NewLine);
                    ccMainLog.SelectionColor = Shared.preferences.colorAccent2;
                    ccMainLog.AppendText("ALL DONE :)" + Environment.NewLine + Environment.NewLine);
                    addLastMessage();
                    File.WriteAllText("lastUpdateLog.txt", ccMainLog.Text);
                    // replace the local resources list with the remote one
                    File.Create(Path.Combine(OnlineResource.LyreUpdaterLocation, "resources.json")).Close();
                    SharedFunctions.saveJSON(Path.Combine(OnlineResource.LyreUpdaterLocation, "resources.json"), remoteResourcesList);
                    ccMainLog.ScrollToCaret();
                }
            }
        }
예제 #10
0
 private void setDownloaderEvents(DownloaderAsync whichToSet)
 {
     whichToSet.MyDownloadCompleted += DA_MyDownloadCompleted;
 }
예제 #11
0
 private void DaResourcesList_MyDownloadChanged(DownloaderAsync sender, DownloadProgressChangedEventArgs e)
 {
 }