Пример #1
0
        public static byte[] PackDir(PackerFileFormat format, string topDirPath, string appendPrefixDirName, ProgressDelegate proc)
        {
            string[]      fileList         = Directory.GetFiles(topDirPath, "*", SearchOption.AllDirectories);
            List <string> relativeFileList = new List <string>();

            foreach (string fileName in fileList)
            {
                string relativePath = IO.GetRelativeFileName(fileName, topDirPath);

                if (Str.IsEmptyStr(appendPrefixDirName) == false)
                {
                    relativePath = IO.RemoteLastEnMark(appendPrefixDirName) + "\\" + relativePath;
                }

                relativeFileList.Add(relativePath);
            }

            return(PackFiles(format, fileList, relativeFileList.ToArray(), proc));
        }
Пример #2
0
        public static byte[] PackFiles(PackerFileFormat format, string[] srcFileNameList, string[] relativeNameList, ProgressDelegate proc)
        {
            if (srcFileNameList.Length != relativeNameList.Length)
            {
                throw new ApplicationException("srcFileNameList.Length != relativeNameList.Length");
            }

            int num = srcFileNameList.Length;
            int i;

            ZipPacker zip = new ZipPacker();
            TarPacker tar = new TarPacker();

            for (i = 0; i < num; i++)
            {
                if (proc != null)
                {
                    bool ret = proc(srcFileNameList[i], relativeNameList[i], i, num);

                    if (ret == false)
                    {
                        continue;
                    }
                }

                byte[]   srcData = File.ReadAllBytes(srcFileNameList[i]);
                DateTime date    = File.GetLastWriteTime(srcFileNameList[i]);

                switch (format)
                {
                case PackerFileFormat.Tar:
                case PackerFileFormat.TarGZip:
                    tar.AddFileSimple(relativeNameList[i], srcData, 0, srcData.Length, date);
                    break;

                case PackerFileFormat.ZipRaw:
                case PackerFileFormat.ZipCompressed:
                    zip.AddFileSimple(relativeNameList[i], date, FileAttributes.Normal, srcData, (format == PackerFileFormat.ZipCompressed));
                    break;
                }
            }

            switch (format)
            {
            case PackerFileFormat.Tar:
                tar.Finish();
                return(tar.GeneratedData.Read());

            case PackerFileFormat.TarGZip:
                tar.Finish();
                return(tar.CompressToGZip());

            case PackerFileFormat.ZipCompressed:
            case PackerFileFormat.ZipRaw:
                zip.Finish();
                return(zip.GeneratedData.Read());

            default:
                throw new ApplicationException("format");
            }
        }
Пример #3
0
 public static byte[] PackFiles(PackerFileFormat format, string[] srcFileNameList, string[] relativeNameList)
 {
     return(PackFiles(format, srcFileNameList, relativeNameList, null));
 }
Пример #4
0
 public static byte[] PackDir(PackerFileFormat format, string rootDirPath, string appendPrefixDirName)
 {
     return(PackDir(format, rootDirPath, appendPrefixDirName, null));
 }
Пример #5
0
        public static byte[] PackFiles(PackerFileFormat format, string[] srcFileNameList, string[] relativeNameList, ProgressDelegate proc)
        {
            if (srcFileNameList.Length != relativeNameList.Length)
            {
                throw new ApplicationException("srcFileNameList.Length != relativeNameList.Length");
            }

            int num = srcFileNameList.Length;
            int i;

            ZipPacker zip = new ZipPacker();
            TarPacker tar = new TarPacker();

            for (i = 0; i < num; i++)
            {
                if (proc != null)
                {
                    bool ret = proc(srcFileNameList[i], relativeNameList[i], i, num);

                    if (ret == false)
                    {
                        continue;
                    }
                }

                byte[] srcData = File.ReadAllBytes(srcFileNameList[i]);
                DateTime date = File.GetLastWriteTime(srcFileNameList[i]);

                switch (format)
                {
                    case PackerFileFormat.Tar:
                    case PackerFileFormat.TarGZip:
                        tar.AddFileSimple(relativeNameList[i], srcData, 0, srcData.Length, date);
                        break;

                    case PackerFileFormat.ZipRaw:
                    case PackerFileFormat.ZipCompressed:
                        zip.AddFileSimple(relativeNameList[i], date, FileAttributes.Normal, srcData, (format == PackerFileFormat.ZipCompressed));
                        break;
                }
            }

            switch (format)
            {
                case PackerFileFormat.Tar:
                    tar.Finish();
                    return tar.GeneratedData.Read();

                case PackerFileFormat.TarGZip:
                    tar.Finish();
                    return tar.CompressToGZip();

                case PackerFileFormat.ZipCompressed:
                case PackerFileFormat.ZipRaw:
                    zip.Finish();
                    return zip.GeneratedData.Read();

                default:
                    throw new ApplicationException("format");
            }
        }
Пример #6
0
 public static byte[] PackFiles(PackerFileFormat format, string[] srcFileNameList, string[] relativeNameList)
 {
     return PackFiles(format, srcFileNameList, relativeNameList, null);
 }
Пример #7
0
        public static byte[] PackDir(PackerFileFormat format, string topDirPath, string appendPrefixDirName, ProgressDelegate proc)
        {
            string[] fileList = Directory.GetFiles(topDirPath, "*", SearchOption.AllDirectories);
            List<string> relativeFileList = new List<string>();

            foreach (string fileName in fileList)
            {
                string relativePath = IO.GetRelativeFileName(fileName, topDirPath);

                if (Str.IsEmptyStr(appendPrefixDirName) == false)
                {
                    relativePath = IO.RemoteLastEnMark(appendPrefixDirName) + "\\" + relativePath;
                }

                relativeFileList.Add(relativePath);
            }

            return PackFiles(format, fileList, relativeFileList.ToArray(), proc);
        }
Пример #8
0
 public static byte[] PackDir(PackerFileFormat format, string rootDirPath, string appendPrefixDirName)
 {
     return PackDir(format, rootDirPath, appendPrefixDirName, null);
 }