public MemoryFileStream GetBinaryFile(string filename) { filename = baseDirectory + filename; MemoryFileStream stream = null; if (!binaryFileDictionary.TryGetValue(filename, out stream)) { stream = new MemoryFileStream(filename); binaryFileDictionary[filename] = stream; } return(stream); }
public void CreateTextFile(FilePath path, string contents) { if (!path.IsFile) { throw new ArgumentException("The specified path is no file.", nameof(path)); } if (!Directories.ContainsKey(path.ParentPath)) { throw new DirectoryNotFoundException(); } Directories[path.ParentPath].Add(path); var file = Files[path] = new MemoryFile(); var stream = new MemoryFileStream(file); var bytes = new UTF8Encoding().GetBytes(contents); stream.Write(bytes, 0, contents.Length); stream.Close(); }
void UpdateRoomData() { // Get the tileDataFile int layoutGroup = area.LayoutGroup; string label = "room" + ((layoutGroup << 8) + (Index & 0xff)).ToString("X4").ToLower(); FileParser parserFile = Project.GetFileWithLabel(label); Data data = parserFile.GetData(label); if (data.CommandLowerCase != "m_roomlayoutdata") { throw new Exception("Expected label \"" + label + "\" to be followed by the m_RoomLayoutData macro."); } string roomString = data.GetValue(0) + ".bin"; try { tileDataFile = Project.GetBinaryFile( "rooms/" + Project.GameString + "/small/" + roomString); } catch (FileNotFoundException) { try { tileDataFile = Project.GetBinaryFile( "rooms/" + Project.GameString + "/large/" + roomString); } catch (FileNotFoundException) { throw new FileNotFoundException("Couldn't find \"" + roomString + "\" in \"rooms/small\" or \"rooms/large\"."); } } if (tileDataFile.Length == 80) // Small map { width = fileWidth = 10; height = 8; } else if (tileDataFile.Length == 176) // Large map { width = 0xf; fileWidth = 0x10; height = 0xb; } else { throw new Exception("Size of file \"" + tileDataFile.Name + "\" was invalid!"); } }
void UpdateRoomData() { // Get the tileDataFile int layoutGroup = area.LayoutGroup; string label = "room" + ((layoutGroup<<8)+(Index&0xff)).ToString("X4").ToLower(); FileParser parserFile = Project.GetFileWithLabel(label); Data data = parserFile.GetData(label); if (data.CommandLowerCase != "m_roomlayoutdata") { throw new Exception("Expected label \"" + label + "\" to be followed by the m_RoomLayoutData macro."); } string roomString = data.GetValue(0) + ".bin"; try { tileDataFile = Project.GetBinaryFile("rooms/small/" + roomString); } catch (FileNotFoundException) { try { tileDataFile = Project.GetBinaryFile("rooms/large/" + roomString); } catch (FileNotFoundException) { throw new FileNotFoundException("Couldn't find \"" + roomString + "\" in \"rooms/small\" or \"rooms/large\"."); } } if (tileDataFile.Length == 80) { // Small map width = fileWidth = 10; height = 8; } else if (tileDataFile.Length == 176) { // Large map width = 0xf; fileWidth = 0x10; height = 0xb; } else throw new Exception("Size of file \"" + tileDataFile.Name + "\" was invalid!"); }