コード例 #1
0
ファイル: FileArchiveManager.cs プロジェクト: 0xCM/Meta.Core
        public Option <Link <FolderPath, FilePath> > CreateArchive(FolderPath SrcDir, FilePath DstPath,
                                                                   bool Overwrite = true, AppMessageObserver Observer = null)
        {
            try
            {
                DstPath.Folder.CreateIfMissing();

                var dstPath = Overwrite
                    ? DstPath.DeleteIfExists().Require()
                    : (DstPath.Exists() ? DstPath.UniqueName() : DstPath);

                using (var stream = new FileStream(DstPath, FileMode.OpenOrCreate))
                {
                    using (var archive = new ZipArchive(stream, ZipArchiveMode.Create))
                    {
                        foreach (var srcFile in SrcDir.Files("*.*", true))
                        {
                            Observer?.Invoke(AddingFileToArchive(srcFile, dstPath));
                            var entry = CreateEntry(SrcDir, srcFile, archive);
                            using (var writer = new StreamWriter(entry.Open()))
                                using (var reader = new StreamReader(srcFile))
                                    reader.BaseStream.CopyTo(writer.BaseStream);
                        }
                    }
                }
                return(link(SrcDir, dstPath));
            }
            catch (Exception e)
            {
                return(none <Link <FolderPath, FilePath> >(e));
            }
        }
コード例 #2
0
 public static IEnumerable <CreateFileArchive> DefineZipFilesCommands(FolderPath srcPath, FolderPath dstPath)
 => from srcFile in srcPath.Files()
 select new CreateFileArchive
 {
     SourceFiles = roitems(FilePath.Parse(srcFile)),
     ArchivePath = dstPath + srcFile.FileName.AddExtension(".zip"),
     Overwrite   = true
 };
コード例 #3
0
ファイル: Folder.ext.cs プロジェクト: 0xCM/Meta.Core
 /// <summary>
 /// Copies (non-recursively) the files in the folder to a target folder
 /// </summary>
 /// <param name="dstFolder">The target folder</param>
 /// <param name="match">The files to match</param>
 /// <returns></returns>
 public static IEnumerable <FileCopyResult> CopyFilesTo(this FolderPath folder, FolderPath dstFolder, string match = null)
 => from srcFile in folder.Files(match)
 select srcFile.CopyTo(dstFolder);
コード例 #4
0
ファイル: FileSystemX.cs プロジェクト: 0xCM/Meta.Core
 /// <summary>
 /// Extracts each zip archive in a folder
 /// </summary>
 /// <param name="C"></param>
 /// <param name="SrcFolder">The folder that contains the zip archives</param>
 /// <param name="DstFolder">The folder that will receive the archive extractions</param>
 /// <param name="PLL">Whether operations should be executed concurently</param>
 /// <returns></returns>
 public static IEnumerable <Option <FlowOneToMany> > UnzipDirFiles(this IApplicationContext C,
                                                                   FolderPath SrcFolder, FolderPath DstFolder, bool PLL = true)
 => C.FileArchiveManager().ExpandArchives(SrcFolder.Files("*.zip"), DstFolder, true, PLL);
コード例 #5
0
ファイル: FileSystemX.cs プロジェクト: 0xCM/Meta.Core
 static IEnumerable <Link <FilePath> > ArchiveFlows(FolderPath SrcFolder, string Match, FolderPath DstFolder)
 => from src in SrcFolder.Files(Match)
 let dst = DstFolder + src.FileName.ChangeExtension("zip")
           select new Link <FilePath>(src, dst);
コード例 #6
0
ファイル: FileArchiveX.cs プロジェクト: 0xCM/Meta.Core
 public static IEnumerable <Option <Link <FilePath, ReadOnlyList <FilePath> > > > ExtractFiles(this IFileArchiveManager ArchiveManager, FolderPath SrcFolder, FolderPath DstFolder)
 => from src in SrcFolder.Files()
 let dst = FolderPath.Parse(DstFolder)
           select ArchiveManager.ExpandArchive(new Link <FilePath, FolderPath>(src, dst));
コード例 #7
0
ファイル: FileArchiveX.cs プロジェクト: 0xCM/Meta.Core
 static IEnumerable <Link <FilePath> > ArchiveFlows(FolderPath Src, FolderPath Dst)
 => from src in Src.Files()
 let dst = Dst + src.FileName.ChangeExtension("zip")
           select new Link <FilePath>(src, dst);
コード例 #8
0
ファイル: files.api.cs プロジェクト: 0xCM/Meta.Core
 /// <summary>
 /// Searches the folder according to specified filter and recursion options
 /// </summary>
 /// <param name="folder">The folder to search</param>
 /// <param name="match">The pattern to match, if any</param>
 /// <param name="recursive">Whether the search should be recursive</param>
 /// <returns></returns>
 public static IEnumerable <FilePath> search(FolderPath folder, string match = null, bool recursive = false)
 => folder.Files(match, recursive);
コード例 #9
0
ファイル: FileArchiveManager.cs プロジェクト: 0xCM/Meta.Core
 public IEnumerable <Option <Link <FilePath, ReadOnlyList <FilePath> > > > ExpandArchives(FolderPath SrcFolder,
                                                                                          FolderPath DstFolder, bool Overwrite = true)
 => from src in SrcFolder.Files()
 let dst = FolderPath.Parse(DstFolder)
           select ExpandArchive(new Link <FilePath, FolderPath>(src, dst), Overwrite);