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


C# ZipArchive.GetHashCode方法代码示例

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


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

示例1: ImportFromProjectArchive

		public List<PrintItem> ImportFromProjectArchive(string loadedFileName = null)
		{
			if (loadedFileName == null)
			{
				loadedFileName = defaultProjectPathAndFileName;
			}

			if (!System.IO.File.Exists(loadedFileName))
			{
				return null;
			}

			try
			{
				using (FileStream fs = File.OpenRead(loadedFileName))
				using (ZipArchive zip = new ZipArchive(fs))
				{
					int projectHashCode = zip.GetHashCode();

					//If the temp folder doesn't exist - create it, otherwise clear it
					string stagingFolder = Path.Combine(applicationDataPath, "data", "temp", "project-extract", projectHashCode.ToString());
					if (!Directory.Exists(stagingFolder))
					{
						Directory.CreateDirectory(stagingFolder);
					}
					else
					{
						System.IO.DirectoryInfo directory = new System.IO.DirectoryInfo(@stagingFolder);
						EmptyFolder(directory);
					}

					List<PrintItem> printItemList = new List<PrintItem>();
					Project projectManifest = null;

					foreach (ZipArchiveEntry zipEntry in zip.Entries)
					{
						string sourceExtension = Path.GetExtension(zipEntry.Name).ToUpper();

						// Note: directories have empty Name properties
						//
						// Only process ZipEntries that are:
						//    - not directories and
						//     - are in the ValidFileExtension list or
						//     - have a .GCODE extension or
						//     - are named manifest.json
						if (!string.IsNullOrWhiteSpace(zipEntry.Name) &&
							(zipEntry.Name == "manifest.json"
							|| MeshFileIo.ValidFileExtensions().Contains(sourceExtension)
							|| sourceExtension == ".GCODE"))
						{
							string extractedFileName = Path.Combine(stagingFolder, zipEntry.Name);

							string neededPathForZip = Path.GetDirectoryName(extractedFileName);
							if (!Directory.Exists(neededPathForZip))
							{
								Directory.CreateDirectory(neededPathForZip);
							}

							using (Stream zipStream = zipEntry.Open())
							using (FileStream streamWriter = File.Create(extractedFileName))
							{
								zipStream.CopyTo(streamWriter);
							}

							if (zipEntry.Name == "manifest.json")
							{
								using (StreamReader sr = new System.IO.StreamReader(extractedFileName))
								{
									projectManifest = (Project)Newtonsoft.Json.JsonConvert.DeserializeObject(sr.ReadToEnd(), typeof(Project));
								}
							}
						}
					}

					if (projectManifest != null)
					{
						foreach (ManifestItem item in projectManifest.ProjectFiles)
						{
							for (int i = 1; i <= item.ItemQuantity; i++)
							{
								printItemList.Add(this.GetPrintItemFromFile(Path.Combine(stagingFolder, item.FileName), item.Name));
							}
						}
					}
					else
					{
						string[] files = Directory.GetFiles(stagingFolder, "*.*", SearchOption.AllDirectories);
						foreach (string fileName in files)
						{
							printItemList.Add(this.GetPrintItemFromFile(fileName, Path.GetFileNameWithoutExtension(fileName)));
						}
					}

					return printItemList;
				}
			}
			catch
			{
				return null;
			}
//.........这里部分代码省略.........
开发者ID:broettge,项目名称:MatterControl,代码行数:101,代码来源:ProjectFileHandler.cs


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