Example #1
0
        public void ZipHelperSerialization()
        {
            string testPath = Path.Combine(
                AppDomain.CurrentDomain.BaseDirectory,
                @"..\..\TestData\CompressTestFolder");

            var compressedItem =
                ZipHelper.Compress(
                    "普選正式選票2008年11月4日,星期二伊利諾州芝加哥市");
            int size = compressedItem.CompressedSize;

            File.WriteAllBytes(
                Path.Combine(testPath, "SerializedCompressed.comp"),
                Encoding.Unicode.GetBytes(compressedItem.ToString()));


            var decompressedItem =
                CompressedItem.FromXml(
                    Encoding.Unicode.GetString(
                        File.ReadAllBytes(
                            Path.Combine(
                                testPath, "SerializedCompressed.comp"))));

            Assert.AreEqual(size, decompressedItem.CompressedSize);

            string decompressedData =
                ZipHelper.Decompress(decompressedItem);


            Assert.AreEqual(
                "普選正式選票2008年11月4日,星期二伊利諾州芝加哥市",
                decompressedData);

            File.Delete(Path.Combine(testPath, "SerializedCompressed.comp"));
        }
        private byte[] _CopyGalleryOfCasesToDownloadDirectory(int imgType, string caseIds, string dlGalleryDir)
        {
            DataTable dt;

            dt = IocObject.Case.SearchGalleryOfCase(imgType, caseIds);
            IList <string> filePaths = new List <string>();

            foreach (DataRow dr in dt.Rows)
            {
                filePaths.Add(dr["imgUrl"].ToString());
            }

            //拷贝图片
            FileInfo file;
            string   baseDir = AppDomain.CurrentDomain.BaseDirectory;

            foreach (string imgUrl in filePaths)
            {
                file = new FileInfo(baseDir + imgUrl);
                File.Copy(file.FullName, dlGalleryDir + "/" + file.Name);
            }

            byte[] data = ZipHelper.Compress(dlGalleryDir);


            return(data);
        }
Example #3
0
        public void 将指定目录打包成ZIP文件_含子目录()
        {
            string srcPath = @"D:\test";
            string zipPath = @"D:\my-github\Snakehead.Cbdmt\src\Snakehead.Cbdmt\bin\bin.zip";

            ZipHelper.Compress(srcPath, zipPath);
        }
Example #4
0
        public void 将内存数据打包成ZIP文件()
        {
            List <Tuple <string, byte[]> > data = null;    // 需要准备好这个结构

            string zipPath = @"D:\my-github\Snakehead.Cbdmt\src\Snakehead.Cbdmt\bin\bin.zip";

            ZipHelper.Compress(data, zipPath);
        }
Example #5
0
        /// <summary>
        /// Create a new instance of TexturePackage
        /// </summary>
        /// <param name="key">Key to use in the content manager</param>
        /// <param name="texture">Texture to include in the package</param>
        public Package(string key, string texturePath)
        {
            this.ContentKey = key;

            Stream stream = File.OpenRead(texturePath);

            this.ContentData = ZipHelper.Compress(stream);
            stream.Close();
        }
Example #6
0
        public void ZipHelperCompressionTest()
        {
            var compressedItem = ZipHelper.Compress("Hello World");

            string decompressedData = ZipHelper.Decompress(compressedItem);

            Assert.AreEqual("Hello World", decompressedData);
            Assert.AreNotEqual("Hello world", decompressedData);
        }
Example #7
0
        /// <summary>
        /// 下载作为一个压缩文件
        /// </summary>
        public void DownloadZip_GET()
        {
            string tpl = Request["tpl"];

            byte[] bytes = ZipHelper.Compress(String.Format("{0}templates/{1}/", Cms.PyhicPath, tpl), tpl);
            Response.BinaryWrite(bytes);
            Response.ContentType = "application/octet-stream";
            Response.AddHeader("Content-Disposition", "attachment;filename=template_" + tpl + ".zip");
            Response.AddHeader("Content-Length", bytes.Length.ToString());
        }
