void PDFConverter(BOOL bDwg) { // test(); resbuf* rb = getFileNameInput(); resbuf* pRb = rb; AcStringArray arrFileName; while (pRb) { arrFileName.append(pRb->resval.rstring); pRb = pRb->rbnext; } acutRelRb(rb); rb = NULL; int page = 0; if (arrFileName.length() == 1) { acedInitGet(4, NULL); // use resource for multi langeage. // modify by yhl, 2016/6/29. CString strPrompt; CAcModuleResourceOverride rs; strPrompt.LoadString(IDS_ASKFORPAGENUMBER); int rc = acedGetInt(strPrompt, &page); // int rc = acedGetInt(_T("\nPlease input the page number, 0 for all <1>: "), &page); if (RTNONE == rc) { page = 1; } else if (RTNORM != rc) { return; } } for (int i=0; i<arrFileName.length(); i++) { convertFile(arrFileName[i], page, bDwg); } }
int main(int argc, char **argv) { FILE *outfile; int ret = 0; int seenf = 0; size_t bufsz = DEFAULT_BUFSZ; const char *fromcpage = 0; const char *tocpage = 0; const char *translit = 0; const char *outfilestr = 0; int fallback = 0; UConverterFromUCallback fromucallback = UCNV_FROM_U_CALLBACK_STOP; const void *fromuctxt = 0; UConverterToUCallback toucallback = UCNV_TO_U_CALLBACK_STOP; const void *touctxt = 0; char **iter; char **end = argv + argc; const char *pname; int printConvs = 0, printCanon = 0; const char *printName = 0; int printTranslits = 0; int verbose = 0; // Get and prettify pname. pname = uprv_strrchr(*argv, U_FILE_SEP_CHAR); #ifdef WIN32 if (!pname) { pname = uprv_strrchr(*argv, '/'); } #endif if (!pname) { pname = *argv; } else { ++pname; } // First, get the arguments from command-line // to know the codepages to convert between // XXX When you add to this loop, you need to add to the similar loop // below. for (iter = argv + 1; iter != end; iter++) { // Check for from charset if (strcmp("-f", *iter) == 0 || !strcmp("--from-code", *iter)) { iter++; if (iter != end) fromcpage = *iter; else usage(pname, 1); } else if (strcmp("-t", *iter) == 0 || !strcmp("--to-code", *iter)) { iter++; if (iter != end) tocpage = *iter; else usage(pname, 1); } else if (strcmp("-x", *iter) == 0) { iter++; if (iter != end) translit = *iter; else usage(pname, 1); } else if (!strcmp("--fallback", *iter)) { fallback = 1; } else if (!strcmp("--no-fallback", *iter)) { fallback = 0; } else if (strcmp("-b", *iter) == 0 || !strcmp("--block-size", *iter)) { iter++; if (iter != end) { bufsz = atoi(*iter); if ((int) bufsz <= 0) { initMsg(pname); UnicodeString str(*iter); initMsg(pname); u_wmsg(stderr, "badBlockSize", str.getBuffer()); return 3; } } else { usage(pname, 1); } } else if (strcmp("-l", *iter) == 0 || !strcmp("--list", *iter)) { if (printTranslits) { usage(pname, 1); } printConvs = 1; } else if (strcmp("--default-code", *iter) == 0) { if (printTranslits) { usage(pname, 1); } printName = ucnv_getDefaultName(); } else if (strcmp("--list-code", *iter) == 0) { if (printTranslits) { usage(pname, 1); } iter++; if (iter != end) { UErrorCode e = U_ZERO_ERROR; printName = ucnv_getAlias(*iter, 0, &e); if (U_FAILURE(e) || !printName) { UnicodeString str(*iter); initMsg(pname); u_wmsg(stderr, "noSuchCodeset", str.getBuffer()); return 2; } } else usage(pname, 1); } else if (strcmp("--canon", *iter) == 0) { printCanon = 1; } else if (strcmp("-L", *iter) == 0 || !strcmp("--list-transliterators", *iter)) { if (printConvs) { usage(pname, 1); } printTranslits = 1; } else if (strcmp("-h", *iter) == 0 || !strcmp("-?", *iter) || !strcmp("--help", *iter)) { usage(pname, 0); } else if (!strcmp("-c", *iter)) { fromucallback = UCNV_FROM_U_CALLBACK_SKIP; } else if (!strcmp("--to-callback", *iter)) { iter++; if (iter != end) { const struct callback_ent *cbe = findCallback(*iter); if (cbe) { fromucallback = cbe->fromu; fromuctxt = cbe->fromuctxt; } else { UnicodeString str(*iter); initMsg(pname); u_wmsg(stderr, "unknownCallback", str.getBuffer()); return 4; } } else { usage(pname, 1); } } else if (!strcmp("--from-callback", *iter)) { iter++; if (iter != end) { const struct callback_ent *cbe = findCallback(*iter); if (cbe) { toucallback = cbe->tou; touctxt = cbe->touctxt; } else { UnicodeString str(*iter); initMsg(pname); u_wmsg(stderr, "unknownCallback", str.getBuffer()); return 4; } } else { usage(pname, 1); } } else if (!strcmp("-i", *iter)) { toucallback = UCNV_TO_U_CALLBACK_SKIP; } else if (!strcmp("--callback", *iter)) { iter++; if (iter != end) { const struct callback_ent *cbe = findCallback(*iter); if (cbe) { fromucallback = cbe->fromu; fromuctxt = cbe->fromuctxt; toucallback = cbe->tou; touctxt = cbe->touctxt; } else { UnicodeString str(*iter); initMsg(pname); u_wmsg(stderr, "unknownCallback", str.getBuffer()); return 4; } } else { usage(pname, 1); } } else if (!strcmp("-s", *iter) || !strcmp("--silent", *iter)) { verbose = 0; } else if (!strcmp("-v", *iter) || !strcmp("--verbose", *iter)) { verbose = 1; } else if (!strcmp("-V", *iter) || !strcmp("--version", *iter)) { printf("%s v2.0\n", pname); return 0; } else if (!strcmp("-o", *iter) || !strcmp("--output", *iter)) { ++iter; if (iter != end && !outfilestr) { outfilestr = *iter; } else { usage(pname, 1); } } else if (**iter == '-' && (*iter)[1]) { usage(pname, 1); } } if (printConvs || printName) { return printConverters(pname, printName, printCanon) ? 2 : 0; } else if (printTranslits) { return printTransliterators(printCanon) ? 3 : 0; } if (!fromcpage || !uprv_strcmp(fromcpage, "-")) { fromcpage = ucnv_getDefaultName(); } if (!tocpage || !uprv_strcmp(tocpage, "-")) { tocpage = ucnv_getDefaultName(); } // Open the correct output file or connect to stdout for reading input if (outfilestr != 0 && strcmp(outfilestr, "-")) { outfile = fopen(outfilestr, "wb"); if (outfile == 0) { UnicodeString str1(outfilestr, ""); UnicodeString str2(strerror(errno), ""); initMsg(pname); u_wmsg(stderr, "cantCreateOutputF", str1.getBuffer(), str2.getBuffer()); return 1; } } else { outfilestr = "-"; outfile = stdout; #ifdef WIN32 if (setmode(fileno(outfile), O_BINARY) == -1) { u_wmsg(stderr, "cantSetOutBinMode"); exit(-1); } #endif } /* Loop again on the arguments to find all the input files, and convert them. XXX Cheap and sloppy. */ for (iter = argv + 1; iter != end; iter++) { if (strcmp("-f", *iter) == 0 || !strcmp("--from-code", *iter)) { iter++; } else if (strcmp("-t", *iter) == 0 || !strcmp("--to-code", *iter)) { iter++; } else if (strcmp("-x", *iter) == 0) { iter++; } else if (!strcmp("--fallback", *iter)) { ; } else if (!strcmp("--no-fallback", *iter)) { ; } else if (strcmp("-b", *iter) == 0 || !strcmp("--block-size", *iter)) { iter++; } else if (strcmp("-l", *iter) == 0 || !strcmp("--list", *iter)) { ; } else if (strcmp("--default-code", *iter) == 0) { ; } else if (strcmp("--list-code", *iter) == 0) { ; } else if (strcmp("--canon", *iter) == 0) { ; } else if (strcmp("-L", *iter) == 0 || !strcmp("--list-transliterators", *iter)) { ; } else if (strcmp("-h", *iter) == 0 || !strcmp("-?", *iter) || !strcmp("--help", *iter)) { ; } else if (!strcmp("-c", *iter)) { ; } else if (!strcmp("--to-callback", *iter)) { iter++; } else if (!strcmp("--from-callback", *iter)) { iter++; } else if (!strcmp("-i", *iter)) { ; } else if (!strcmp("--callback", *iter)) { iter++; } else if (!strcmp("-s", *iter) || !strcmp("--silent", *iter)) { ; } else if (!strcmp("-v", *iter) || !strcmp("--verbose", *iter)) { ; } else if (!strcmp("-V", *iter) || !strcmp("--version", *iter)) { ; } else if (!strcmp("-o", *iter) || !strcmp("--output", *iter)) { ++iter; } else { seenf = 1; if (!convertFile (pname, fromcpage, toucallback, touctxt, tocpage, fromucallback, fromuctxt, fallback, bufsz, translit, *iter, outfile, verbose)) { goto error_exit; } } } if (!seenf) { if (!convertFile (pname, fromcpage, toucallback, touctxt, tocpage, fromucallback, fromuctxt, fallback, bufsz, translit, 0, outfile, verbose)) { goto error_exit; } } goto normal_exit; error_exit: ret = 1; normal_exit: if (outfile != stdout) fclose(outfile); return ret; }
int main(int argc, const char * argv[]) { printVersion(); // check number of arguments and if all arguments can be read if (argc < 3 || !readArguments(argc, argv)) { printUsage(); return -1; } // check if the input path exist if (!FS_NAMESPACE::exists(inFilePath)) { std::cout << "Error: Invalid input file/directory \"" << inFilePath.string() << "\"!" << std::endl; return -2; } if (createBinary) { // check if argument 2 is a file if (FS_NAMESPACE::is_directory(outFilePath)) { std::cout << "Error: Output must be a file if -b is used!" << std::endl; return -2; } } else if (appendFile) { // check if argument 2 is a file if (FS_NAMESPACE::is_directory(outFilePath)) { std::cout << "Error: Output must be a file if -a is used!" << std::endl; return -2; } } else if (FS_NAMESPACE::is_directory(inFilePath) != FS_NAMESPACE::is_directory(outFilePath)) { // check if output directory exists if (FS_NAMESPACE::is_directory(outFilePath) && !FS_NAMESPACE::exists(outFilePath)) { std::cout << "Error: Invalid output directory \"" << outFilePath.string() << "\"!" << std::endl; return -2; } // check if arguments 1 and 2 are both files or both directories std::cout << "Error: Input and output file must be both either a file or a directory!" << std::endl; return -2; } if (appendFile) { // append file a to b if (!appendAtoB(outFilePath, inFilePath)) { std::cout << "Error: Failed to append data to executable!" << std::endl; return -3; } } else { // build list of files to process std::vector<FileData> fileList; if (FS_NAMESPACE::is_directory(inFilePath) && FS_NAMESPACE::is_directory(inFilePath)) { // both files are directories, build file ist fileList = getFileDataFrom(inFilePath, outFilePath, inFilePath, useRecursion); if (fileList.empty()) { std::cout << "Error: No files to convert!" << std::endl; return -3; } } else { // just add single input/output file FileData temp; temp.inPath = inFilePath; temp.outPath = outFilePath; temp.internalName = inFilePath.filename().string(); // remove all, but the file name and extension if (beVerbose) { std::cout << "Found input file " << inFilePath << std::endl; std::cout << "Internal name will be \"" << temp.internalName << "\"" << std::endl; std::cout << "Output path is " << temp.outPath << std::endl; } // get file size try { temp.size = static_cast<uint64_t>(FS_NAMESPACE::file_size(inFilePath)); if (beVerbose) { std::cout << "Size is " << temp.size << " bytes." << std::endl; } } catch (...) { std::cout << "Error: Failed to get size of " << inFilePath << "!" << std::endl; temp.size = 0; } fileList.push_back(temp); } // does the user want an binary file? if (createBinary) { // yes. build it. if (!createBlob(fileList, outFilePath)) { std::cout << "Error: Failed to convert to binary file!" << std::endl; return -4; } } else { // no. convert files to .c/.cpp. loop through list, converting files for (auto fdIt = fileList.begin(); fdIt != fileList.cend(); ++fdIt) { if (!convertFile(*fdIt, commonHeaderFilePath)) { std::cout << "Error: Failed to convert all files. Aborting!" << std::endl; return -4; } } // do we need to write a header file? if (!commonHeaderFilePath.empty()) { if (!createCommonHeader(fileList, commonHeaderFilePath, !utilitiesFilePath.empty(), useC)) { return -5; } // do we need to create utilities? if (!utilitiesFilePath.empty()) { if (!createUtilities(fileList, utilitiesFilePath, commonHeaderFilePath, useC, combineResults)) { return -6; } } } } } // if (!appendFile) { // profit!!! std::cout << "res2h succeeded." << std::endl; return 0; }
bool createUtilities(std::vector<FileData> & fileList, const FS_NAMESPACE::path & utilitiesPath, const FS_NAMESPACE::path & commonHeaderPath, bool useCConstructs = false, bool addFileData = false) { // try opening the output file. truncate it when it exists std::ofstream outStream; outStream.open(utilitiesPath.generic_string(), std::ofstream::out | std::ofstream::trunc); if (outStream.is_open() && outStream.good()) { if (beVerbose) { std::cout << std::endl << "Creating utilities file " << utilitiesPath; } // add message outStream << "// this file was auto-generated by res2h" << std::endl << std::endl; // create path to include file RELATIVE to this file FS_NAMESPACE::path relativePath = naiveUncomplete(commonHeaderPath, utilitiesPath); // include header file outStream << "#include \"" << relativePath.string() << "\"" << std::endl << std::endl; // if the data should go to this file too, add it if (addFileData) { for (auto fdIt = fileList.begin(); fdIt != fileList.cend(); ++fdIt) { if (!convertFile(*fdIt, commonHeaderFilePath, outStream, false)) { std::cout << "Error: Failed to convert all files. Aborting!" << std::endl; outStream.close(); return false; } } } // begin data arrays. switch depending whether C or C++ outStream << "const uint32_t res2hNrOfFiles = " << fileList.size() << ";" << std::endl; // add files outStream << "const Res2hEntry res2hFiles[res2hNrOfFiles] = {" << std::endl; outStream << " "; // first indent for (auto fdIt = fileList.cbegin(); fdIt != fileList.cend();) { outStream << "{\"" << fdIt->internalName << "\", " << fdIt->sizeVariableName << ", " << fdIt->dataVariableName << "}"; // was this the last entry? ++fdIt; if (fdIt != fileList.cend()) { // no. add comma. outStream << ","; // add break after every entry and add indent again outStream << std::endl << " "; } } outStream << std::endl << "};" << std::endl; if (!useCConstructs) { // add files to map outStream << std::endl << "res2hMapType::value_type mapTemp[] = {" << std::endl; outStream << " "; for (auto fdIt = fileList.cbegin(); fdIt != fileList.cend();) { outStream << "std::make_pair(\"" << fdIt->internalName << "\", res2hFiles[" << (fdIt - fileList.cbegin()) << "])"; // was this the last entry? ++fdIt; if (fdIt != fileList.cend()) { // no. add comma. outStream << ","; // add break after every entry and add indent again outStream << std::endl << " "; } } outStream << std::endl << "};" << std::endl << std::endl; // create map outStream << "res2hMapType res2hMap(mapTemp, mapTemp + sizeof mapTemp / sizeof mapTemp[0]);" << std::endl; } // close file outStream.close(); if (beVerbose) { std::cout << " - succeeded." << std::endl; } return true; } else { std::cout << "Error: Failed to open file \"" << utilitiesPath << "\" for writing!" << std::endl; } return true; }
static void processFile(char *name) { char errbuf[4096]; switch(mode) { case MD_DETECT_FILE_TYPE: if(verbose) fprintf(stdout, "ProcessMode: Detect Filetype\n"); #ifdef ENABLEGT if (apimode == API_GT) detectFileType(name); #endif #ifdef ENABLEKSI if (apimode == API_KSI) detectFileTypeKSI(name); #endif break; case MD_DUMP: if(verbose) fprintf(stdout, "ProcessMode: Dump FileHashes\n"); if (apimode == API_GT) #ifdef ENABLEGT dumpFile(name); #else fprintf(stderr, "ERROR, unable to perform dump using GuardTime Api, rsyslog need to be configured with --enable-guardtime.\n"); #endif if (apimode == API_KSI) #ifdef ENABLEKSI dumpFileKSI(name); #else fprintf(stderr, "ERROR, unable to perform dump using GuardTime KSI Api, rsyslog need to be configured with --enable-gt-ksi.\n"); #endif break; case MD_SHOW_SIGBLK_PARAMS: if(verbose) fprintf(stdout, "ProcessMode: Show SigBlk Params\n"); #ifdef ENABLEGT if (apimode == API_GT) showSigblkParams(name); #endif #ifdef ENABLEKSI if (apimode == API_KSI) showSigblkParamsKSI(name); #endif break; case MD_CONVERT: #ifdef ENABLEGT if (apimode == API_GT) convertFile(name); #endif #ifdef ENABLEKSI if (apimode == API_KSI) convertFileKSI(name); #endif break; case MD_VERIFY: case MD_EXTEND: if(verbose) fprintf(stdout, "ProcessMode: Verify/Extend\n"); verify(name, errbuf); break; } }
int main() { WIN32_FIND_DATA FindFileData; HANDLE hFind = NULL; u32 count = 0; char buf[MAX_PATH] = {0}; SetConsoleCP(GetACP()); SetConsoleOutputCP(GetACP()); printf("DeSmuME cheats file converter\n"); printf("Copyright (C) 2009 by DeSmuME Team\n"); printf("Version 0.1\n"); printf("\n"); printf("All files (.cht) of deception in a current directory will be renamed\n"); printf("Are you sure?"); int ch = 0; do { ch = getch(); if ((ch == 'N') || (ch == 'n')) { printf(" no\n\n"); return 2; } } while ((ch != 'Y') && (ch != 'y')); printf(" yes\n"); printf("\n"); hFind = FindFirstFile("*.dct", &FindFileData); if (hFind == INVALID_HANDLE_VALUE) { printf("%s\n", error()); return 1; } do { if (!(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { if (strncmp(FindFileData.cFileName + (strlen(FindFileData.cFileName) - 4), ".dct", 4) != 0) continue; printf("%s", FindFileData.cFileName); sprintf(buf, ".\\%s", FindFileData.cFileName); if (convertFile(buf)) { printf(" - Ok\n"); count++; } else printf(" - Failed\n"); } } while (FindNextFile(hFind, &FindFileData)); FindClose(hFind); printf("\nConverted %i files\n\n", count); printf("Done\n\n"); return 0; }