void TransCompiler (CXMLElement *pCmdLine) // TransCompiler // // Compile the Transcendence game and resource files // // <TransCompiler // input="{input filespec}" // output="{output filespec}" // /> { ALERROR error; printf("TransCompiler v1.0\n"); printf("Copyright (c) 2003 by Neurohack, Inc. All Rights Reserved.\n\n"); if (pCmdLine->GetAttributeBool(NOARGS) || pCmdLine->GetAttributeBool(SWITCH_HELP)) { printf(" /input:{input filespec}\n"); printf(" /output:{output filespec}\n"); printf("\n"); return; } // Figure out the folder for the input filespec. All filenames will // be relative to this root. CString sInputFilespec = pCmdLine->GetAttribute(ATTRIB_INPUT); if (sInputFilespec.IsBlank()) sInputFilespec = CONSTLIT("Transcendence.xml"); CString sRoot = pathGetPath(sInputFilespec); // Figure out the output filespec CString sOutputFilespec = pCmdLine->GetAttribute(ATTRIB_OUTPUT); if (sOutputFilespec.IsBlank()) sOutputFilespec = CONSTLIT("Transcendence.tdb"); // Create the output file if (error = CDataFile::Create(sOutputFilespec, 4096, 0)) { printf("Unable to create '%s'\n", sOutputFilespec.GetASCIIZPointer()); return; } CDataFile Out(sOutputFilespec); if (error = Out.Open()) { printf("Unable to open '%s'\n", sOutputFilespec.GetASCIIZPointer()); return; } // Prepare a symbol table to hold all the resource files CSymbolTable Resources(FALSE, TRUE); // Write out the main module and recurse int iGameFile; if (error = WriteModule(sInputFilespec, NULL_STR, NULL, Resources, Out, &iGameFile)) return; // Write out the header if (error = WriteHeader(iGameFile, Resources, Out)) return; // Done Out.Close(); }
CResourceDb::CResourceDb (const CString &sFilespec, CResourceDb *pMainDb, bool bExtension) : m_iVersion(TDB_VERSION), m_pDb(NULL), m_pResourceMap(NULL), m_pMainDb(NULL) // CResourceDb constructor // // sFilespec = "Extensions/MyExtension" // // If Extensions/MyExtension.tdb exists, then look for the definitions // and the resources in the .tdb file. // // Otherwise, use Extensions/MyExtension.xml for the definitions and // Look for resource files in the Extensions folder. { if (pMainDb || bExtension) { // We assume this is an extension CString sTDB = sFilespec; sTDB.Append(CONSTLIT(".")); sTDB.Append(FILE_TYPE_TDB); if (pathExists(sTDB)) { m_pDb = new CDataFile(sTDB); m_sRoot = pathGetPath(sTDB); m_sGameFile = pathGetFilename(sTDB); m_bGameFileInDb = true; m_bResourcesInDb = true; } else { CString sXML = sFilespec; sXML.Append(CONSTLIT(".")); sXML.Append(FILE_TYPE_XML); m_pDb = NULL; m_sRoot = pathGetPath(sFilespec); m_sGameFile = pathGetFilename(sXML); m_bGameFileInDb = false; m_bResourcesInDb = false; } m_pMainDb = pMainDb; } else { CString sType = pathGetExtension(sFilespec); if (sType.IsBlank()) { CString sXML = sFilespec; sXML.Append(CONSTLIT(".")); sXML.Append(FILE_TYPE_XML); // If Transcendence.xml exists, then use the file and load // the resources from the same location. if (pathExists(sXML)) { m_sRoot = pathGetPath(sXML); m_sGameFile = pathGetFilename(sXML); m_bGameFileInDb = false; // If a resources path exists, then use the resources in the // folder. Otherwise, use resources in the tdb CString sResourcesPath = pathAddComponent(m_sRoot, RESOURCES_FOLDER); if (pathExists(sResourcesPath)) { m_pDb = NULL; m_bResourcesInDb = false; } // Otherwise, use the tdb file else { CString sTDB = sFilespec; sTDB.Append(CONSTLIT(".")); sTDB.Append(FILE_TYPE_TDB); m_pDb = new CDataFile(sTDB); m_bResourcesInDb = true; } } // Otherwise, use the .tdb file for both else { CString sTDB = sFilespec; sTDB.Append(CONSTLIT(".")); sTDB.Append(FILE_TYPE_TDB); m_pDb = new CDataFile(sTDB); m_bGameFileInDb = true; m_bResourcesInDb = true; } } else if (strEquals(sType, FILE_TYPE_XML)) { m_sRoot = pathGetPath(sFilespec); m_sGameFile = pathGetFilename(sFilespec); m_pDb = NULL; m_bGameFileInDb = false; m_bResourcesInDb = false; } else { m_pDb = new CDataFile(sFilespec); m_bGameFileInDb = true; m_bResourcesInDb = true; } // This is the main file m_pMainDb = NULL; } }
ALERROR CExtension::LoadModuleElement (SDesignLoadCtx &Ctx, CXMLElement *pDesc) // LoadModuleElement // // Loads <Module> { ALERROR error; CString sFilename = pDesc->GetAttribute(FILENAME_ATTRIB); // Load the module XML CXMLElement *pModuleXML; if (error = Ctx.pResDb->LoadModule(Ctx.sFolder, sFilename, &pModuleXML, &Ctx.sError)) { if (error == ERR_NOTFOUND) Ctx.sError = strPatternSubst(CONSTLIT("%s: %s"), Ctx.pResDb->GetFilespec(), Ctx.sError); return error; } if (!strEquals(pModuleXML->GetTag(), TRANSCENDENCE_MODULE_TAG)) { delete pModuleXML; Ctx.sError = strPatternSubst(CONSTLIT("Module must have <TranscendenceModule> root element: %s"), sFilename); return ERR_FAIL; } // We are loading a module bool bOldLoadModule = Ctx.bLoadModule; Ctx.bLoadModule = true; // Look for resources relative to the module path CString sOldFolder = Ctx.sFolder; CString sFolder = pathGetPath(sFilename); if (!sFolder.IsBlank() && Ctx.GetAPIVersion() >= 26) Ctx.sFolder = pathAddComponent(Ctx.sFolder, sFolder); // Errors credited to this file. CString sOldErrorFilespec = Ctx.sErrorFilespec; if (strEquals(pathGetExtension(sOldErrorFilespec), FILESPEC_TDB_EXTENSION)) Ctx.sErrorFilespec = strPatternSubst(CONSTLIT("%s#%s"), sOldErrorFilespec, sFilename); else Ctx.sErrorFilespec = sFilename; // Process each design element in the module if (error = LoadModuleContent(Ctx, pModuleXML)) return error; // Clean up Ctx.sFolder = sOldFolder; Ctx.sErrorFilespec = sOldErrorFilespec; Ctx.bLoadModule = bOldLoadModule; // If we're keeping the XML, then add it to our table if (Ctx.bKeepXML && !m_ModuleXML.Find(sFilename)) m_ModuleXML.Insert(sFilename, pModuleXML); else delete pModuleXML; return NOERROR; }