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


C# ResourceReader.GetResourceData方法代码示例

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


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

示例1: build_page_1

        private void build_page_1()
        {
            TextView tv1 = new TextView ();

            try
            {
                string rez = "Adeptus.Resources.resources";
                string key = "mystring1";
                string resourceType = "";
                byte[] resourceData;
                ResourceReader r = new ResourceReader(rez);
                r.GetResourceData (key, out resourceType, out resourceData);
                r.Close();
                System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
                tv1.Buffer.Text = enc.GetString (resourceData);
            }
            catch (Exception exp)
            {
                tv1.Buffer.Text = exp.Message;
            }

            tv1.WrapMode = WrapMode.Word;
            tv1.Editable = false;

            this.AppendPage (tv1);
            this.SetPageTitle (tv1, "Introduction");
            this.SetPageType (tv1, AssistantPageType.Intro);
            this.SetPageComplete (tv1, true);
        }
开发者ID:sgtnasty,项目名称:battle,代码行数:29,代码来源:NewCharacterWindow.cs

示例2: copyFiles

		public void copyFiles() {
			using (
				var msData =
					(UnmanagedMemoryStream)
					Assembly.GetExecutingAssembly().GetManifestResourceStream("updateSystemDotNet.Setup.setup.package")) {
				using (var resReader = new ResourceReader(msData)) {
					//Dateimap einlesen
					var xmlMap = new XmlDocument();
					byte[] mapData = null;
					string tempString;
					resReader.GetResourceData("map", out tempString, out mapData);
					using (var msMap = new MemoryStream(mapData)) {
						using (var srMap = new StreamReader(msMap, Encoding.UTF8)) {
							xmlMap.Load(srMap);
						}
					}

					int totalFiles = (xmlMap.SelectNodes("Files/File").Count);
					int currentFile = 0;

					//Dateien verarbeiten
					foreach (XmlNode fileNode in xmlMap.SelectNodes("Files/File")) {
						byte[] compressedFileData = null;
						resReader.GetResourceData(fileNode.SelectSingleNode("Id").InnerText, out tempString, out compressedFileData);
						writeCompressedFile(
							compressedFileData,
							fileNode.SelectSingleNode("Directory").InnerText,
							fileNode.SelectSingleNode("Filename").InnerText);

						currentFile++;
						if (fileProgressChanged != null)
							fileProgressChanged(this, new ProgressChangedEventArgs(Percent(currentFile, totalFiles), null));
					}
				}
			}
		}
开发者ID:hbaes,项目名称:updateSystem.NET,代码行数:36,代码来源:setupPackage.cs

示例3: PostRename

        public void PostRename(ConfuserContext context, INameService service, ProtectionParameters parameters, 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();
                        name = document.DocumentName;
                    }

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

示例4: GetResourceData2

		public void GetResourceData2 ()
		{
			byte [] expected = new byte [] {
				0x00, 0x01, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF,
				0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x0C, 0x02, 0x00, 0x00, 0x00, 0x51, 0x53,
				0x79, 0x73, 0x74, 0x65, 0x6D, 0x2E, 0x44, 0x72,
				0x61, 0x77, 0x69, 0x6E, 0x67, 0x2C, 0x20, 0x56,
				0x65, 0x72, 0x73, 0x69, 0x6F, 0x6E, 0x3D, 0x32,
				0x2E, 0x30, 0x2E, 0x30, 0x2E, 0x30, 0x2C, 0x20,
				0x43, 0x75, 0x6C, 0x74, 0x75, 0x72, 0x65, 0x3D,
				0x6E, 0x65, 0x75, 0x74, 0x72, 0x61, 0x6C, 0x2C,
				0x20, 0x50, 0x75, 0x62, 0x6C, 0x69, 0x63, 0x4B,
				0x65, 0x79, 0x54, 0x6F, 0x6B, 0x65, 0x6E, 0x3D,
				0x62, 0x30, 0x33, 0x66, 0x35, 0x66, 0x37, 0x66,
				0x31, 0x31, 0x64, 0x35, 0x30, 0x61, 0x33, 0x61,
				0x05, 0x01, 0x00, 0x00, 0x00, 0x13, 0x53, 0x79,
				0x73, 0x74, 0x65, 0x6D, 0x2E, 0x44, 0x72, 0x61,
				0x77, 0x69, 0x6E, 0x67, 0x2E, 0x53, 0x69, 0x7A,
				0x65, 0x02, 0x00, 0x00, 0x00, 0x05, 0x77, 0x69,
				0x64, 0x74, 0x68, 0x06, 0x68, 0x65, 0x69, 0x67,
				0x68, 0x74, 0x00, 0x00, 0x08, 0x08, 0x02, 0x00,
				0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00,
				0x00, 0x00, 0x0B};
			ResourceReader r = new ResourceReader ("Test/resources/bug81759.resources");
			string type;
			byte [] bytes;
			r.GetResourceData ("imageList.ImageSize", out type, out bytes);
			// Note that const should not be used here.
			Assert.AreEqual ("System.Drawing.Size, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", type, "#1");
			Assert.AreEqual (expected, bytes, "#2");
			r.Close ();
		}
