Exemplo n.º 1
0
        void IdentifyRequiredArchives(List <ArchiveFilename> ArchivesRequired, Manifest.Entry Entry)
        {
            try
            {
                if (Entry is Manifest.File)
                {
                    Manifest.File File = (Manifest.File)Entry;
                    TotalBytes += (long)File.Length;
                    ArchiveFilename Archive = ArchiveFilename.Parse(File.ArchiveFile);
                    if (!ArchivesRequired.Contains(Archive))
                    {
                        ArchivesRequired.Add(Archive);
                    }
                }
                else if (Entry is Manifest.Folder)
                {
                    Manifest.Folder Folder = (Manifest.Folder)Entry;
                    foreach (Manifest.File File in Folder.Files)
                    {
                        IdentifyRequiredArchives(ArchivesRequired, File);
                    }
                    foreach (Manifest.Folder Subfolder in Folder.Folders)
                    {
                        IdentifyRequiredArchives(ArchivesRequired, Subfolder);
                    }
                }
                else
                {
                    throw new ArgumentException();
                }
            }
            catch (CancelException ce) { throw ce; }
            catch (Exception ex)
            {
                try
                {
                    ZippyForm.LogWriteLine(LogLevel.Information, "Error while identifying required archive for '" + Entry.RelativePath + "': " + ex.Message);
                    ZippyForm.LogWriteLine(LogLevel.LightDebug, "Detailed error: " + ex.ToString());

                    throw new Exception(ex.Message + "\nWhile analyzing archives for entry '" + Entry.RelativePath + "'.", ex);
                }
                catch (Exception exc)
                {
                    throw new Exception(exc.Message + "\nWhile generating error message for: \n\n" + ex.Message, exc);
                }
            }
        }
Exemplo n.º 2
0
        void RunEntry(ZipFile zip, ArchiveFilename Archive, Manifest.Entry Entry, string DestinationFolder)
        {
            if (Entry == null || String.IsNullOrEmpty(DestinationFolder))
            {
                throw new ArgumentException("Invalid manifest entry or processing error for manifest entry.", "Entry");
            }
            bool IsArchiveRoot = (String.IsNullOrEmpty(Entry.Name)) && Entry is Manifest.Folder;

            Progress.label2.Text = "Extracting:  " + Entry.RelativePath;
            DoEvents();

            string Path = Utility.StripTrailingSlash(DestinationFolder) + "\\" + Entry.Name;

            if (Entry is Manifest.File)
            {
                Manifest.File File = (Manifest.File)Entry;
                try
                {
                    ArchiveFilename NeededArchive = ArchiveFilename.Parse(File.ArchiveFile);
                    if (NeededArchive == Archive)
                    {
                        Directory.CreateDirectory(DestinationFolder);
                        ExtractFile(zip, File, Path);
                        ExtractProperties(File, Path);
                        BytesCompleted += (long)File.Length;
                    }
                }
                catch (CancelException ce) { throw ce; }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message + "\nWhile extracting file '" + Entry.RelativePath + "'.", ex);
                }
            }
            else if (Entry is Manifest.Folder)
            {
                Manifest.Folder Folder = (Manifest.Folder)Entry;
                try
                {
                    Directory.CreateDirectory(Path);
                    foreach (Manifest.File File in Folder.Files)
                    {
                        RunEntry(zip, Archive, File, Path);
                    }
                    foreach (Manifest.Folder Subfolder in Folder.Folders)
                    {
                        RunEntry(zip, Archive, Subfolder, Path);
                    }
                    if (!IsArchiveRoot)
                    {
                        ExtractProperties(Folder, Path);
                    }
                }
                catch (CancelException ce) { throw ce; }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message + "\nWhile extracting folder '" + Entry.RelativePath + "'.", ex);
                }
            }
            else
            {
                throw new ArgumentException();
            }

            Progress.OverallProgressBar.Value = (int)(10000L * BytesCompleted / TotalBytes);
            return;
        }