Example #8
0
        /// <summary>
        /// 下载作为一个压缩文件
        /// </summary>
        public void DownloadZip()
        {
            string tpl   = Request.Query("tpl");
            var    bytes = ZipHelper.Compress($"{Cms.PhysicPath}templates/{tpl}/", tpl);

            Response.WriteAsync(bytes);
            Response.ContentType("application/octet-stream");
            Response.AddHeader("Content-Disposition", "attachment;filename=template_" + tpl + ".zip");
            Response.AddHeader("Content-Length", bytes.Length.ToString());
        }
Example #9
0
        /// <summary>
        /// 压缩文件
        /// </summary>
        public void CompressFile()
        {
            byte[] rawData1 = File.ReadAllBytes(filename);
            byte[] outData1 = ZipHelper.Compress(rawData1);
            File.WriteAllBytes(datfile, outData1);

            byte[] rawData2 = File.ReadAllBytes(filename_new);
            byte[] outData2 = ZipHelper.Compress(rawData2);
            File.WriteAllBytes(datfile_new, outData2);
        }
Example #10
0
        public void BeforeSave(bool insert)
        {
            m_compressedCells = new byte[Cells.Length * Cell.StructSize];

            for (int i = 0; i < Cells.Length; i++)
            {
                Array.Copy(Cells[i].Serialize(), 0, m_compressedCells, i * Cell.StructSize, Cell.StructSize);
            }

            m_compressedCells = ZipHelper.Compress(m_compressedCells);
        }
Example #11
0
        public void ZipHelperExtendedUnicodeCompressionTest()
        {
            var compressedItem =
                ZipHelper.Compress(
                    "普選正式選票2008年11月4日,星期二伊利諾州芝加哥市");

            string decompressedData = ZipHelper.Decompress(compressedItem);

            Assert.AreEqual(
                "普選正式選票2008年11月4日,星期二伊利諾州芝加哥市",
                decompressedData);
        }
Example #12
0
    public static void GenerateInfoData(bool isMakeBundle, bool isIncludeBundle, string outpath)
    {
        if (isMakeBundle)
        {
            if (Directory.Exists(BundleConfig.appOutputPath))
            {
                Directory.Delete(BundleConfig.appOutputPath, true);
            }
            Directory.CreateDirectory(BundleConfig.appOutputPath);


            Dictionary <int, Dictionary <string, BundleMaker.BundleFileInfo> > dicGenerateFiles = new Dictionary <int, Dictionary <string, BundleMaker.BundleFileInfo> >();
            List <string> fileList = new List <string>();
            getAllPartFileList(Application.dataPath, BundleConfig.assetsPathRoot + "/", fileList);
            getAllDependenciesPath(fileList);
            AddFileToInfo(0, fileList, outpath, dicGenerateFiles);

            string     resourcesVersion = System.DateTime.Now.ToString("yyyyMMddHHmmss");
            List <int> keylist          = new List <int>(dicGenerateFiles.Keys);
            for (int i = 0; i < keylist.Count; i++)
            {
                string buildVersionPath = string.Format("{0}{1}", outpath, BundleConfig.resourceVersionFileName);
                if (File.Exists(buildVersionPath))
                {
                    System.IO.File.Delete(buildVersionPath);
                }
                string doc = resourcesVersion + "\n";

                doc += GetBundMainFestDoc(BundleConfig.mainManifestFile, outpath, false);

                string namePath = string.Format("{0}_{1}.zip", BundleConfig.allResourceZipFileName, System.DateTime.Now.ToString("yyyyMMddHHmmss")).ToLower();
                string zipdir   = outpath;
                string zipDoc   = "";
                if (Directory.Exists(zipdir))
                {
                    ZipHelper.Compress(zipdir, outpath + namePath);
                    zipDoc += GetBundMainFestDoc(namePath, outpath, false);
                }
                doc += zipDoc;

                doc += getVersionTxt(dicGenerateFiles[i]);

                WriteStringToFile(buildVersionPath, doc, false);
            }

            //copyFileToStream(outpath + string.Format(BundleConfig.resourceVersionFileName, (int)BundlePart.BundlePart0), BundleConfig.appOutputPath + string.Format(BundleConfig.resourceOldVersionFileName, (int)BundlePart.BundlePart0));
            // copyFileToStream(outpath + BundleConfig.mainManifestFile, BundleConfig.appOutputPath + BundleConfig.mainManifestFile);
        }
    }
 public void BeforeSave(bool insert)
 {
     this.m_compressedCells = new byte[this.Cells.Length * 11];
     for (int i = 0; i < this.Cells.Length; i++)
     {
         System.Array.Copy(this.Cells[i].Serialize(), 0, this.m_compressedCells, i * 11, 11);
     }
     this.m_compressedCells    = ZipHelper.Compress(this.m_compressedCells);
     this.m_compressedElements = new byte[this.Elements.Length * 6];
     for (int i = 0; i < this.Elements.Length; i++)
     {
         System.Array.Copy(this.Elements[i].Serialize(), 0, this.m_compressedElements, i * 6, 6);
     }
     this.m_compressedElements = ZipHelper.Compress(this.m_compressedElements);
 }
    byte[] getdata()
    {
        string end = "[";
        bool   bf  = false;

        foreach (string d in datas)
        {
            if (bf)
            {
                end += ",";
            }
            end += d;
            bf   = true;
        }
        end += "]";

        return(ZipHelper.Compress(Encoding.UTF8.GetBytes(end)));
    }