开发者ID:KonajuGames,项目名称:SharpLang,代码行数:33,代码来源:ResourceReaderTest.cs

示例5: GetResourceData

		public void GetResourceData ()
		{
			byte [] t1 = new byte [] {0x16, 0x00, 0x00, 0x00, 0x76, 0x65, 0x72, 0x69, 0x74, 0x61, 0x73, 0x20, 0x76, 0x6F, 0x73, 0x20, 0x6C, 0x69, 0x62, 0x65, 0x72, 0x61, 0x62, 0x69, 0x74, 0x0A};
			byte [] t2 = new byte [] {0x0A, 0x73, 0x6F, 0x6D, 0x65, 0x73, 0x74, 0x72, 0x69, 0x6E, 0x67};
			byte [] t3 = new byte [] {0x0E, 0x00, 0x00, 0x00, 0x73, 0x68, 0x61, 0x72, 0x64, 0x65, 0x6E, 0x66, 0x72, 0x65, 0x75, 0x64, 0x65, 0x0A};

			ResourceReader r = new ResourceReader ("Test/resources/StreamTest.resources");
			Hashtable items = new Hashtable ();
			foreach (DictionaryEntry de in r) {
				string type;
				byte [] bytes;
				r.GetResourceData ((string) de.Key, out type, out bytes);
				items [de.Key] = new DictionaryEntry (type, bytes);
			}

			DictionaryEntry p = (DictionaryEntry) items ["test"];
			Assert.AreEqual ("ResourceTypeCode.Stream", p.Key as string, "#1-1");
			Assert.AreEqual (t1, p.Value as byte [], "#1-2");

			p = (DictionaryEntry) items ["test2"];
			Assert.AreEqual ("ResourceTypeCode.String", p.Key as string, "#2-1");
			Assert.AreEqual (t2, p.Value as byte [], "#2-2");

			p = (DictionaryEntry) items ["test3"];
			Assert.AreEqual ("ResourceTypeCode.ByteArray", p.Key as string, "#3-1");
			Assert.AreEqual (t3, p.Value as byte [], "#3-2");

			r.Close ();
		}
开发者ID:KonajuGames,项目名称:SharpLang,代码行数:29,代码来源:ResourceReaderTest.cs

示例6: GetResourceDataNullName

		public void GetResourceDataNullName ()
		{
			ResourceReader r = new ResourceReader ("Test/resources/StreamTest.resources");
			string type;
			byte [] bytes;

			try {
				r.GetResourceData (null, out type, out bytes);
				Assert.Fail ("#1");
			} catch (ArgumentNullException ex) {
				Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
				Assert.IsNull (ex.InnerException, "#3");
				Assert.IsNotNull (ex.Message, "#4");
				Assert.IsNotNull (ex.ParamName, "#5");
				Assert.AreEqual ("resourceName", ex.ParamName, "#6");
			} finally {
				r.Close ();
			}
		}
开发者ID:KonajuGames,项目名称:SharpLang,代码行数:19,代码来源:ResourceReaderTest.cs

