public OggOpusFile(Stream sourceStream, bool leaveOpen = false) { if (sourceStream == null || !sourceStream.CanRead) throw new ArgumentException("fileStream must be a readable stream."); _sourceStream = sourceStream; _leaveOpen = leaveOpen; _read = new ReadFunc(ReadCallback); _seek = new SeekFunc(SeekCallback); _tell = new TellFunc(TellCallback); var cb = new _OpusFileCallbacks() { read = Marshal.GetFunctionPointerForDelegate(_read), seek = _sourceStream.CanSeek ? Marshal.GetFunctionPointerForDelegate(_seek) : IntPtr.Zero, tell = _sourceStream.CanSeek ? Marshal.GetFunctionPointerForDelegate(_tell) : IntPtr.Zero, close = IntPtr.Zero, }; OpusError error; _opusFile = op_open_callbacks(IntPtr.Zero, ref cb, IntPtr.Zero, IntPtr.Zero, out error); if (_opusFile == IntPtr.Zero) throw new OpusException(error); }
public void Array(string inKey, ref System.UInt64[] ioArray, FieldOptions inOptions = FieldOptions.None) { DoArray <System.UInt64>(inKey, ref ioArray, inOptions, Read_UInt64_Cached ?? (Read_UInt64_Cached = Read_UInt64), Write_UInt64_Cached ?? (Write_UInt64_Cached = Write_UInt64)); }
public void UInt64ProxyMap <ProxyType>(string inKey, ref Dictionary <int, ProxyType> ioMap, FieldOptions inOptions = FieldOptions.None) where ProxyType : struct, ISerializedProxy <System.UInt64> { DoProxyMap <ProxyType, System.UInt64>(inKey, ref ioMap, inOptions, Read_UInt64_Cached ?? (Read_UInt64_Cached = Read_UInt64), Write_UInt64_Cached ?? (Write_UInt64_Cached = Write_UInt64)); }
/// <summary> /// Serializes a set on the current object. /// </summary> private void DoSetUnity <T>(string inKey, ref HashSet <T> ioSet, FieldOptions inOptions, ReadFunc <T> inReader, WriteFunc <T> inWriter) where T : UnityEngine.Object { if (IsReading) { bool bSuccess = BeginReadArray(inKey); { if (IsMissing()) { if ((inOptions & FieldOptions.Optional) != 0) { SafeDispose(ref ioSet); } else { bSuccess = false; } } else if (IsNull()) { SafeDispose(ref ioSet); } else { int nodeCount = GetChildCount(); SafeRecreate(ref ioSet); for (int i = 0; i < nodeCount; ++i) { T obj = default(T); bSuccess &= DoReadUnity(i, ref obj, FieldOptions.None, inReader); ioSet.Add(obj); } } } EndArray(); if (!bSuccess) { AddErrorMessage("Unable to read array '{0}'.", inKey); } return; } if (ioSet == null) { if ((inOptions & FieldOptions.Optional) == 0 || RequiresExplicitNull()) { WriteNull(inKey); } } else { BeginWriteArray(inKey); DeclareChildCount(ioSet.Count); foreach (var item in ioSet) { T obj = item; DoWriteUnity <T>(ref obj, FieldOptions.None, inWriter); } EndArray(); } }
/// <summary> /// Serializes a value on the current object. /// </summary> private void DoSerializeUnity <T>(string inKey, ref T ioData, FieldOptions inOptions, ReadFunc <T> inReader, WriteFunc <T> inWriter) where T : UnityEngine.Object { if (IsReading) { bool bSuccess = DoReadUnity <T>(inKey, ref ioData, inOptions, inReader); if (!bSuccess) { AddErrorMessage("Unable to read value '{0}'.", inKey); } return; } if (ioData == null) { if ((inOptions & FieldOptions.Optional) == 0 || RequiresExplicitNull()) { WriteNull(inKey); } } else { DoWriteUnity <T>(inKey, ref ioData, inOptions, inWriter); } }
/// <summary> /// Завантаження інформації товарів /// </summary> /// <param name="localLoadedTempFiles">Шляхи до файлів</param> /// <param name="onlyUpdate">Якщо ture то завантажувати інформацію лише з нових файлів в іншому випадку завантажувати з всіх</param> /// <returns>Завантажена інформація</returns> public static object[] LoadData(string[] localLoadedTempFiles, bool onlyUpdate) { winapi.WApi.OutputDebugString("--- LoadData_begin"); FileStream fs = null; DataTable[] dTables = new DataTable[3]; bool exchangeFldUsed = false; IntPtr hFile = IntPtr.Zero; ReadFunc[] rdFunc = new ReadFunc[3]; rdFunc[0] = ReadArtSDF; rdFunc[1] = ReadAltSDF; rdFunc[2] = ReadCardSDF; CreateFunc[] crFunc = new CreateFunc[3]; crFunc[0] = CreateArtDataTable; crFunc[1] = CreateAltDataTable; crFunc[2] = CreateCardDataTable; if (!Directory.Exists(AppConfig.Path_Articles)) Directory.CreateDirectory(AppConfig.Path_Articles); string[] artFiles = new string[3]; artFiles[0] = AppConfig.Path_Articles + "\\" + string.Format("Art_{0:X2}.saf", AppConfig.APP_SubUnit); artFiles[1] = AppConfig.Path_Articles + "\\" + string.Format("Alt_{0:X2}.saf", AppConfig.APP_SubUnit); artFiles[2] = AppConfig.Path_Articles + "\\" + "DCards.saf"; for (int i = 0; i < artFiles.Length; i++) if (localLoadedTempFiles != null && localLoadedTempFiles[i] != "") { winapi.WApi.OutputDebugString("EXCHAGE LoadingFromNewSource_begin"); dTables[i] = crFunc[i].Invoke(); rdFunc[i].Invoke(localLoadedTempFiles[i], ref dTables[i]); fs = new FileStream(artFiles[i], FileMode.Create); binF.Serialize(fs, dTables[i]); //dTables[i].TableName = Path.GetFileNameWithoutExtension(localLoadedTempFiles[i]); //dTables[i].WriteXml(fs); fs.Close(); fs.Dispose(); exchangeFldUsed = true; if (!AppConfig.Content_Articles_KeepDataAfterImport) Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile(localLoadedTempFiles[i], UIOption.AllDialogs, RecycleOption.SendToRecycleBin); winapi.WApi.OutputDebugString("EXCHAGE LoadingFromNewSource_end"); } else { if (!onlyUpdate && winapi.WApi.PathFileExists(artFiles[i])) { winapi.WApi.OutputDebugString("LOCAL LoadingFromLocalCopy_begin"); fs = new FileStream(artFiles[i], FileMode.Open, FileAccess.Read); //dTables[i].ReadXml(fs); dTables[i] = (DataTable)binF.Deserialize(fs); if (!new sgmode.ClassMode().FullLoader()) { DataTable tDt = dTables[i].Clone(); for (int jp = 0; jp < 10; jp++) { if (dTables[i].Rows.Count <= jp) break; tDt.Rows.Add(dTables[i].Rows[jp].ItemArray); } dTables[i] = tDt.Copy(); } fs.Close(); fs.Dispose(); winapi.WApi.OutputDebugString("LOCAL LoadingFromLocalCopy_end"); } } if (fs != null) fs.Dispose(); object[] rez = new object[] { dTables, exchangeFldUsed }; winapi.WApi.OutputDebugString("--- LoadData_end"); return rez; }
public void Array(string inKey, ref List <System.UInt32> ioArray, FieldOptions inOptions = FieldOptions.None) { DoArray <System.UInt32>(inKey, ref ioArray, inOptions, Read_UInt32_Cached ?? (Read_UInt32_Cached = Read_UInt32), Write_UInt32_Cached ?? (Write_UInt32_Cached = Write_UInt32)); }
public void SingleProxySet <ProxyType>(string inKey, ref HashSet <ProxyType> ioSet, FieldOptions inOptions = FieldOptions.None) where ProxyType : struct, ISerializedProxy <System.Single> { DoProxySet <ProxyType, System.Single>(inKey, ref ioSet, inOptions, Read_Single_Cached ?? (Read_Single_Cached = Read_Single), Write_Single_Cached ?? (Write_Single_Cached = Write_Single)); }
public void Binary(string inKey, ref System.Byte[] ioData, FieldOptions inOptions = FieldOptions.None) { DoSerialize <System.Byte[]>(inKey, ref ioData, inOptions, Read_ByteArray_Cached ?? (Read_ByteArray_Cached = Read_ByteArray), Write_ByteArray_Cached ?? (Write_ByteArray_Cached = Write_ByteArray)); }
public void Map(string inKey, ref Dictionary <int, UnityEngine.Texture2D> ioMap, TextureOptions inTextureOptions = TextureOptions.Default, FieldOptions inOptions = FieldOptions.None) { DoMapUnity <UnityEngine.Texture2D>(inKey, ref ioMap, inOptions, Read_Texture2D_Cached ?? (Read_Texture2D_Cached = Read_Texture2D), GetTextureWriter(inTextureOptions)); }
public void Set(string inKey, ref HashSet <UnityEngine.Texture2D> ioSet, TextureOptions inTextureOptions = TextureOptions.Default, FieldOptions inOptions = FieldOptions.None) { DoSetUnity <UnityEngine.Texture2D>(inKey, ref ioSet, inOptions, Read_Texture2D_Cached ?? (Read_Texture2D_Cached = Read_Texture2D), GetTextureWriter(inTextureOptions)); }
public void Array(string inKey, ref UnityEngine.Texture2D[] ioArray, TextureOptions inTextureOptions = TextureOptions.Default, FieldOptions inOptions = FieldOptions.None) { DoArrayUnity <UnityEngine.Texture2D>(inKey, ref ioArray, inOptions, Read_Texture2D_Cached ?? (Read_Texture2D_Cached = Read_Texture2D), GetTextureWriter(inTextureOptions)); }
public void Serialize(string inKey, ref UnityEngine.Texture2D ioData, TextureOptions inTextureOptions = TextureOptions.Default, FieldOptions inOptions = FieldOptions.None) { DoSerializeUnity <UnityEngine.Texture2D>(inKey, ref ioData, inOptions, Read_Texture2D_Cached ?? (Read_Texture2D_Cached = Read_Texture2D), GetTextureWriter(inTextureOptions)); }
public void DoubleProxyArray <ProxyType>(string inKey, ref ProxyType[] ioArray, FieldOptions inOptions = FieldOptions.None) where ProxyType : struct, ISerializedProxy <System.Double> { DoProxyArray <ProxyType, System.Double>(inKey, ref ioArray, inOptions, Read_Double_Cached ?? (Read_Double_Cached = Read_Double), Write_Double_Cached ?? (Write_Double_Cached = Write_Double)); }
public void Array(string inKey, ref List <System.Double> ioArray, FieldOptions inOptions = FieldOptions.None) { DoArray <System.Double>(inKey, ref ioArray, inOptions, Read_Double_Cached ?? (Read_Double_Cached = Read_Double), Write_Double_Cached ?? (Write_Double_Cached = Write_Double)); }
public void Map(string inKey, ref Dictionary <string, System.UInt64> ioMap, FieldOptions inOptions = FieldOptions.None) { DoMap <System.UInt64>(inKey, ref ioMap, inOptions, Read_UInt64_Cached ?? (Read_UInt64_Cached = Read_UInt64), Write_UInt64_Cached ?? (Write_UInt64_Cached = Write_UInt64)); }
public void BinaryArray(string inKey, ref System.Byte[][] ioArray, FieldOptions inOptions = FieldOptions.None) { DoArray <System.Byte[]>(inKey, ref ioArray, inOptions, Read_ByteArray_Cached ?? (Read_ByteArray_Cached = Read_ByteArray), Write_ByteArray_Cached ?? (Write_ByteArray_Cached = Write_ByteArray)); }
public void BinarySet(string inKey, ref HashSet <System.Byte[]> ioSet, FieldOptions inOptions = FieldOptions.None) { DoSet <System.Byte[]>(inKey, ref ioSet, inOptions, Read_ByteArray_Cached ?? (Read_ByteArray_Cached = Read_ByteArray), Write_ByteArray_Cached ?? (Write_ByteArray_Cached = Write_ByteArray)); }
public void Serialize(string inKey, ref System.UInt32 ioData, FieldOptions inOptions = FieldOptions.None) { DoSerialize <System.UInt32>(inKey, ref ioData, inOptions, Read_UInt32_Cached ?? (Read_UInt32_Cached = Read_UInt32), Write_UInt32_Cached ?? (Write_UInt32_Cached = Write_UInt32)); }
public void BinaryMap(string inKey, ref Dictionary <int, System.Byte[]> ioMap, FieldOptions inOptions = FieldOptions.None) { DoMap <System.Byte[]>(inKey, ref ioMap, inOptions, Read_ByteArray_Cached ?? (Read_ByteArray_Cached = Read_ByteArray), Write_ByteArray_Cached ?? (Write_ByteArray_Cached = Write_ByteArray)); }
public void UInt32ProxySet <ProxyType>(string inKey, ref HashSet <ProxyType> ioSet, FieldOptions inOptions = FieldOptions.None) where ProxyType : struct, ISerializedProxy <System.UInt32> { DoProxySet <ProxyType, System.UInt32>(inKey, ref ioSet, inOptions, Read_UInt32_Cached ?? (Read_UInt32_Cached = Read_UInt32), Write_UInt32_Cached ?? (Write_UInt32_Cached = Write_UInt32)); }
public void BinaryProxyMap <ProxyType>(string inKey, ref Dictionary <int, ProxyType> ioMap, FieldOptions inOptions = FieldOptions.None) where ProxyType : struct, ISerializedProxy <System.Byte[]> { DoProxyMap <ProxyType, System.Byte[]>(inKey, ref ioMap, inOptions, Read_ByteArray_Cached ?? (Read_ByteArray_Cached = Read_ByteArray), Write_ByteArray_Cached ?? (Write_ByteArray_Cached = Write_ByteArray)); }
/// <summary> /// Reads a value from the current node. /// </summary> private bool DoReadUnity <T>(string inKey, ref T ioData, FieldOptions inOptions, ReadFunc <T> inReader) where T : UnityEngine.Object { bool bSuccess = BeginReadValue(inKey); if (IsMissing()) { if ((inOptions & FieldOptions.Optional) != 0) { SafeDispose(ref ioData); bSuccess = true; } else { bSuccess &= false; } } else if (IsNull()) { SafeDispose(ref ioData); bSuccess = true; } else { bSuccess &= inReader(ref ioData); } EndObject(); return(bSuccess); }
public void SingleProxyMap <ProxyType>(string inKey, ref Dictionary <string, ProxyType> ioMap, FieldOptions inOptions = FieldOptions.None) where ProxyType : struct, ISerializedProxy <System.Single> { DoProxyMap <ProxyType, System.Single>(inKey, ref ioMap, inOptions, Read_Single_Cached ?? (Read_Single_Cached = Read_Single), Write_Single_Cached ?? (Write_Single_Cached = Write_Single)); }
/// <summary> /// Serializes an array on the current object. /// </summary> private void DoArrayUnity <T>(string inKey, ref T[] ioArray, FieldOptions inOptions, ReadFunc <T> inReader, WriteFunc <T> inWriter) where T : UnityEngine.Object { if (IsReading) { bool bSuccess = BeginReadArray(inKey); { if (IsMissing()) { if ((inOptions & FieldOptions.Optional) != 0) { SafeDispose(ref ioArray); } else { bSuccess = false; } } else if (IsNull()) { SafeDispose(ref ioArray); } else { int nodeCount = GetChildCount(); if (ioArray != null) { // Make sure to dispose the objects cut off by the new length for (int i = nodeCount; i < ioArray.Length; ++i) { SafeDispose(ref ioArray[i]); } System.Array.Resize(ref ioArray, nodeCount); } else { ioArray = new T[nodeCount]; } for (int i = 0; i < nodeCount; ++i) { T obj = default(T); bSuccess &= DoReadUnity(i, ref obj, FieldOptions.None, inReader); ioArray[i] = obj; } } } EndArray(); if (!bSuccess) { AddErrorMessage("Unable to read array '{0}'.", inKey); } return; } if (ioArray == null) { if ((inOptions & FieldOptions.Optional) == 0 || RequiresExplicitNull()) { WriteNull(inKey); } } else { BeginWriteArray(inKey); DeclareChildCount(ioArray.Length); for (int i = 0; i < ioArray.Length; ++i) { T obj = ioArray[i]; DoWriteUnity <T>(ref obj, FieldOptions.None, inWriter); } EndArray(); } }
public void Serialize(string inKey, ref System.Single ioData, System.Single inDefault, FieldOptions inOptions = FieldOptions.None) { DoSerialize <System.Single>(inKey, ref ioData, inDefault, inOptions, Read_Single_Cached ?? (Read_Single_Cached = Read_Single), Write_Single_Cached ?? (Write_Single_Cached = Write_Single)); }
/// <summary> /// Serializes a map on the current object. /// </summary> private void DoMapUnity <T>(string inKey, ref Dictionary <int, T> ioMap, FieldOptions inOptions, ReadFunc <T> inReader, WriteFunc <T> inWriter) where T : UnityEngine.Object { if (IsReading) { bool bSuccess = BeginReadArray(inKey); { if (IsMissing()) { if ((inOptions & FieldOptions.Optional) != 0) { SafeDispose(ref ioMap); } else { bSuccess = false; } } else if (IsNull()) { SafeDispose(ref ioMap); } else { int nodeCount = GetChildCount(); SafeRecreate(ref ioMap); for (int i = 0; i < nodeCount; ++i) { bSuccess &= BeginReadObject(i); { int key = default(int); bSuccess &= DoRead(MAP_KEY, ref key, FieldOptions.None, Read_Int32_Cached ?? (Read_Int32_Cached = Read_Int32)); T obj = default(T); bSuccess &= DoReadUnity(MAP_VALUE, ref obj, FieldOptions.None, inReader); ioMap.Add(key, obj); } EndObject(); } } } EndArray(); if (!bSuccess) { AddErrorMessage("Unable to read map '{0}'.", inKey); } return; } if (ioMap == null) { if ((inOptions & FieldOptions.Optional) == 0 || RequiresExplicitNull()) { WriteNull(inKey); } } else { BeginWriteArray(inKey); DeclareChildCount(ioMap.Count); foreach (var keyValue in ioMap) { BeginWriteObject(); int key = keyValue.Key; DoWrite(MAP_KEY, ref key, FieldOptions.PreferAttribute, this.Write_Int32); T obj = keyValue.Value; DoWriteUnity(MAP_VALUE, ref obj, FieldOptions.None, inWriter); EndObject(); } EndArray(); } }
public void Array(string inKey, ref System.Single[] ioArray, FieldOptions inOptions = FieldOptions.None) { DoArray <System.Single>(inKey, ref ioArray, inOptions, Read_Single_Cached ?? (Read_Single_Cached = Read_Single), Write_Single_Cached ?? (Write_Single_Cached = Write_Single)); }
public void Serialize(string inKey, ref System.UInt64 ioData, System.UInt64 inDefault, FieldOptions inOptions = FieldOptions.None) { DoSerialize <System.UInt64>(inKey, ref ioData, inDefault, inOptions, Read_UInt64_Cached ?? (Read_UInt64_Cached = Read_UInt64), Write_UInt64_Cached ?? (Write_UInt64_Cached = Write_UInt64)); }
public void Set(string inKey, ref HashSet <System.Single> ioSet, FieldOptions inOptions = FieldOptions.None) { DoSet <System.Single>(inKey, ref ioSet, inOptions, Read_Single_Cached ?? (Read_Single_Cached = Read_Single), Write_Single_Cached ?? (Write_Single_Cached = Write_Single)); }
public void Set(string inKey, ref HashSet <System.UInt64> ioSet, FieldOptions inOptions = FieldOptions.None) { DoSet <System.UInt64>(inKey, ref ioSet, inOptions, Read_UInt64_Cached ?? (Read_UInt64_Cached = Read_UInt64), Write_UInt64_Cached ?? (Write_UInt64_Cached = Write_UInt64)); }
public void Map(string inKey, ref Dictionary <int, System.Single> ioMap, FieldOptions inOptions = FieldOptions.None) { DoMap <System.Single>(inKey, ref ioMap, inOptions, Read_Single_Cached ?? (Read_Single_Cached = Read_Single), Write_Single_Cached ?? (Write_Single_Cached = Write_Single)); }
private unsafe int ReadCompressedInteger(byte[] bytes, TryReadFunc tryRead, ReadFunc read) { fixed (byte* ptr = bytes) { var reader = new BlobReader(new MemoryBlock(ptr, bytes.Length)); int value; bool valid = tryRead(ref reader, out value); if (valid) { Assert.Equal(bytes.Length, reader.Offset); reader.Reset(); Assert.Equal(value, read(ref reader)); Assert.Equal(bytes.Length, reader.Offset); } else { Assert.Equal(0, reader.Offset); Assert.Throws<BadImageFormatException>(() => reader.ReadCompressedInteger()); Assert.Equal(value, BlobReader.InvalidCompressedInteger); Assert.Equal(0, reader.Offset); } return value; } }
/// <summary> /// Завантаження інформації товарів /// </summary> /// <param name="localLoadedTempFiles">Шляхи до файлів</param> /// <param name="onlyUpdate">Якщо ture то завантажувати інформацію лише з нових файлів в іншому випадку завантажувати з всіх</param> /// <returns>Завантажена інформація</returns> public static object[] LoadData(string[] localLoadedTempFiles, bool onlyUpdate) { FileStream fs = null; DataTable[] dTables = new DataTable[3]; bool exchangeFldUsed = false; IntPtr hFile = IntPtr.Zero; ReadFunc[] rdFunc = new ReadFunc[3]; rdFunc[0] = ReadArtSDF; rdFunc[1] = ReadAltSDF; rdFunc[2] = ReadCardSDF; CreateFunc[] crFunc = new CreateFunc[3]; crFunc[0] = CreateArtDataTable; crFunc[1] = CreateAltDataTable; crFunc[2] = CreateCardDataTable; if (!Directory.Exists(AppConfig.Path_Articles)) Directory.CreateDirectory(AppConfig.Path_Articles); string[] artFiles = new string[3]; artFiles[0] = AppConfig.Path_Articles + "\\" + string.Format("Art_{0:X2}.saf", AppConfig.APP_SubUnit); artFiles[1] = AppConfig.Path_Articles + "\\" + string.Format("Alt_{0:X2}.saf", AppConfig.APP_SubUnit); artFiles[2] = AppConfig.Path_Articles + "\\" + "DCards.saf"; for (int i = 0; i < artFiles.Length; i++) if (localLoadedTempFiles != null && localLoadedTempFiles[i] != "") { dTables[i] = crFunc[i].Invoke(); rdFunc[i].Invoke(localLoadedTempFiles[i], ref dTables[i]); fs = new FileStream(artFiles[i], FileMode.Create); binF.Serialize(fs, dTables[i]); fs.Close(); fs.Dispose(); exchangeFldUsed = true; if (!AppConfig.Content_Articles_KeepDataAfterImport) Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile(localLoadedTempFiles[i], UIOption.AllDialogs, RecycleOption.SendToRecycleBin); } else { if (!onlyUpdate && winapi.WApi.PathFileExists(artFiles[i])) { fs = new FileStream(artFiles[i], FileMode.Open, FileAccess.Read); dTables[i] = (DataTable)binF.Deserialize(fs); fs.Close(); fs.Dispose(); } } if (fs != null) fs.Dispose(); object[] rez = new object[] { dTables, exchangeFldUsed }; return rez; }