OpenRead() public static method

Opens a ZipArchive on the specified path for reading. The specified file is opened with FileMode.Open.
archiveFileName is a zero-length string, contains only white space, or contains one /// or more invalid characters as defined by InvalidPathChars. archiveFileName is null. The specified archiveFileName exceeds the system-defined maximum length. /// For example, on Windows-based platforms, paths must be less than 248 characters, /// and file names must be less than 260 characters. The specified archiveFileName is invalid, (for example, it is on an unmapped drive). An unspecified I/O error occurred while opening the file. archiveFileName specified a directory. /// -OR- The caller does not have the required permission. The file specified in archiveFileName was not found. archiveFileName is in an invalid format. The specified file could not be interpreted as a Zip file.
public static OpenRead ( string archiveFileName ) : ZipArchive
archiveFileName string A string specifying the path on the filesystem to open the archive on. The path is permitted /// to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory.
return ZipArchive
Ejemplo n.º 1
0
        void Client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
        {
            this.BeginInvoke((MethodInvoker) delegate
            {
                DownloadProgress.Style = ProgressBarStyle.Marquee;

                string updatePath = Path.GetDirectoryName(Application.ExecutablePath) + "\\";
                using (ZipArchive archive = ZipFile.OpenRead(tempNameZip))
                {
                    int numFiles = archive.Entries.Count;
                    int current  = 1;

                    DownloadProgress.Style = ProgressBarStyle.Blocks;

                    foreach (ZipArchiveEntry entry in archive.Entries)
                    {
                        string fullName = entry.FullName;

                        if (fullName.Substring(fullName.Length - 1) == "/")
                        {
                            string folderName = fullName.Remove(fullName.Length - 1);
                            if (Directory.Exists(folderName))
                            {
                                Directory.Delete(folderName, true);
                            }

                            Directory.CreateDirectory(folderName);
                        }
                        else
                        {
                            if (fullName != "GameLauncherUpdater.exe")
                            {
                                if (File.Exists(fullName))
                                {
                                    File.Delete(fullName);
                                }

                                Information.Text = "Extracting: " + fullName;
                                try { entry.ExtractToFile(Path.Combine(updatePath, fullName)); } catch { }
                                Delay.WaitMSeconds(200);
                            }
                        }

                        DownloadProgress.Value = (int)((long)100 * current / numFiles);
                        current++;
                    }
                }

                Process.Start(@"GameLauncher.exe");
                error("Update completed. Starting GameLauncher.exe");
            });
        }
Ejemplo n.º 2
0
        private static void Extract45Framework(string zipFile, string extractPath)
        {
            ZipArchive zipArchive = DotNetZipFile.OpenRead(zipFile);

            if (zipArchive.Entries != null && zipArchive.Entries.Count > 0)
            {
                Console.WriteLine("Extracting...");
                foreach (ZipArchiveEntry entry in zipArchive.Entries)
                {
                    try
                    {
                        if (string.IsNullOrEmpty(entry.Name))
                        {
                            // skip directory
                            continue;
                        }
                        string file = Path.Combine(extractPath, entry.FullName);
                        string path = Path.GetDirectoryName(file);
                        if (!Directory.Exists(path))
                        {
                            Directory.CreateDirectory(path);
                        }
                        Console.WriteLine(" - '" + entry.FullName + "'...");
                        if (File.Exists(file))
                        {
                            //Console.WriteLine("   - delete previous version...");
                            File.Delete(file);
                        }
                        entry.ExtractToFile(file);
                        long length = (new FileInfo(file)).Length;
                        if (entry.Length != length)
                        {
                            Console.WriteLine($"   - Failed to extract! Extracted only {length} out of {entry.Length} bytes");
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("   - Failed to extract: " + ex.Message);
                    }
                }
            }
        }