/* FileNameToHandle - return handle corresponding to the file name * * FileNameToHandle is used to locate the buffer pointer corresponding to * a specified file. Short names are allowed. If the input name is 0-length * we return the current file. * * pName character pointer to name being located. Case is significant. * pShortName short name of file. This may be NULL * * Returns handle to specified file (if found) or NULL. */ PFILE FileNameToHandle ( char const *pName, char const *pShortName ) { char const *pBaseShortName; char const *pFileName; PFILE pFileTmp; pathbuf nbuf; int n, o; if (pName[0] == 0) { return pFileHead; } for (pFileTmp = pFileHead; pFileTmp != NULL; pFileTmp = pFileTmp->pFileNext) if (!_stricmp (pName, pFileTmp->pName)) return pFileTmp; if ( pShortName != NULL && GetFileAttributes( pName ) == -1) { pBaseShortName = pShortName; pFileName = pShortName; while (pFileName = strchr(pFileName, '\\')) { pBaseShortName = ++pFileName; } n = strlen (pBaseShortName); for (pFileTmp = pFileHead->pFileNext; pFileTmp != NULL; pFileTmp = pFileTmp->pFileNext) { if (fileext (pFileTmp->pName, nbuf) && !_strnicmp (pBaseShortName, nbuf, n)) { n = pBaseShortName - pShortName; if (n == 0) { return pFileTmp; } if (path (pFileTmp->pName, nbuf) && (o = strlen(nbuf)-n) > 0 && !_strnicmp(nbuf+o, pShortName, n) ) { return pFileTmp; } } } if (fileext (pFileHead->pName, nbuf) && !_strnicmp (pBaseShortName, nbuf, n)) { return pFileHead; } } return NULL; }
void build_asset(std::string const &src) { std::string dst(Reference::makeOutputName(src)); std::string ext = fileext(src); if (ext == "obj") { fprintf(stderr, "Converting obj %s to bin %s with scale %g\n", src.c_str(), dst.c_str(), gScale); obj_to_bin(src.c_str(), dst.c_str(), gScale); } else if (is_supported_bitmap_ext(ext)) { fprintf(stderr, "Converting image %s to %s\n", src.c_str(), dst.c_str()); image_build(src, dst); } else if (ext == "scn") { fprintf(stderr, "Converting scn %s to %s\n", src.c_str(), dst.c_str()); // todo: build scene file by loading it, extracting references, and then saving it copy_file(src, dst); } else { throw std::runtime_error(std::string("Don't know how to build asset: ") + src); } std::string str(dst + "::\t" + src + "\nall::\t" + dst + "\n"); std::string dst_d(dst + ".d"); IxWrite *iw = IxWrite::writeToFile(dst_d.c_str()); iw->write(str.c_str(), str.size()); delete iw; }
static struct sound_loader_t * search_sound_loader(const char * filename) { struct sound_loader_t * loader = &__sound_loader[0]; const char * ext = fileext(filename); if(!ext) return NULL; while(loader && loader->ext) { if(strcasecmp(ext, loader->ext) == 0) return loader; loader++; } return NULL; }
Bitmap *loadFromPath(std::string const &path) { bitmap_init(); Bitmap *ret = NULL; IxRead *ir = IxRead::readFromFile(path.c_str()); try { ret = loadFromData(ir->dataSegment(0, ir->size()), ir->size(), fileext(path)); } catch (...) { delete ir; throw; } delete ir; return ret; }
static std::string rel_path(std::string const &path) { std::string file; if (path.substr(0, 4) == "art/") { file = path.substr(4); } else { // there must be an "art" folder in the path size_t pos = path.find_first_of("/art/"); if (pos == std::string::npos) { throw std::runtime_error(std::string("Cannot make a reference to an asset not in an /art/ directory.\n") + path); } file = path.substr(pos + 5); } std::string ext = fileext(file); std::string subExt = new_ext(ext); return file.substr(0, file.size() - ext.size()) + subExt; }
void MainWindow::on_doItButton_clicked(){ int len=ui->listWidget->count(); if(isoFilename.isEmpty()){ carp("iso not selected"); return; } if(len==0) return; ui->doItButton->setEnabled(false); iso=new Iso(isoFilename); if(!iso->issue.isEmpty()){ carp(iso->issue); delete iso; ui->doItButton->setEnabled(true); return; } QString yum; rwops *rwyum=NULL; if((rwyum=iso->open("/PSP_GAME/USRDIR/YUMFILE_1.BIN"))!=NULL){ yum="/PSP_GAME/USRDIR/YUMFILE_1.BIN"; } else if((rwyum=iso->open("/PSP_GAME/USRDIR/YUMFILE_2.BIN"))!=NULL){ yum="/PSP_GAME/USRDIR/YUMFILE_2.BIN"; } else if((rwyum=iso->open("/PSP_GAME/USRDIR/YUMFILE_3.BIN"))!=NULL){ yum="/PSP_GAME/USRDIR/YUMFILE_3.BIN"; } if(rwyum){ delete rwyum; } else{ delete iso; ui->doItButton->setEnabled(true); carp("None of YUMFILE_1.BIN YUMFILE_2.BIN or YUMFILE_3.BIN were found in iso"); return; } QHash<QString,int> dups; GenericJob *job; QRegExp mifFile("(\\d+)\\.mif\\.png$"); QRegExp imageFile("(\\d+)(-(\\d+)|)(-[a-z]+)?\\.(png|gif|jpe?g|bmp)$"); QRegExp emailFile("(\\d+)\\.mail\\.txt$"); for(int i=0;i<len;i++){ QString file=ui->listWidget->item(i)->text(); QString name=filename(file); QString ext=fileext(file); int no=isanumberfile(name); if(dups.contains(file)){ job=new GenericJob(); job->issue="Skipped: already in the list"; job->state=JOB_STATE_SKIPPED; job->type="NONE"; no=-1; } else if(name.toUpper()=="EBOOT.BIN"){ job=new IsoFileJob(); job->iso_filename="/PSP_GAME/SYSDIR/EBOOT.BIN"; job->type="ISO-FILE"; } else if(file.right(10)==".lines.txt"){ job=new ExecutableLinesJob(); job->iso_filename="/PSP_GAME/SYSDIR/EBOOT.BIN"; job->type="EXEC-LINES"; } else if(emailFile.indexIn(name)!=-1){ YumMailJob *yjob=new YumMailJob(); yjob->number=no=emailFile.cap(1).toInt(); job=yjob; job->iso_filename=yum; job->type="EMAIL"; } else if(no!=-1 && ext=="txt"){ YumScriptJob *yjob=new YumScriptJob(); yjob->number=no; job=yjob; job->iso_filename=yum; job->type="SCRIPT"; } else if(mifFile.indexIn(name)!=-1){ YumMifJob *yjob=new YumMifJob(); yjob->number=no=mifFile.cap(1).toInt(); job=yjob; job->iso_filename=yum; job->type="MIF"; } else if(imageFile.indexIn(name)!=-1){ YumPomJob *yjob=new YumPomJob(); yjob->number=no=imageFile.cap(1).toInt(); bool ok; yjob->subnumber=imageFile.cap(3).toInt(&ok); if(!ok) yjob->subnumber=1; job=yjob; job->iso_filename=yum; job->type="POM"; } else if(no!=-1){ YumFileJob *yjob=new YumFileJob(); yjob->number=no; job=yjob; job->iso_filename=yum; job->type="YUM-FILE"; } else{ job=new GenericJob(); job->state=JOB_STATE_SKIPPED; job->type="NONE"; job->issue="Don't know what to do with this file"; } dups.insert(file,1); job->source=file; if(job->desc.isEmpty()) job->desc=name; jobs.append(job); if(no!=-1){ QList<unsigned short> d=yum_dups(no); for(int i=0;i<d.count();i++){ int n=d.at(i); YumCopyJob *yjob=new YumCopyJob(); yjob->number=no; yjob->target=n; yjob->type="COPY"; yjob->desc=QString("%1.pom").arg(n); yjob->output+=QString("Duplicate of %1").arg(name); yjob->source=job->source; yjob->iso_filename=job->iso_filename; jobs.append(yjob); } } } thread.start(); ok(); }
int _tmain(int argc, _TCHAR* argv[]) { try { po::options_description desc( "Options" ); desc.add_options() ( "help,h", "Show detailed help." ) ( "options,p", "Show parameter information." ) ( "version,p", "Show version information." ) ( "input-file,i", po::value<std::vector<std::string>>(), "Define file(s) for the convertion input." ) ( "input-type,I", po::value<std::vector<std::string>>(), "Define file type(s) for automatic conversion of files in the working directory." ) ( "output-file,o", po::value<std::string>(), "Define file for the convertion output." ) ( "noheader,h", "Disable adding of header support defines." ) ( "const,C", "Define array as const." ) ( "respectcase,r", "Disable converting file types into lower case." ) ( "wxnone,w", "Disable adding of wxWidgets support macro's." ) ( "wxheader,W", po::value<std::string>()->default_value( "wx/wx.h" ), "Select the header that includes wxWidgets (precompiled header?)." ) ( "appendtype,t", "Add the file type at the end of the identifier (myimage_png)." ) ( "text,T", "Disable binary output and use text output, converts feed codes to systems defaults." ) ; po::positional_options_description posdesc; posdesc.add( "input-file", -1 ); po::variables_map opt; po::store( po::command_line_parser( argc, argv ).options( desc ).positional( posdesc ).run(), opt ); po::store( po::parse_config_file( fs::ifstream( fs::path( "default.cfg" ) ), desc ), opt ); po::notify( opt ); std::cout << WXINCLUDE_INFO << std::endl; /* Show options when requested */ if ( opt.count( "options" ) ) { std::cout << desc << std::endl << std::endl; exit( 0 ); } /* Show help when requested */ if ( opt.count( "help" ) ) { std::cout << WXINCLUDE_HELP; std::cout << std::endl << desc << std::endl << std::endl; exit( 0 ); } /* Show version when requested */ if ( opt.count( "version" ) ) { std::cout << WXINCLUDE_VERSION << std::endl; exit( 0 ); } /* Process */ if ( opt.count( "input-file" ) || opt.count( "input-type" ) ) { if ( opt.count( "output-file" ) ) { /* Create timer */ boost::timer timer; /* Create output file */ std::string headername( opt[ "output-file" ].as<std::string>() ); fs::path outputpath( headername ); fs::ofstream output( outputpath, std::ios::out | std::ios::trunc ); /* Use buffer */ char outbuffer[BUFFER_SIZE]; output.rdbuf()->pubsetbuf( outbuffer, BUFFER_SIZE ); if ( !opt.count( "text" ) ) output.setf( std::ios::binary ); if ( !output ) throw std::runtime_error( "Failed to create output file!" ); /* Show status */ std::cout << "Build : file '" << outputpath.leaf() << "'..." << std::endl; /* Get base name of file */ headername = fs::basename( outputpath ); /* Data string stream */ std::ostringstream data; /* Write header start when wanted */ if ( !opt.count( "noheader" ) ) defineheader_start( data, headername, opt.count( "wxnone" ) ? false : true, opt.count( "const" ) ? true : false ); /* Get defined or else default wx header */ std::string includename( opt[ "wxheader" ].as<std::string>() ); /* Write macros when wanted */ if ( !opt.count( "wxnone" ) ) definemacros( data, includename, opt[ "wxheader" ].defaulted() ); /* Common input buffer */ char inbuffer[BUFFER_SIZE]; /* Process input files based on provided list */ if ( opt.count( "input-file" ) ) { std::vector<std::string> files( opt[ "input-file" ].as<std::vector<std::string>>() ); BOOST_FOREACH( std::string& file, files ) { fs::path inputpath( file ); std::string fileext( fs::extension( inputpath ) ); fs::ifstream input( inputpath, std::ios::in | std::ios::binary | std::ios::ate ); input.rdbuf()->pubsetbuf( inbuffer, BUFFER_SIZE ); if ( input.is_open() ) { /* Show status */ std::cout << "Process: file '" << file << "'..." << std::endl; /* Remove extension */ boost::erase_last( file, fileext ); if ( !opt.count( "respectcase" ) ) boost::to_lower( fileext ); /* Append type */ if ( opt.count( "appendtype" ) ) { boost::erase_first( fileext, "." ); /* Static and NO copy constructor for speed */ static boost::format fmt( "%1%_%2%" ); file = boost::str( fmt % file % fileext ); } /* Lower case names when wanted */ if ( !opt.count( "respectcase" ) ) boost::to_lower( file ); /* Process file */ definefile( data, input, file, opt.count( "const" ) ? true : false ); } else { /* Only show warning, other files need to be processed */ std::cout << "Warning: input file '" << file << "' failed to open." << std::endl; } } } /* Process input files based on provided type */ if ( opt.count( "input-type" ) ) { std::vector<std::string> types( opt[ "input-type" ].as<std::vector<std::string>>() ); for ( fs::directory_iterator dir_itr( fs::initial_path() ); dir_itr != fs::directory_iterator(); ++dir_itr ) { BOOST_FOREACH( std::string& type, types ) { /* Normal file? */ if ( fs::is_regular( dir_itr->status() ) ) { /* Wanted type? */ std::string fileext( fs::extension( dir_itr->path() )); bool equals = false; if ( opt.count( "respectcase" ) ) equals = boost::equals( fileext, type ); else equals = boost::iequals( fileext, type ); if ( equals ) { fs::ifstream input( dir_itr->path(), std::ios::in | std::ios::binary | std::ios::ate ); input.rdbuf()->pubsetbuf( inbuffer, BUFFER_SIZE ); std::string file( dir_itr->path().leaf() ); if ( input.is_open() ) { /* Show status */ std::cout << "Process: file '" << file << "'..." << std::endl; /* Remove extension */ boost::erase_last( file, fileext ); /* Append type */ if ( opt.count( "appendtype" ) ) { boost::erase_first( fileext, "." ); /* Static and NO copy constructor for speed */ static boost::format fmt( "%1%_%2%" ); file = boost::str( fmt % file % fileext ); } /* Lower case names when wanted */ if ( !opt.count( "respectcase" ) ) boost::to_lower( file ); /* Process file */ definefile( data, input, file, opt.count( "const" ) ? true : false ); } else { /* Only show warning, other files need to be processed */ std::cout << "Warning: input file '" << file << "' failed to open." << std::endl; } } } } } }
Bitmap *Bitmap::readFromFile(IxRead *file, GLContext *ctx, std::string const &dir, std::string const &filename) { return loadFromData(file->dataSegment(0, file->size()), file->size(), fileext(filename)); }