/// <summary> /// 写入 中文 资源文件. /// </summary> public void WriteChinaResource() { // 构造写入器. ResourceWriter rw = new ResourceWriter("China.resource"); rw.AddResource("Hello", "你好"); rw.Close(); }
/// <summary> /// Build .resx file to .resource /// </summary> /// <param name="input"></param> /// <param name="output"></param> public static void Build(string input) { var resxs = Directory.GetFiles(input, "*.resx"); foreach (var resxFile in resxs) { var binFile = Path.GetDirectoryName(resxFile) +"\\"+ Path.GetFileNameWithoutExtension(resxFile) + ".resources"; if (File.Exists(binFile)) { var resxFileInfo = new FileInfo(resxFile); var binFileInfo = new FileInfo(binFile); if (resxFileInfo.LastWriteTime > binFileInfo.LastWriteTime) File.Delete(binFile); //Re-complied } if (!File.Exists(binFile)) { using (var reader = new ResXResourceReader(resxFile)) { using (var writer = new ResourceWriter(binFile)) { foreach (DictionaryEntry d in reader) { writer.AddResource(d.Key.ToString(), d.Value); } } } } } }
public void Run() { Catalog catalog = new Catalog(); foreach(string fileName in Options.InputFiles) { Catalog temp = new Catalog(); temp.Load(fileName); catalog.Append(temp); } using (ResourceWriter writer = new ResourceWriter(Options.OutFile)) { foreach (CatalogEntry entry in catalog) { try { writer.AddResource(entry.Key, entry.IsTranslated ? entry.GetTranslation(0) : entry.String); } catch (Exception e) { string message = String.Format("Error adding item {0}", entry.String); if (!String.IsNullOrEmpty(entry.Context)) message = String.Format("Error adding item {0} in context '{1}'", entry.String, entry.Context); throw new Exception(message, e); } } writer.Generate(); } }
static void Main(string[] args) { ResourceWriter myResource = new ResourceWriter("Images.resources"); myResource.AddResource("flash", new Bitmap("flashScreen.png")); Image simpleImage = new Image(); simpleImage.Margin = new Thickness(0); BitmapImage bi = new BitmapImage(); //BitmapImage.UriSource must be in a BeginInit/EndInit block bi.BeginInit(); bi.UriSource = new Uri(@"pack://siteoforigin:,,,/alarm3.png"); bi.EndInit(); //set image source simpleImage.Source = bi; // simpleImage.Stretch = Stretch.None; simpleImage.HorizontalAlignment = HorizontalAlignment.Center; simpleImage.Visibility = Visibility.Hidden; simpleImage.Name = "AlarmIndicator"; simpleImage.Width = 13; myResource.AddResource("alarm", new Image("alarm3.png")); myResource.Close(); }
private static void WriteResourceFile(string resxFilePath) { using (var fs = File.OpenRead(resxFilePath)) { var document = XDocument.Load(fs); var binDirPath = Path.Combine(Path.GetDirectoryName(resxFilePath), "bin"); if (!Directory.Exists(binDirPath)) { Directory.CreateDirectory(Path.Combine(Path.GetDirectoryName(resxFilePath), "bin")); } // Put in "bin" sub-folder of resx file var targetPath = Path.Combine(binDirPath, Path.ChangeExtension(Path.GetFileName(resxFilePath), ".resources")); using (var targetStream = File.Create(targetPath)) { var rw = new ResourceWriter(targetStream); foreach (var e in document.Root.Elements("data")) { var name = e.Attribute("name").Value; var value = e.Element("value").Value; rw.AddResource(name, value); } rw.Generate(); } } }
public SpecialResourceWriter() { // Load all bunlde IList<IResourceBundle> allBundle = new List<IResourceBundle>(20); allBundle.Add(ResourceBundleFactory.CreateBundle("CanonMarkernote", null, ResourceBundleFactory.USE_TXTFILE)); allBundle.Add(ResourceBundleFactory.CreateBundle("CasioMarkernote", null, ResourceBundleFactory.USE_TXTFILE)); allBundle.Add(ResourceBundleFactory.CreateBundle("Commons", null, ResourceBundleFactory.USE_TXTFILE)); allBundle.Add(ResourceBundleFactory.CreateBundle("ExifInteropMarkernote", null, ResourceBundleFactory.USE_TXTFILE)); allBundle.Add(ResourceBundleFactory.CreateBundle("ExifMarkernote", null, ResourceBundleFactory.USE_TXTFILE)); allBundle.Add(ResourceBundleFactory.CreateBundle("FujiFilmMarkernote", null, ResourceBundleFactory.USE_TXTFILE)); allBundle.Add(ResourceBundleFactory.CreateBundle("GpsMarkernote", null, ResourceBundleFactory.USE_TXTFILE)); allBundle.Add(ResourceBundleFactory.CreateBundle("IptcMarkernote", null, ResourceBundleFactory.USE_TXTFILE)); allBundle.Add(ResourceBundleFactory.CreateBundle("JpegMarkernote", null, ResourceBundleFactory.USE_TXTFILE)); allBundle.Add(ResourceBundleFactory.CreateBundle("KodakMarkernote", null, ResourceBundleFactory.USE_TXTFILE)); allBundle.Add(ResourceBundleFactory.CreateBundle("KyoceraMarkernote", null, ResourceBundleFactory.USE_TXTFILE)); allBundle.Add(ResourceBundleFactory.CreateBundle("NikonTypeMarkernote", null, ResourceBundleFactory.USE_TXTFILE)); allBundle.Add(ResourceBundleFactory.CreateBundle("OlympusMarkernote", null, ResourceBundleFactory.USE_TXTFILE)); allBundle.Add(ResourceBundleFactory.CreateBundle("PanasonicMarkernote", null, ResourceBundleFactory.USE_TXTFILE)); allBundle.Add(ResourceBundleFactory.CreateBundle("PentaxMarkernote", null, ResourceBundleFactory.USE_TXTFILE)); allBundle.Add(ResourceBundleFactory.CreateBundle("SonyMarkernote", null, ResourceBundleFactory.USE_TXTFILE)); foreach(IResourceBundle bdl in allBundle) { ResourceWriter rw = new ResourceWriter(bdl.Fullname+".resources"); IDictionary<string,string> idic = bdl.Entries; IDictionaryEnumerator enumDic = (IDictionaryEnumerator)idic.GetEnumerator(); while (enumDic.MoveNext()) { rw.AddResource((string)enumDic.Key, (string)enumDic.Value); } rw.Close(); rw.Dispose(); } }
/// <summary> /// 写入 英文 资源文件. /// </summary> public void WriteEnglishResource() { // 构造写入器. ResourceWriter rw = new ResourceWriter("English.resource"); rw.AddResource("Hello", "Hello"); rw.Close(); }
public void SystemResourceTests_Should_WriteUpdateValueToResx() { var filename = Path.Combine(TestContext.TestRunDirectory, Guid.NewGuid().ToString() + ".resx"); var inputData = "TheInputData"; using (ResourceWriter w = new ResourceWriter(filename)) { w.AddResource("InvariantName", inputData); w.Generate(); } inputData = "TheUpdatedInputData"; using (ResourceWriter w = new ResourceWriter(filename)) { w.AddResource("InvariantName", inputData); w.Generate(); } var data = string.Empty; using( var r = new ResourceReader(filename)) { var rr = r.GetEnumerator(); rr.MoveNext(); data = rr.Value as string; } Assert.IsTrue(inputData == data); }
public void Process(EmbeddedResource embeddedResource, ResourceWriter resourceWriter) { if (_bamlStreams.Count == 0) return; WriteCollectedBamlStreams(resourceWriter); PatchGenericThemesBaml(resourceWriter); }
public void Save() { if(rw != null) { rw.Close(); rw = null; } }
private void InitRes() { if(rw == null) { resourceFilePath = OutDirMan.MakeOutFileName(resourceFilePath); rw = new ResourceWriter(resourceFilePath); } }
public void BuildResource(string outputPath) { using (ResourceWriter w1 = new ResourceWriter(outputPath)) { foreach (Item item in _items) w1.AddResource(item.Name, item.Value); } }
public static void ExceptionforResWriter01() { Assert.Throws<ArgumentNullException>(() => { MemoryStream ms2 = null; var rw = new ResourceWriter(ms2); }); }
private void WriteCollectedBamlStreams(ResourceWriter resourceWriter) { foreach (var bamlStream in _bamlStreams) { resourceWriter.AddResourceData( GetResourceName(bamlStream.Key, bamlStream.Value), bamlStream.Key.type, bamlStream.Key.data); } }
public static void AddFileAsStringResource(string resourceFile, string resourceName, string inputFile) { ResourceWriter writer = new ResourceWriter(resourceFile); StreamReader reader = new StreamReader(inputFile); string s = reader.ReadToEnd(); reader.Close(); writer.AddResource(resourceName, s); writer.Close(); }
public bool Process(AssemblyDefinition containingAssembly, Res resource, ResReader resourceReader, ResourceWriter resourceWriter) { if (!resource.IsBamlStream) return false; _bamlStreams.Add(resource, containingAssembly); return true; }
private static Stream MakeResourceStream() { var stream = new MemoryStream(); var resourceWriter = new ResourceWriter(stream); resourceWriter.AddResource("TestName", "value"); resourceWriter.Generate(); stream.Position = 0; return stream; }
static void Main(string[] args) { var getopt = new Getopt(Assembly.GetExecutingAssembly().GetName().Name, args, "i:o:") { Opterr = false }; string input = null; string output = null; int option; while (-1 != (option = getopt.getopt())) { switch (option) { case 'i': input = getopt.Optarg; break; case 'o': output = getopt.Optarg; break; default: PrintUsage(); return; } } if (input == null || output == null) { PrintUsage(); return; } try { if (!File.Exists(input)) { Console.WriteLine("File {0} not found", input); return; } Dictionary<string, string> entries; var parser = new PoParser(); using (var reader = new StreamReader(input)) { entries = parser.ParseIntoDictionary(reader); } using (var writer = new ResourceWriter(output)) { foreach (var kv in entries) { try { writer.AddResource(kv.Key, kv.Value); } catch (Exception e) { Console.WriteLine("Error adding item {0}: {1}", kv.Key, e.Message); } } writer.Generate(); } } catch (Exception ex) { Console.WriteLine("Error during execution: {0}", ex.Message); return; } }
internal void EnsureRepositoryFileExists() { if (!File.Exists(this.RepositoryFilename)) { using (IResourceWriter writer = new ResourceWriter(this.RepositoryFilename)) { writer.Generate(); } } }
public bool Process( AssemblyDefinition containingAssembly, Res resource, ResReader resourceReader, ResourceWriter resourceWriter) { if (!resource.IsBamlStream) return false; resource.data = GetProcessedResource(resource, containingAssembly); return false; }
public static void InsertEmployee(ResourceObj emp) { l.Add(emp); ResourceWriter rsxw = new ResourceWriter(path); for (int i = 0; i < l.Count; i++) { rsxw.AddResource("obj" + i.ToString(), l[i]); } rsxw.Close(); }
public void AddItem(string entity, string key, string value, string culture) { var filename = GetResourceFilename(entity, culture); using (var writer = new ResourceWriter(filename)) { writer.AddResource(key, value); writer.Generate(); } }
internal ResWriterData(ResourceWriter resWriter, Stream memoryStream, string strName, string strFileName, string strFullFileName, ResourceAttributes attribute) { this.m_resWriter = resWriter; this.m_memoryStream = memoryStream; this.m_strName = strName; this.m_strFileName = strFileName; this.m_strFullFileName = strFullFileName; this.m_nextResWriter = null; this.m_attribute = attribute; }
public static bool CombineResourceFile(string fileName, string language, string outputFileName) { if (language == null || language.Length == 0) { return(false); } if (fileName == null || fileName.Length == 0) { throw new ArgumentNullException("fileName"); } if (File.Exists(fileName) == false) { throw new FileNotFoundException(fileName); } var values = new Dictionary <string, System.Tuple <string, byte[]> >(); FillValues2(fileName, values); var rootPath = Path.GetDirectoryName(fileName); var fn2 = Path.Combine( Path.Combine(rootPath, language), Path.GetFileNameWithoutExtension(fileName) + "." + language + EXT_resources); if (File.Exists(fn2)) { if (FillValues2(fn2, values) > 0) { if (outputFileName == null || outputFileName.Length == 0) { outputFileName = fileName; } using (var writer = new System.Resources.ResourceWriter(outputFileName)) { var names = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase); foreach (var item in values) { if (names.ContainsKey(item.Key) == false) { writer.AddResourceData(item.Key, item.Value.Item1, item.Value.Item2); names[item.Key] = null; } else { Console.ForegroundColor = ConsoleColor.Red; Console.BackgroundColor = ConsoleColor.White; Console.WriteLine("Same name resource item:" + fileName + " # " + item.Key); Console.ResetColor(); } } } return(true); } } return(false); }
public static void ExceptionforResWriter02() { Assert.Throws<ArgumentException>(() => { byte[] buffer = new byte[_RefBuffer.Length]; using (var ms2 = new MemoryStream(buffer, false)) { var rw = new ResourceWriter(ms2); } }); }
/// <summary> /// Adds a given resourcename and data to the app resources in the target assembly /// </summary> /// <param name="ResourceName"></param> /// <param name="ResourceData"></param> /// <remarks></remarks> public void Add(string ResourceName, byte[] ResourceData) { // make sure the writer is initialized InitAssembly(); // have to enumerate this way for (var x = 0; x <= _Resources.Count - 1; x++) { var res = _Resources[x]; if (res.Name.Contains(".Resources.resources")) { // Have to assume this is the root application's .net resources. // That might not be the case though. // cast as embeded resource to get at the data var EmbededResource = (Mono.Cecil.EmbeddedResource)res; // a Resource reader is required to read the resource data var ResReader = new ResourceReader(new MemoryStream(EmbededResource.GetResourceData())); // Use this output stream to capture all the resource data from the // existing resource block, so we can add the new resource into it var MemStreamOut = new MemoryStream(); var ResWriter = new System.Resources.ResourceWriter(MemStreamOut); var ResEnumerator = ResReader.GetEnumerator(); byte[] resdata = null; while (ResEnumerator.MoveNext()) { var resname = (string)ResEnumerator.Key; string restype = ""; // if we come across a resource named the same as the one // we're about to add, skip it if (Strings.StrComp(resname, ResourceName, CompareMethod.Text) != 0) { ResReader.GetResourceData(resname, out restype, out resdata); ResWriter.AddResourceData(resname, restype, resdata); } } // add the new resource data here ResWriter.AddResourceData(ResourceName, "ResourceTypeCode.ByteArray", ResourceData); // gotta call this to render the memory stream ResWriter.Generate(); // update the resource var buf = MemStreamOut.ToArray(); var NewEmbedRes = new EmbeddedResource(res.Name, res.Attributes, buf); _Resources.Remove(res); _Resources.Add(NewEmbedRes); // gotta bail out, there can't be 2 embedded resource chunks, right? break; // TODO: might not be correct. Was : Exit For } } }
public bool Process(AssemblyDefinition containingAssembly, Res resource, ResReader resourceReader, ResourceWriter resourceWriter) { if (!resource.IsString) return false; string content = (string)resourceReader.GetObject(resource); content = _repackContext.FixStr(content); resourceWriter.AddResource(resource.name, content); return true; }
void GenerationData(int countOfObj) { Random rand = new Random(); ResourceWriter rsxw = new ResourceWriter(Server.MapPath("~/Resources/") + "res.resx"); for (int i = 0; i < countOfObj; i++) { rsxw.AddResource("obj" + i.ToString(), new ResourceObj(rand)); } rsxw.Close(); }
public void SystemResourceTests_Should_CreateResxFile() { var filename = Path.Combine(TestContext.TestRunDirectory, Guid.NewGuid().ToString() + ".resx"); using (ResourceWriter w = new ResourceWriter(filename)) { w.Generate(); } Assert.IsTrue(File.Exists(filename)); }
public System.Resources.IResourceWriter GetResourceWriter(System.Globalization.CultureInfo info) { if (writer == null) { if (ms == null) { ms = new MemoryStream(); } writer = new ResourceWriter(ms); } return writer; }
// Read all msgid/msgstr pairs, register them in the ResourceWriter, // and write the binary contents to the output stream. private void ReadAllInput (ResourceWriter rw) { for (;;) { String msgid = ReadString(); if (msgid == null) break; String msgstr = ReadString(); if (msgstr == null) break; rw.AddResource(msgid, msgstr); } rw.Generate(); }
public IResourceWriter GetResourceWriter(CultureInfo info) { if (this.writer == null) { if (this.ms == null) { this.ms = new MemoryStream(); } this.writer = new ResourceWriter(this.ms); } return this.writer; }
private void Comp() { if (radioButton1.Checked == true) { System.Resources.ResourceWriter w = new System.Resources.ResourceWriter("res.resources"); //Declaration du nouvelle ressource w.AddResource("file", Cryptoclass.DexEncrypt(System.IO.File.ReadAllBytes(textBox1.Text), this.key)); // lit tout les bytes du fichier source, les encrypt, et les ajout dans la ressource w.Close(); } if (radioButton2.Checked == true) { System.Resources.ResourceWriter w = new System.Resources.ResourceWriter("res.resources"); //Declaration du nouvelle ressource w.AddResource("file", Cryptoclass.RC4EncryptDecrypt(System.IO.File.ReadAllBytes(textBox1.Text), this.key)); // lit tout les bytes du fichier source, les encrypt, et les ajout dans la ressource w.Close(); } if (radioButton4.Checked == true) { System.Resources.ResourceWriter w = new System.Resources.ResourceWriter("res.resources"); //Declaration du nouvelle ressource w.AddResource("file", Cryptoclass.RijndaelEncrypt(System.IO.File.ReadAllBytes(textBox1.Text), this.key)); // lit tout les bytes du fichier source, les encrypt, et les ajout dans la ressource w.Close(); } }
private void InitBarManager() { //string[] strMenus = { "系统管理", "会员管理", "财务管理", "报表管理", "基础资料", "货品管理", "客户管理", "物流管理" }; //Utils.ImageCollection largeImgs; var query = CacheInfo.listMenuInfoModel().Where(p => p.MenuBig == true).ToList(); if (query == null || query.Count() == 0) { return; } string imagePath = Application.StartupPath + "\\TempImage"; int imgindex = 0; string fileName = string.Empty; foreach (var model in query) { if (model.MenuBigImage == null) { return; } //添加图标到资源文件 fileName = string.Format("{0}.png", model.MenuFrmName); ImageTools.CreateImage(imagePath, fileName, model.MenuBigImage); System.Resources.IResourceWriter rw = new System.Resources.ResourceWriter("Resource.resx"); rw.AddResource(model.MenuFrmName, (Image)Image.FromStream(new MemoryStream(model.MenuBigImage)).Clone());//Image.FromFile( imagePath + "\\" + fileName) rw.Close(); //把资源文件中的图像添加到largeImgs中 this.largeImgs.Images.Add((Image)Image.FromStream(new MemoryStream(model.MenuBigImage)).Clone(), model.MenuFrmName); //this.largeImgs.Images.SetKeyName(imgindex, fileName); //创建大图标菜单 DevExpress.XtraBars.BarLargeButtonItem barLargeItem = new DevExpress.XtraBars.BarLargeButtonItem(barMain, model.MenuName); barLargeItem.LargeGlyph = largeImgs.Images[imgindex];//也可以设置 barLargeItem.LargeImageIndex,但是效果不是很好,可以试试 barLargeItem.Hint = model.MenuName; barLargeItem.Tag = model.MenuName; barTop.LinksPersistInfo.Add(new DevExpress.XtraBars.LinkPersistInfo(barLargeItem, true)); barMain.Items.Add(barLargeItem); imgindex++; } }
/********************************************** * * Define stand alone managed resource for Assembly * **********************************************/ /// <include file='doc\AssemblyBuilder.uex' path='docs/doc[@for="AssemblyBuilder.DefineResource1"]/*' /> public IResourceWriter DefineResource( String name, String description, String fileName, ResourceAttributes attribute) { CodeAccessPermission.DemandInternal(PermissionType.ReflectionEmit); try { Enter(); BCLDebug.Log("DYNIL", "## DYNIL LOGGING: AssemblyBuilder.DefineResource( " + name + ", " + fileName + ")"); if (name == null) { throw new ArgumentNullException("name"); } if (name.Length == 0) { throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), name); } if (fileName == null) { throw new ArgumentNullException("fileName"); } if (fileName.Length == 0) { throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), "fileName"); } if (!String.Equals(fileName, Path.GetFileName(fileName))) { throw new ArgumentException(Environment.GetResourceString("Argument_NotSimpleFileName"), "fileName"); } m_assemblyData.CheckResNameConflict(name); m_assemblyData.CheckFileNameConflict(fileName); ResourceWriter resWriter; String fullFileName; if (m_assemblyData.m_strDir == null) { // If assembly directory is null, use current directory fullFileName = Path.Combine(Environment.CurrentDirectory, fileName); resWriter = new ResourceWriter(fullFileName); } else { // Form the full path given the directory provided by user fullFileName = Path.Combine(m_assemblyData.m_strDir, fileName); resWriter = new ResourceWriter(fullFileName); } // get the full path fullFileName = Path.GetFullPath(fullFileName); // retrieve just the file name fileName = Path.GetFileName(fullFileName); m_assemblyData.AddResWriter(new ResWriterData(resWriter, null, name, fileName, fullFileName, attribute)); return(resWriter); } finally { Exit(); } }
public void writeToUnknownSink(string key, string str) { System.Resources.ResourceWriter writer = new System.Resources.ResourceWriter(key); writer.AddResource(key, str); }
public void Generate() { if (this._resourceList == null) { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_ResourceWriterSaved")); } BinaryWriter binaryWriter1 = new BinaryWriter(this._output, Encoding.UTF8); List <string> types = new List <string>(); binaryWriter1.Write(ResourceManager.MagicNumber); binaryWriter1.Write(ResourceManager.HeaderVersionNumber); MemoryStream memoryStream1 = new MemoryStream(240); BinaryWriter binaryWriter2 = new BinaryWriter((Stream)memoryStream1); string assemblyQualifiedName = MultitargetingHelpers.GetAssemblyQualifiedName(typeof(ResourceReader), this.typeConverter); binaryWriter2.Write(assemblyQualifiedName); string str = ResourceManager.ResSetTypeName; binaryWriter2.Write(str); binaryWriter2.Flush(); binaryWriter1.Write((int)memoryStream1.Length); binaryWriter1.Write(memoryStream1.GetBuffer(), 0, (int)memoryStream1.Length); binaryWriter1.Write(2); int count = this._resourceList.Count; if (this._preserializedData != null) { count += this._preserializedData.Count; } binaryWriter1.Write(count); int[] keys = new int[count]; int[] items = new int[count]; int index1 = 0; MemoryStream memoryStream2 = new MemoryStream(count * 40); BinaryWriter binaryWriter3 = new BinaryWriter((Stream)memoryStream2, Encoding.Unicode); Stream output = (Stream)null; PermissionSet permissionSet = new PermissionSet(PermissionState.None); permissionSet.AddPermission((IPermission) new EnvironmentPermission(PermissionState.Unrestricted)); permissionSet.AddPermission((IPermission) new FileIOPermission(PermissionState.Unrestricted)); try { permissionSet.Assert(); string tempFileName = Path.GetTempFileName(); int num1 = 8448; File.SetAttributes(tempFileName, (FileAttributes)num1); int num2 = 3; int num3 = 3; int num4 = 1; int bufferSize = 4096; int num5 = 201326592; output = (Stream) new FileStream(tempFileName, (FileMode)num2, (FileAccess)num3, (FileShare)num4, bufferSize, (FileOptions)num5); } catch (UnauthorizedAccessException ex) { output = (Stream) new MemoryStream(); } catch (IOException ex) { output = (Stream) new MemoryStream(); } finally { PermissionSet.RevertAssert(); } using (output) { BinaryWriter binaryWriter4 = new BinaryWriter(output, Encoding.UTF8); IFormatter objFormatter = (IFormatter) new BinaryFormatter((ISurrogateSelector)null, new StreamingContext(StreamingContextStates.File | StreamingContextStates.Persistence)); SortedList sortedList = new SortedList((IDictionary)this._resourceList, (IComparer)FastResourceComparer.Default); if (this._preserializedData != null) { foreach (KeyValuePair <string, ResourceWriter.PrecannedResource> keyValuePair in this._preserializedData) { sortedList.Add((object)keyValuePair.Key, (object)keyValuePair.Value); } } IDictionaryEnumerator enumerator = sortedList.GetEnumerator(); while (enumerator.MoveNext()) { keys[index1] = FastResourceComparer.HashFunction((string)enumerator.Key); items[index1++] = (int)binaryWriter3.Seek(0, SeekOrigin.Current); binaryWriter3.Write((string)enumerator.Key); binaryWriter3.Write((int)binaryWriter4.Seek(0, SeekOrigin.Current)); object obj = enumerator.Value; ResourceTypeCode typeCode = this.FindTypeCode(obj, types); ResourceWriter.Write7BitEncodedInt(binaryWriter4, (int)typeCode); ResourceWriter.PrecannedResource precannedResource = obj as ResourceWriter.PrecannedResource; if (precannedResource != null) { binaryWriter4.Write(precannedResource.Data); } else { this.WriteValue(typeCode, obj, binaryWriter4, objFormatter); } } binaryWriter1.Write(types.Count); for (int index2 = 0; index2 < types.Count; ++index2) { binaryWriter1.Write(types[index2]); } Array.Sort <int, int>(keys, items); binaryWriter1.Flush(); int num1 = (int)binaryWriter1.BaseStream.Position & 7; if (num1 > 0) { for (int index2 = 0; index2 < 8 - num1; ++index2) { binaryWriter1.Write("PAD"[index2 % 3]); } } foreach (int num2 in keys) { binaryWriter1.Write(num2); } foreach (int num2 in items) { binaryWriter1.Write(num2); } binaryWriter1.Flush(); binaryWriter3.Flush(); binaryWriter4.Flush(); int num3 = (int)(binaryWriter1.Seek(0, SeekOrigin.Current) + memoryStream2.Length) + 4; binaryWriter1.Write(num3); binaryWriter1.Write(memoryStream2.GetBuffer(), 0, (int)memoryStream2.Length); binaryWriter3.Close(); output.Position = 0L; output.CopyTo(binaryWriter1.BaseStream); binaryWriter4.Close(); } binaryWriter1.Flush(); this._resourceList = (Dictionary <string, object>)null; }
public void Generate() { if (this._resourceList == null) { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_ResourceWriterSaved")); } BinaryWriter binaryWriter = new BinaryWriter(this._output, Encoding.UTF8); List <string> list = new List <string>(); binaryWriter.Write(ResourceManager.MagicNumber); binaryWriter.Write(ResourceManager.HeaderVersionNumber); MemoryStream memoryStream = new MemoryStream(240); BinaryWriter binaryWriter2 = new BinaryWriter(memoryStream); binaryWriter2.Write(MultitargetingHelpers.GetAssemblyQualifiedName(typeof(ResourceReader), this.typeConverter)); binaryWriter2.Write(ResourceManager.ResSetTypeName); binaryWriter2.Flush(); binaryWriter.Write((int)memoryStream.Length); binaryWriter.Write(memoryStream.GetBuffer(), 0, (int)memoryStream.Length); binaryWriter.Write(2); int num = this._resourceList.Count; if (this._preserializedData != null) { num += this._preserializedData.Count; } binaryWriter.Write(num); int[] array = new int[num]; int[] array2 = new int[num]; int num2 = 0; MemoryStream memoryStream2 = new MemoryStream(num * 40); BinaryWriter binaryWriter3 = new BinaryWriter(memoryStream2, Encoding.Unicode); Stream stream = null; PermissionSet permissionSet = new PermissionSet(PermissionState.None); permissionSet.AddPermission(new EnvironmentPermission(PermissionState.Unrestricted)); permissionSet.AddPermission(new FileIOPermission(PermissionState.Unrestricted)); try { permissionSet.Assert(); string tempFileName = Path.GetTempFileName(); File.SetAttributes(tempFileName, FileAttributes.Temporary | FileAttributes.NotContentIndexed); stream = new FileStream(tempFileName, FileMode.Open, FileAccess.ReadWrite, FileShare.Read, 4096, FileOptions.DeleteOnClose | FileOptions.SequentialScan); } catch (UnauthorizedAccessException) { stream = new MemoryStream(); } catch (IOException) { stream = new MemoryStream(); } finally { PermissionSet.RevertAssert(); } using (stream) { BinaryWriter binaryWriter4 = new BinaryWriter(stream, Encoding.UTF8); IFormatter objFormatter = new BinaryFormatter(null, new StreamingContext(StreamingContextStates.File | StreamingContextStates.Persistence)); SortedList sortedList = new SortedList(this._resourceList, FastResourceComparer.Default); if (this._preserializedData != null) { foreach (KeyValuePair <string, ResourceWriter.PrecannedResource> keyValuePair in this._preserializedData) { sortedList.Add(keyValuePair.Key, keyValuePair.Value); } } IDictionaryEnumerator enumerator2 = sortedList.GetEnumerator(); while (enumerator2.MoveNext()) { array[num2] = FastResourceComparer.HashFunction((string)enumerator2.Key); array2[num2++] = (int)binaryWriter3.Seek(0, SeekOrigin.Current); binaryWriter3.Write((string)enumerator2.Key); binaryWriter3.Write((int)binaryWriter4.Seek(0, SeekOrigin.Current)); object value = enumerator2.Value; ResourceTypeCode resourceTypeCode = this.FindTypeCode(value, list); ResourceWriter.Write7BitEncodedInt(binaryWriter4, (int)resourceTypeCode); ResourceWriter.PrecannedResource precannedResource = value as ResourceWriter.PrecannedResource; if (precannedResource != null) { binaryWriter4.Write(precannedResource.Data); } else { this.WriteValue(resourceTypeCode, value, binaryWriter4, objFormatter); } } binaryWriter.Write(list.Count); for (int i = 0; i < list.Count; i++) { binaryWriter.Write(list[i]); } Array.Sort <int, int>(array, array2); binaryWriter.Flush(); int num3 = (int)binaryWriter.BaseStream.Position & 7; if (num3 > 0) { for (int j = 0; j < 8 - num3; j++) { binaryWriter.Write("PAD"[j % 3]); } } foreach (int value2 in array) { binaryWriter.Write(value2); } foreach (int value3 in array2) { binaryWriter.Write(value3); } binaryWriter.Flush(); binaryWriter3.Flush(); binaryWriter4.Flush(); int num4 = (int)(binaryWriter.Seek(0, SeekOrigin.Current) + memoryStream2.Length); num4 += 4; binaryWriter.Write(num4); binaryWriter.Write(memoryStream2.GetBuffer(), 0, (int)memoryStream2.Length); binaryWriter3.Close(); stream.Position = 0L; stream.CopyTo(binaryWriter.BaseStream); binaryWriter4.Close(); } binaryWriter.Flush(); this._resourceList = null; }
public void writeToUnknownSink3(string pattern, string str) { System.Resources.ResourceWriter writer = new System.Resources.ResourceWriter(str); writer.AddResource(pattern, str); }