protected string deleteFiles(IPM pm, Argument[] files, Argument[] except = null) { if(files.Any(p => p.type != ArgumentType.StringDouble)) { throw new InvalidArgumentException("Incorrect data from input files. Define as {\"f1\", \"f2\", ...}"); } if(except != null && except.Any(p => p.type != ArgumentType.StringDouble)) { throw new InvalidArgumentException("Incorrect data from the 'except' argument. Define as {\"f1\", \"f2\", ...}"); } Func<string, int, string> exs = delegate(string file, int idx) { if(!String.IsNullOrWhiteSpace(file)) { return location(file); } throw new InvalidArgumentException("File name is empty. Fail in '{0}' position.", idx); }; string[] input = files.Select((f, i) => exs((string)f.data, i)).ToArray().ExtractFiles(); #if DEBUG Log.Trace("deleteFiles: Found files `{0}`", String.Join(", ", input)); #endif if(except != null) { input = input.Except(except .Where(f => !String.IsNullOrWhiteSpace((string)f.data)) .Select(f => location((string)f.data)) .ToArray() .ExtractFiles() ).ToArray(); } if(input.Length < 1) { throw new InvalidArgumentException("The input files was not found. Check your mask and the exception list if used."); } deleteFiles(input); return Value.Empty; }
protected string stPackFiles(Argument[] files, string name, Argument[] except, OutArchiveFormat type, CompressionMethod method, CompressionLevel rate, IPM pm) { Log.Trace("stPackFiles: `{0}` : type({1}), method({2}), level({3})", name, type, method, rate); if(String.IsNullOrWhiteSpace(name)) { throw new InvalidArgumentException("The output name of archive is empty."); } if(files.Length < 1) { throw new InvalidArgumentException("List of files is empty."); } if(files.Any(p => p.type != ArgumentType.StringDouble)) { throw new InvalidArgumentException("Incorrect data from input files. Define as {\"f1\", \"f2\", ...}"); } if(except != null && except.Any(p => p.type != ArgumentType.StringDouble)) { throw new InvalidArgumentException("Incorrect data from the 'except' argument. Define as {\"f1\", \"f2\", ...}"); } // additional checking of input files. // The SevenZipSharp creates directories if input file is not exist o_O string[] input = files.Select((f, i) => pathToFile((string)f.data, i)).ToArray().ExtractFiles(); #if DEBUG Log.Trace("stPackFiles: Found files `{0}`", String.Join(", ", input)); #endif if(except != null) { input = input.Except(except .Where(f => !String.IsNullOrWhiteSpace((string)f.data)) .Select(f => location((string)f.data)) .ToArray() .ExtractFiles() ).ToArray(); } if(input.Length < 1) { throw new InvalidArgumentException("The input files was not found. Check your mask and the exception list if used."); } SevenZipCompressor zip = new SevenZipCompressor() { ArchiveFormat = type, CompressionMethod = method, CompressionLevel = rate, CompressionMode = CompressionMode.Create, FastCompression = true, // to disable some events inside SevenZip DirectoryStructure = true, }; compressFiles(zip, location(name), input); return Value.Empty; }
protected string copyFile(IPM pm, string src, string dest, bool overwrite, Argument[] except = null) { if(String.IsNullOrWhiteSpace(src) || String.IsNullOrWhiteSpace(dest)) { throw new InvalidArgumentException("The source file or the destination path argument is empty."); } if(except != null && except.Any(p => p.type != ArgumentType.StringDouble)) { throw new InvalidArgumentException("Incorrect data from the 'except' argument. Define as {\"f1\", \"f2\", ...}"); } dest = location(dest.TrimEnd()); string destDir = Path.GetDirectoryName(dest); string destFile = Path.GetFileName(dest); src = location(src); string[] input = new[] { src }.ExtractFiles(); #if DEBUG Log.Trace("Found files to copy `{0}`", String.Join(", ", input)); #endif if(except != null) { string path = Path.GetDirectoryName(src); input = input.Except(except .Where(f => !String.IsNullOrWhiteSpace((string)f.data)) .Select(f => location((string)f.data, path)) .ToArray() .ExtractFiles() ).ToArray(); } if(input.Length < 1) { throw new InvalidArgumentException("The input files was not found. Check your mask and the exception list if used."); } copyFile(destDir, destFile, overwrite, input); return Value.Empty; }