private static Write7BitEncodedInt ( |
||
store | ||
value | int | |
return | void |
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; }