Example #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);
     }
 }
Example #2
0
        public File(string url, Dictionary <string, string> options)
        {
            var uri = new Utility.Uri(url);

            m_path = uri.HostAndPath;

            if (options.ContainsKey("auth-username"))
            {
                m_username = options["auth-username"];
            }
            if (options.ContainsKey("auth-password"))
            {
                m_password = options["auth-password"];
            }
            if (!string.IsNullOrEmpty(uri.Username))
            {
                m_username = uri.Username;
            }
            if (!string.IsNullOrEmpty(uri.Password))
            {
                m_password = uri.Password;
            }

            if (!System.IO.Path.IsPathRooted(m_path))
            {
                m_path = systemIO.PathGetFullPath(m_path);
            }

            if (options.ContainsKey(OPTION_ALTERNATE_PATHS))
            {
                List <string> paths = new List <string>
                {
                    m_path
                };
                paths.AddRange(options[OPTION_ALTERNATE_PATHS].Split(new string[] { System.IO.Path.PathSeparator.ToString() }, StringSplitOptions.RemoveEmptyEntries));

                //On windows we expand the drive letter * to all drives
                if (!Platform.IsClientPosix)
                {
                    System.IO.DriveInfo[] drives = System.IO.DriveInfo.GetDrives();

                    for (int i = 0; i < paths.Count; i++)
                    {
                        if (paths[i].StartsWith("*:", StringComparison.Ordinal))
                        {
                            string rpl_path = paths[i].Substring(1);
                            paths.RemoveAt(i);
                            i--;
                            foreach (System.IO.DriveInfo di in drives)
                            {
                                paths.Insert(++i, di.Name[0] + rpl_path);
                            }
                        }
                    }
                }

                string markerfile = null;

                //If there is a marker file, we do not allow the primary target path
                // to be accepted, unless it contains the marker file
                if (options.ContainsKey(OPTION_DESTINATION_MARKER))
                {
                    markerfile = options[OPTION_DESTINATION_MARKER];
                    m_path     = null;
                }

                foreach (string p in paths)
                {
                    try
                    {
                        if (systemIO.DirectoryExists(p) && (markerfile == null || systemIO.FileExists(systemIO.PathCombine(p, markerfile))))
                        {
                            m_path = p;
                            break;
                        }
                    }
                    catch
                    {
                    }
                }

                if (m_path == null)
                {
                    throw new UserInformationException(Strings.FileBackend.NoDestinationWithMarkerFileError(markerfile, paths.ToArray()), "NoDestinationWithMarker");
                }
            }

            m_moveFile                = Utility.Utility.ParseBoolOption(options, OPTION_MOVE_FILE);
            m_forceReauth             = Utility.Utility.ParseBoolOption(options, OPTION_FORCE_REAUTH);
            m_verifyDestinationLength = Utility.Utility.ParseBoolOption(options, OPTION_DISABLE_LENGTH_VERIFICATION);
            m_hasAutenticated         = false;
        }