当前位置: 首页>>代码示例>>C#>>正文


C# SevenZipCompressor.CompressFileDictionary方法代码示例

本文整理汇总了C#中SevenZip.SevenZipCompressor.CompressFileDictionary方法的典型用法代码示例。如果您正苦于以下问题:C# SevenZipCompressor.CompressFileDictionary方法的具体用法?C# SevenZipCompressor.CompressFileDictionary怎么用?C# SevenZipCompressor.CompressFileDictionary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SevenZip.SevenZipCompressor的用法示例。


在下文中一共展示了SevenZipCompressor.CompressFileDictionary方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Export

        public static bool Export(string exportPath)
        {
            try
            {
                Set7ZipLibraryPath();

                SevenZipCompressor zip = new SevenZipCompressor();
                zip.ArchiveFormat = OutArchiveFormat.SevenZip;
                zip.CompressionLevel = CompressionLevel.Normal;
                zip.CompressionMethod = CompressionMethod.Lzma2;

                Dictionary<string, string> files = new Dictionary<string, string>();
                if (Program.Settings.ExportSettings)
                {
                    AddFileToDictionary(files, Program.ApplicationConfigFilePath);
                    AddFileToDictionary(files, Program.HotkeysConfigFilePath);
                    AddFileToDictionary(files, Program.UploadersConfigFilePath);
                    AddFileToDictionary(files, Program.GreenshotImageEditorConfigFilePath);
                }

                if (Program.Settings.ExportHistory)
                {
                    AddFileToDictionary(files, Program.HistoryFilePath);
                }

                if (Program.Settings.ExportLogs)
                {
                    foreach (string file in Directory.GetFiles(Program.LogsFolder, "*.txt", SearchOption.TopDirectoryOnly))
                    {
                        AddFileToDictionary(files, file, Path.GetFileName(Program.LogsFolder));
                    }
                }

                zip.CompressFileDictionary(files, exportPath);

                return true;
            }
            catch (Exception e)
            {
                DebugHelper.WriteException(e);
                MessageBox.Show("Error while exporting backup:\r\n\r\n" + e, "ShareX - Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            return false;
        }
开发者ID:TJHeuvel,项目名称:ShareX,代码行数:45,代码来源:ExportImportManager.cs

示例2: DoWork


//.........这里部分代码省略.........

					string strScreenshotPath = Path.Combine(strTmpDirectory, "screenshot.jpg");
					strScreenshotPath = Path.ChangeExtension(strScreenshotPath, prjModProject.Screenshot.GetExtension());
					File.WriteAllBytes(strScreenshotPath, prjModProject.Screenshot.Data);
					dicFiles[Path.Combine(NexusMod.MetaFolder, Path.GetFileName(strScreenshotPath))] = strScreenshotPath;

					StepOverallProgress();
					if (Status == TaskStatus.Cancelling)
						return null;
				}

				if (prjModProject.ModReadme != null)
				{
					ItemMessage = "Generating Readme...";
					ItemProgressMaximum = 1;
					ItemProgress = 0;

					string strReadmePath = Path.Combine(strTmpDirectory, "readme.txt");
					strReadmePath = Path.ChangeExtension(strReadmePath, prjModProject.ModReadme.Extension);
					File.WriteAllText(strReadmePath, prjModProject.ModReadme.Text);
					dicFiles[Path.Combine(NexusMod.MetaFolder, Path.GetFileName(strReadmePath))] = strReadmePath;

					StepOverallProgress();
					if (Status == TaskStatus.Cancelling)
						return null;
				}

				if (prjModProject.InstallScript != null)
				{
					ItemMessage = "Generating Install Script...";
					ItemProgressMaximum = 1;
					ItemProgress = 0;

					XDocument xmlScript = new XDocument();
					IScriptType stpType = prjModProject.InstallScript.Type;
					XElement xelScript = XElement.Parse(stpType.SaveScript(prjModProject.InstallScript));
					xmlScript.Add(xelScript);

					string strScriptPath = Path.Combine(strTmpDirectory, stpType.FileNames[0]);
					xmlScript.Save(strScriptPath);
					dicFiles[Path.Combine(NexusMod.MetaFolder, stpType.FileNames[0])] = strScriptPath;

					StepOverallProgress();
					if (Status == TaskStatus.Cancelling)
						return null;
				}

				ItemMessage = "Compressing Files...";
				ItemProgressMaximum = dicFiles.Count;
				ItemProgress = 0;

				szcCompressor = new SevenZipCompressor();
				szcCompressor.CompressionLevel = CompressionLevel.Fast;
				szcCompressor.ArchiveFormat = OutArchiveFormat.SevenZip;
				szcCompressor.CompressionMethod = CompressionMethod.Default;
				switch (szcCompressor.ArchiveFormat)
				{
					case OutArchiveFormat.Zip:
					case OutArchiveFormat.GZip:
					case OutArchiveFormat.BZip2:
						szcCompressor.CustomParameters.Add("mt", "on");
						break;
					case OutArchiveFormat.SevenZip:
					case OutArchiveFormat.XZ:
						szcCompressor.CustomParameters.Add("mt", "on");
						szcCompressor.CustomParameters.Add("s", "off");
						break;
				}
				szcCompressor.CompressionMode = CompressionMode.Create;
				szcCompressor.FileCompressionStarted += new EventHandler<FileNameEventArgs>(Compressor_FileCompressionStarted);
				szcCompressor.FileCompressionFinished += new EventHandler<EventArgs>(Compressor_FileCompressionFinished);

				szcCompressor.CompressFileDictionary(dicFiles, strFileName);
			}
			finally
			{
				if (!String.IsNullOrEmpty(strTmpDirectory))
				{
					if (szcCompressor != null)
					{
						szcCompressor = null;
						//this is bad form - really we should be disposing szcCompressor, but
						// we can't as it doesn't implement IDisposable, so we have to rely
						// on the garbage collector the force szcCompressor to release its
						// resources (in this case, file locks)
						System.GC.Collect();
					}
					//this try/catch is just in case the GC doesn't go as expected
					// and szcCompressor didn't release its resources
					try
					{
						FileUtil.ForceDelete(strTmpDirectory);
					}
					catch (IOException)
					{
					}
				}
			}
			return null;
		}
