void FileBrowser::onChangeCartridge(const string &path) { string filename; if(QDir(path).exists()) filename = resolveFilename(path); else filename = path; string info; string image = sprint(nall::basename(filename), ".png"); string patch = sprint(filepath(nall::basename(filename), config().path.patch), ".ups"); if(file::exists(filename)) { if(striend(filename, ".sfc")) { Cartridge::Information cartinfo; if(cartridge.information(filename, cartinfo)) { info << "<small><table>"; info << "<tr><td><b>Title: </b></td><td>" << cartinfo.name << "</td></tr>"; info << "<tr><td><b>Region: </b></td><td>" << cartinfo.region << "</td></tr>"; info << "<tr><td><b>ROM: </b></td><td>" << cartinfo.romSize * 8 / 1024 / 1024 << "mbit</td></tr>"; info << "<tr><td><b>RAM: </b></td><td>"; cartinfo.ramSize ? info << cartinfo.ramSize * 8 / 1024 << "kbit</td></tr>" : info << "None</td></tr>"; info << "</table></small>"; } } else if(striend(filename, ".st")) { unsigned size = file::size(filename); info << "<small><table>"; info << "<tr><td><b>ROM: </b></td><td>" << size * 8 / 1024 / 1024 << "mbit</td></tr>"; info << "</table></small>"; } } if(info == "") info = "<small><font color='#808080'>No preview available</font></small>"; previewInfo->setText(info); previewImage->setStyleSheet(string() << "background: url('" << image << "') center left no-repeat;"); previewApplyPatch->setVisible(file::exists(patch)); }
const File Project::getLocalJuceFolder() { ScopedPointer <ProjectExporter> exp (ProjectExporter::createPlatformDefaultExporter (*this)); if (exp != nullptr) { File f (resolveFilename (exp->getJuceFolder().toString())); if (FileHelpers::isJuceFolder (f)) return f; } return StoredSettings::getInstance()->getLastKnownJuceFolder(); }
void ExternalInfoPlugin::start () { terminate (); if (isBlank (command)) OUTPUT_AND_RETURN (tr ("No command specified")); QString commandProper; QString parameters; SkProcess::splitCommand (commandProper, parameters, command); QString resolved=resolveFilename (commandProper, Settings::instance ().pluginPaths); if (isBlank (resolved)) OUTPUT_AND_RETURN (tr ("Command not found")); if (!QFile::exists (resolved)) OUTPUT_AND_RETURN (tr ("Command does not exist")); if (!process->startAndWait (resolved+notr (" ")+parameters)) OUTPUT_AND_RETURN (tr ("Error: %1").arg (process->getProcess ()->errorString ())); outputText (tr ("Process started")); // Note that on Windows, we may have to add the interpreter explicitly. }
void FileBrowser::onAcceptCartridge(const string &path) { string filename; if(QDir(path).exists()) { filename = resolveFilename(path); } else { filename = path; } if(file::exists(filename)) { close(); config().path.current.cartridge = fileSystemModel->rootPath().toUtf8().constData(); if(cartridgeMode == LoadDirect) { config().path.current.filter = filterBox->currentIndex(); string filter = filterBox->currentText().toUtf8().constData(); if(0); //file extension detection else if(striend(filename, ".sfc")) acceptNormal(filename); else if(striend(filename, ".bs")) acceptBsx(filename); else if(striend(filename, ".st")) acceptSufamiTurbo(filename); else if(striend(filename, ".gb")) acceptSuperGameBoy(filename); else if(striend(filename, ".sgb")) acceptSuperGameBoy(filename); else if(striend(filename, ".gbc")) acceptSuperGameBoy(filename); //filter detection else if(strbegin(filter, "SNES cartridges")) acceptNormal(filename); else if(strbegin(filter, "BS-X cartridges")) acceptBsx(filename); else if(strbegin(filter, "Sufami Turbo cartridges")) acceptSufamiTurbo(filename); else if(strbegin(filter, "Game Boy cartridges")) acceptSuperGameBoy(filename); //fallback behavior else acceptNormal(filename); } else if(cartridgeMode == LoadBase) { loaderWindow->selectBaseCartridge(filename); } else if(cartridgeMode == LoadSlot1) { loaderWindow->selectSlot1Cartridge(filename); } else if(cartridgeMode == LoadSlot2) { loaderWindow->selectSlot2Cartridge(filename); } } }
/** * Converts file names with a given pattern (used for e.g. batch rename) * The pattern is: * <d:3> is replaced with the cIdx value (:3 -> zero padding up to 3 digits) * <c:0> int (0 = no change, 1 = to lower, 2 = to upper) * * if it ends with .jpg we assume a fixed extension. * .<old> is replaced with the fileName extension. * * So a filename could look like this: * some-fixed-name-<c:1><d:3>.<old> * @return QString **/ QString DkFileNameConverter::getConvertedFileName() { QString newFileName = mPattern; QRegExp rx("<.*>"); rx.setMinimal(true); while (rx.indexIn(newFileName) != -1) { QString tag = rx.cap(); QString res = ""; if (tag.contains("<c:")) res = resolveFilename(tag); else if (tag.contains("<d:")) res = resolveIdx(tag); else if (tag.contains("<old>")) res = resolveExt(tag); // replace() replaces all matches - so if two tags are the very same, we save a little computing newFileName = newFileName.replace(tag, res); } return newFileName; }
Error parseLatexLog(const FilePath& logFilePath, LogEntries* pLogEntries) { static boost::regex regexOverUnderfullLines(" at lines (\\d+)--(\\d+)\\s*(?:\\[])?$"); static boost::regex regexWarning("^(?:.*?) Warning: (.+)"); static boost::regex regexWarningEnd(" input line (\\d+)\\.$"); static boost::regex regexLnn("^l\\.(\\d+)\\s"); static boost::regex regexCStyleError("^(.+):(\\d+):\\s(.+)$"); std::vector<std::string> lines; Error error = readStringVectorFromFile(logFilePath, &lines, false); if (error) return error; std::vector<size_t> linesUnwrapped; unwrapLines(&lines, &linesUnwrapped); FilePath rootDir = logFilePath.parent(); FileStack fileStack(rootDir); for (std::vector<std::string>::const_iterator it = lines.begin(); it != lines.end(); it++) { const std::string& line = *it; int logLineNum = (it - lines.begin()) + 1; // We slurp overfull/underfull messages with no further processing // (i.e. not manipulating the file stack) if (beginsWith(line, "Overfull ", "Underfull ")) { std::string msg = line; int lineNum = -1; // Parse lines, if present boost::smatch overUnderfullLinesMatch; if (boost::regex_search(line, overUnderfullLinesMatch, regexOverUnderfullLines)) { lineNum = safe_convert::stringTo<int>(overUnderfullLinesMatch[1], -1); } // Single line case bool singleLine = boost::algorithm::ends_with(line, "[]"); if (singleLine) { msg.erase(line.size()-2, 2); boost::algorithm::trim_right(msg); } pLogEntries->push_back(LogEntry(logFilePath, calculateWrappedLine(linesUnwrapped, logLineNum), LogEntry::Box, fileStack.currentFile(), lineNum, msg)); if (singleLine) continue; for (; it != lines.end(); it++) { // For multi-line case, we're looking for " []" on a line by itself if (*it == " []") break; } // The iterator would be incremented by the outer for loop, must not // let it go past the end! (If we did get to the end, it would // mean the log file was malformed, but we still can't crash in this // situation.) if (it == lines.end()) break; else continue; } fileStack.processLine(line); // Now see if it's an error or warning if (beginsWith(line, "! ")) { std::string errorMsg = line.substr(2); int lineNum = -1; boost::smatch match; for (it++; it != lines.end(); it++) { if (boost::regex_search(*it, match, regexLnn)) { lineNum = safe_convert::stringTo<int>(match[1], -1); break; } } pLogEntries->push_back(LogEntry(logFilePath, calculateWrappedLine(linesUnwrapped, logLineNum), LogEntry::Error, fileStack.currentFile(), lineNum, errorMsg)); // The iterator would be incremented by the outer for loop, must not // let it go past the end! (If we did get to the end, it would // mean the log file was malformed, but we still can't crash in this // situation.) if (it == lines.end()) break; else continue; } boost::smatch warningMatch; if (boost::regex_search(line, warningMatch, regexWarning)) { std::string warningMsg = warningMatch[1]; int lineNum = -1; while (true) { if (boost::algorithm::ends_with(warningMsg, ".")) { boost::smatch warningEndMatch; if (boost::regex_search(*it, warningEndMatch, regexWarningEnd)) { lineNum = safe_convert::stringTo<int>(warningEndMatch[1], -1); } break; } if (++it == lines.end()) break; warningMsg.append(*it); } pLogEntries->push_back(LogEntry(logFilePath, calculateWrappedLine(linesUnwrapped, logLineNum), LogEntry::Warning, fileStack.currentFile(), lineNum, warningMsg)); // The iterator would be incremented by the outer for loop, must not // let it go past the end! (If we did get to the end, it would // mean the log file was malformed, but we still can't crash in this // situation.) if (it == lines.end()) break; else continue; } boost::smatch cStyleErrorMatch; if (boost::regex_search(line, cStyleErrorMatch, regexCStyleError)) { FilePath cstyleFile = resolveFilename(rootDir, cStyleErrorMatch[1]); if (cstyleFile.exists()) { int lineNum = safe_convert::stringTo<int>(cStyleErrorMatch[2], -1); pLogEntries->push_back(LogEntry(logFilePath, calculateWrappedLine(linesUnwrapped, logLineNum), LogEntry::Error, cstyleFile, lineNum, cStyleErrorMatch[3])); } } } return Success(); }
void GPUProgram::reload(const std::string& _code) { std::string code = _code; // If a syntax error occurs while loading the shader we want to break. // However, it makes no sense to break in this loading code when the // error is really in the shader code. To hack this under MSVC we print // out the error as if it were a MSVC error so double clicking will take // us there, then break in this code. To reload the shader we jump back // to the top of the loading routine and try again. bool reloadFromFile = (code == ""); bool ignore = false; LOADSHADER: if (reloadFromFile) { if (fileExists(filename)) { code = readFileAsString(filename); } else { error("Critical Error", std::string("Cannot locate file \"") + filename + "\" to reload it.", true); exit(-1); } } unit = getUnitFromCode(code, extension); glPushAttrib(GL_ALL_ATTRIB_BITS); glEnable(unit); genPrograms(1, &glProgram); bindProgram(unit, glProgram); // Clear the error flag. glGetError(); loadProgram(code); // Check for load errors if ((glGetError() == GL_INVALID_OPERATION) && (! ignore)) { int pos = 0; const unsigned char* msg = NULL; getProgramError(pos, msg); deletePrograms(1, &glProgram); int line = 1; int col = 1; // Find the line and column position. int x = 0; for (x = 0, col = 1; x < pos; ++x, ++col) { if (code[x] == '\n') { ++line; col = 1; } } if (col > 1) { --col; } // Count forward to the end of the line int endCol = col; while ((x < (int)code.size()) && (code[x] != '\n') && (code[x] != '\r')) { ++x; ++endCol; } // Extract the line std::string codeLine = code.substr(pos - col + 1, endCol - col); // Show the line std::string text = format("%s (%d:%d) : %s%s%s", filename.c_str(), line, col, msg, NEWLINE, NEWLINE); text += codeLine + NEWLINE; for (int i = 0; i < col - 1; ++i) { text += " "; } text += "^"; #ifdef G3D_WIN32 { // Print the error message in MSVC format std::string fullFilename = resolveFilename(filename); debugPrintf("%s%s(%d) : GPU Program Error : %s%s%s", NEWLINE, fullFilename.c_str(), line, msg, NEWLINE, NEWLINE); } #endif #ifndef _DEBUG Log::common()->print("\n******************************\n"); Log::common()->print(text); exit(-1); #endif const char* choice[] = {"Debug", "Ignore", "Ignore All", "Exit"}; switch (prompt("Error Loading Program", text.c_str(), choice, 4, true)) { case 0: // Debug { //////////////////////////////////////////////////////////////////////////// // // // PUSH F4 // // // // If your program breaks on this line in debug mode under Windows, // // go to the MSVC Debug window and click on the error message (or // // just press F4 be taken to the error line in your shader. // // // // When you change it and press continue, G3D will try to reload your // // shader (if it came from a file). // // // //////////////////////////////////////////////////////////////////////////// debugBreak(); reloadFromFile = true; goto LOADSHADER; break; } case 1: // Ignore break; case 2: // Ignore all ignore = true; break; case 3: // Exit exit(-1); } } bindingTable.parse(code); glPopAttrib(); }
void test_resolve() { char *path; int pathLen; printf ("Resolve Filename\n"); KeySet *modules = ksNew(0); elektraModulesInit (modules, 0); Plugin *plugin = elektraPluginOpen("resolver", modules, set_pluginconf(), 0); exit_if_fail (plugin, "could not load resolver plugin"); KeySet *test_config = set_pluginconf(); KeySet *config = elektraPluginGetConfig (plugin); succeed_if (config != 0, "there should be a config"); compare_keyset(config, test_config); ksDel (test_config); succeed_if (plugin->kdbOpen != 0, "no open pointer"); succeed_if (plugin->kdbClose != 0, "no open pointer"); succeed_if (plugin->kdbGet != 0, "no open pointer"); succeed_if (plugin->kdbSet != 0, "no open pointer"); succeed_if (plugin->kdbError!= 0, "no open pointer"); succeed_if (!strcmp(plugin->name, "resolver"), "got wrong name"); resolverHandles *h = elektraPluginGetData(plugin); succeed_if (h != 0, "no plugin handle"); resolverClose(&h->system); resolverClose(&h->user); Key *forKey = keyNew("system", KEY_END); succeed_if (resolveFilename(forKey, &h->system, forKey) != -1, "could not resolve filename"); succeed_if (!strcmp(h->system.path, "elektra.ecf"), "path not set correctly"); succeed_if (!strcmp(h->system.filename, KDB_DB_SYSTEM "/elektra.ecf"), "resulting filename not correct"); resolverClose(&h->system); keySetName(forKey, "user"); succeed_if (resolveFilename(forKey, &h->user, forKey) != -1, "could not resolve filename"); pathLen = tempHomeLen + 1 + strlen (KDB_DB_USER) + 12 + 1; path = malloc (pathLen); succeed_if (path != 0, "malloc failed"); snprintf (path, pathLen, "%s/%s/elektra.ecf", tempHome, KDB_DB_USER); succeed_if (!strcmp(h->user.path, "elektra.ecf"), "path not set correctly"); succeed_if (!strcmp(h->user.filename, path), "filename not set correctly"); resolverClose(&h->user); #ifdef HAVE_SETENV unsetenv("USER"); unsetenv("HOME"); keySetName(forKey, "system"); succeed_if (resolveFilename(forKey, &h->system, forKey) != -1, "could not resolve filename"); succeed_if (!strcmp(h->system.path, "elektra.ecf"), "path not set correctly"); succeed_if (!strcmp(h->system.filename, KDB_DB_SYSTEM "/elektra.ecf"), "resulting filename not correct"); resolverClose(&h->system); keySetName(forKey, "user"); succeed_if (resolveFilename(forKey, &h->user, forKey) != -1, "could not resolve filename"); succeed_if (!strcmp(h->user.path, "elektra.ecf"), "path not set correctly"); succeed_if (!strcmp(h->user.filename, KDB_DB_HOME "/" KDB_DB_USER "/elektra.ecf"), "filename not set correctly"); resolverClose(&h->user); setenv("USER","other",1); succeed_if (resolveFilename(forKey, &h->user, forKey) != -1, "could not resolve filename"); succeed_if (!strcmp(h->user.path, "elektra.ecf"), "path not set correctly"); succeed_if (!strcmp(h->user.filename, KDB_DB_HOME "/other/" KDB_DB_USER "/elektra.ecf"), "filename not set correctly"); resolverClose(&h->user); setenv("HOME","/nfshome//max//",1); succeed_if (resolveFilename(forKey, &h->user, forKey) != -1, "could not resolve filename"); succeed_if (!strcmp(h->user.path, "elektra.ecf"), "path not set correctly"); succeed_if (!strcmp(h->user.filename, "/nfshome/max/" KDB_DB_USER "/elektra.ecf"), "filename not set correctly"); resolverClose(&h->user); unsetenv("HOME"); unsetenv("USER"); #endif keySetName(forKey, "user"); succeed_if (resolveFilename(forKey, &h->user, forKey) != -1, "could not resolve filename"); succeed_if (!strcmp(h->user.path, "elektra.ecf"), "path not set correctly"); succeed_if (!strcmp(h->user.filename, KDB_DB_HOME "/" KDB_DB_USER "/elektra.ecf"), "filename not set correctly"); resolverClose(&h->user); keyDel (forKey); elektraPluginClose(plugin, 0); elektraModulesClose(modules, 0); ksDel (modules); free (path); }