예제 #1
0
 private void ExtractPackage(Package package)
 {
     labelStatus.Text = "Extracting " + packageOnDownloading.Name;
     try
     {
         var packagelocation = Path.Combine(tempFolder.FullName, package.Name);
         using (var zippkg = ZipFile.Read(packagelocation))
             foreach (var entry in zippkg)
                 entry.Extract(hyperFolder.FullName, ExtractExistingFileAction.OverwriteSilently);
         package.Extracted = true;
     }
     catch (Exception e)
     {
         MessageBox.Show(string.Format("Failed to extract {0}\nError: {1}", package.Name, e.Message), "ExtractPackage");
         CleanDirectory(tempFolder);
         Environment.Exit(0);
     }
 }
예제 #2
0
        private async void DownloadFiles(List<Package> packagelist)
        {
            if (packagelist != null && packagelist.Count > 0)
            {
                labelStatus.Text = "Attempt to download files. Please wait.";
                Refresh();
                tempFolder = Directory.CreateDirectory("tmp");
                CleanFiles(tempFolder);
                patcherIsDownloading = false;
                updateCompleted = false;
                hasUpdates = true;
                var count = 0;

                while (!updateCompleted)
                {
                    foreach (var package in packagelist)
                    {
                        count++;
                        package.Localization = Path.Combine(tempFolder.FullName, package.Name);

                        while (patcherIsDownloading)
                            await Task.Delay(1000);

                        if (!package.Downloaded)
                        {
                            using (webClient = new WebClient())
                            {
                                stopwatch.Start();
                                webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
                                webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
                                labelStatus.Text = "Fetching " + package.Name;
                                this.Text = string.Format("[{1}/{2}] {0}", windowTitle, count, packagelist.Count);
                                try
                                {
                                    var fileaddress = new Uri(patchesWebPath.AbsoluteUri + package.Name);
                                    webClient.DownloadFileAsync(fileaddress, package.Localization);
                                    packageOnDownloading = package;
                                    patcherIsDownloading = true;
                                }
                                catch (Exception e)
                                {
                                    MessageBox.Show(e.Message);
                                    return;
                                }
                            }
                        }
                    }
                    while (patcherIsDownloading)
                        await Task.Delay(1000);
                    updateCompleted = true;
                    RecheckPackages(packagelist);
                }
            }
            FinishPatchProcess();
            return;
        }
예제 #3
0
        private List<Package> BuildDownloadList(string patchlist)
        {
            labelStatus.Text = "Building download list.";
            Refresh();
            var filelist = new List<Package>();
            patchlist = patchlist.Replace("\r", "");
            patchlist = patchlist.Replace("\n", Environment.NewLine);
            using (var reader = new StringReader(patchlist))
            {
                var line = string.Empty;
                while ((line = reader.ReadLine()) != null)
                {
                    var splitline = line.Split('\t');
                    var package = new Package();
                    try
                    {
                        package.Version = Convert.ToUInt32(splitline[0]);
                        package.Name = splitline[1];
                    }
                    catch (Exception e)
                    {
                        labelStatus.Text = "Patch list is not correct. - Line: " + line + "\nError: " + e.Message;
                        Refresh();
                        return null;
                    }

                    if ((package.Name.Contains(".zip")) && package.Version > patchVersion) //autoupdate files
                        filelist.Add(package);

                    else if (package.Name.Contains(".hyp") && package.Version > hyperVersion) //autoupdate patcher
                        HyperbyteUpdate();
                }
            }
            return filelist;
        }
예제 #4
0
 private Package BuildDownloadList(string patchlist)
 {
     labelStatus.Text = "Fetching update.";
     Refresh();
     Package package2download = null;
     patchlist.Replace("\r", "");
     using (var reader = new StringReader(patchlist))
     {
         var line = string.Empty;
         while ((line = reader.ReadLine()) != null)
         {
             var splitline = line.Split('\t');
             var package = new Package();
             try
             {
                 package.Version = Convert.ToUInt32(splitline[0]);
                 package.Name = splitline[1];
             }
             catch (Exception e)
             {
                 labelStatus.Text = "Patch list is incorret. - Line: " + line + "\nError: " + e.Message;
                 Refresh();
                 return null;
             }
             if (package.Name.Contains(".hyp") && package.Version > hyperVersion) //select the last one (newer)
                 package2download = package;
         }
     }
     return package2download;
 }
예제 #5
0
 private void RecheckPackages(Package packagelist)
 {
     labelStatus.Text = "Rechecking Packages.";
     var pkg = packagelist;
     if (pkg.Downloaded == false || pkg.Extracted == false)
     {
         updateCompleted = false;
         return;
     }
 }
예제 #6
0
        private async void DownloadFiles(Package package)
        {
            if (package != null)
            {
                labelStatus.Text = "Attempt to download. Please wait.";
                Refresh();
                tempFolder = Directory.CreateDirectory("tmp");
                CleanFiles(tempFolder);
                patcherIsDownloading = false;
                updateCompleted = false;

                while (!updateCompleted)
                {
                    package.Localization = Path.Combine(tempFolder.FullName, package.Name);

                    while (patcherIsDownloading)
                        await Task.Delay(1000);

                    if (!package.Downloaded)
                    {
                        using (webClient = new WebClient())
                        {
                            webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
                            webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
                            labelStatus.Text = "Fetching " + package.Name;
                            try
                            {
                                var fileaddress = new Uri(patchesWebPath.AbsoluteUri + package.Name);
                                webClient.DownloadFileAsync(fileaddress, package.Localization);
                                packageOnDownloading = package;
                                patcherIsDownloading = true;
                            }
                            catch (Exception e)
                            {
                                MessageBox.Show(e.Message);
                                return;
                            }
                        }
                    }
                    while (patcherIsDownloading)
                        await Task.Delay(1000);

                    updateCompleted = true;
                    RecheckPackages(package);
                }
                FinishUpdateProcess();
            }
            else
                StartPatcher();
        }