/// <summary> /// Load the specified ROPT file (in plain format) into the dictionary. /// </summary> public void LoadFromTxt(String Path) { Clear(); lock (Parts) lock (Dumies) { Ini Ini = new Ini(Path); Int32 PartAmount = Ini.ReadInt32("Config", "Count"); Int32 DumyAmount = Int32.Parse(Ini.ReadValue("Dumy", "Count").TrimEnd('¡')); Byte *pStr = stackalloc Byte[Kernel.MAX_BUFFER_SIZE]; for (Int32 i = 0; i < PartAmount; i++) { String Name = Ini.ReadValue("Config", "Part" + i); String MeshIni = Ini.ReadValue("Config", "MeshIni" + i); String MotionIni = Ini.ReadValue("Config", "MotionIni" + i); Part *pPart = (Part *)Kernel.calloc(sizeof(Part)); Name.ToPointer(pStr); Kernel.memcpy(pPart->Name, pStr, Math.Min(MAX_NAMESIZE - 1, Kernel.strlen(pStr))); MeshIni.ToPointer(pStr); Kernel.memcpy(pPart->MeshIni, pStr, Math.Min(MAX_PATHSIZE - 1, Kernel.strlen(pStr))); MotionIni.ToPointer(pStr); Kernel.memcpy(pPart->MotionIni, pStr, Math.Min(MAX_PATHSIZE - 1, Kernel.strlen(pStr))); if (!Parts.ContainsKey(Kernel.cstring(pPart->Name, MAX_NAMESIZE))) { Parts.Add(Kernel.cstring(pPart->Name, MAX_NAMESIZE), (IntPtr)pPart); } } for (Int32 i = 0; i < DumyAmount; i++) { String Name = Ini.ReadValue("Dumy", "Dumy" + i) + "\0"; Dumy *pDumy = (Dumy *)Kernel.calloc(sizeof(Dumy)); pDumy->UniqId = i; Name.ToPointer(pStr); Kernel.memcpy(pDumy->Name, pStr, Math.Min(MAX_NAMESIZE - 1, Kernel.strlen(pStr))); if (!Dumies.ContainsKey(pDumy->UniqId)) { Dumies.Add(pDumy->UniqId, (IntPtr)pDumy); } } } }
/// <summary> /// Load the specified ROPT file (in binary format) into the dictionary. /// </summary> public void LoadFromDat(String Path) { Clear(); lock (Parts) lock (Dumies) { using (FileStream Stream = new FileStream(Path, FileMode.Open, FileAccess.Read, FileShare.Read)) { Byte[] Buffer = new Byte[Kernel.MAX_BUFFER_SIZE]; Header *pHeader = stackalloc Header[1]; Stream.Read(Buffer, 0, sizeof(Header)); Kernel.memcpy(pHeader, Buffer, sizeof(Header)); if (pHeader->Identifier != ROPT_IDENTIFIER) { throw new Exception("Invalid ROPT Header in file: " + Path); } for (Int32 i = 0; i < pHeader->PartAmount; i++) { Part *pPart = (Part *)Kernel.malloc(sizeof(Part)); Stream.Read(Buffer, 0, sizeof(Part)); Kernel.memcpy(pPart, Buffer, sizeof(Part)); if (!Parts.ContainsKey(Kernel.cstring(pPart->Name, MAX_NAMESIZE))) { Parts.Add(Kernel.cstring(pPart->Name, MAX_NAMESIZE), (IntPtr)pPart); } } for (Int32 i = 0; i < pHeader->DumyAmount; i++) { Dumy *pDumy = (Dumy *)Kernel.malloc(sizeof(Dumy)); Stream.Read(Buffer, 0, sizeof(Dumy)); Kernel.memcpy(pDumy, Buffer, sizeof(Dumy)); if (!Dumies.ContainsKey(pDumy->UniqId)) { Dumies.Add(pDumy->UniqId, (IntPtr)pDumy); } } } } }
/// <summary> /// Save all the dictionary to the specified ROPT file (in binary format). /// </summary> public void SaveToDat(String Path) { using (FileStream Stream = new FileStream(Path, FileMode.Create, FileAccess.ReadWrite, FileShare.Read)) { lock (Parts) lock (Dumies) { Byte[] Buffer = new Byte[Kernel.MAX_BUFFER_SIZE]; IntPtr[] Pointers = new IntPtr[0]; Header *pHeader = stackalloc Header[1]; pHeader->Identifier = ROPT_IDENTIFIER; pHeader->PartAmount = Parts.Count; pHeader->DumyAmount = Dumies.Count; Kernel.memcpy(Buffer, pHeader, sizeof(Header)); Stream.Write(Buffer, 0, sizeof(Header)); Pointers = new IntPtr[Parts.Count]; Parts.Values.CopyTo(Pointers, 0); for (Int32 i = 0; i < Pointers.Length; i++) { Part *pPart = (Part *)Pointers[i]; Kernel.memcpy(Buffer, pPart, sizeof(Part)); Stream.Write(Buffer, 0, sizeof(Part)); } Pointers = new IntPtr[Dumies.Count]; Dumies.Values.CopyTo(Pointers, 0); for (Int32 i = 0; i < Pointers.Length; i++) { Dumy *pDumy = (Dumy *)Pointers[i]; Kernel.memcpy(Buffer, pDumy, sizeof(Dumy)); Stream.Write(Buffer, 0, sizeof(Dumy)); } } } }
/// <summary> /// Save all the dictionary to the specified ROPT file (in plain format). /// </summary> public void SaveToTxt(String Path) { using (StreamWriter Stream = new StreamWriter(Path, false, Encoding.GetEncoding("Windows-1252"))) { lock (Parts) lock (Dumies) { IntPtr[] Pointers = new IntPtr[0]; Pointers = new IntPtr[Parts.Count]; Parts.Values.CopyTo(Pointers, 0); Stream.WriteLine("[Config]"); Stream.WriteLine("Count={0}", Parts.Count); for (Int32 i = 0; i < Pointers.Length; i++) { Part *pPart = (Part *)Pointers[i]; Stream.WriteLine("Part{0}={1}", i, Kernel.cstring(pPart->Name, MAX_NAMESIZE)); Stream.WriteLine("MeshIni{0}={1}", i, Kernel.cstring(pPart->MeshIni, MAX_PATHSIZE)); Stream.WriteLine("MotionIni{0}={1}", i, Kernel.cstring(pPart->MotionIni, MAX_PATHSIZE)); } Stream.WriteLine(); Pointers = new IntPtr[Dumies.Count]; Dumies.Values.CopyTo(Pointers, 0); Stream.WriteLine("[Dumy]"); Stream.WriteLine("Count={0}¡¡¡¡¡¡", Dumies.Count); for (Int32 i = 0; i < Pointers.Length; i++) { Dumy *pDumy = (Dumy *)Pointers[i]; Stream.WriteLine("Dumy{0}={1}", i, Kernel.cstring(pDumy->Name, MAX_NAMESIZE)); } } } }