示例7: prepareEditUpdatePackage

		public prepareEditPackageResult prepareEditUpdatePackage(updatePackage package) {

			var result = new prepareEditPackageResult();

			//Temporäres Verzeichnis für die Updatedaten erstellen
			string tempPackagePath = Path.Combine(Environment.GetEnvironmentVariable("tmp"), package.ID);
			result.tempPackagePath = tempPackagePath;
			result.updatePackage = package;

			if (!Directory.Exists(tempPackagePath))
				Directory.CreateDirectory(tempPackagePath);

			//Pfad zum Updatepaket ermitteln
			string packagePath = Path.Combine(Path.Combine(_session.currentProjectDirectory, "Updates"), package.getFilename());
			if (!File.Exists(packagePath))
				throw new FileNotFoundException("Das Updatepaket konnte nicht gefunden werden.", packagePath);

			//Updatepaket öffnen
			using(var fsPackage = File.OpenRead(packagePath)) {
				using(var packageReader = new ResourceReader(fsPackage)) {

					//Dateien entpacken und im Tempverzeichnis abspeichern
					foreach (var copyAction in package.fileCopyActions) {
						foreach (var file in copyAction.Files) {
							string newFilename = string.Format("{0}.{1}", file.ID, file.Filename);
							using(var fsFileOut = new FileStream(Path.Combine(tempPackagePath, newFilename), FileMode.Create)) {
								byte[] resourceData;
								string tempType; //ungenutzt aber trotzdem notwendig
								packageReader.GetResourceData(file.ID, out tempType, out resourceData);
								byte[] decompressedData = decompressData(resourceData);
								fsFileOut.Write(decompressedData, 0, decompressedData.Length);
							}

							//Neuen Dateinamen in Updatepaket übernehmen
							file.Fullpath = Path.Combine(tempPackagePath, newFilename);
						}
					}
				}
			}

			//Changelog lesen
			string changelogPath = Path.Combine(Path.Combine(_session.currentProjectDirectory, "Updates"),
			                                    package.getChangelogFilename());
			if(!File.Exists(changelogPath))
				throw new FileNotFoundException("Der Changelog konnte nicht gefunden werden", changelogPath);
			
			using(var fsChangelog = new StreamReader(changelogPath, Encoding.UTF8)) {
				var xmlChangelog = new XmlDocument();
				xmlChangelog.Load(fsChangelog);

				XmlNodeList changelogItems = xmlChangelog.SelectNodes("updateSystemDotNet.Changelog/Items/Item");
				if(changelogItems == null)
					throw new InvalidOperationException("Es konnte im Changelog keine Änderungseinträge gefunden werden.");

				if (changelogItems.Count >= 1 && changelogItems[0].SelectSingleNode("Change") != null)
					result.changelogGerman = changelogItems[0].SelectSingleNode("Change").InnerText;
				if (changelogItems.Count >= 2 && changelogItems[1].SelectSingleNode("Change") != null)
					result.changelogEnglish = changelogItems[1].SelectSingleNode("Change").InnerText;

			}

			return result;
		}
开发者ID:hbaes,项目名称:updateSystem.NET,代码行数:63,代码来源:updateFactory.cs

示例8: AnalyzeResources

        void AnalyzeResources(ConfuserContext context, INameService service, ModuleDefMD module)
        {
            if (analyzer == null) {
                analyzer = new BAMLAnalyzer(context, service);
                analyzer.AnalyzeElement += AnalyzeBAMLElement;
            }

            var wpfResInfo = new Dictionary<string, Dictionary<string, BamlDocument>>();

            foreach (EmbeddedResource res in module.Resources.OfType<EmbeddedResource>()) {
                Match match = ResourceNamePattern.Match(res.Name);
                if (!match.Success)
                    continue;

                var resInfo = new Dictionary<string, BamlDocument>();

                res.Data.Position = 0;
                var reader = new ResourceReader(new ImageStream(res.Data));
                IDictionaryEnumerator enumerator = reader.GetEnumerator();
                while (enumerator.MoveNext()) {
                    var name = (string)enumerator.Key;
                    if (!name.EndsWith(".baml"))
                        continue;

                    string typeName;
                    byte[] data;
                    reader.GetResourceData(name, out typeName, out data);
                    BamlDocument document = analyzer.Analyze(module, name, data);
                    document.DocumentName = name;
                    resInfo.Add(name, document);
                }

                if (resInfo.Count > 0)
                    wpfResInfo.Add(res.Name, resInfo);
            }
            if (wpfResInfo.Count > 0)
                context.Annotations.Set(module, BAMLKey, wpfResInfo);
        }
开发者ID:RSchwoerer,项目名称:ConfuserEx,代码行数:38,代码来源:WPFAnalyzer.cs

