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


C# ResourceWriter.AddResourceData方法代码示例

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


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

示例1: Process

        public bool Process(AssemblyDefinition containingAssembly, Res resource, ResReader resourceReader, ResourceWriter resourceWriter)
        {
            string fix = _repackContext.FixStr(resource.type);
            if (fix == resource.type)
            {
                resourceWriter.AddResourceData(resource.name, resource.type, resource.data);
            }
            else
            {
                var output2 = new MemoryStream(resource.data.Length);
                var sr = new SerReader(_repackContext, new MemoryStream(resource.data), output2);
                sr.Stream();
                resourceWriter.AddResourceData(resource.name, fix, output2.ToArray());
            }

            return true;
        }
开发者ID:jinjingcai2014,项目名称:il-repack,代码行数:17,代码来源:GenericResourceProcessor.cs

示例2: WriteCollectedBamlStreams

 private void WriteCollectedBamlStreams(ResourceWriter resourceWriter)
 {
     foreach (var bamlStream in _bamlStreams)
     {
         resourceWriter.AddResourceData(
             GetResourceName(bamlStream.Key, bamlStream.Value), bamlStream.Key.type, bamlStream.Key.data);
     }
 }
开发者ID:jinjingcai2014,项目名称:il-repack,代码行数:8,代码来源:BamlStreamCollector.cs

示例3: Main

		static void Main(string[] args) {

			string dataDirectory = args[0];
			string targetFile = args[1];

			XmlDocument map = new XmlDocument();
			XmlNode xFilesNode = map.CreateElement("Files");
			ResourceWriter writer = new ResourceWriter(targetFile);

			foreach (string file in Directory.GetFiles(dataDirectory, "*", SearchOption.AllDirectories)) {

				XmlNode xFile = map.CreateElement("File");
				string id = Guid.NewGuid().ToString();
				string targetDirectory = Path.GetDirectoryName(file).Replace(dataDirectory, "");
				if (targetDirectory.StartsWith("\\"))
					targetDirectory = targetDirectory.Substring(1);

				xFile.AppendChild(createNode(map, "Id", id));
				xFile.AppendChild(createNode(map, "Directory", targetDirectory)); ;
				xFile.AppendChild(createNode(map, "Filename", Path.GetFileName(file)));
				xFilesNode.AppendChild(xFile);

				writer.AddResourceData(id, "setupData", Compress(File.ReadAllBytes(file)));
				
			}

			map.AppendChild(xFilesNode);
			using (MemoryStream msData = new MemoryStream()) {
				using (StreamWriter sw = new StreamWriter(msData, Encoding.UTF8)) {
					map.Save(sw);
					writer.AddResourceData("map", "setupData", msData.ToArray());
				}
			}

			writer.Generate();
			writer.Dispose();
		}
开发者ID:hbaes,项目名称:updateSystem.NET,代码行数:37,代码来源:Program.cs

示例4: PostRename

        public void PostRename(ConfuserContext context, INameService service, IDnlibDef def)
        {
            var module = def as ModuleDefMD;
            if (module == null)
                return;

            var wpfResInfo = context.Annotations.Get<Dictionary<string, Dictionary<string, BamlDocument>>>(module, BAMLKey);
            if (wpfResInfo == null)
                return;

            foreach (EmbeddedResource res in module.Resources.OfType<EmbeddedResource>()) {
                Dictionary<string, BamlDocument> resInfo;

                if (!wpfResInfo.TryGetValue(res.Name, out resInfo))
                    continue;

                var stream = new MemoryStream();
                var writer = new ResourceWriter(stream);

                res.Data.Position = 0;
                var reader = new ResourceReader(new ImageStream(res.Data));
                IDictionaryEnumerator enumerator = reader.GetEnumerator();
                while (enumerator.MoveNext()) {
                    var name = (string)enumerator.Key;
                    string typeName;
                    byte[] data;
                    reader.GetResourceData(name, out typeName, out data);

                    BamlDocument document;
                    if (resInfo.TryGetValue(name, out document)) {
                        var docStream = new MemoryStream();
                        docStream.Position = 4;
                        BamlWriter.WriteDocument(document, docStream);
                        docStream.Position = 0;
                        docStream.Write(BitConverter.GetBytes((int)docStream.Length - 4), 0, 4);
                        data = docStream.ToArray();
                    }

                    writer.AddResourceData(name, typeName, data);
                }
                writer.Generate();
                res.Data = MemoryImageStream.Create(stream.ToArray());
            }
        }