Example #15
0
        public void SendMessage(ushort nOpcode, byte[] rMessageBytes)
        {
            if (rMessageBytes.Length > 100)
            {
                byte[] rNewMessageBytes = ZipHelper.Compress(rMessageBytes);
                if (rNewMessageBytes.Length < rMessageBytes.Length)
                {
                    rMessageBytes = rNewMessageBytes;
                    nOpcode      |= 0x8000;
                }
            }

            byte[] rOpcodeBytes = BitConverter.GetBytes(nOpcode);

            this.mByteses[0] = rOpcodeBytes;
            this.mByteses[1] = rMessageBytes;

            mChannel.Send(this.mByteses);
        }
Example #16
0
        /// <summary>
        /// Save the specified package and path.
        /// </summary>
        /// <param name="package">Package.</param>
        /// <param name="path">Path.</param>
        public static void Save(Package package, string path)
        {
            if (!Directory.Exists(path))
            {
                throw new Exception("Path not exist");
            }

            var completeFilePath = Path.Combine(path, package.FileName);

            using (var stream = new MemoryStream())
            {
                var formatter = new BinaryFormatter();
                formatter.Serialize(stream, package);

                var byteArray         = stream.ToArray();
                var compressByteArray = ZipHelper.Compress(ref byteArray);

                File.WriteAllBytes(completeFilePath, compressByteArray);
            }
        }
        public void CompressTest()
        {
            byte[] bytes = new byte[1] {
                12
            };
            byte[] bytesExpected = new byte[21] {
                31, 139, 8, 0, 0, 0, 0, 0, 4, 0, 227, 1, 0, 166, 163, 180, 219, 1, 0, 0, 0
            };
            MemoryStream ms = new MemoryStream(bytes);

            byte[] compressBytes = ZipHelper.Compress(ms);
            ms.Close();

            Assert.AreEqual(bytesExpected.Length, compressBytes.Length);

            for (int i = 0; i < bytesExpected.Length; i++)
            {
                Assert.AreEqual(bytesExpected[i], compressBytes[i]);
            }
        }
        /// <summary>
        /// 复制相册文件到目录下
        /// </summary>
        /// <param name="caseId"></param>
        /// <param name="imgType"></param>
        /// <param name="imgIds"></param>
        /// <param name="dlGalleryDir"></param>
        private byte[] _CopyGalleryToDownloadDirectory(int caseId, int imgType, string imgIds, string dlGalleryDir)
        {
            DataTable dt;
            bool      isTypeFilter = imgType != -1;
            Array     idArrary     = null;

            if (!String.IsNullOrEmpty(imgIds))
            {
                idArrary = imgIds.Split(',');
            }

            dt = IocObject.Case.GetGalleryOfCase(caseId);
            IList <string> filePaths = new List <string>();

            foreach (DataRow dr in dt.Rows)
            {
                if ((!isTypeFilter || int.Parse(dr["imgType"].ToString()) == imgType) &&
                    (idArrary == null || Array.IndexOf(idArrary, dr["id"].ToString()) != -1))
                {
                    filePaths.Add(dr["imgUrl"].ToString());
                }
            }

            //拷贝图片
            FileInfo file;
            string   baseDir = AppDomain.CurrentDomain.BaseDirectory;

            foreach (string imgUrl in filePaths)
            {
                file = new FileInfo(baseDir + imgUrl);
                File.Copy(file.FullName, dlGalleryDir + "/" + file.Name);
            }

            byte[] data = ZipHelper.Compress(dlGalleryDir);


            return(data);
        }
        //窗口关闭后将这些东西写到xml里面
        private void ClosedFunc(object sender, FormClosedEventArgs e)
        {
            //Stopwatch sp = new Stopwatch();
            //sp.Start();
            //string filterStr = string.Empty;
            StringBuilder sb = new StringBuilder();

            foreach (var item in _treeView.Nodes)
            {
                TreeNode channelTree = (TreeNode)item;
                foreach (var item1 in channelTree.Nodes)
                {
                    TreeNode labelTree = (TreeNode)item1;
                    foreach (var item2 in labelTree.Nodes)
                    {
                        TreeNode sdiTree = (TreeNode)item2;
                        foreach (var item3 in sdiTree.Nodes)
                        {
                            TreeNode ssmTree = (TreeNode)item3;
                            if (ssmTree.Checked == true)
                            {
                                //filterStr += "1_";
                                sb.Append("1_");
                            }
                            else
                            {
                                //filterStr += "0_";
                                sb.Append("0_");
                            }
                        }
                    }
                }
            }
            //_device429.filterStr = ZipHelper.Compress(filterStr);
            _device429.filterStr = ZipHelper.Compress(sb.ToString());
            //sp.Stop();
            //MessageBox.Show(sp.ElapsedMilliseconds.ToString());
        }
