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; }
std::string Encoder::getOutputFilePath() const { if (m_FileOutputPath.size() > 0) { return m_FileOutputPath; } else { //generate an output file int pos = m_FilePath.find_last_of('.'); std::string outputFilePath(pos > 0 ? m_FilePath.substr(0, pos) : m_FilePath); outputFilePath.append(getOutputFileExtension()); return outputFilePath; } }
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; }
void Compression::huffmanEncode(const char* inputFile) { FILE * src = fopen(inputFile, "rb"); char outputPath[1000]; const char * fileExtension = ".bin"; outputFilePath(inputFile, outputPath, fileExtension); FILE * dest = fopen(outputPath, "wb"); if (src == NULL || dest == NULL) { printf("Не удается найти файл."); exit(EXIT_FAILURE); } unsigned int fileSize; fileSize = getFileSize(src); unsigned int * freqList; freqList = (unsigned int *)calloc(CHARS_LIMIT, sizeof(unsigned int)); calcCharFreq(src, freqList); unsigned int numOfFreq; numOfFreq = calcNumOfFreq(freqList); HuffNode * nodeList = NULL; buildNodeList(&nodeList, freqList); buildHuffTree(&nodeList); HuffNode * treeRoot = nodeList; unsigned int i; HuffCode newCode; HuffCode * huffCodeTable; huffCodeTable = (HuffCode *)calloc(CHARS_LIMIT, sizeof(HuffCode)); for(i=0; i<CHARS_LIMIT; i++) { if(freqList[i] > 0) { newCode.length = 0; buildHuffCode(treeRoot, &newCode, i); huffCodeTable[i] = newCode; } } HuffHeader hHeader; writeHeader(dest, hHeader, numOfFreq, fileSize); HuffFreq hFreq; writeFreq(dest, freqList, hFreq); writeEncodedData(src, dest, huffCodeTable, fileSize); freeHuffTree(treeRoot); treeRoot = NULL; free(huffCodeTable); free(freqList); fclose(src); fclose(dest); }