Exemplo n.º 1
0
        void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker  worker     = sender as BackgroundWorker;
            IArchive          compressed = e.Argument as IArchive;
            DownloadableAddon addon      = archiveToAddon[compressed];

            string destinationDirectory = this.main.path;
            int    i = 0;

            foreach (var entry in compressed.Entries)
            {
                if (i == 0)
                {
                    addonToRootPath[addon] = entry.FilePath.Replace("/", "");
                }
                if (!entry.IsDirectory)
                {
                    try
                    {
                        entry.WriteToDirectory(destinationDirectory, ExtractOptions.ExtractFullPath | ExtractOptions.Overwrite);
                        List <object> objectsToGive = new List <object>();
                        objectsToGive.Add(i);
                        objectsToGive.Add(addon);
                        bytesRecievedOfAddon[addon] += entry.Size;
                    }
                    catch (Exception ex)
                    {
                        ErrorWriter.writeError(ex.Message + " " + ex.StackTrace);
                    }
                    //worker.ReportProgress(1, objectsToGive);
                }
                i++;
            }
        }
Exemplo n.º 2
0
        public void extractRar(DownloadableAddon addon, String extention)
        {
            try
            {
                BackgroundWorker worker = new BackgroundWorker();
                worker.WorkerReportsProgress = true;
                worker.DoWork             += new DoWorkEventHandler(worker_DoWork);
                worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);
                worker.ProgressChanged    += new ProgressChangedEventHandler(worker_ProgressChanged);

                IArchive compressed = ArchiveFactory.Open(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\" + addon.fileName);
                compressed.CompressedBytesRead += new EventHandler <CompressedBytesReadEventArgs>(compressed_CompressedBytesRead);
                archiveToAddon.Add(compressed, addon);

                backgroundWorkerToAddon.Add(worker, addon);
                addonToBackgroundDownloader.Add(addon, worker);
                backGroundWorkerToArchive.Add(worker, compressed);
                bytesRecievedOfAddon.Add(addon, 0);

                worker.RunWorkerAsync(compressed);
            }
            catch (Exception ex)
            {
                int num = (int)MessageBox.Show("Fehler beim entpacken: " + ex.Message);
                this.main.reportProgress(addon, " - Fehler beim entpacken.", true);
            }
        }
Exemplo n.º 3
0
        private void webClient_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
        {
            WebClient w = (WebClient)sender;

            speedCounter.Remove(w);

            this.main.reportProgress(e.UserState as DownloadableAddon, "Entpacke...", true);
            this.main.AllowUIToUpdate();
            DownloadableAddon addon = e.UserState as DownloadableAddon;

            addon.fileName = System.IO.Path.GetFileName(addon.Link);
            string extension = Path.GetExtension(addon.fileName);

            if (extension == ".zip" && false)
            {
                this.extractZip(addon);
                this.removeDownloadedAddon(addon);
            }
            else
            {
                this.extractRar(addon, extension);
            }

            /*else
             * {
             *  int num = (int)MessageBox.Show("Das addon " + addon.fileName + " hat ein unbekanntes dateiformat. (Es werden nur .zip und .rar erkannt");
             * }*/
            ConfigManager.writeVersionFileForAddon(addon, this.main.path);
        }
 private bool isNewerVersionOfAddonUploaded(DownloadableAddon addon)
 {
     foreach (System.Windows.Controls.CheckBox checkBox in (IEnumerable)this.listAddons.Items)
     {
         if ((checkBox.Content as string).Equals(addon.name) && checkBox.Tag != null && checkBox.Tag is DownloadableAddon)
         {
             return((checkBox.Tag as DownloadableAddon).version < addon.version);
         }
     }
     return(true);
 }
