int CStatsUtil::DoImportGameStrings() { Poco::Path inpath(m_inputPath); Poco::Path outpath; if( m_outputPath.empty() ) throw runtime_error("Output path unspecified!"); if( utils::isFolder( m_outputPath ) ) { outpath = Poco::Path(m_outputPath).makeAbsolute().makeDirectory(); GameStats gstats( outpath.toString(), m_langconf ); gstats.AnalyzeGameDir(); gstats.ImportStrings( m_inputPath ); gstats.WriteStrings(); } else { outpath = Poco::Path(m_outputPath).makeAbsolute(); if( ! m_flocalestr.empty() ) { auto myloc = std::locale( m_flocalestr ); pmd2::filetypes::WriteTextStrFile( outpath.toString(), utils::io::ReadTextFileLineByLine( m_inputPath, myloc ), myloc ); } else { pmd2::filetypes::WriteTextStrFile( outpath.toString(), utils::io::ReadTextFileLineByLine(m_inputPath) ); } } return 0; }
void ImageReader::loadImages() { namespace fs = boost::filesystem; fs::path inpath(m_infilename); if ( fs::exists(inpath) && fs::is_directory(inpath) ) { for (fs::directory_iterator it(inpath); it != fs::directory_iterator(); it++) { fs::path p(*it); if ( fs::exists(p) && fs::is_regular_file(p) ) { m_filenames.push_back(p.string()); } } std::sort(m_filenames.begin(), m_filenames.end()); } else { m_filenames.push_back(m_infilename); } }
int CStatsUtil::DoExportGameScripts() { //Validate output + input paths Poco::Path inpath(m_inputPath); Poco::Path outpath; if( m_outputPath.empty() ) outpath = inpath.absolute().makeParent().append(DefExportScriptsDir); else outpath = Poco::Path(m_outputPath).makeAbsolute(); Poco::File fTestOut = outpath; if( ! fTestOut.exists() ) { cout << "Created output directory \"" << fTestOut.path() <<"\"!\n"; fTestOut.createDirectory(); } else if( ! fTestOut.isDirectory() ) throw runtime_error("CStatsUtil::DoExportGameScripts(): Output path is not a directory!"); //Setup the script handler GameScripts scripts( inpath.absolute().toString() ); //Convert to XML scripts.ExportScriptsToXML( outpath.toString() ); return 0; }
static void fillpath(void) { char *key=NULL, *tok=NULL, *pathcp, *path = getenv("PATH"); int i = 0; if (!path) return; pathcp = xstrdup(path); for (tok = strtok_r(pathcp, ":", &key); tok; tok = strtok_r(NULL, ":", &key)) { /* make sure we don't repeat the search path */ if (inpath(tok)) continue; pathdir = xrealloc(pathdir, (i + 1) * sizeof(char *)); pathdir[i++] = xstrdup(tok); } pathdir = xrealloc(pathdir, (i + 1) * sizeof(char *)); pathdir[i] = NULL; dirp = pathdir; free(pathcp); }
int CStatsUtil::DoExportAll() { Poco::Path inpath(m_inputPath); Poco::Path outpath; if( m_outputPath.empty() ) { outpath = inpath.absolute().makeParent().append(DefExportAllDir); } else { outpath = Poco::Path(m_outputPath).makeAbsolute(); } GameStats gstats( m_inputPath, m_langconf ); gstats.Load(); //Test output path Poco::File fTestOut = outpath; if( ! fTestOut.exists() ) { cout << "Created output directory \"" << fTestOut.path() <<"\"!\n"; fTestOut.createDirectory(); } gstats.ExportAll(outpath.toString()); return 0; }
void CompressGob::execute() { Common::File stk; Common::File gobConf; uint16 chunkCount; Common::Filename inpath(_inputPaths[0].path); // We output with .stk extension, if there is no specific out file if (_outputPath.empty()) { _outputPath = inpath; } // Open input (config) file gobConf.open(inpath, "r"); // Read the input into memory _chunks = readChunkConf(gobConf, inpath, chunkCount); gobConf.close(); _outputPath.setFullName(inpath.getFullName()); stk.open(_outputPath, "wb"); // Output in compressed format writeEmptyHeader (stk, chunkCount); writeBody(&inpath, stk, _chunks); rewriteHeader(stk, chunkCount, _chunks); }
//For exporting the game strings from the text_*.str file directly int CStatsUtil::DoExportGameStringsFromFile() { Poco::Path inpath(m_inputPath); Poco::Path outpath; if( m_outputPath.empty() ) { outpath = inpath.parent().append(DefExportStrName).makeFile(); } else outpath = Poco::Path(m_outputPath); vector<string> gamestrings = pmd2::filetypes::ParseTextStrFile( inpath.toString(), std::locale(m_flocalestr) ); WriteTextFileLineByLine( gamestrings, outpath.toString() ); return 0; }
int CStatsUtil::DoImportAll() { Poco::Path inpath(m_inputPath); Poco::Path outpath; if( m_outputPath.empty() ) throw runtime_error("Output path is empty!"); if( !utils::isFolder( m_outputPath ) ) throw runtime_error("Output path doesn't exist, or isn't a directory!"); outpath = Poco::Path(m_outputPath); GameStats gstats ( m_outputPath, m_langconf ); gstats.ImportAll( m_inputPath ); gstats.Write(); return 0; }
int CStatsUtil::DoImportGameScripts() { //Validate output + input paths Poco::Path inpath(m_inputPath); Poco::Path outpath; if( m_outputPath.empty() ) throw runtime_error("CStatsUtil::DoImportGameScripts() : Output path is empty!"); if( !utils::isFolder( m_outputPath ) ) throw runtime_error("CStatsUtil::DoImportGameScripts() : Output path doesn't exist, or isn't a directory!"); outpath = Poco::Path(m_outputPath); //Setup the script handler GameScripts scripts( outpath.absolute().toString() ); //Import from XML scripts.ImportScriptsFromXML( inpath.absolute().toString() ); return 0; }
void CompressTouche::execute() { Common::Filename inpath(_inputPaths[0].path); Common::Filename &outpath = _outputPath; if (outpath.getFullName().empty()) { switch(_format) { case AUDIO_MP3: outpath.setFullName(OUTPUT_MP3); break; case AUDIO_VORBIS: outpath.setFullName(OUTPUT_OGG); break; case AUDIO_FLAC: outpath.setFullName(OUTPUT_FLA); break; default: throw ToolException("Unknown audio format"); break; } } compress_sound_data(&inpath, &outpath); }
/* * calcPath - Find a path through the graph * * This uses the "nearest neighbor" algorithm, which simply means that it chooses the * next node based on which one is closest (and which hasn't already been visited). */ int Path::calcPath(Cities c, int start_city) { // Each bit records if a vertex is already included in the path // For thread safety reasons, don't store flag in the City graph std::vector<bool> inpath(c.size(), false); inpath[start_city] = true; // Allow the calling routine to determine the start city (allows multiple/concurrent searches) int curr_city = start_city; path.push_back(start_city); for (int i=1; i<c.size(); i++) { // Scan the "curr_city" row to find nearest (unvisited) neighbor int closest = -1; int closest_cost = INT_MAX; for (int ix=0; ix<c.size(); ix++) { if ((!inpath[ix]) && (cost_matrix.getCost(curr_city, ix) < closest_cost)) { closest = ix; closest_cost = cost_matrix.getCost(curr_city, closest); } } assert(closest != -1); inpath[closest] = true; // add this city to the path path.push_back(closest); pathcost += cost_matrix.getCost(curr_city, closest); // prepare for next iteration curr_city = closest; } // Now add in the cost of the final link back to the initial city pathcost += cost_matrix.getCost(curr_city, start_city); return pathcost; }
int CStatsUtil::DoExportGameStrings() { Poco::Path inpath(m_inputPath); Poco::Path outpath; if( m_outputPath.empty() ) { outpath = inpath.parent().append(DefExportStrName).makeFile(); } else { Poco::File outfilecheck(m_outputPath); //Check if output is a directory if( outfilecheck.exists() && outfilecheck.isDirectory() ) outpath = Poco::Path(m_outputPath).append(DefExportStrName).makeFile(); else outpath = Poco::Path(m_outputPath); } if( !m_forcedLocale ) { cout << "Detecting game language...\n"; GameStats mystats( m_inputPath, m_langconf ); mystats.LoadStrings(); cout << "Writing...\n"; mystats.ExportStrings( outpath.toString() ); } else { cout << "A forced locale string was specified! Skipping game language detection.\n"; vector<string> gamestrings; pmd2::filetypes::ParseTextStrFile( inpath.toString(), std::locale(m_flocalestr) ); WriteTextFileLineByLine( gamestrings, outpath.toString() ); } return 0; }
/* forward a packet - main routing function, all packets pass through here */ static void forward(imc_packet *p) { imc_info *i; int broadcast, isbroadcast; const char *to; imc_reminfo *route; imc_info *direct; imc_connect *c; char recievedfrom[IMC_MAXBUF]; /* SPAM fix - shogar */ imc_connect *rf; /* SPAM fix - shogar */ /* check for duplication, and register the packet in the sequence memory */ if (p->i.sequence && checkrepeat(imc_mudof(p->i.from), p->i.sequence)) return; /* check for packets we've already forwarded */ if (inpath(p->i.path, imc_name)) return; /* check for really old packets */ route=imc_find_reminfo(imc_mudof(p->i.from), 1); if (route) { if ((p->i.sequence+IMC_PACKET_LIFETIME) < route->top_sequence) { imc_stats.sequence_drops++; #ifdef LOG_LATE_PACKETS /* kind of spammy, but late packets are natural when the path is broken between sender and reciever if(imc_is_router) /* spare the muds from seeing this - shogar */ imc_logstring("sequence drop: %s (seq=%ld, top=%ld)", p->i.path, p->i.sequence, route->top_sequence); #endif return; } if (p->i.sequence > route->top_sequence) route->top_sequence=p->i.sequence; } /* update our routing info */ updateroutes(p->i.path); /* forward to our mud if it's for us */ if (!strcmp(imc_mudof(p->i.to), "*") || !strcasecmp(imc_mudof(p->i.to), imc_name)) { strcpy(p->to, imc_nameof(p->i.to)); /* strip the name from the 'to' */ strcpy(p->from, p->i.from); imc_recv(p); } /* if its only to us (ie. not broadcast) don't forward it */ if (!strcasecmp(imc_mudof(p->to), imc_name)) return; /* check if we should just drop it (policy rules) */ if (!can_forward(p)) return; /* convert a specific destination to a broadcast in some cases */ to=imc_mudof(p->i.to); isbroadcast=!strcmp(to, "*"); /* broadcasts are, well, broadcasts */ broadcast=1; /* unless we know better, flood packets */ i=0; /* make gcc happy */ direct=NULL; /* no direct connection to send on */ /* convert 'to' fields that we have a route for to a hop along the route */ if (!isbroadcast && (route=imc_find_reminfo(to, 0)) != NULL && route->route != NULL && !inpath(p->i.path, route->route)) /* avoid circular routing */ { /* check for a direct connection: if we find it, and the route isn't * to it, then the route is a little suspect.. also send it direct */ if (strcasecmp(to, route->route) && (i=imc_getinfo(to))!=NULL && i->connection) direct=i; to=route->route; } /* check for a direct connection */ if (!isbroadcast && (i=imc_getinfo(to)) != NULL && i->connection && !(i->flags & IMC_BROADCAST)) broadcast=0; if (broadcast) { /* need to forward a packet */ /* SPAM fix - hubcnt and who just gave us the packet- shogar */ int hubcnt,fromhub; hubcnt=0; fromhub=0; strcpy(recievedfrom,imc_lastinpath(p->i.path)); for (rf=imc_connect_list; rf; rf=rf->next) { if(rf->info && rf->info->name && !strcmp(recievedfrom,rf->info->name)) { if(rf->info->flags & IMC_HUB) fromhub=1; } } /* end SPAM fix */ for (c=imc_connect_list; c; c=c->next) if (c->state==IMC_CONNECTED) { /* don't forward to sites that have already received it, * or sites that don't need this packet */ if (inpath(p->i.path, c->info->name) || (p->i.stamp & c->info->noforward)!=0) continue; /* SPAM fix - shogar */ if(c->info->flags & IMC_HUB) { if(!imc_is_router) { if (fromhub) continue; if(hubcnt) { continue; } else { hubcnt=1; } } /* if for imc3 we need to do this - shogar */ /* if (imc_getkeyi(&p->data,"channel",0) == 2) continue; */ } /* end SPAM fix */ do_send_packet(c, p); } } else /* forwarding to a specific connection */ { /* but only if they haven't seen it (sanity check) */ if (i->connection && !inpath(p->i.path, i->name)) do_send_packet(i->connection, p); /* send on direct connection, if we have one */ if (direct && direct!=i && direct->connection && !inpath(p->i.path, direct->name)) do_send_packet(direct->connection, p); } }
void ExtractScummMac::execute() { unsigned long file_record_off, file_record_len; unsigned long file_off, file_len; unsigned long data_file_len; char file_name[0x20]; char *buf; unsigned long i; int j; Common::Filename inpath(_inputPaths[0].path); Common::Filename outpath(_outputPath); if (outpath.empty()) outpath.setFullPath("./"); Common::File ifp(inpath, "rb"); /* Get the length of the data file to use for consistency checks */ data_file_len = ifp.size(); /* Read offset and length to the file records */ file_record_off = ifp.readUint32BE(); file_record_len = ifp.readUint32BE(); /* Do a quick check to make sure the offset and length are good */ if (file_record_off + file_record_len > data_file_len) { error("\'%s\'. file records out of bounds.", inpath.getFullPath().c_str()); } /* Do a little consistancy check on file_record_length */ if (file_record_len % 0x28) { error("\'%s\'. file record length not multiple of 40.", inpath.getFullPath().c_str()); } /* Extract the files */ for (i = 0; i < file_record_len; i += 0x28) { /* read a file record */ ifp.seek(file_record_off + i, SEEK_SET); file_off = ifp.readUint32BE(); file_len = ifp.readUint32BE(); ifp.read_throwsOnError(file_name, 0x20); if (!file_name[0]) error("\'%s\'. file has no name.", inpath.getFullPath().c_str()); print("extracting \'%s\'", file_name); /* For convenience compatibility with scummvm (and case sensitive * file systems) change the file name to lowercase. * * if i ever add the ability to pass flags on the command * line, i will make this optional, but i really don't * see the point to bothering */ for (j = 0; j < 0x20; j++) { if (!file_name[j]) { break; } #ifdef CHANGECASE file_name[j] = tolower(file_name[j]); #endif } if (j == 0x20) { file_name[0x1f] = 0; warning("\'%s\'. file name not null terminated.", file_name); print("data file \'%s\' may be not a file extract_scumm_mac can extract.", inpath.getFullPath().c_str()); } print(", saving as \'%s\'", file_name); /* Consistency check. make sure the file data is in the file */ if (file_off + file_len > data_file_len) { error("\'%s\'. file out of bounds.", inpath.getFullPath().c_str()); } /* Write a file */ ifp.seek(file_off, SEEK_SET); outpath.setFullName(file_name); Common::File ofp(outpath, "wb"); if (!(buf = (char *)malloc(file_len))) { error("Could not allocate %ld bytes of memory.", file_len); } ifp.read_throwsOnError(buf, file_len); ofp.write(buf, file_len); free(buf); } }
void makePlots( const char * model, const char * target, const char * src, const char * config, const char * infile) { double MAXY = 2.4; double x_Q13_SetI = sin(8.8*TMath::Pi()/180.0)*sin(8.8*TMath::Pi()/180.0); double x_Q13_SetII = sin(12.0*TMath::Pi()/180.0)*sin(12.0*TMath::Pi()/180.0); //Input path TString inpath("./root_files/RvsQ13/"); TString inputfile = inpath + TString(infile); //Output path TString path("./paper02-plots/ratio/"); TList * v_Variations = new TList(); TObjString *var; var = new TObjString("Sin2Q13-1.8-dCP0"); v_Variations->Add( var ); var = new TObjString("Sin2Q13-1.8-dCP180"); v_Variations->Add( var ); if ( TString(model) != TString("StdPicture") ) { var = new TObjString("Sin2Q13-2.0-dCP0"); v_Variations->Add( var ); var = new TObjString("Sin2Q13-2.0-dCP180"); v_Variations->Add( var ); } else { var = new TObjString("Sin2Q13-2-dCP0"); v_Variations->Add( var ); var = new TObjString("Sin2Q13-2-dCP180"); v_Variations->Add( var ); } var = new TObjString("Sin2Q13-2.2-dCP0"); v_Variations->Add( var ); var = new TObjString("Sin2Q13-2.2-dCP180"); v_Variations->Add( var ); int * linewidth = new int[6]; int * linestyle = new int[6]; int * linecolor = new int[6]; linewidth[0] = 2; linewidth[1] = 3; linewidth[2] = 2; linewidth[3] = 3; linewidth[4] = 2; linewidth[5] = 3; linecolor[0] = 1; linecolor[1] = 2; linecolor[2] = 1; linecolor[3] = 2; linecolor[4] = 1; linecolor[5] = 2; linestyle[0] = 1; linestyle[1] = 1; linestyle[2] = 2; linestyle[3] = 2; linestyle[4] = 3; linestyle[5] = 3; TList * v_Labels = new TList(); TObjString *label; label = new TObjString( "#alpha = 1.8" ); v_Labels->Add( label ); label = new TObjString( "#alpha = 2.0" ); v_Labels->Add( label ); label = new TObjString( "#alpha = 2.2" ); v_Labels->Add( label ); TFile * f1 = new TFile( inputfile.Data() ); f1->cd(); TList * v_Graphs = new TList(); int max = v_Variations->GetEntries(); for( int k = 0; k < max; ++k ) { TString current = ((TObjString*)v_Variations->At(k))->GetString(); TString dataPxx = TString( "Ratio_" ) + TString( model ) + TString("_") + TString( target ) + TString("_") + TString( src ) + TString("_") + TString( current.Data() ) + TString("/data"); std::cout << dataPxx << std::endl; TTree * PxxTreeNu = (TTree*)gDirectory->Get( dataPxx.Data() ); //Branches double xx = 0.0; double yy = 0.0; PxxTreeNu->SetBranchAddress("Xx",&xx); PxxTreeNu->SetBranchAddress("Ratio",&yy); Long64_t nentries = PxxTreeNu->GetEntries(); TGraph * g1 = new TGraph(); for (Long64_t i=0;i<nentries;i++) { PxxTreeNu->GetEntry(i); g1->SetPoint( i, xx, yy); } v_Graphs->Add( g1 ); } TString cname = TString("Ratio") + TString("_") + TString(model) + TString("_") + TString(config); TCanvas * c1 = new TCanvas( cname.Data(), "track/shower ratio", 206,141,722,575); c1->SetBorderSize(2); TLegend * leg = new TLegend(0.18,0.64,0.44,0.87); leg->SetBorderSize(0); leg->SetTextFont(22); leg->SetTextSize(0.062); leg->SetLineColor(1); leg->SetLineStyle(1); leg->SetLineWidth(1); leg->SetFillColor(0); leg->SetFillStyle(0); int labelpos = 0; for( int k = 0; k < max; ++k ) { TGraph * gg = (TGraph*)v_Graphs->At(k); gg->SetMarkerStyle(25); gg->SetFillColor(10); gg->SetLineColor(linecolor[k]); gg->SetLineWidth(linewidth[k]); gg->SetLineStyle(linestyle[k]); gg->SetMaximum(MAXY); gg->SetMinimum(1.6); gg->GetXaxis()->SetLimits( 0.0, 0.055 ); gg->GetXaxis()->SetTitle("sin^{2}#theta_{13}"); gg->GetXaxis()->CenterTitle(true); gg->GetXaxis()->SetLabelFont(42); gg->GetXaxis()->SetLabelOffset(0.006); gg->GetXaxis()->SetLabelSize(0.06); gg->GetXaxis()->SetTitleSize(0.06); gg->GetXaxis()->SetTickLength(0.05); gg->GetXaxis()->SetTitleOffset(1.07); gg->GetXaxis()->SetTitleFont(42); gg->GetXaxis()->SetNdivisions(509); gg->GetYaxis()->SetTitle("R"); gg->GetYaxis()->CenterTitle(true); gg->GetYaxis()->SetNdivisions(509); gg->GetYaxis()->SetLabelFont(42); gg->GetYaxis()->SetLabelOffset(0.007); gg->GetYaxis()->SetLabelSize(0.06); gg->GetYaxis()->SetTitleSize(0.06); gg->GetYaxis()->SetTitleOffset(0.93); gg->GetYaxis()->SetTitleFont(42); if ( ((k+1) % 2) == 0 ) { TString alpha = ((TObjString*)v_Labels->At(labelpos))->GetString(); leg->AddEntry( gg, alpha.Data(),"l"); labelpos+=1; } c1->cd(); if( k == 0 ) gg->Draw("AC"); else gg->Draw("C"); TString ThisModel; TString ThisConfig; if( TString(model) == TString("StdPicture") ) ThisModel = TString("No matter effect"); else { ThisModel = TString(model); ThisModel.Insert(5," "); } ThisConfig = TString(config); ThisConfig.Insert(3," "); TLatex * tex = new TLatex(0.033, (MAXY-(MAXY*0.035)), ThisModel.Data() ); tex->SetLineWidth(2); tex->Draw(); if ( TString(model) != TString("StdPicture") ) { tex = new TLatex(0.033, (MAXY-(MAXY*0.055)), ThisConfig.Data() ); tex->SetLineWidth(2); tex->Draw(); } } leg->Draw(); double y_min = 1.60; double y_max = MAXY; TLine *line = new TLine(x_Q13_SetI, y_min,x_Q13_SetI, y_max); //line->Draw(); line = new TLine(x_Q13_SetII, y_min,x_Q13_SetII, y_max); //line->Draw(); c1->cd(); std::stringstream saveAs; saveAs.str(""); saveAs << path << model << "/pdf/" << "RvsSin2Q13_" << model << "_" << target << "_" << config << ".pdf"; c1->SaveAs( saveAs.str().c_str() ); saveAs.str(""); saveAs << path << model << "/png/" << "RvsSin2Q13_" << model << "_" << target << "_" << config << ".png"; c1->SaveAs( saveAs.str().c_str() ); saveAs.str(""); saveAs << path << model << "/eps/" << "RvsSin2Q13_" << model<< "_" << target << "_" << config << ".eps"; c1->SaveAs( saveAs.str().c_str() ); }
void CompressSword2::execute() { int j; uint32 indexSize; uint32 totalSize; uint32 length; Common::Filename inpath(_inputPaths[0].path); Common::Filename &outpath = _outputPath; if (outpath.empty()) // Extensions change between the in/out files, so we can use the same directory outpath = inpath; switch (_format) { case AUDIO_MP3: _audioOutputFilename = TEMP_MP3; outpath.setExtension(".cl3"); break; case AUDIO_VORBIS: _audioOutputFilename = TEMP_OGG; outpath.setExtension(".clg"); break; case AUDIO_FLAC: _audioOutputFilename = TEMP_FLAC; outpath.setExtension(".clf"); break; default: throw ToolException("Unknown audio format"); break; } _input.open(inpath, "rb"); indexSize = _input.readUint32LE(); totalSize = 12 * (indexSize + 1); if (_input.readUint32BE() != 0xfff0fff0) { error("This doesn't look like a cluster file"); } _output_idx.open(TEMP_IDX, "wb"); _output_snd.open(TEMP_DAT, "wb"); _output_idx.writeUint32LE(indexSize); _output_idx.writeUint32BE(0xfff0fff0); _output_idx.writeUint32BE(0xfff0fff0); for (int i = 0; i < (int)indexSize; i++) { // Update progress, this loop is where most of the time is spent updateProgress(i, indexSize); uint32 pos; uint32 enc_length; _input.seek(8 * (i + 1), SEEK_SET); pos = _input.readUint32LE(); length = _input.readUint32LE(); if (pos != 0 && length != 0) { uint16 prev; Common::File f(TEMP_WAV, "wb"); /* * The number of decodeable 16-bit samples is one less * than the length of the resource. */ length--; /* * Back when this tool was written, encodeAudio() had * no way of encoding 16-bit data, so it was simpler to * output a WAV file. */ f.writeUint32BE(0x52494646); /* "RIFF" */ f.writeUint32LE(2 * length + 36); f.writeUint32BE(0x57415645); /* "WAVE" */ f.writeUint32BE(0x666d7420); /* "fmt " */ f.writeUint32LE(16); f.writeUint16LE(1); /* PCM */ f.writeUint16LE(1); /* mono */ f.writeUint32LE(22050); /* sample rate */ f.writeUint32LE(44100); /* bytes per second */ f.writeUint16LE(2); /* basic block size */ f.writeUint16LE(16); /* sample width */ f.writeUint32BE(0x64617461); /* "data" */ f.writeUint32LE(2 * length); _input.seek(pos, SEEK_SET); /* * The first sample is stored uncompressed. Subsequent * samples are stored as some sort of 8-bit delta. */ prev = _input.readUint16LE(); f.writeUint16LE(prev); for (j = 1; j < (int)length; j++) { byte data; uint16 out; data = _input.readByte(); if (GetCompressedSign(data)) out = prev - (GetCompressedAmplitude(data) << GetCompressedShift(data)); else out = prev + (GetCompressedAmplitude(data) << GetCompressedShift(data)); f.writeUint16LE(out); prev = out; } f.close(); encodeAudio(TEMP_WAV, false, -1, tempEncoded, _format); enc_length = append_to_file(_output_snd, tempEncoded); _output_idx.writeUint32LE(totalSize); _output_idx.writeUint32LE(length); _output_idx.writeUint32LE(enc_length); totalSize = totalSize + enc_length; } else { _output_idx.writeUint32LE(0); _output_idx.writeUint32LE(0); _output_idx.writeUint32LE(0); } } _output_snd.close(); _output_idx.close(); Common::File output(outpath, "wb"); append_to_file(output, TEMP_IDX); append_to_file(output, TEMP_DAT); output.close(); Common::removeFile(TEMP_DAT); Common::removeFile(TEMP_IDX); Common::removeFile(TEMP_MP3); Common::removeFile(TEMP_OGG); Common::removeFile(TEMP_FLAC); Common::removeFile(TEMP_WAV); }
void CStatsUtil::DetermineOperation() { Poco::Path inpath( m_inputPath ); Poco::File infile( inpath ); if( m_operationMode != eOpMode::Invalid ) return; //Skip if we have a forced mode if( !m_outputPath.empty() && !Poco::File( Poco::Path( m_outputPath ).makeAbsolute().parent() ).exists() ) throw runtime_error("Specified output path does not exists!"); if( infile.exists() ) { if( infile.isFile() ) { if( m_hndlStrings ) { if(m_force == eOpForce::Import) { m_operationMode = eOpMode::ImportGameStrings; } else if( m_force == eOpForce::Export ) { m_operationMode = eOpMode::ExportGameStringsFromFile; } } else throw runtime_error("Can't import anything else than strings from a file!"); } else if( infile.isDirectory() ) { if( m_hndlStrings ) { if( m_force == eOpForce::Export ) m_operationMode = eOpMode::ExportGameStrings; else throw runtime_error("Can't import game strings from a directory : " + m_inputPath); } else if( m_hndlItems ) { if( m_force == eOpForce::Export ) m_operationMode = eOpMode::ExportItemsData; else m_operationMode = eOpMode::ImportItemsData; } else if( m_hndlMoves ) { if( m_force == eOpForce::Export ) m_operationMode = eOpMode::ExportMovesData; else m_operationMode = eOpMode::ImportMovesData; } else if( m_hndlPkmn ) { if( m_force == eOpForce::Export ) m_operationMode = eOpMode::ExportPokemonData; else m_operationMode = eOpMode::ImportPokemonData; } else if( m_hndlScripts ) { if( m_force == eOpForce::Export ) m_operationMode = eOpMode::ExportGameScripts; else m_operationMode = eOpMode::ImportGameScripts; } else { if( m_force == eOpForce::Import || isImportAllDir(m_inputPath) ) m_operationMode = eOpMode::ImportAll; else m_operationMode = eOpMode::ExportAll; //If all else fails, try an export all! } } else throw runtime_error("Cannot determine the desired operation!"); } else throw runtime_error("The input path does not exists!"); }