コード例 #1
0
ファイル: FileArchiveManager.cs プロジェクト: 0xCM/Meta.Core
        public Option <FlowOneToMany> ExpandArchive(FilePath Src, FolderPath Dst, bool Overwrite = true)
        {
            try
            {
                Dst.CreateIfMissing().Require();

                var paths = MutableList.Create <FilePath>();
                using (var stream = new FileStream(Src, FileMode.Open))
                {
                    using (var archive = new ZipArchive(stream, ZipArchiveMode.Read))
                    {
                        foreach (var entry in archive.Entries)
                        {
                            var dstPath = Dst.GetCombinedFilePath(RelativePath.Parse(entry.FullName));
                            if (dstPath.Exists() && not(Overwrite))
                            {
                                dstPath = dstPath.UniqueName();
                            }
                            else
                            {
                                dstPath.DeleteIfExists().Require();
                            }
                            paths.Add(Expand(entry, dstPath).Target);
                        }
                    }
                }
                return(new FlowOneToMany(Src, paths.ToReadOnlyList()));
            }
            catch (Exception e)
            {
                return(none <FlowOneToMany>(e));
            }
        }