Exemplo n.º 5
0
 public void removeDownloadedAddon(DownloadableAddon addon)
 {
     try
     {
         System.IO.File.Delete(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\" + addon.fileName);
     }
     catch (Exception ex)
     {
         int num = (int)MessageBox.Show("Konnte Addon " + addon.name + " nicht löschen. " + ex.Message);
     }
 }
Exemplo n.º 6
0
        void compressed_CompressedBytesRead(object sender, CompressedBytesReadEventArgs e)
        {
            DownloadableAddon addon = archiveToAddon[sender as IArchive];

            BackgroundWorker worker = addonToBackgroundDownloader[addon];

            List <object> objectsToGive = new List <object>();

            objectsToGive.Add(e.CompressedBytesRead);
            objectsToGive.Add(addon);

            worker.ReportProgress(1, objectsToGive);
        }
Exemplo n.º 7
0
        void worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            List <Object>     objects       = e.UserState as List <Object>;
            long              BytesRecieved = (long)objects[0];
            DownloadableAddon addon         = objects[1] as DownloadableAddon;

            BytesRecieved += bytesRecievedOfAddon[addon];
            long TotalBytesToRecieve = backGroundWorkerToArchive[addonToBackgroundDownloader[addon]].TotalSize;

            double d1   = (double)(BytesRecieved / 1000L) / 1000.0;
            string str1 = this.doubleToShortenedString(d1);
            double d2   = (double)(TotalBytesToRecieve / 1000L) / 1000.0;
            string str2 = this.doubleToShortenedString(d2);

            double d3 = 100.0 / d2 * d1;

            this.main.reportProgress(addon, " Entpacke: " + str1 + " MB / " + str2 + " MB (" + this.doubleToShortenedString(d3) + "%)", false);
        }
Exemplo n.º 8
0
        public void downloadAddon(DownloadableAddon addon)
        {
            bool   flag = false;
            string str  = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\";

            flag = false;
            WebClient webClient = (WebClient) new WebClient();

            webClient.Proxy = (IWebProxy)null;
            webClient.DownloadFileCompleted   += new AsyncCompletedEventHandler(this.webClient_DownloadFileCompleted);
            webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(this.webClient_DownloadProgressChanged);
            webClient.DownloadFileAsync(new Uri(addon.Link), str + System.IO.Path.GetFileName(addon.Link), (object)addon);

            NetSpeedCounter counter = new NetSpeedCounter(webClient);

            speedCounter.Add(webClient, counter);
            counter.Start();
        }
 public void addonWasSuccesfullyExtracted(DownloadableAddon addon)
 {
     --this.currentDownloadCount;
     System.Windows.Controls.CheckBox checkBox1 = (System.Windows.Controls.CheckBox)null;
     foreach (System.Windows.Controls.CheckBox checkBox2 in (IEnumerable)this.listAllPheonixAddons.Items)
     {
         if ((checkBox2.Tag as DownloadableAddon).name.Equals(addon.fileName))
         {
             checkBox1 = checkBox2;
             break;
         }
     }
     if (checkBox1 == null)
     {
         return;
     }
     this.checkForAddons(true);
     this.getDownloadableAddons();
 }
Exemplo n.º 10
0
        void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            DownloadableAddon addon    = backgroundWorkerToAddon[sender as BackgroundWorker];
            IArchive          archive  = backGroundWorkerToArchive[sender as BackgroundWorker];
            String            pathName = addonToRootPath[addon];

            archiveToAddon.Remove(archive);
            backgroundWorkerToAddon.Remove(sender as BackgroundWorker);
            addonToBackgroundDownloader.Remove(addon);
            backGroundWorkerToArchive.Remove(sender as BackgroundWorker);
            addonToRootPath.Remove(addon);

            this.main.reportProgress(addon, " durchsuche Ordner", false);

            List <String> pathes = new List <string>();

            getRealModFolders(main.path + "\\" + pathName, ref pathes);
            copyFoldersToRightPosition(pathes);

            this.main.reportProgress(addon, " Fertig.", false);
        }
Exemplo n.º 11
0
 public void extractZip(DownloadableAddon addon)
 {
     try
     {
         string fileName      = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\" + addon.fileName;
         string baseDirectory = this.main.path;
         using (ZipFile zipFile = ZipFile.Read(fileName))
         {
             foreach (ZipEntry zipEntry in zipFile)
             {
                 zipEntry.Extract(baseDirectory, ExtractExistingFileAction.OverwriteSilently);
             }
         }
         this.main.addonWasSuccesfullyExtracted(addon);
     }
     catch (Exception ex)
     {
         int num = (int)MessageBox.Show("Fehler beim entpacken: " + ex.Message);
         this.main.reportProgress(addon, " - Fehler beim entpacken.", true);
     }
 }