开发者ID:GavinHwa,项目名称:ConfuserEx,代码行数:44,代码来源:WPFAnalyzer.cs

示例5: buildUpdatePackage

		public void buildUpdatePackage(updatePackage package, string changesDe, string changesEn) {

			//Argumente prüfen
			if (package == null)
				throw new ArgumentException("package");
			if (string.IsNullOrEmpty(changesDe) && string.IsNullOrEmpty(changesEn))
				throw new ArgumentException("changesDe und changesEn");

			//Prüfen ob das Projekt schon gespeichert wurde (notwendig!)
			if (string.IsNullOrEmpty(_session.currentProjectPath))
				throw new Exception("Das Projekt muss gespeichert werden bevor Updatepakete erstellt werden können.");

			//Lokales Basisverzeichnis für die Aktualisieren bestimmen.
			string updateDirectory = Path.Combine(Path.GetDirectoryName(_session.currentProjectPath), _projectStructure[0]);
			
			//Updatepaket für die Dateien erstellen
			using (var fsUpdatePackage = new FileStream(Path.Combine(updateDirectory, package.getFilename()), FileMode.Create)) {
				using (var writer = new ResourceWriter(fsUpdatePackage)) {

					//Jede Datei ins Paket schreiben und vorher komprimieren
					foreach (var fcAction in package.fileCopyActions)
						foreach (var fileData in fcAction.Files)
							if (File.Exists(fileData.Fullpath))
								writer.AddResourceData(fileData.ID, "fileCopyActionData", compressData(File.ReadAllBytes(fileData.Fullpath)));
					writer.Generate();
				}
			}

			//Paketgröße setzen
			package.packageSize = new FileInfo(Path.Combine(updateDirectory, package.getFilename())).Length;

			string packageHash =
				Convert.ToBase64String(
					SHA512.Create().ComputeHash(File.ReadAllBytes(Path.Combine(updateDirectory, package.getFilename()))));
			package.packageSignature = updateSystemDotNet.Core.RSA.Sign(packageHash, _session.currentProject.keyPair.privateKey);

			//Changelog erstellen und speichern
			XmlDocument xChangelog = createChangelogs(changesDe, changesEn);
			using(var xWriter = new StreamWriter(Path.Combine(updateDirectory,package.getChangelogFilename()), false,Encoding.UTF8)) {
				xChangelog.Save(xWriter);
			}
		}
开发者ID:hbaes,项目名称:updateSystem.NET,代码行数:42,代码来源:updateFactory.cs

