示例#1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="literalPath">A PSPath; A PSPath is always literal/resolved.</param>
        /// <returns></returns>
        /// <remarks>Path argument must be a resolved path (e.g. from PSPath property on input object).</remarks>
        protected PscxPathInfo GetPscxPathInfoFromPSPath(string literalPath)
        {
            //new PscxPathInfo(path, this.SessionState);
            PscxPathInfo pscxPath = PscxPathInfo.GetPscxPathInfo(this.SessionState, literalPath);

            return(pscxPath);
        }
示例#2
0
        public override void ProcessFile(FileInfo file)
        {
            if (file.FullName == _archivePath)
            {
                return;
            }

            _currentInputFile = file.Name;

            string fullPath;

            if (Command.ParameterSetName == "Object")
            {
                // get specified entry path root, default to CWD if null.
                string root = (Command.EntryPathRoot ??
                               PscxPathInfo.GetPscxPathInfo(Command.SessionState, ".")).ProviderPath;

                if (file.FullName.StartsWith(root))
                {
                    // trim off the start root
                    fullPath = file.FullName.Remove(0, root.Length)
                               .Replace('\\', Path.AltDirectorySeparatorChar) // flip slashes
                               .TrimStart(Path.AltDirectorySeparatorChar);    // remove leading slash

                    Command.WriteVerbose("ProcessFile: " + fullPath);
                }
                else
                {
                    // file falls outside of root, so error out
                    Command.ErrorHandler.WriteFileError(
                        file.FullName,
                        new ArgumentException(
                            String.Format(
                                Properties.Resources.InputFileOutsideOfRoot,
                                file.Name,
                                root)));
                    return;
                }
            }
            else
            {
                // literalpath / path parameterset
                fullPath = Path.Combine(CurrentPath, _currentInputFile);
            }

            if (!IsExcludedPath(file.FullName))
            {
                OpenEntry(_compressedOutputStream, fullPath);

                Command.FileHandler.ProcessRead(file, delegate(Stream inputStream)
                {
                    WriteStream(inputStream, _compressedOutputStream);
                    ExcludePath(file.FullName);
                });

                CloseEntry(_compressedOutputStream);
            }
        }
示例#3
0
        protected SevenZipBaseEx(PscxCmdlet command, FileInfo file, ArchiveFormat format)
        {
            //Debug.Assert(format != ArchiveFormat.Unknown, "format != ArchiveFormat.Unknown");

            _command         = command;
            _file            = file;
            _format          = format;
            _archivePscxPath = PscxPathInfo.GetPscxPathInfo(_command.SessionState, file.FullName);
        }
示例#4
0
文件: WriterBase.cs 项目: zyonet/Pscx
 /// <summary>
 ///
 /// </summary>
 /// <param name="directory"></param>
 public virtual void ProcessDirectory(DirectoryInfo directory)
 {
     if (Command.ParameterSetName != PscxInputObjectPathCommandBase.ParameterSetObject)
     {
         foreach (string path in Directory.GetFileSystemEntries(directory.FullName))
         {
             ProcessPath(PscxPathInfo.GetPscxPathInfo(Command.SessionState, path));
         }
     }
 }
示例#5
0
        public override void ProcessDirectory(DirectoryInfo directory)
        {
            string fullPath;

            if (Command.ParameterSetName == "Object")
            {
                // get specified entry path root, default to CWD if null.
                string root = (Command.EntryPathRoot ??
                               PscxPathInfo.GetPscxPathInfo(Command.SessionState, ".")).ProviderPath;

                if (directory.FullName.StartsWith(root))
                {
                    // trim off the start root
                    fullPath = directory.FullName.Remove(0, root.Length)
                               .Replace('\\', Path.AltDirectorySeparatorChar) // flip slashes
                               .TrimStart(Path.AltDirectorySeparatorChar);    // remove leading slash
                }
                else
                {
                    // file falls outside of root, so error out
                    Command.ErrorHandler.WriteFileError(
                        directory.FullName,
                        new ArgumentException(
                            String.Format(
                                Properties.Resources.InputFileOutsideOfRoot,
                                directory.Name,
                                root)));
                    return;
                }

                Command.WriteVerbose("ProcessFile: " + fullPath);
            }
            else
            {
                // note: unix style separator used for ziplib (tar, zip directories etc)
                string name = directory.Name + Path.AltDirectorySeparatorChar;

                string fullName = CurrentPath + name;

                OpenEntry(_compressedOutputStream, fullName);

                _currentPath.Add(name);

                base.ProcessDirectory(directory);

                CloseEntry(_compressedOutputStream);

                _currentPath.RemoveAt(_currentPath.Count - 1);
            }
        }
示例#6
0
        protected SevenZipBaseEx(PscxCmdlet command, FileInfo file, InArchiveFormat format)
        {
            //Debug.Assert(format != ArchiveFormat.Unknown, "format != ArchiveFormat.Unknown");

            _command         = command;
            _file            = file;
            _format          = format;
            _archivePscxPath = PscxPathInfo.GetPscxPathInfo(_command.SessionState, file.FullName);

            string sevenZDll  = PscxContext.Instance.Is64BitProcess ? "7z64.dll" : "7z.dll";
            string sevenZPath = Path.Combine(PscxContext.Instance.Home, sevenZDll);

            Trace.Assert(File.Exists(sevenZPath), sevenZPath + " not found or inaccessible.");

            SevenZipBase.SetLibraryPath(sevenZPath);
            _extractor = new SevenZipExtractor(file.FullName);
        }
示例#7
0
 private void ProcessSnapIn(PSSnapInInfo snapinInfo)
 {
     ProcessPath(PscxPathInfo.GetPscxPathInfo(this.SessionState, snapinInfo.ModuleName));
 }