开发者ID:NexusMods,项目名称:NexusModManager-4.5,代码行数:101,代码来源:ModPackager.cs

示例3: CompressFileDictionaryTest

		public void CompressFileDictionaryTest(){
			var tmp = new SevenZipCompressor();
			Dictionary<string, string> fileDict = new Dictionary<string, string>();
			var arch = Path.Combine(tempFolder, TestContext.TestName + ".7z");
			fileDict.Add("ololol.bin", testFile1);
			tmp.FileCompressionStarted += (o, e) =>{
				//TestContext.WriteLine(String.Format("[{0}%] {1}", e.PercentDone, e.FileName));
			};
			tmp.CompressFileDictionary(fileDict, arch);
		}
开发者ID:KOLANICH,项目名称:SevenZipSharp,代码行数:10,代码来源:SevenZipTestPack.cs

示例4: CreateWrappedArchive

        public static byte[] CreateWrappedArchive(string basePath, string[] includes, string[] excludes)
        {
            using (MemoryStream inStream = new MemoryStream()) {
                var zipOut = new SevenZipCompressor();
                zipOut.ArchiveFormat = OutArchiveFormat.Zip;
                zipOut.CompressionLevel = SevenZip.CompressionLevel.None;

                List<string> FileList = new List<string>(Search.FindFiles(
                    basePath, includes, excludes, SearchOption.AllDirectories
                ));

                SevenZipBase.SetLibraryPath(Inits.EnsureBinaries());
                zipOut.CompressFileDictionary(
                    FileList.ToDictionary(f => f.Replace(basePath, null), f => f),
                    inStream
                );

                inStream.Position = 0;

                using (var outStream = new MemoryStream()) {
                    using (var LzmaStream = new LzmaEncodeStream(outStream)) {
                        int byt = 0;
                        while ((byt = inStream.ReadByte()) != -1)
                            LzmaStream.WriteByte((byte)byt);
                    }
                    return outStream.ToArray();
                }
            }
        }
开发者ID:IsaacSanch,项目名称:KoruptLib,代码行数:29,代码来源:Lzma.cs

示例5: Zip

        public void Zip()
        {
            if (_Directories != null)
            {
                SevenZipCompressor.SetLibraryPath(@"C:\\Program Files\\7-Zip\\7z.dll");
                SevenZipCompressor c = new SevenZipCompressor();
                c.DirectoryStructure = true;
                c.PreserveDirectoryRoot = false;
                c.CompressionMode = CompressionMode.Create;
                c.ArchiveFormat = OutArchiveFormat.Zip;
                c.PreserveDirectoryRoot = true;

                c.CompressFileDictionary(_Directories, _Dir.FullName + "\\output.docx");
            }
        }
开发者ID:TonyBarnett,项目名称:TeXToWordCompiler,代码行数:15,代码来源:ZipFiles.cs


注:本文中的SevenZip.SevenZipCompressor.CompressFileDictionary方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。