private static string CreateDummyResourceFile() { System.IO.MemoryStream ms = new System.IO.MemoryStream(); System.IO.StreamWriter sw = new System.IO.StreamWriter(ms, new System.Text.UTF8Encoding(false)); System.Resources.ResXResourceWriter writer = new System.Resources.ResXResourceWriter(sw); writer.AddResource("MyLittleResource", "MyLittleResourceValue"); writer.Generate(); ms.Flush(); ms.Seek(0, System.IO.SeekOrigin.Begin); return(System.Text.Encoding.UTF8.GetString(ms.ToArray())); }
static int Main(string[] args) { if (args.Length == 0) { MessageBox.Show("错误:没有打包资源参数...请拖拽需要打包的文件到本exe上"); return(2); } // 生成的资源包文件路径 string output_file = "FKResourcePack.resx"; output_file = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), output_file); // 逐个打到资源包里 System.Resources.ResXResourceWriter rsxw = new System.Resources.ResXResourceWriter(output_file); for (int i = 0; i < args.Length; i++) { string strSourceResFile = args[i]; if (File.Exists(strSourceResFile)) { FileStream fs = File.OpenRead(strSourceResFile); byte[] data = new byte[fs.Length]; fs.Read(data, 0, data.Length); fs.Close(); rsxw.AddResource(Path.GetFileName(strSourceResFile), data); } else { MessageBox.Show(string.Format("错误:需要打包的资源文件 \"{0}\" 不存在...", strSourceResFile)); return(1); } } rsxw.Generate(); rsxw.Close(); MessageBox.Show(string.Format("打包完成,资源包目录为: \"{0}\"", output_file)); return(0); }
private static void CreateResourceFile(string inputFile, string outputFile) { string fileName = Path.GetFileName(inputFile); System.Resources.IResourceWriter writer = null; FileStream fs = null; BinaryReader br = null; try { //writer = new System.Resources.ResourceWriter(outputFile); writer = new System.Resources.ResXResourceWriter(outputFile); fs = new FileStream(inputFile, FileMode.Open); br = new BinaryReader(fs); byte[] myBuffer = new byte[br.BaseStream.Length]; for (long i = 0; i < br.BaseStream.Length; i++) { myBuffer[i] = br.ReadByte(); } writer.AddResource(fileName, myBuffer); writer.Generate(); //writer.Close(); } finally { if (writer != null) { writer.Close(); } if (fs != null) { fs.Close(); } if (br != null) { br.Close(); } } }
static int Main(string[] args) { if (args.Length == 0) { System.Console.WriteLine("Error: no arguments."); return(2); } string output_file = "driver.resx"; output_file = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), output_file); System.Resources.ResXResourceWriter rsxw = new System.Resources.ResXResourceWriter(output_file); for (int i = 0; i < args.Length; i++) { string driver_file = args[i]; if (File.Exists(driver_file)) { FileStream fs = File.OpenRead(driver_file); byte[] data = new byte[fs.Length]; fs.Read(data, 0, data.Length); fs.Close(); rsxw.AddResource(Path.GetFileName(driver_file), data); } else { System.Console.WriteLine("Error: file \"{0}\" not found.", driver_file); return(1); } } rsxw.Generate(); rsxw.Close(); return(0); }
static int Main(string[] args) { if (args.Length == 0) { System.Console.WriteLine("Error: no arguments."); return 2; } string output_file = "driver.resx"; output_file = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), output_file); System.Resources.ResXResourceWriter rsxw = new System.Resources.ResXResourceWriter(output_file); for (int i = 0; i < args.Length; i++) { string driver_file = args[i]; if (File.Exists(driver_file)) { FileStream fs = File.OpenRead(driver_file); byte[] data = new byte[fs.Length]; fs.Read(data, 0, data.Length); fs.Close(); rsxw.AddResource(Path.GetFileName(driver_file), data); } else { System.Console.WriteLine("Error: file \"{0}\" not found.", driver_file); return 1; } } rsxw.Generate(); rsxw.Close(); return 0; }
private void generateResourceMenuItem_Click(object sender, EventArgs e) { Point origStart = GetOriginalXY(selStartMousePos); Point origEnd = GetOriginalXY(selEndMousePos); if (selStartMousePos.X != 0 || selStartMousePos.Y != 0) { int top = origStart.Y < origEnd.Y ? origStart.Y : origEnd.Y; int left = origStart.X < origEnd.X ? origStart.X : origEnd.X; int width = Math.Abs(origEnd.X - origStart.X); int height = Math.Abs(origEnd.Y - origStart.Y); Rectangle box = new Rectangle(left, top, width, height); Bitmap bitmap = ((Bitmap)image).Clone(box, ((Bitmap)image).PixelFormat); if (Statics.DTE.Solution.IsOpen) { foreach (EnvDTE.Project proj in Statics.DTE.Solution.Projects) { if (proj.Name.Contains("Test")) { try { ImageInputForm inputForm = new ImageInputForm(); inputForm.ShowDialog(); Microsoft.CSharp.CSharpCodeProvider codeProvider = new Microsoft.CSharp.CSharpCodeProvider(); string resFile = Path.GetDirectoryName(proj.FileName) + @"\Properties\Resources.resx"; string resDesginFile = Path.GetDirectoryName(proj.FileName) + @"\Properties\Resources.Designer.cs"; System.Resources.ResXResourceReader reader = new System.Resources.ResXResourceReader(resFile); using (System.Resources.ResXResourceWriter writer = new System.Resources.ResXResourceWriter(resFile + ".new")) { System.Collections.IDictionaryEnumerator iterator = reader.GetEnumerator(); while (iterator.MoveNext()) { writer.AddResource(iterator.Key.ToString(), iterator.Value); } writer.AddResource(inputForm.Input, bitmap); writer.Generate(); } File.Copy(resFile + ".new", resFile, true); File.Delete(resFile + ".new"); string[] unMatched; System.CodeDom.CodeCompileUnit unit = System.Resources.Tools.StronglyTypedResourceBuilder.Create(resFile, "Resources", proj.Properties.Item("DefaultNamespace").Value + ".Properties", codeProvider, true, out unMatched); using (StreamWriter designWriter = new StreamWriter(resDesginFile)) { codeProvider.GenerateCodeFromCompileUnit(unit, designWriter, new System.CodeDom.Compiler.CodeGeneratorOptions()); } MessageBox.Show("Image generation succeeded", "Resources Updated"); return; } catch (Exception ex) { MessageBox.Show("Image generation failed\n" + ex.Message, "Resources Did Not Update"); } } } MessageBox.Show("You need to have a project open, named *Test*", "Resources Did Not Update"); return; } MessageBox.Show("You need to have a solution open with a project named *Test*", "Resources Did Not Update"); return; } }
private void CreateResourceFromImage(bool entire) { Bitmap bitmap = null; if (entire) { bitmap = (Bitmap)(zoomPanControl.ZoomPanImage.Clone()); } else if (HasImageSelection && !entire) { bitmap = ((Bitmap)zoomPanControl.ZoomPanImage).Clone(partBox, ((Bitmap)zoomPanControl.ZoomPanImage).PixelFormat); } if (bitmap != null) { if (Statics.DTE.Solution.IsOpen) { foreach (EnvDTE.Project proj in Statics.DTE.Solution.Projects) { if (proj.Name.Contains("Test")) { try { string resFile, resDesignFile, resNameSpace; System.CodeDom.Compiler.CodeDomProvider provider; if (proj.FileName.EndsWith("vbproj")) { resFile = Path.GetDirectoryName(proj.FileName) + @"\My Project\Resources.resx"; resDesignFile = Path.GetDirectoryName(proj.FileName) + @"\My Project\Resources.Designer.vb"; vbNS = resNameSpace = proj.Properties.Item("RootNamespace").Value.ToString(); provider = new Microsoft.VisualBasic.VBCodeProvider(); } else { resFile = Path.GetDirectoryName(proj.FileName) + @"\Properties\Resources.resx"; resDesignFile = Path.GetDirectoryName(proj.FileName) + @"\Properties\Resources.Designer.cs"; resNameSpace = proj.Properties.Item("DefaultNamespace").Value + ".Properties"; provider = new Microsoft.CSharp.CSharpCodeProvider(); } ImageInputForm inputForm = new ImageInputForm(); inputForm.ShowDialog(); System.Resources.ResXResourceReader reader = new System.Resources.ResXResourceReader(resFile); using (System.Resources.ResXResourceWriter writer = new System.Resources.ResXResourceWriter(resFile + ".new")) { System.Collections.IDictionaryEnumerator iterator = reader.GetEnumerator(); while (iterator.MoveNext()) { writer.AddResource(iterator.Key.ToString(), iterator.Value); } writer.AddResource(inputForm.Input, bitmap); writer.Generate(); } File.Copy(resFile + ".new", resFile, true); File.Delete(resFile + ".new"); string[] unMatched; System.CodeDom.CodeCompileUnit unit = System.Resources.Tools.StronglyTypedResourceBuilder.Create(resFile, "Resources", resNameSpace, provider, true, out unMatched); using (StreamWriter designWriter = new StreamWriter(resDesignFile)) { provider.GenerateCodeFromCompileUnit(unit, designWriter, new System.CodeDom.Compiler.CodeGeneratorOptions()); } MessageBox.Show("Image generation succeeded", "Resources Updated"); if (entire) { entireResName = inputForm.Input; NotifyPropertyChanged("EntireResName"); } else { partResName = inputForm.Input; NotifyPropertyChanged("PartialResName"); } return; } catch (Exception ex) { MessageBox.Show("Image generation failed\n" + ex.Message, "Resources Did Not Update"); return; } } } MessageBox.Show("You need to have a project open, named *Test*", "Resources Did Not Update"); return; } MessageBox.Show("You need to have a solution open with a project named *Test*", "Resources Did Not Update"); return; } }
private static void CreateResourceFile(string inputFile, string outputFile) { string fileName = Path.GetFileName(inputFile); System.Resources.IResourceWriter writer = null; FileStream fs = null; BinaryReader br = null; try { //writer = new System.Resources.ResourceWriter(outputFile); writer = new System.Resources.ResXResourceWriter(outputFile); fs = new FileStream(inputFile, FileMode.Open); br = new BinaryReader(fs); byte[] myBuffer = new byte[br.BaseStream.Length]; for (long i = 0; i < br.BaseStream.Length; i++) { myBuffer[i] = br.ReadByte(); } writer.AddResource(fileName, myBuffer); writer.Generate(); //writer.Close(); } finally { if (writer != null) { writer.Close(); } if (fs != null) { fs.Close(); } if (br != null) { br.Close(); } } }