示例6: Execute

		/// <summary>See <see cref="Task.Execute"/>.</summary>
		public override bool Execute()
		{
			TaskLoggingHelper log = base.Log;
			ITaskItem targetManifestResource = this._targetManifestResource;
			ITaskItem[] mergeResources = this._mergeResources;
			this._outputResource = null;

			if (mergeResources.Length <= 0)
			{
				// If we don't have any resources to merge, then we have already succeeded at (not) merging them.
				return true;
			}

			FileInfo targetManifestResourceFileInfo = new FileInfo(targetManifestResource.GetMetadata("FullPath"));

			if (!targetManifestResourceFileInfo.Exists)
			{
				log.LogError("The specified manifest resource file (\"{0}\") does not exist.", targetManifestResource.ItemSpec);
				return false;
			}

			// UNDONE: In all of the IO in this method, we aren't doing any handling of situations where the file changes between when we initially
			// look at its size and when we actually read the content.

			// Get all of the new resources and their values.
			Dictionary<string, byte[]> mergeResourcesValues = new Dictionary<string, byte[]>(mergeResources.Length, StringComparer.Ordinal);
			foreach (ITaskItem mergeResource in mergeResources)
			{
				System.Diagnostics.Debug.Assert(string.Equals(mergeResource.GetMetadata("MergeTarget"), targetManifestResource.ItemSpec, StringComparison.OrdinalIgnoreCase),
					"Trying to emit a resource into a different manifest resource than the one specified for MergeTarget.");

				FileInfo mergeResourceFileInfo = new FileInfo(mergeResource.GetMetadata("FullPath"));
				if (!mergeResourceFileInfo.Exists)
				{
					log.LogError("The specified resource file to merge (\"{0}\") does not exist.", mergeResource.ItemSpec);
					return false;
				}

				byte[] mergeResourceBytes = new byte[mergeResourceFileInfo.Length];
				using (FileStream mergeResourceFileStream = new FileStream(mergeResourceFileInfo.FullName, FileMode.Open,
					FileAccess.Read, FileShare.Read, mergeResourceBytes.Length, FileOptions.SequentialScan))
				{
					mergeResourceFileStream.Read(mergeResourceBytes, 0, mergeResourceBytes.Length);
				}

				string resourceName = mergeResource.GetMetadata("ResourceName");
				if (string.IsNullOrEmpty(resourceName))
				{
					log.LogError("The specified resource file to merge (\"{0}\") is missing a ResourceName metadata value.", mergeResource.ItemSpec);
					return false;
				}

				if (mergeResourcesValues.ContainsKey(resourceName))
				{
					log.LogError("The specified resource file to merge (\"{0}\") has a duplicate ResourceName metadata value (\"{2}\").", mergeResource.ItemSpec, resourceName);
					return false;
				}
				mergeResourcesValues.Add(resourceName, mergeResourceBytes);
			}

			// Read the existing .resources file into a byte array.
			byte[] originalResourcesBytes = new byte[targetManifestResourceFileInfo.Length];
			using (FileStream originalResourcesFileStream = new FileStream(targetManifestResourceFileInfo.FullName, FileMode.Open,
				FileAccess.Read, FileShare.Read, originalResourcesBytes.Length, FileOptions.SequentialScan))
			{
				originalResourcesFileStream.Read(originalResourcesBytes, 0, originalResourcesBytes.Length);
			}

			// The FileMode.Truncate on the next line is to make the .resources file zero-length so that we don't have to worry about any excess being left behind.
			using (ResourceWriter resourceWriter = new ResourceWriter(new FileStream(targetManifestResourceFileInfo.FullName, FileMode.Truncate,
			FileAccess.ReadWrite, FileShare.None, originalResourcesBytes.Length + (mergeResources.Length * 1024), FileOptions.SequentialScan)))
			{
				// Copy the resources from the original .resources file (now stored in the byte array) into the new .resources file.
				using (ResourceReader resourceReader = new ResourceReader(new MemoryStream(originalResourcesBytes, 0, originalResourcesBytes.Length, false, false)))
				{
					foreach (System.Collections.DictionaryEntry entry in resourceReader)
					{
						string resourceName = (string)entry.Key;
						string resourceType;
						byte[] resourceData;
						resourceReader.GetResourceData(resourceName, out resourceType, out resourceData);

						if (mergeResourcesValues.ContainsKey(resourceName))
						{
							log.LogMessage(MessageImportance.Normal, "Skipping copying resource \"{0}\" of type \"{1}\" to new manifest resource file \"{2}\". A new resource with this name will be merged.",
								resourceName, resourceType, targetManifestResource.ItemSpec);
						}
						else
						{
							resourceWriter.AddResourceData(resourceName, resourceType, resourceData);
							log.LogMessage(MessageImportance.Low, "Copied resource \"{0}\" of type \"{1}\" to new manifest resource file \"{2}\".", resourceName, resourceType, targetManifestResource.ItemSpec);
						}
					}
				}

				// Add each of the new resources into the new .resources file.
				foreach (KeyValuePair<string, byte[]> mergeResourceValue in mergeResourcesValues)
				{
					resourceWriter.AddResource(mergeResourceValue.Key, mergeResourceValue.Value);
//.........这里部分代码省略.........
开发者ID:cjheath,项目名称:NORMA,代码行数:101,代码来源:ResourceMerger.cs

示例7: AddNewGenericThemesXaml

        private void AddNewGenericThemesXaml(
            ResourceWriter resourceWriter, IEnumerable<string> genericThemeResources)
        {
            _logger.Info("Creating new themes/generic.xaml");
            var newBamlDocument = _bamlGenerator.GenerateThemesGenericXaml(genericThemeResources);

            resourceWriter.AddResourceData(
                GenericThemesBamlName, "ResourceTypeCode.Stream",
                BamlUtils.ToResourceBytes(newBamlDocument));
        }
开发者ID:jinjingcai2014,项目名称:il-repack,代码行数:10,代码来源:BamlStreamCollector.cs


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