Inventory::Inventory() { std::ifstream ifs("recipes/ENABLED_RECIPES.cfg"); if(ifs.fail()) { ifs.close(); return; } std::string temp; std::vector<std::string> receiptFiles; std::string text; while(getline(ifs, temp)) { //If empty line if(temp.size() == 0) continue; // If commentline -> skip to next if(temp[0] == COMMENTPREFIX) continue; receiptFiles.push_back(temp + ".recipe"); } ifs.close(); for(unsigned int i = 0; i < receiptFiles.size(); i++) { readRecipe("recipes/" + receiptFiles[i]); } }
void RezkonvImporter::parseFile( const QString &filename ) { QFile input( filename ); if ( input.open( QIODevice::ReadOnly ) ) { QTextStream stream( &input ); stream.skipWhiteSpace(); QString line; while ( !stream.atEnd() ) { line = stream.readLine(); if ( line.contains( QRegExp( "^=====.*REZKONV.*", Qt::CaseInsensitive ) ) ) { QStringList raw_recipe; while ( !( line = stream.readLine() ).contains( QRegExp( "^=====\\s*$" ) ) && !stream.atEnd() ) raw_recipe << line; readRecipe( raw_recipe ); } } if ( fileRecipeCount() == 0 ) setErrorMsg( i18n( "No recipes found in this file." ) ); } else setErrorMsg( i18n( "Unable to open file." ) ); }
int generateRandom(char* filename,int* values) { Recipe* r=readRecipe(filename); //read files; int resul=getvalues(r, values); freeRecipe(r); return resul;// get list of int }
Inventory::Inventory(const std::string& path, const std::string& suffix, const std::string& cfg) { std::vector<std::string> receiptFiles; getEnabledRecipes( receiptFiles, cfg); for (unsigned int i = 0; i < receiptFiles.size(); i++) { readRecipe(path + '/' + receiptFiles[i]); } }
void MX2Importer::parseFile( const QString& filename ) { QFile file( filename ); kDebug() << "loading file: " << filename ; if ( file.open( QIODevice::ReadOnly ) ) { kDebug() << "file opened" ; QDomDocument doc; //hopefully a temporary hack, since MasterCook creates invalid xml declarations QTextStream stream( &file ); QString all_data = stream.readAll(); if ( all_data.startsWith( "<?xml" ) ) all_data.remove( 0, all_data.indexOf( "?>" ) + 2 ); QString error; int line; int column; if ( !doc.setContent( all_data, &error, &line, &column ) ) { kDebug() << QString( "error: \"%1\" at line %2, column %3" ).arg( error ).arg( line ).arg( column ) ; setErrorMsg( i18n( "\"%1\" at line %2, column %3. This may not be a *.mx2 file.", error, line, column ) ); return ; } QDomElement mx2 = doc.documentElement(); // TODO Check if there are changes between versions if ( mx2.tagName() != "mx2" /*|| mx2.attribute("source") != "MasterCook 5.0"*/ ) { setErrorMsg( i18n( "This file does not appear to be a *.mx2 file" ) ); return ; } QDomNodeList l = mx2.childNodes(); for ( int i = 0; i < l.count(); i++ ) { QDomElement el = l.item( i ).toElement(); if ( el.tagName() == "RcpE" ) { Recipe recipe; recipe.title = el.attribute( "name" ); Element author( el.attribute( "author" ) ); recipe.authorList.append( author ); readRecipe( el.childNodes(), &recipe ); add ( recipe ); } } } else setErrorMsg( i18n( "Unable to open file." ) ); }
Inventory::Inventory() { std::ifstream ifs(std::string(RECIPE_PATH + RECIPE_LIST).c_str()); if (ifs.fail()) { ifs.close(); return; } std::string temp; std::vector<std::string> receiptFiles; std::string text; while (getline(ifs, temp)) { //If empty line if (temp.size() == 0) { continue; } // If commentline -> skip to next if (temp[0] == COMMENTPREFIX) { continue; } receiptFiles.push_back(temp + RECIPE_SUFFIX); } ifs.close(); for (unsigned int i = 0; i < receiptFiles.size(); i++) { readRecipe(RECIPE_PATH + receiptFiles[i]); } }