예제 #1
0
파일: Api.cs 프로젝트: JonasUJ/czip
        public static void Zip(IEnumerable <string> paths, string location)
        {
            ZipDirectory rootDir = new ZipDirectory
            {
                Name = Path.GetFileName(paths.First().TrimEnd('\\', '/'))
            };

            foreach (string path in paths)
            {
                ConsoleUtil.PrintMessage($"Zipping {path}");
                FileInfo fi = new FileInfo(path);
                if (fi.Exists)
                {
                    ZipFile zfile = PackFile(fi);
                    if (zfile != null)
                    {
                        rootDir.Files.Add(zfile);
                    }
                    continue;
                }
                DirectoryInfo di = new DirectoryInfo(path);
                if (di.Exists)
                {
                    ZipDirectory zdir = PackDirectory(di);
                    if (zdir != null)
                    {
                        rootDir.Directories.Add(zdir);
                    }
                }
            }

            long offset = rootDir.Serialize().Length;

            rootDir.OffsetFiles(offset);
            using (FileStream fs = File.Create(location))
            {
                SerializedData sd = rootDir.Serialize();
                sd.CopyTo(fs);
                foreach (ZipFile zfile in rootDir.AllFiles())
                {
                    zfile.CopyToFile(fs);
                }
                ConsoleUtil.PrintMessage($"Created .czip file {location}");
            }
        }
예제 #2
0
        public SerializedData Serialize()
        {
            SerializedData sd = new SerializedData();

            sd.Add(Name);
            sd.AddGS();

            foreach (ZipFile zfile in Files)
            {
                sd.AddRS();
                sd.Add(zfile.Serialize());
            }
            sd.AddGS();

            foreach (ZipDirectory zdir in Directories)
            {
                sd.AddRS();
                sd.Add(zdir.Serialize());
            }
            sd.AddGS();

            return(sd);
        }