示例9: CollectTranslatedResource

        private void CollectTranslatedResource(string bundleName, IDictionaryEnumerator dict, ResourceReader reader, List<ResourceTranslation> translations)
        {
            Object dictValue = null;
            try
            {
                dictValue = dict.Value;
            }
            catch (Exception)
            {
                // wenn eine Assembly wie MeonaKernel gebraucht wird, um dict.Value aufzulösen
                return;
            }

            String key = dict.Key.ToString();
            if (key.StartsWith(">>"))
                return;

            String type;
            byte[] data;
            reader.GetResourceData(dict.Key.ToString(), out type, out data);

            ResourceTranslation translation = new ResourceTranslation();
            translation.BinaryValue = data;
            translation.StringValue = dict.Value != null ? dict.Value.ToString() : null;
            translation.TranslationDateTime = DateTime.UtcNow;
            translation.TranslationStatus = COLLECT_STATUS;
            translation.TranslationBy = TRANSLATION_IMPORTER;

            if (translation.StringValue != null || translation.BinaryValue != null)
            {
                translation.Locale = assembly.GetName().CultureInfo.Name;
                translation.Resource = new Resource();
                translation.Resource.Key = key;
                translation.Resource.ResourceClass = type;

                translations.Add(translation);
            }
        }
开发者ID:wuttke,项目名称:tinytranslator,代码行数:38,代码来源:AssemblyTranslationCollector.cs

示例10: GetImageResource

		/// <summary>
		///     Получение иконок для хинтов из ресурсов проекта Controls
		/// </summary>
		/// <param name="resName">Путь к ресурсу формата GKIcons/RSR2_Bush_Fire.png</param>
		/// <returns></returns>
		public static Tuple<string, System.Drawing.Size> GetImageResource(string resName)
		{
			resName = resName.Replace("/Controls;component/", "");
			var assembly = Assembly.GetAssembly(typeof(Controls.AlarmButton));
			var name =
				assembly.GetManifestResourceNames().FirstOrDefault(n => n.EndsWith(".resources", StringComparison.Ordinal));
			var resourceStream = assembly.GetManifestResourceStream(name);
			if (resourceStream == null)
			{
				return new Tuple<string, System.Drawing.Size>("", new System.Drawing.Size());
			}
			byte[] values;
			using (var reader = new ResourceReader(resourceStream))
			{
				string type;
				reader.GetResourceData(resName.ToLowerInvariant(), out type, out values);
			}

			// Получили массив байтов ресурса, теперь преобразуем его в png bitmap, а потом снова в массив битов
			// уже корректного формата, после чего преобразуем его в base64string для удобства обратного преобразования
			// на клиенте

			const int offset = 4;
			var size = BitConverter.ToInt32(values, 0);
			var value1 = new Bitmap(new MemoryStream(values, offset, size));
			byte[] byteArray;
			using (var stream = new MemoryStream())
			{
				value1.Save(stream, ImageFormat.Png);
				stream.Close();

				byteArray = stream.ToArray();
			}

			return new Tuple<string, System.Drawing.Size>(Convert.ToBase64String(byteArray), value1.Size);
		}
开发者ID:xbadcode,项目名称:Rubezh,代码行数:41,代码来源:InternalConverterOld.cs

示例11: accessUpdatePackage

		/// <summary>
		/// Bietet Zugriff auf die Resourcen in einem Updatepaket.
		/// </summary>
		/// <param name="packagePath">Der Pfad zu dem Updatepaket.</param>
		/// <param name="resID">Die ID der Resource die ausgelesen werden soll.</param>
		/// <returns>Gibt die Resource in Form eines ByteArrays zurück.</returns>
		protected byte[] accessUpdatePackage(string packagePath, string resID) {
			var resReader = new ResourceReader(packagePath);
			try {
				byte[] outData;
				string outType;
				resReader.GetResourceData(resID, out outType, out outData);
				return outData;
			}
			finally {
				resReader.Close();
			}
		}
开发者ID:hbaes,项目名称:updateSystem.NET,代码行数:18,代码来源:applyUpdateBase.cs

示例12: GetResourceAsStream

 private Stream GetResourceAsStream(string name)
 {
     Stream stream = Assembly.GetEntryAssembly().GetManifestResourceStream("Concierge_Manager.Properties.Resources.resources");
     ResourceReader reader = new ResourceReader(stream);
     string resourceType = "";
     byte[] data = null;
     reader.GetResourceData(name, out resourceType , out data );
     MemoryStream ms = new MemoryStream(data, 4, data.Length - 4); // it seems that we are getting the file length in the first four bytes
     return ms;
 }
开发者ID:cpbuck12,项目名称:Db,代码行数:10,代码来源:ObjectForScripting.cs