Example #20
0
        public static void ExportAssetBundlePackage()
        {
            if (Directory.Exists(TempABPath))
            {
                Directory.Delete(TempABPath, true);
            }
            string[] allFile = Directory.GetFiles(FilePathHelper.AssetBundlePath, "*.*", SearchOption.AllDirectories);
            //剔除.manifest文件;
            List <string> allAB = new List <string>();

            foreach (string tempPath in allFile)
            {
                string path = tempPath.Replace("\\", "/");
                if (Path.GetExtension(path) == ".manifest")
                {
                    continue;
                }
                allAB.Add(path);
            }

            EditorUtility.ClearProgressBar();
            int index = 0;
            int count = allAB.Count;

            foreach (string ab in allAB)
            {
                index++;
                EditorUtility.DisplayProgressBar("复制AssetBundle", "复制AssetBundle文件", (float)index / (float)count);
                string target     = ab.Replace(FilePathHelper.AssetBundlePath, TempABPath + "/AssetBundle");
                string targetPath = Path.GetDirectoryName(target);
                if (!Directory.Exists(targetPath))
                {
                    Directory.CreateDirectory(targetPath);
                    File.Copy(ab, target);
                }
            }
            EditorUtility.ClearProgressBar();

            bool   compressState    = true;
            float  compressProgress = 0f;
            string zipFile          = ZipHelper.Compress(TempABPath, ZipABPath, "AssetBundle", (progress) =>
            {
                compressProgress = progress;
                if (compressProgress >= 1)
                {
                    compressState = false;
                }
            });

            while (compressState)
            {
                EditorUtility.DisplayProgressBar("压缩AssetBundle", "压缩AssetBundle文件", compressProgress);
            }
            EditorUtility.ClearProgressBar();

            if (Directory.Exists(TempABPath))
            {
                Directory.Delete(TempABPath, true);
            }
            if (File.Exists(ZipStreamingAssetsPath))
            {
                File.Delete(ZipStreamingAssetsPath);
            }
            File.Copy(zipFile, ZipStreamingAssetsPath);
        }
Example #21
0
 public static void Compress(DirectoryInfo directorySelected, string directoryPath)
 {
     ZipHelper.Compress(directorySelected, directoryPath);
 }