Esempio n. 1
0
 /// <summary>
 /// Alternative to System.IO.Compression.ZipFile.ExtractToDirectory()
 /// that handles long paths.
 /// </summary>
 protected static void ZipFileExtractToDirectory(string sourceArchiveFileName, string destinationDirectoryName)
 {
     if (Platform.IsClientWindows)
     {
         // Handle long paths under Windows by extracting to a
         // temporary file and moving the resulting file to the
         // actual destination using functions that support
         // long paths.
         using (var archive = ZipFile.OpenRead(sourceArchiveFileName))
         {
             foreach (var entry in archive.Entries)
             {
                 // By the ZIP spec, directories end in a forward slash
                 var isDirectory = entry.FullName.EndsWith("/");
                 var destination =
                     systemIO.PathGetFullPath(systemIO.PathCombine(destinationDirectoryName, entry.FullName));
                 if (isDirectory)
                 {
                     systemIO.DirectoryCreate(destination);
                 }
                 else
                 {
                     // Not every directory is recorded separately,
                     // so create directories if needed
                     systemIO.DirectoryCreate(systemIO.PathGetDirectoryName(destination));
                     // Extract file to temporary file, then move to
                     // the (possibly) long path destination
                     var tempFile = Path.GetTempFileName();
                     try
                     {
                         entry.ExtractToFile(tempFile, true);
                         systemIO.FileMove(tempFile, destination);
                     }
                     finally
                     {
                         if (systemIO.FileExists(tempFile))
                         {
                             systemIO.FileDelete(tempFile);
                         }
                     }
                 }
             }
         }
     }
     else
     {
         ZipFile.ExtractToDirectory(sourceArchiveFileName, destinationDirectoryName);
     }
 }