QString FGame::cachedImage(int size, FGameSizeConstrain fsc, FGameArt imgType ) { QString fscI; if(fsc == FWidth) fscI = "w_"; else fscI = "h_"; QString fName(QString::number(dbId) + "_" + FGameArtToStr(imgType) + "_" + fscI + QString::number(size) + ".png"); QString dir = getCacheDir(); QString cached = dir + "/" + fName; if(QFile(cached).exists()) return cached; else { QString unCached = getArt(imgType); if(unCached == "") return unCached; QPixmap p(unCached); if(fsc == FWidth) p= p.scaledToWidth(size, Qt::SmoothTransformation); else p = p.scaledToHeight(size, Qt::SmoothTransformation); QFile file(cached); file.open(QIODevice::WriteOnly); p.save(&file, "png", 90); file.close(); qDebug() << "Resized " << cached; return cached; } }
void StagePackager::package(const char *stageName, const char *version, bool obfuscate) { bool refresh = true; try { fileManager_->packageStage(getStagesDir().c_str(), stageName, version, getCacheDir().c_str(), getTmpDir().c_str(), obfuscate, false); } catch (FileExistsException *e) { std::stringstream overwriteStream; overwriteStream << "File already exists: " << e->what() << std::endl << std::endl << "OK to overwrite it?"; wxMessageDialog errorMessage(NULL, overwriteStream.str(), "Are you sure?", wxOK | wxCANCEL | wxICON_QUESTION); int r = errorMessage.ShowModal(); if (r == wxID_OK) { fileManager_->packageStage(getStagesDir().c_str(), stageName, version, getCacheDir().c_str(), getTmpDir().c_str(), obfuscate, true); fileManager_->deleteFromCache(getCacheDir().c_str(), e->what()); } else { refresh = false; } delete e; } catch (std::exception *e) { packagingConsole_->clear(); packagingConsole_->Show(); packagingConsole_->println("Packaging stage failed: "); packagingConsole_->print(" "); packagingConsole_->println(e->what()); refresh = false; delete e; } if (refresh) { guiManager_->loadStages(); } }
std::string LLDir::findSkinnedFilename(const std::string &subdir1, const std::string &subdir2, const std::string &filename) const { // generate subdirectory path fragment, e.g. "/foo/bar", "/foo", "" std::string subdirs = ((subdir1.empty() ? "" : mDirDelimiter) + subdir1) + ((subdir2.empty() ? "" : mDirDelimiter) + subdir2); std::vector<std::string> search_paths; search_paths.push_back(getUserSkinDir() + subdirs); // first look in user skin override search_paths.push_back(getSkinDir() + subdirs); // then in current skin search_paths.push_back(getDefaultSkinDir() + subdirs); // then default skin search_paths.push_back(getCacheDir() + subdirs); // and last in preload directory std::string found_file = findFile(filename, search_paths); return found_file; }
QString QStandardPaths::writableLocation(StandardLocation type) { switch (type) { case QStandardPaths::MusicLocation: return getExternalStoragePublicDirectory("DIRECTORY_MUSIC"); case QStandardPaths::MoviesLocation: return getExternalStoragePublicDirectory("DIRECTORY_MOVIES"); case QStandardPaths::PicturesLocation: return getExternalStoragePublicDirectory("DIRECTORY_PICTURES"); case QStandardPaths::DocumentsLocation: if (QtAndroidPrivate::androidSdkVersion() > 18) return getExternalStoragePublicDirectory("DIRECTORY_DOCUMENTS"); else return getExternalStorageDirectory() + QLatin1String("/Documents"); case QStandardPaths::DownloadLocation: return getExternalStoragePublicDirectory("DIRECTORY_DOWNLOADS"); case QStandardPaths::GenericConfigLocation: case QStandardPaths::ConfigLocation: return getFilesDir() + testDir() + QLatin1String("/settings"); case QStandardPaths::GenericDataLocation: return getExternalStorageDirectory() + testDir(); case QStandardPaths::AppDataLocation: case QStandardPaths::AppLocalDataLocation: return getFilesDir() + testDir(); case QStandardPaths::GenericCacheLocation: case QStandardPaths::RuntimeLocation: case QStandardPaths::TempLocation: case QStandardPaths::CacheLocation: return getCacheDir() + testDir(); case QStandardPaths::DesktopLocation: case QStandardPaths::HomeLocation: return getFilesDir(); case QStandardPaths::ApplicationsLocation: case QStandardPaths::FontsLocation: default: break; } return QString(); }
std::string LLDir::getExpandedFilename(ELLPath location, const std::string& subdir1, const std::string& subdir2, const std::string& in_filename) const { std::string prefix; switch (location) { case LL_PATH_NONE: // Do nothing break; case LL_PATH_APP_SETTINGS: prefix = getAppRODataDir(); prefix += mDirDelimiter; prefix += "app_settings"; break; case LL_PATH_CHARACTER: prefix = getAppRODataDir(); prefix += mDirDelimiter; prefix += "character"; break; case LL_PATH_MOTIONS: prefix = getAppRODataDir(); prefix += mDirDelimiter; prefix += "motions"; break; case LL_PATH_HELP: prefix = "help"; break; case LL_PATH_CACHE: prefix = getCacheDir(); break; case LL_PATH_USER_SETTINGS: prefix = getOSUserAppDir(); prefix += mDirDelimiter; prefix += "user_settings"; break; case LL_PATH_PER_SL_ACCOUNT: prefix = getLindenUserDir(); break; case LL_PATH_CHAT_LOGS: prefix = getChatLogsDir(); break; case LL_PATH_PER_ACCOUNT_CHAT_LOGS: prefix = getPerAccountChatLogsDir(); break; case LL_PATH_LOGS: prefix = getOSUserAppDir(); prefix += mDirDelimiter; prefix += "logs"; break; case LL_PATH_TEMP: prefix = getTempDir(); break; case LL_PATH_TOP_SKIN: prefix = getSkinDir(); break; case LL_PATH_SKINS: prefix = getAppRODataDir(); prefix += mDirDelimiter; prefix += "skins"; break; //case LL_PATH_HTML: // prefix = getSkinDir(); // prefix += mDirDelimiter; // prefix += "html"; // break; case LL_PATH_MOZILLA_PROFILE: prefix = getOSUserAppDir(); prefix += mDirDelimiter; prefix += "browser_profile"; break; case LL_PATH_EXECUTABLE: prefix = getExecutableDir(); break; default: llassert(0); } std::string filename = in_filename; if (!subdir2.empty()) { filename = subdir2 + mDirDelimiter + filename; } if (!subdir1.empty()) { filename = subdir1 + mDirDelimiter + filename; } std::string expanded_filename; if (!filename.empty()) { if (!prefix.empty()) { expanded_filename += prefix; expanded_filename += mDirDelimiter; expanded_filename += filename; } else { expanded_filename = filename; } } else if (!prefix.empty()) { // Directory only, no file name. expanded_filename = prefix; } else { expanded_filename.assign(""); } //llinfos << "*** EXPANDED FILENAME: <" << expanded_filename << ">" << llendl; return expanded_filename; }
void TrackingSyncSource::enableServerMode() { SyncSourceAdmin::init(m_operations, this); SyncSourceBlob::init(m_operations, getCacheDir()); }
FramePtr Video::getCurrentFrameRef(){ cv::Mat shot; if (getFrame(shot)) return FramePtr(new Frame(this, shot, getCacheDir())); return FramePtr(NULL); }
void GuiManager::runNewMatch(const char *stageName, char **teamNames, int numUserTeams) { tpsFactor_ = 0.5; nextDrawTime_ = 1; showedResults_ = false; sf::RenderWindow *window; bool maintainWindowScale = false; double prevScale = 1.0; double backingScale = getBackingScaleFactor(); int screenWidth = backingScale * sf::VideoMode::getDesktopMode().width; int screenHeight = backingScale * sf::VideoMode::getDesktopMode().height; int dockSize = backingScale * DOCK_SIZE; if (window_ != 0) { if (restarting_) { prevScale = ((double) (window_->getSize().x - dockSize)) / viewWidth_; maintainWindowScale = true; } } // On Mac OS X, we need to init SFML before the wxWidgets stuff below or we // hit some unexplainable crashes when we delete an SFML window. I don't know // why, I've merely devised a work-around. Judging from some SFML forum // threads, it sounds likely to be an issue with nightmare-ish video drivers. if (window_ == 0) { window = initMainWindow(backingScale * screenWidth, backingScale * (screenHeight - 75)); } else { window = window_; } if (!restarting_) { saveCurrentMatchSettings(stageName, teamNames, numUserTeams); } if (engine_ != 0) { delete engine_; engine_ = 0; } if (restarting_) { stageConsole_->clear(); guiPrintHandler_->restartMode(); } else { destroyStageConsole(); stageConsole_ = new OutputConsole(stageName, CONSOLE_SHIP_STAGE, menuBarMaker_); stageConsole_->Hide(); if (guiPrintHandler_ != 0) { delete guiPrintHandler_; guiPrintHandler_ = 0; } guiPrintHandler_ = new GuiPrintHandler(stageConsole_, 0, menuBarMaker_); } engine_ = new BerryBotsEngine(guiPrintHandler_, fileManager_, resourcePath().c_str()); Stage *stage = engine_->getStage(); if (restarting_) { stage->setGfxEnabled(stageConsole_->isChecked()); } stageConsole_->setListener(new StageConsoleListener(stage)); try { engine_->initStage(getStagesDir().c_str(), stageName, getCacheDir().c_str()); engine_->initShips(getShipsDir().c_str(), teamNames, numUserTeams, getCacheDir().c_str()); teamConsoles_ = guiPrintHandler_->getTeamConsoles(); } catch (EngineException *e) { errorConsole_->print(stageName); errorConsole_->print(": "); errorConsole_->println(e->what()); wxMessageDialog errorMessage(NULL, e->what(), "BerryBots engine init failed", wxOK | wxICON_EXCLAMATION); errorMessage.ShowModal(); delete engine_; engine_ = 0; restarting_ = false; newMatchDialog_->Show(); delete e; return; } viewWidth_ = stage->getWidth() + (STAGE_MARGIN * 2); viewHeight_ = stage->getHeight() + (STAGE_MARGIN * 2); double windowScale; if (restarting_ && maintainWindowScale) { windowScale = prevScale; } else { windowScale = std::min(backingScale, std::min( ((double) screenWidth - dockSize) / viewWidth_, ((double) screenHeight) / viewHeight_)); } unsigned int targetWidth = round(windowScale * viewWidth_) + dockSize; unsigned int targetHeight = round(windowScale * viewHeight_); window->setSize(sf::Vector2u(targetWidth, targetHeight)); interrupted_ = false; paused_ = false; newMatchDialog_->Hide(); packageStageDialog_->Hide(); packageShipDialog_->Hide(); gfxHandler_ = new GfxEventHandler(); stage->addEventHandler((EventHandler*) gfxHandler_); // TODO: If/when SFML getPosition() works, adjust the window position to // keep the whole window on the screen (if necessary). Might be worth // platform-specific implementations using getSystemHandle() if that // doesn't happen in a reasonable timeframe. // We could just set it to (0, 0) or centered on screen every time, but // that seems potentially super annoying to a user - less annoying than // having to move the window occasionally if you switch to a bigger // stage that goes off-screen. gfxManager_->initBbGfx(window, backingScale, viewHeight_, stage, engine_->getTeams(), engine_->getNumTeams(), engine_->getShips(), engine_->getNumShips()); gfxManager_->initViews(window, viewWidth_, viewHeight_); window->setVisible(true); drawFrame(window); #ifdef __WXOSX__ // SFML 2.1+ has a weird scaling issue. Some of it is documented here: // https://github.com/SFML/SFML/issues/474 // Basically, OS X caps the window height, but SFML reports the requested // height instead of the actual height. My work-around is to manually trigger // a resize after drawing one frame. processMainWindowEvents(window, gfxManager_, viewWidth_, viewHeight_); gfxManager_->onResize(window, viewWidth_, viewHeight_); #endif runCurrentMatch(); }
bool GuiManager::isValidShipFile(const char *srcFilename, BerryBotsEngine *engine) { // TODO: Is this too slow? Should we keep this list in the cache so we don't // have to do this on every startup / refresh - at least for packaged // ships? In fact, just the presence in the cache could be considered // a sign of validity. // TODO: Move this out of the GUI code. if (fileManager_->isLuaFilename(srcFilename) || fileManager_->isZipFilename(srcFilename)) { char *shipDir = 0; char *shipFilename = 0; try { fileManager_->loadShipFileData(getShipsDir().c_str(), srcFilename, &shipDir, &shipFilename, getCacheDir().c_str()); } catch (FileNotFoundException *fnfe) { // Only possible if user deletes file from disk after we find it on disk // but before we validate it. Seems safe to fail silently. if (shipDir != 0) { delete shipDir; } if (shipFilename != 0) { delete shipFilename; } delete fnfe; return false; } catch (ZipperException *ze) { if (shipDir != 0) { delete shipDir; } if (shipFilename != 0) { delete shipFilename; } errorConsole_->print(srcFilename); errorConsole_->print(": "); errorConsole_->println(ze->what()); wxMessageDialog errorMessage(NULL, ze->what(), "Unzip failure", wxOK | wxICON_EXCLAMATION); errorMessage.ShowModal(); delete ze; return false; } catch (PackagedSymlinkException *pse) { if (shipDir != 0) { delete shipDir; } if (shipFilename != 0) { delete shipFilename; } errorConsole_->print(srcFilename); errorConsole_->print(": "); errorConsole_->println(pse->what()); delete pse; return false; } lua_State *shipState; initShipState(&shipState, shipDir); if (luaL_loadfile(shipState, shipFilename) || engine->callUserLuaCode(shipState, 0, "", PCALL_VALIDATE)) { logErrorMessage(shipState, "Problem loading ship: %s"); lua_close(shipState); delete shipDir; delete shipFilename; return false; } lua_getglobal(shipState, "configure"); lua_getglobal(shipState, "init"); if (lua_isnil(shipState, -1) || !lua_isnil(shipState, -2)) { lua_close(shipState); delete shipDir; delete shipFilename; return false; } lua_close(shipState); delete shipDir; delete shipFilename; return true; } return false; }
char* GuiManager::getCacheDirCopy() { char *cacheDir = new char[getCacheDir().length() + 1]; strcpy(cacheDir, getCacheDir().c_str()); return cacheDir; }
std::string LLDir::getExpandedFilename(ELLPath location, const std::string& subdir1, const std::string& subdir2, const std::string& in_filename) const { std::string prefix; switch (location) { case LL_PATH_NONE: // Do nothing break; case LL_PATH_APP_SETTINGS: prefix = getAppRODataDir(); prefix += mDirDelimiter; prefix += "app_settings"; break; case LL_PATH_CHARACTER: prefix = getAppRODataDir(); prefix += mDirDelimiter; prefix += "character"; break; case LL_PATH_FS_RESOURCES: prefix = getAppRODataDir(); prefix += mDirDelimiter; prefix += "fs_resources"; break; case LL_PATH_HELP: prefix = "help"; break; case LL_PATH_CACHE: prefix = getCacheDir(); break; case LL_PATH_USER_SETTINGS: prefix = getOSUserAppDir(); prefix += mDirDelimiter; prefix += "user_settings"; break; case LL_PATH_PER_SL_ACCOUNT: prefix = getLindenUserDir(); if (prefix.empty()) { // if we're asking for the per-SL-account directory but we haven't logged in yet (or otherwise don't know the account name from which to build this string), then intentionally return a blank string to the caller and skip the below warning about a blank prefix. return std::string(); } break; case LL_PATH_CHAT_LOGS: prefix = getChatLogsDir(); break; case LL_PATH_PER_ACCOUNT_CHAT_LOGS: prefix = getPerAccountChatLogsDir(); break; case LL_PATH_LOGS: prefix = getOSUserAppDir(); prefix += mDirDelimiter; prefix += "logs"; break; case LL_PATH_TEMP: prefix = getTempDir(); break; case LL_PATH_TOP_SKIN: prefix = getSkinDir(); break; // [SL:KB] - Catznip Viewer-Skins case LL_PATH_TOP_SKINTHEME: prefix = getSkinThemeDir(); break; case LL_PATH_DEFAULT_SKIN: prefix = getDefaultSkinDir(); break; case LL_PATH_USER_SKIN: prefix = getUserSkinDir(); break; case LL_PATH_SKINS: prefix = getSkinBaseDir(); break; case LL_PATH_LOCAL_ASSETS: prefix = getAppRODataDir(); prefix += mDirDelimiter; prefix += "local_assets"; break; case LL_PATH_EXECUTABLE: prefix = getExecutableDir(); break; case LL_PATH_FONTS: prefix = getAppRODataDir(); prefix += mDirDelimiter; prefix += "fonts"; break; default: llassert(0); } std::string filename = in_filename; if (!subdir2.empty()) { filename = subdir2 + mDirDelimiter + filename; } if (!subdir1.empty()) { filename = subdir1 + mDirDelimiter + filename; } if (prefix.empty()) { llwarns << "prefix is empty, possible bad filename" << llendl; } std::string expanded_filename; if (!filename.empty()) { if (!prefix.empty()) { expanded_filename += prefix; expanded_filename += mDirDelimiter; expanded_filename += filename; } else { expanded_filename = filename; } } else if (!prefix.empty()) { // Directory only, no file name. expanded_filename = prefix; } else { expanded_filename.assign(""); } //llinfos << "*** EXPANDED FILENAME: <" << expanded_filename << ">" << llendl; return expanded_filename; }
void StagePreview::showPreview(sf::RenderWindow *window, const char *stageName, int x, int y) { if (stageName_ != 0) { delete stageName_; } stageName_ = new char[strlen(stageName) + 1]; strcpy(stageName_, stageName); SetPosition(wxPoint(x, y)); infoSizer_->Clear(true); descSizer_->Clear(true); BerryBotsEngine *engine = new BerryBotsEngine(0, fileManager_, 0); Stage *stage = engine->getStage(); try { engine->initStage(getStagesDir().c_str(), stageName, getCacheDir().c_str()); } catch (EngineException *e) { wxMessageDialog errorMessage(NULL, e->what(), "Preview failure", wxOK | wxICON_EXCLAMATION); errorMessage.ShowModal(); delete engine; delete e; return; } SetTitle(wxString::Format(wxT("%s"), stage->getName())); unsigned int targetWidth; unsigned int targetHeight; char *previewFilename = savePreviewImage(window, engine, targetWidth, targetHeight); wxImage previewImage(previewFilename); delete previewFilename; double backingScale = getBackingScaleFactor(); if (backingScale > 1) { targetWidth /= backingScale; targetHeight /= backingScale; } visualPreview_->SetMinSize(wxSize(targetWidth, targetHeight)); visualPreview_->SetMaxSize(wxSize(targetWidth, targetHeight)); #ifdef __WXOSX__ int padding = 4; #else int padding = 8; #endif wxSizer *infoGrid = new wxFlexGridSizer(2, 0, padding); addInfo(infoGrid, "Name:", stage->getName()); addInfo(infoGrid, "Size:", wxString::Format(wxT("%i x %i"), stage->getWidth(), stage->getHeight())); if (engine->getTeamSize() > 1) { addInfo(infoGrid, "Team size:", engine->getTeamSize()); } addInfo(infoGrid, "Walls:", (stage->getWallCount() - 4)); addInfo(infoGrid, "Zones:", stage->getZoneCount()); addInfo(infoGrid, "Starts:", stage->getStartCount()); int numStageShips = stage->getStageShipCount(); if (numStageShips > 0) { char **stageShips = stage->getStageShips(); for (int x = 0; x < numStageShips; x++) { const char *shipName = stageShips[x]; if (shipName != 0) { int count = 1; for (int y = x + 1; y < numStageShips; y++) { const char *shipName2 = stageShips[y]; if (shipName2 != 0 && strcmp(shipName, shipName2) == 0) { count++; stageShips[y] = 0; } } wxString wxShipName = (count == 1) ? wxString(stageShips[x]) : wxString::Format(wxT("%s x%i"), shipName, count); addInfo(infoGrid, (x == 0 ? "Ships:" : ""), wxShipName); } } } infoSizer_->Add(infoGrid); char *description = fileManager_->getStageDescription( getStagesDir().c_str(), stageName, getCacheDir().c_str()); if (description == 0) { std::string descstr("<No description>"); description = new char[descstr.length() + 1]; strcpy(description, descstr.c_str()); } wxStaticText *descCtrl = new wxStaticText(mainPanel_, wxID_ANY, description); descSizer_->Add(descCtrl); delete description; mainPanel_->GetSizer()->SetSizeHints(mainPanel_); mainPanel_->Layout(); Fit(); mainPanel_->SetFocus(); wxBitmap bitmap; #ifdef __WINDOWS__ bitmap = wxBitmap(previewImage); #else bitmap.CreateScaled(targetWidth, targetHeight, wxBITMAP_SCREEN_DEPTH, backingScale); wxMemoryDC dc(bitmap); double logicalScale = (backingScale > 1) ? (1.0 / backingScale) : 1; dc.SetLogicalScale(logicalScale, logicalScale); dc.DrawBitmap(wxBitmap(previewImage), 0, 0); #endif // On Windows, if we set the bitmap before the Layout/Fit stuff, we get visual // artifacts when paging through the stages with up/down keys. visualPreview_->SetBitmap(bitmap); delete engine; }