Exemplo n.º 1
0
            private void ProcessDownload(object state)
            {
                try {
                    string source = System.IO.Path.Combine(Sys.Settings.LibraryLocation, "temp", File);
                    _dest = System.IO.Path.Combine(Sys.Settings.LibraryLocation, File);
                    byte[] sig = new byte[4];
                    using (var iro = new _7thWrapperLib.IrosArc(source, true)) {
                        if (!iro.CheckValid())
                        {
                            throw new Exception("IRO archive appears to be invalid: corrupted download?");
                        }
                        if (!Controller.WaitForPatches())
                        {
                            throw new Exception("Failed to acquire patches");
                        }

                        int numPatch = Controller.PatchFiles.Count;
                        int pDone    = 0;
                        foreach (string pfile in Controller.PatchFiles)
                        {
                            string patchfile = System.IO.Path.Combine(Sys.Settings.LibraryLocation, "temp", pfile);
                            using (var patch = new _7thWrapperLib.IrosArc(patchfile)) {
                                iro.ApplyPatch(patch, (d, _) => SetPCComplete((int)((100 / numPatch) * pDone + 100 * d / numPatch)));
                            }
                            pDone++;
                        }
                    }
                    System.IO.File.Move(source, _dest);
                } catch (Exception e) {
                    Error(e);
                    return;
                }
                SetPCComplete(100);
                Complete();
            }
Exemplo n.º 2
0
            private void ProcessDownload(object state)
            {
                try
                {
                    string source = System.IO.Path.Combine(Sys.Settings.LibraryLocation, "temp", File);
                    _dest = System.IO.Path.Combine(Sys.Settings.LibraryLocation, File);
                    byte[] sig = new byte[4];
                    using (var fs = new System.IO.FileStream(source, System.IO.FileMode.Open, System.IO.FileAccess.Read))
                    {
                        fs.Read(sig, 0, 4);
                        int isig = BitConverter.ToInt32(sig, 0);
                        if (isig == _7thWrapperLib.IrosArc.SIG)
                        {
                            //plain IRO file, just move into place
                            fs.Close();
                            using (var iro = new _7thWrapperLib.IrosArc(source))
                                if (!iro.CheckValid())
                                {
                                    throw new Exception("IRO archive appears to be invalid: corrupted download?");
                                }

                            SetPCComplete(50);

                            System.IO.File.Copy(source, _dest, overwrite: true);
                            System.IO.File.Delete(source);
                        }
                        else
                        {
                            var archive = ArchiveFactory.Open(fs);
                            var iroEnt  = archive.Entries.FirstOrDefault(e => System.IO.Path.GetExtension(e.Key).Equals(".iro", StringComparison.InvariantCultureIgnoreCase));
                            if (iroEnt != null)
                            {
                                SetPCComplete(50);
                                iroEnt.WriteToFile(_dest);
                            }
                            else
                            {
                                //extract entire archive...
                                if (_dest.EndsWith(".iro", StringComparison.InvariantCultureIgnoreCase))
                                {
                                    _dest = _dest.Substring(0, _dest.Length - 4);
                                }
                                var    entries   = archive.Entries.ToArray();
                                string extractTo = _dest;
                                if (!String.IsNullOrEmpty(ExtractInto))
                                {
                                    extractTo = System.IO.Path.Combine(extractTo, ExtractInto);
                                }
                                System.IO.Directory.CreateDirectory(extractTo);
                                using (var reader = archive.ExtractAllEntries())
                                {
                                    int count = 0;
                                    while (reader.MoveToNextEntry())
                                    {
                                        if (!reader.Entry.IsDirectory)
                                        {
                                            string filepath = reader.Entry.Key.Replace('/', '\\');
                                            if (String.IsNullOrEmpty(ExtractSubFolder) || filepath.StartsWith(ExtractSubFolder, StringComparison.InvariantCultureIgnoreCase))
                                            {
                                                string path = System.IO.Path.Combine(extractTo, filepath.Substring(ExtractSubFolder.Length).TrimStart('\\', '/'));
                                                System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(path));
                                                using (var fOut = new System.IO.FileStream(path, System.IO.FileMode.Create))
                                                    reader.WriteEntryTo(fOut);
                                            }
                                            count++;
                                            float prog = (float)count / (float)entries.Length;
                                            SetPCComplete((int)(50 * prog) + 50);  // start at 50% go up to 100%
                                        }
                                    }
                                }
                            }
                            fs.Close();
                            System.IO.File.Delete(source);
                        }
                    }
                }
                catch (Exception e)
                {
                    Error(e);
                    return;
                }
                SetPCComplete(100);
                Complete();
            }
