std::string ConvertToDDS(const char *filePath, filepath &baseDirectory, filepath &rootInputDirectory, filepath &rootOutputDirectory) { filepath relativePath(filePath); filepath relativeDDSPath(relativePath); relativeDDSPath.replace_extension("dds"); // If the file already exists in the output directory, we don't need to do anything filepath outputFilePath(rootOutputDirectory.file_string() + "\\" + relativeDDSPath.file_string()); if (exists(outputFilePath)) { return relativeDDSPath; } // Guarantee the output directory exists filepath outputDirectory(outputFilePath.parent_path()); create_directories(outputDirectory); // If input is already dds, but doesn't exist in the output directory, just copy the file to the output filepath inputFilePath(rootInputDirectory.file_string() + "\\" + relativePath.file_string()); if (_stricmp(relativePath.extension().c_str(), "dds") == 0) { copy_file(inputFilePath, outputFilePath); return relativeDDSPath; } // Otherwise, convert the file to DDS std::string call = baseDirectory.file_string() + "\\texconv.exe -ft dds -o " + outputDirectory.file_string() + " " + inputFilePath.file_string() + " > NUL"; std::system(call.c_str()); return relativeDDSPath; }
void FileTestContext::workingFileFromTemplate( const char* templateName, ///< testInputDir file TemplateConverter* converter, ///< conversion function const char* filename ///< testWorkingDir file ) { /* * The template in the testInputDir and the filename in testWorkingDir are opened, * and then both files are passed to the converter. * * The converter is responsible for reading the template and writing the filename. * * If no filename is supplied, its name is the same as the templateName. */ CPPUNIT_ASSERT(templateName != NULL); CPPUNIT_ASSERT(converter != NULL); // Open the template file UtlString templatePath; inputFilePath(templateName, templatePath); OsPath input(templatePath); OsFile inputFile(input); CPPUNIT_ASSERT_EQUAL(OS_SUCCESS, inputFile.open(OsFile::READ_ONLY)); // Create/open the registration DB file. UtlString workingPath; workingFilePath(filename ? filename : templateName, workingPath); OsPath working(workingPath); OsFile workingFile(working); CPPUNIT_ASSERT_EQUAL(OS_SUCCESS, workingFile.open(OsFile::CREATE)); // Let the converter convert the files converter(&inputFile, &workingFile); CPPUNIT_ASSERT_EQUAL(OS_SUCCESS, workingFile.flush()); Os::Logger::instance().log(FAC_UNIT_TEST, PRI_NOTICE, "FileTestContext::workingFileFromTemplate '%s' -> '%s'", templateName, workingPath.data()); inputFile.close(); workingFile.close(); }
void FileTestContext::inputFile(const char* filename) { UtlString inputPath; inputFilePath(filename, inputPath); UtlString workingPath; workingFilePath(filename, workingPath); OsPath input(inputPath); OsPath working(workingPath); OsPath workingDirPath(working.getDirName()); workingDirPath.strip(UtlString::trailing, OsPath::separator(0)); OsDir workingDir(workingDirPath); if (!workingDir.exists()) { UtlString msg; msg.append("FileTestContext::inputFile failed to create working directory '"); msg.append(working.getDirName().data()); msg.append("'"); CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), OS_SUCCESS,OsFileSystem::createDir(workingDirPath,TRUE)); } UtlString msg; msg.append("FileTestContext::inputFile copy failed from '"); msg.append(inputPath); msg.append("' -> '"); msg.append(workingPath); msg.append("'"); CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), OS_SUCCESS, OsFileSystem::copy(input, working) ); Os::Logger::instance().log(FAC_UNIT_TEST, PRI_NOTICE, "FileTestContext::inputFile '%s' -> '%s'", inputPath.data(), workingPath.data()); }
int main(int argc, char *argv[]) { enum ExitCode { Success, ParseFailure, ArgumentError, WriteError, FileFailure }; QCoreApplication app(argc, argv); QTextStream errorStream(stderr); if (argc != 2) { errorStream << PrettyPrint::tr( "Usage: prettyprint <path to XML file>\n"); return ArgumentError; } QString inputFilePath(QCoreApplication::arguments().at(1)); QFile inputFile(inputFilePath); if (!QFile::exists(inputFilePath)) { errorStream << PrettyPrint::tr( "File %1 does not exist.\n").arg(inputFilePath); return FileFailure; } else if (!inputFile.open(QIODevice::ReadOnly)) { errorStream << PrettyPrint::tr( "Failed to open file %1.\n").arg(inputFilePath); return FileFailure; } QFile outputFile; if (!outputFile.open(stdout, QIODevice::WriteOnly)) { QTextStream(stderr) << PrettyPrint::tr("Failed to open stdout."); return WriteError; } QXmlStreamReader reader(&inputFile); int indentation = 0; QHash<int,QPair<int, int> > indentationStack; while (!reader.atEnd()) { reader.readNext(); if (reader.isStartElement()) { indentationStack[indentation] = QPair<int,int>( reader.lineNumber(), reader.columnNumber()); indentation += 1; } else if (reader.isEndElement()) { indentationStack.remove(indentation); indentation -= 1; } if (reader.error()) { errorStream << PrettyPrint::tr( "Error: %1 in file %2 at line %3, column %4.\n").arg( reader.errorString(), inputFilePath, QString::number(reader.lineNumber()), QString::number(reader.columnNumber())); if (indentationStack.contains(indentation-1)) { int line = indentationStack[indentation-1].first; int column = indentationStack[indentation-1].second; errorStream << PrettyPrint::tr( "Opened at line %1, column %2.\n").arg( QString::number(line), QString::number(column)); } return ParseFailure; } else if (reader.isStartElement() && !reader.name().isEmpty()) { outputFile.write(QByteArray().fill(' ', indentation)); outputFile.write(reader.name().toString().toLocal8Bit()); outputFile.write(QString(" line %1, column %2\n").arg( reader.lineNumber()).arg(reader.columnNumber()).toLocal8Bit()); } } return Success; }
int main(int argc, char *argv[]) { enum ExitCode { Success, ParseFailure, ArgumentError, WriteError, FileFailure }; QCoreApplication app(argc, argv); QTextStream errorStream(stderr); if (argc != 2) { errorStream << XmlStreamLint::tr( "Usage: xmlstreamlint <path to XML file>\n"); return ArgumentError; } QString inputFilePath(QCoreApplication::arguments().at(1)); QFile inputFile(inputFilePath); if (!QFile::exists(inputFilePath)) { errorStream << XmlStreamLint::tr( "File %1 does not exist.\n").arg(inputFilePath); return FileFailure; } else if (!inputFile.open(QIODevice::ReadOnly)) { errorStream << XmlStreamLint::tr( "Failed to open file %1.\n").arg(inputFilePath); return FileFailure; } QFile outputFile; if (!outputFile.open(stdout, QIODevice::WriteOnly)) { errorStream << XmlStreamLint::tr("Failed to open stdout."); return WriteError; } //! [0] QXmlStreamReader reader(&inputFile); QXmlStreamWriter writer(&outputFile); //! [0] //! [1] while (!reader.atEnd()) { reader.readNext(); if (reader.error()) { errorStream << XmlStreamLint::tr( "Error: %1 in file %2 at line %3, column %4.\n").arg( reader.errorString(), inputFilePath, QString::number(reader.lineNumber()), QString::number(reader.columnNumber())); return ParseFailure; //! [1] //! [2] } else writer.writeCurrentToken(reader); } //! [2] return Success; }
int main(int argc, char *argv[]) { putenv("UNICODEMAP_JP=cp932"); //Encoder needs this to encode in the correct varient of S-JIS if(argc < 2) { fprintf(stderr, "\nERR: No parameters! See usage info below.\n\n"); printHelp(); } if(strncmp(argv[1], "--help", strlen("--help")) == 0) { printf("\n"); printHelp(); } else if(strncmp(argv[1], "--decode-pac", strlen("--decode-pac")) == 0) { if(argc != 4) { fprintf(stderr, "\nERR: Incorrect amount of parameters! See usage info below.\n\n"); printHelp(); } QString inputFilePath(argv[2]); QString outputFilePath(argv[3]); packer.unpack(inputFilePath, outputFilePath); } else if (strncmp(argv[1], "--encode-pac", strlen("--encode-pac")) == 0) { if(argc != 4) { fprintf(stderr, "\nERR: Incorrect amount of parameters! See usage info below.\n\n"); printHelp(); } QString inputFilePath(argv[2]); QString outputFilePath(argv[3]); packer.pack(inputFilePath, outputFilePath); } else if (strncmp(argv[1], "--encode-arc", strlen("--encode-arc")) == 0) { if(argc != 5) { fprintf(stderr, "\nERR: Incorrect amount of parameters! See usage info below.\n\n"); printHelp(); } QString inputDirPath(argv[2]); QString inputStructureFile(argv[3]); QString outputFilePath(argv[4]); writer.loadStructure(inputStructureFile); writer.buildArchive(inputDirPath, outputFilePath); } else if (strncmp(argv[1], "--decode-arc", strlen("--decode-arc")) == 0) { if(argc != 5) { fprintf(stderr, "\nERR: Incorrect amount of parameters! See usage info below.\n\n"); printHelp(); } QString inputFilePath(argv[2]); QString outputDirPath(argv[3]); QString outputStructureFile(argv[4]); reader.open(inputFilePath); reader.decode(); reader.extract(outputDirPath); reader.saveStructure(outputStructureFile); } else if(strncmp(argv[1], "--decode-scf", strlen("--decode-scf")) == 0) { if(argc < 4) { fprintf(stderr, "\nERR: Incorrect amount of parameters! See usage info below.\n\n"); printHelp(); } QString inputFilePath(argv[2]); QString outputFilePath(argv[3]); scf2xml.load(inputFilePath); scf2xml.saveXml(outputFilePath); } else if(strncmp(argv[1], "--encode-scf", strlen("--encode-scf")) == 0) { if(argc < 4) { fprintf(stderr, "\nERR: Incorrect amount of parameters! See usage info below.\n\n"); printHelp(); } int nextParam = 2; if(strncmp(argv[2], "--translate", strlen("--translate")) == 0) { lang_id translateTo = getLangIdByName(argv[3]); if(translateTo == LANGUAGE_UNKNOWN) { fprintf(stderr, "\nERR: Unknown translation language! See usage info below.\n\n"); printHelp(); } xml2scf.setLanguage(translateTo); } QString inputFilePath(argv[nextParam]); QString outputFilePath(argv[nextParam + 1]); xml2scf.load(inputFilePath); xml2scf.saveScf(outputFilePath); } else if(strncmp(argv[1], "--rename-scf", strlen("--rename-scf")) == 0) { if(argc != 4) { fprintf(stderr, "\nERR: Incorrect amount of parameters! See usage info below.\n\n"); printHelp(); } QString dirPath(argv[3]); if (strnicmp(argv[2], "--toReal", strlen("--toReal")) == 0) { printf("toReal...\n"); scfrename.numToReal(dirPath); } else if (strnicmp(argv[2], "--toNum", strlen("--toNum")) == 0) { printf("toNum...\n"); scfrename.realToNum(dirPath); } else { printHelp(); } } else if(strncmp(argv[1], "--rename-xml", strlen("--rename-xml")) == 0) { if(argc != 4) { fprintf(stderr, "\nERR: Incorrect amount of parameters! See usage info below.\n\n"); printHelp(); } QString dirPath(argv[3]); if (strnicmp(argv[2], "--toReal", strlen("--toReal")) == 0) { printf("toReal...\n"); xmlrename.numToReal(dirPath); } else if (strnicmp(argv[2], "--toNum", strlen("--toNum")) == 0) { printf("toNum...\n"); xmlrename.realToNum(dirPath); } else { printHelp(); } } else if(strncmp(argv[1], "--alphafix", strlen("--alphafix")) == 0) { if(argc != 4) { fprintf(stderr, "\nERR: Incorrect amount of parameters! See usage info below.\n\n"); printHelp(); } QString modeSelect(argv[2]); QString inputFilePath(argv[3]); if (modeSelect == "-u") { alphafix.fixalpha(inputFilePath, 2); } else if (modeSelect == "-d") { alphafix.fixalpha(inputFilePath, 1); } else { fprintf(stderr, "\nERR: Incorrect mode imput! See usage info below.\n\n"); printHelp(); } } else if(strncmp(argv[1], "--cltappend", strlen("--cltappend")) == 0) { if(argc != 5) { fprintf(stderr, "\nERR: Incorrect amount of parameters! See usage info below.\n\n"); printHelp(); } char *inputFilePath=argv[2]; char *inputCLTFilePath=argv[3]; char *outputFilePath=argv[4]; cltprocessor.appendClut(inputFilePath, inputCLTFilePath, outputFilePath); } else if(strncmp(argv[1], "--cltremove", strlen("--cltremove")) == 0) { if(argc != 4) { fprintf(stderr, "\nERR: Incorrect amount of parameters! See usage info below.\n\n"); printHelp(); } char *inputFilePath=argv[2]; char *outputFilePath=argv[3]; cltprocessor.removeClut(inputFilePath, outputFilePath); } else if (strncmp(argv[1], "--extract-img", strlen("--extract-img")) == 0) { if(argc != 5) { fprintf(stderr, "\nERR: Incorrect amount of parameters! See usage info below.\n\n"); printHelp(); } QString inputFilePath(argv[2]); QString outputDirPath(argv[3]); QString outputStructureFile(argv[4]); extractor.extract(inputFilePath, outputDirPath, outputStructureFile); } else if(strncmp(argv[1], "--sync-xml", strlen("--sync-xml")) == 0) { if(argc < 5) { fprintf(stderr, "\nERR: Incorrect amount of parameters! See usage info below.\n\n"); printHelp(); } QString inputFilePath(argv[2]); //source file: containing newest strings QString templateFilePath(argv[3]); //template file: new strings applied to this QString outputFilePath(argv[4]); //output file: new file for updated template xmlsync.load(inputFilePath, 0); xmlsync.load(templateFilePath, 1); if(argc == 6 && (strncmp(argv[5], "-2", strlen("-2")) == 0)) { xmlsync.syncStrings(2); //Slower, brute-force scan } else if(argc == 6 && (strncmp(argv[5], "-1", strlen("-1")) == 0)) { xmlsync.syncStrings(1); //Faster, one-to-one scan } else { xmlsync.syncStrings(0); //Automatically pick mode } xmlsync.saveXml(outputFilePath); } else if(strncmp(argv[1], "--swizzleprocess", strlen("--swizzleprocess")) == 0) { if(argc != 5) { fprintf(stderr, "\nERR: Incorrect amount of parameters! See usage info below.\n\n"); printHelp(); } QString modeSelect(argv[2]); QString inputFilePath(argv[3]); QString outputFilePath(argv[4]); if (modeSelect == "-d") { swizzleprocessor.swizzleProcess(inputFilePath, outputFilePath, 0); } else if (modeSelect == "-r") { swizzleprocessor.swizzleProcess(inputFilePath, outputFilePath, 1); } else { fprintf(stderr, "\nERR: Incorrect mode imput! See usage info below.\n\n"); printHelp(); } } else if (argc == 3) { QString inputFilePath(argv[2]); if(inputFilePath.endsWith(".xml")) { QString outputFilePath = inputFilePath.replace(inputFilePath.length() - 4, 3, "scf"); xml2scf.load(inputFilePath); xml2scf.saveScf(outputFilePath); } else if(inputFilePath.endsWith(".scf")) { QString outputFilePath = inputFilePath.replace(inputFilePath.length() - 4, 3, "xml"); scf2xml.load(inputFilePath); scf2xml.saveXml(outputFilePath); } else if(inputFilePath.endsWith(".pac")) { QString outputFilePath = inputFilePath.replace(inputFilePath.length() - 4, 3, "arc"); packer.unpack(inputFilePath, outputFilePath); } else { fprintf(stderr, "\nERR: Incorrect input file extension! See usage info below.\n\n"); printHelp(); } } else { fprintf(stderr, "\nERR: Unknown command! See usage info below.\n\n"); printHelp(); } fprintf(stderr, "\nDone!\n"); return 0; }