示例13: CollectSingleResource

        private void CollectSingleResource(string resourceName, IDictionaryEnumerator dict, ResourceBundle bundle, ResourceReader reader, Object dictValue)
        {
            var resource = new Resource();
            resource.Key = dict.Key.ToString();
            resource.CreateDateTime = DateTime.UtcNow;
            resource.LastChangeDateTime = DateTime.UtcNow;
            resource.DesignerSupportFlag = resource.Key.StartsWith(">>");

            String type;
            byte[] data;
            reader.GetResourceData(dict.Key.ToString(), out type, out data);
            resource.ResourceClass = type;
            resource.BinaryValue = data;

            bundle.Resources.Add(resource);

            resource.StringValue = dictValue != null ? dictValue.ToString() : null;
            if (dictValue is String)
                resource.ResourceType = ResourceType.STRING;
            else if (dictValue is Bitmap)
                resource.ResourceType = ResourceType.IMAGE;
            else
                resource.ResourceType = ResourceType.OTHER_BINARY;
        }
开发者ID:wuttke,项目名称:tinytranslator,代码行数:24,代码来源:AssemblyResourceCollector.cs

示例14: 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

示例15: Write

        /// <inheritdoc/>
        public void Write(
            TinyBinaryWriter writer)
        {
            var orderedResources = new SortedDictionary<Int16, Tuple<ResourceKind, Byte[]>>();
            foreach (var item in _resources.OfType<EmbeddedResource>())
            {
                var count = 0U;
                using (var reader = new ResourceReader(item.GetResourceStream()))
                {
                    foreach (DictionaryEntry resource in reader)
                    {
                        String resourceType;
                        Byte[] resourceData;
                        var resourceName = resource.Key.ToString();

                        reader.GetResourceData(resourceName, out resourceType, out resourceData);

                        var kind = GetResourceKind(resourceType, resourceData);

                        if (kind == ResourceKind.Bitmap)
                        {
                            using (var stream = new MemoryStream(resourceData.Length))
                            {
                                var bitmapProcessor = new TinyBitmapProcessor((Bitmap)resource.Value);
                                bitmapProcessor.Process(writer.GetMemoryBasedClone(stream));
                                resourceData = stream.ToArray();
                            }
                        }

                        orderedResources.Add(GenerateIdFromResourceName(resourceName),
                            new Tuple<ResourceKind, Byte[]>(kind, resourceData));

                        ++count;
                    }
                }

                _context.ResourceFileTable.AddResourceFile(item, count);
            }

            foreach (var item in orderedResources)
            {
                var kind = item.Value.Item1;
                var bytes = item.Value.Item2;

                var padding = 0;
                switch (kind)
                {
                    case ResourceKind.String:
                        var stringLength = (Int32)bytes[0];
                        if (stringLength < 0x7F)
                        {
                            bytes = bytes.Skip(1).Concat(Enumerable.Repeat((Byte)0, 1)).ToArray();
                        }
                        else
                        {
                            bytes = bytes.Skip(2).Concat(Enumerable.Repeat((Byte)0, 1)).ToArray();
                        }
                        break;
                    case ResourceKind.Bitmap:
                        padding = _context.ResourceDataTable.AlignToWord();
                        break;
                    case ResourceKind.Binary:
                        bytes = bytes.Skip(4).ToArray();
                        break;
                    case ResourceKind.Font:
                        padding = _context.ResourceDataTable.AlignToWord();
                        bytes = bytes.Skip(32).ToArray(); // File size + resource header size
                        break;
                }

                // Pre-process font data (swap endiannes if needed).
                if (kind == ResourceKind.Font)
                {
                    using (var stream = new MemoryStream(bytes.Length))
                    {
                        var fontProcessor = new TinyFontProcessor(bytes);
                        fontProcessor.Process(writer.GetMemoryBasedClone(stream));
                        bytes = stream.ToArray();
                    }
                }

                writer.WriteInt16(item.Key);
                writer.WriteByte((Byte)kind);
                writer.WriteByte((Byte)padding);
                writer.WriteInt32(_context.ResourceDataTable.CurrentOffset);

                _context.ResourceDataTable.AddResourceData(bytes);
            }

            if (orderedResources.Count != 0)
            {
                writer.WriteInt16(0x7FFF);
                writer.WriteByte((Byte)ResourceKind.None);
                writer.WriteByte(0x00);
                writer.WriteInt32(_context.ResourceDataTable.CurrentOffset);
            }
        }
开发者ID:Roddoric,项目名称:Monkey.Robotics,代码行数:98,代码来源:TinyResourcesTable.cs


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