Exemplo n.º 3
0
            private void ProcessDownload(object state)
            {
                // check if already finished processing download and call Complete()
                if (HasProcessed)
                {
                    SetPercentComplete?.Invoke(100);
                    Complete();
                    return;
                }

                try
                {
                    string source = Path.Combine(Sys.Settings.LibraryLocation, "temp", FileName);
                    _dest = Path.Combine(Sys.Settings.LibraryLocation, FileName);

                    byte[] sig  = new byte[4];
                    int    isig = 0;
                    using (var fs = new FileStream(source, FileMode.Open, FileAccess.Read))
                    {
                        fs.Read(sig, 0, 4);
                        isig = BitConverter.ToInt32(sig, 0);
                        fs.Close();
                    }

                    if (isig == _7thWrapperLib.IrosArc.SIG)
                    {
                        //plain IRO file, just move into place
                        using (var iro = new _7thWrapperLib.IrosArc(source))
                            if (!iro.CheckValid())
                            {
                                throw new Exception("IRO archive appears to be invalid: corrupted download?");
                            }

                        SetPercentComplete?.Invoke(50);

                        File.Copy(source, _dest, overwrite: true);
                        File.Delete(source);
                    }
                    else
                    {
                        using (var fs = new FileStream(source, FileMode.Open, FileAccess.Read))
                        {
                            var archive = ArchiveFactory.Open(fs);
                            var iroEnt  = archive.Entries.FirstOrDefault(e => Path.GetExtension(e.Key).Equals(".iro", StringComparison.InvariantCultureIgnoreCase));
                            if (iroEnt != null)
                            {
                                SetPercentComplete?.Invoke(50);
                                iroEnt.WriteToFile(_dest, new SharpCompress.Common.ExtractionOptions()
                                {
                                    Overwrite = true
                                });
                            }
                            else
                            {
                                //extract entire archive...
                                if (_dest.EndsWith(".iro", StringComparison.InvariantCultureIgnoreCase))
                                {
                                    _dest = _dest.Substring(0, _dest.Length - 4);
                                }
                                string extractTo = _dest;
                                if (!String.IsNullOrEmpty(ExtractInto))
                                {
                                    extractTo = Path.Combine(extractTo, ExtractInto);
                                }
                                Directory.CreateDirectory(extractTo);

                                using (var reader = archive.ExtractAllEntries())
                                {
                                    var entries = archive.Entries.ToArray();
                                    int count   = 0;
                                    while (reader.MoveToNextEntry())
                                    {
                                        if (!reader.Entry.IsDirectory)
                                        {
                                            reader.WriteEntryToDirectory(extractTo, new ExtractionOptions()
                                            {
                                                ExtractFullPath = true, Overwrite = true
                                            });
                                        }

                                        count++;
                                        float prog = (float)count / (float)entries.Length;
                                        SetPercentComplete?.Invoke((int)(50 * prog) + 50); // start at 50% go up to 100%
                                    }
                                }
                            }
                            fs.Close();
                        }

                        File.Delete(source);
                    }
                }
                catch (Exception e)
                {
                    Error(e);
                    return;
                }


                HasProcessed = true; // if reached this point then successfully processed the download with no error
                SetPercentComplete?.Invoke(100);
                Complete();
            }