Exemple #1
0
        public static void Update3dsdbXMLFile()
        {
            FileInfo l3dsdb = new FileInfo(Path.Combine(BQDirectory.DBDir, _3dsreleasesFileName));

            BQLog.WriteMsgToUI("开始更新3dsrelease.xml");
            if (!l3dsdb.Exists)
            {
                BQLog.WriteMsgToUI("开始从3dsdb.com下载");
                BQWeb.DownloadWebFile(URL3dsdb, l3dsdb);
            }
            else
            {
                FileInfo l3dsdbNew = new FileInfo(l3dsdb.FullName + "new");
                if (l3dsdbNew.Exists)
                {
                    BQLog.WriteMsgToUI("删除上次残留的3dsrelease.xml文件");
                    l3dsdbNew.Delete();
                }
                BQLog.WriteMsgToUI("开始从3dsdb.com下载");
                BQWeb.DownloadWebFile(URL3dsdb, l3dsdbNew);
                l3dsdb.Delete();
                l3dsdbNew.MoveTo(l3dsdb.FullName);
            }

            BQLog.WriteMsgToUI("3dsrelease.xml更新成功");
        }
        public static void CompressionFile(FileInfo pSrcFile, FileInfo pTarFile)
        {
            if (pTarFile.Directory.Exists == false)
            {
                Directory.CreateDirectory(pTarFile.Directory.FullName);
            }

            if (IntPtr.Size == 4)
            {
                SevenZipCompressor.SetLibraryPath(@"x86\7z.dll");
            }
            else
            {
                SevenZipCompressor.SetLibraryPath(@"x64\7z.dll");
            }

            // Set Temp Folder
            string lCompressTempFolder = Environment.GetEnvironmentVariable("TEMP");
            var    lSevenZipCompressor = new SevenZipCompressor(lCompressTempFolder);

            // Print Temp Folder
            Console.WriteLine(lSevenZipCompressor.TempFolderPath);

            // Set CompressionLevel
            lSevenZipCompressor.CompressionLevel = SevenZip.CompressionLevel.Normal;

            // Set Compress Type
            lSevenZipCompressor.ArchiveFormat = OutArchiveFormat.SevenZip;

            // Save DirectoryStructure
            lSevenZipCompressor.DirectoryStructure = true;

            // Compress blank folder
            lSevenZipCompressor.IncludeEmptyDirectories = true;

            // Use root folder
            lSevenZipCompressor.PreserveDirectoryRoot = false;

            // Encrypt Header
            lSevenZipCompressor.EncryptHeaders = false;

            // Zip Encryption Method
            lSevenZipCompressor.ZipEncryptionMethod = ZipEncryptionMethod.ZipCrypto;

            // Fast Compression
            // No started event, only finish event
            lSevenZipCompressor.FastCompression = false;

            // start compression file
            lSevenZipCompressor.FileCompressionStarted += (sender, eventArgs) =>
            {
                BQLog.UpdateProgress("开始压缩:" + eventArgs.FileName, 0, 100);
            };

            //lSevenZipCompressor.FileCompressionFinished += (sender, eventArgs) =>
            //{
            //    BQLog.UpdateProgress("FileCompressionFinished", 100, 100);
            //};

            lSevenZipCompressor.Compressing += (sender, eventArgs) =>
            {
                BQLog.UpdateProgress("压缩中(" + eventArgs.PercentDone + "%):" + pSrcFile.Name, eventArgs.PercentDone, 100);
            };

            lSevenZipCompressor.CompressionFinished += (sender, eventArgs) =>
            {
                BQLog.UpdateProgress("压缩完成", 100, 100);
            };

            //lSevenZipCompressor.CompressFiles(pTarFile.FullName, pSrcFile.FullName + ".7z");

            Dictionary <string, string> MyDic = new Dictionary <string, string>();

            MyDic.Add(pTarFile.Name, pSrcFile.FullName);
            lSevenZipCompressor.CompressFileDictionary(MyDic, pTarFile.FullName + ".7z");
        }