/////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Read or write font data to/from file /// </summary> /// <param name="serializer"> The serializer to handle the data </param> /////////////////////////////////////////////////////////////////////////////////////////// private void TransferFontFile(TCUtil.ISimpleSerializer serializer) { // The game resource key int fourCCVal = ResourceCS.ResourceToolsDB.REZ_FOURCC.ToInt32(); serializer.AddData(ref fourCCVal); TCBase.FourCC fourCC = new TCBase.FourCC(fourCCVal); if (fourCC != ResourceCS.ResourceToolsDB.REZ_FOURCC) { } // The resource type int resTypeVal = (int)ResourceCS.ResourceType.Font; serializer.AddData(ref resTypeVal); ResourceCS.ResourceType resType = (ResourceCS.ResourceType)resTypeVal; if (resType != ResourceCS.ResourceType.Font) { } // Create a buffer for the name and clear its data char[] fontName = new char[ResourceCS.ResourceToolsDB.REZ_NAME_LEN]; for (int charIndex = 0; charIndex < fontName.Length; ++charIndex) { fontName[charIndex] = '\x0000'; } // The name of the font if (serializer.InReadMode) { serializer.AddData(ref fontName); m_Name = new String(fontName); } // Otherwise we are saving the font else { m_Name.CopyTo(0, fontName, 0, m_Name.Length); serializer.AddData(ref fontName); } // The font file version int fileVer = FONT_FILE_VER; serializer.AddData(ref fileVer); // The character height serializer.AddData(ref m_CharHeight); // The letter spacing serializer.AddData(ref m_LetterSpacing); // The image file resource ID serializer.AddData(ref m_ImageResID); // The number of characters int charCount = 0; if (serializer.InWriteMode) { charCount = m_CharList.Count; } else { m_CharList.Clear(); } serializer.AddData(ref charCount); if (serializer.InWriteMode) { foreach (char curChar in m_CharList.Keys) { // The character char curCharCopy = curChar; serializer.AddData(ref curCharCopy); // The glyph rectangle Rectangle glyphRect = m_CharList[curChar]; int rectVal = glyphRect.X; serializer.AddData(ref rectVal); rectVal = glyphRect.Y; serializer.AddData(ref rectVal); rectVal = glyphRect.Width; serializer.AddData(ref rectVal); rectVal = glyphRect.Height; serializer.AddData(ref rectVal); } } else { // Go through each character for (int charIndex = 0; charIndex < charCount; ++charIndex) { // The character char curChar = '\0'; serializer.AddData(ref curChar); // The glyph rectangle Rectangle glyphRect = new Rectangle(); int rectVal = 0; serializer.AddData(ref rectVal); glyphRect.X = rectVal; serializer.AddData(ref rectVal); glyphRect.Y = rectVal; serializer.AddData(ref rectVal); glyphRect.Width = rectVal; serializer.AddData(ref rectVal); glyphRect.Height = rectVal; // Store the data if we are reading in m_CharList.Add(curChar, glyphRect); } } }
/////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Load a tool resource index file. /// </summary> /// <param name="sFileName"> The file name to load </param> /// <returns></returns> /////////////////////////////////////////////////////////////////////////////////////////// public bool LoadToolsIndex(string sFileName) { try { // Open the file System.IO.FileStream inFile = new System.IO.FileStream(sFileName, System.IO.FileMode.Open, System.IO.FileAccess.Read); System.IO.BinaryReader binReader = new System.IO.BinaryReader(inFile, Encoding.Unicode); // Read in the file key TCBase.FourCC FOURCC_TOOLSDB = new TCBase.FourCC("TRDB"); int fourCCVal = binReader.ReadInt32(); TCBase.FourCC fileFourCC = new TCBase.FourCC(fourCCVal); // Ensure a proper key if (fourCCVal != FOURCC_TOOLSDB.ToInt32()) { inFile.Close(); return(false); } // Read in the version int fileVersion = binReader.ReadInt32(); if (fileVersion == 1) { } else if (fileVersion == 2) { int numChars = (int)binReader.ReadUInt32(); byte[] stringBytes = binReader.ReadBytes(numChars * 2); // Read in the resource base path RootResourcePath = Encoding.Unicode.GetString(stringBytes); } else { throw new ApplicationException("Bad file version"); } // Read in the number of resources int numResources = binReader.ReadInt32(); // Size the list based on the number of resources m_ResList = new SortedList <uint, ResourceIndexItem>(numResources); // Read in the resource index items for (int itemIndex = 0; itemIndex < numResources; ++itemIndex) { ResourceIndexItem newItem = new ResourceIndexItem(); // Read in the length of the name int nameLen = binReader.ReadInt32(); // Read in the name char[] resName = binReader.ReadChars(nameLen); newItem.sName = new string(resName); // Read in the length of the file name int fileNameLen = binReader.ReadInt32(); // Read in the file name char[] fileName = binReader.ReadChars(fileNameLen); newItem.sFileName = new string(fileName); // Read in the type int resType = binReader.ReadInt32(); newItem.type = (ResourceType)resType; // Read in the length of the resource define identifier int defineNameLen = binReader.ReadInt32(); // Read in the resource define char[] defineName = binReader.ReadChars(defineNameLen); newItem.sDefineName = new string(defineName); // Read in the ID newItem.ID = binReader.ReadUInt32(); // Read in the image type int imageType = binReader.ReadInt32(); // Store the item m_ResList.Add(newItem.ID, newItem); } // Close the file inFile.Close(); } catch (Exception exc) { System.Windows.Forms.MessageBox.Show(exc.Message, "Failed To Load Tools Resource Index"); return(false); } // Return success return(true); }