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


C# ZipFile.SafeAddEntry方法代码示例

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


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

示例1: CreateArchive

		public void CreateArchive(string mutatorPath, bool hideFromModList = false)
		{
			var script = GetScript();
			var modInfo = GetModInfo(hideFromModList);
			var luaMissionData = SerializeToLua();
			if (Debugger.IsAttached)
			{
				File.WriteAllText("startscript.txt", script);
				File.WriteAllText("modinfo.txt", modInfo);
				//File.WriteAllText("mission.lua", luaMissionData);
			}
			var textEncoding = Encoding.GetEncoding("iso-8859-1"); // ASCIIEncoding()
			using (var zip = new ZipFile())
			{
				if (!String.IsNullOrEmpty(ContentFolderPath) && Directory.Exists(ContentFolderPath)) zip.SafeAddDirectory(ContentFolderPath);

				var assemblyLocation = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
				var basePath = Path.Combine(assemblyLocation, "MissionBase");
				zip.SafeAddDirectory(basePath);

				zip.SafeAddEntry("modinfo.lua", textEncoding.GetBytes(modInfo));
				zip.SafeAddEntry("mission.lua", textEncoding.GetBytes(luaMissionData));
				zip.SafeAddEntry("script.txt", textEncoding.GetBytes(script));
				zip.SafeAddEntry(GlobalConst.MissionScriptFileName, textEncoding.GetBytes(script));
				zip.SafeAddEntry("slots.lua", textEncoding.GetBytes(GetLuaSlots().ToString()));
				zip.SafeAddEntry("dependencies.txt", String.Join(";", Mod.Dependencies)); // FIXME

				{
					var stream = new MemoryStream();
					using (var writer = XmlWriter.Create(stream, new XmlWriterSettings { Indent = true, CheckCharacters = true })) new NetDataContractSerializer().WriteObject(writer, this);
					stream.Position = 0;
					zip.SafeAddEntry("project.mission.xml", stream);
				}

				{
					var serializer = new XmlSerializer(typeof(List<MissionSlot>));
					var stream = new MemoryStream();
					serializer.Serialize(stream, GetSlots());
					stream.Position = 0;
					zip.SafeAddEntry(GlobalConst.MissionSlotsFileName, stream);
				}

				// disable scripts by hiding them with a blank file
				var blank = textEncoding.GetBytes("-- intentionally left blank --");
				foreach (var widget in disabledWidgets.Distinct()) zip.SafeAddEntry("LuaUI/Widgets/" + widget, blank);
				foreach (var gadget in disabledGadgets.Distinct()) zip.SafeAddEntry("LuaRules/Gadgets/" + gadget, blank);

				// include media in mod archive
				foreach (var item in AllLogic)
				{
                    // note we want a silent failure if file not found (with the new read-from-archive system it often won't fail anyway)
					if (item is GuiMessageAction)
					{
						var action = (GuiMessageAction)item;
						if (!String.IsNullOrEmpty(action.ImagePath))
						{
							if (File.Exists(action.ImagePath)) zip.SafeAddFile(action.ImagePath, "LuaUI/Images/");
						}
					}
                    else if (item is GuiMessagePersistentAction)
                    {
                        var action = (GuiMessagePersistentAction)item;
                        if (!String.IsNullOrEmpty(action.ImagePath))
                        {
                            if (File.Exists(action.ImagePath)) zip.SafeAddFile(action.ImagePath, "LuaUI/Images/");
                        }
                    }
                    else if (item is ConvoMessageAction)
                    {
                        var action = (ConvoMessageAction)item;
                        if (!String.IsNullOrEmpty(action.ImagePath))
                        {
                            if (File.Exists(action.ImagePath)) zip.SafeAddFile(action.ImagePath, "LuaUI/Images/");
                        }
                        if (!String.IsNullOrEmpty(action.SoundPath) && File.Exists(action.SoundPath))
                        {
                            if (File.Exists(action.SoundPath)) zip.SafeAddFile(action.SoundPath, "LuaUI/Sounds/convo");
                        }
                    }
                    else if (item is SoundAction)
                    {
                        var action = (SoundAction)item;
                        if (!String.IsNullOrEmpty(action.SoundPath) && File.Exists(action.SoundPath))
                        {
                            if (File.Exists(action.SoundPath)) zip.SafeAddFile(action.SoundPath, "LuaUI/Sounds/");
                        }
                    }
                    else if (item is MusicAction)
                    {
                        var action = (MusicAction)item;
                        if (!String.IsNullOrEmpty(action.TrackPath) && File.Exists(action.TrackPath))
                        {
                            zip.SafeAddFile(action.TrackPath, "LuaUI/Sounds/music/");
                        }
                    }
                    else if (item is MusicLoopAction)
                    {
                        var action = (MusicLoopAction)item;
                        if (!String.IsNullOrEmpty(action.TrackIntroPath) && File.Exists(action.TrackIntroPath))
                        {
//.........这里部分代码省略.........
开发者ID:ParzivalX,项目名称:Zero-K-Infrastructure,代码行数:101,代码来源:Mission.cs


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