std::string ApplicationContextImpl::getRuntimeDataPath() const { #if defined(POSIX) && defined (PKGDATADIR) return std::string(PKGDATADIR) + "/"; #else return getApplicationPath(); #endif }
Tab::Tab(Browser* browser) : m_id(nextTabId++) , m_browser(browser) { // FIXME Find a good way to find where the injected bundle is WKStringRef wkStr = WKStringCreateWithUTF8CString((getApplicationPath() + "/../ContentsInjectedBundle/libPageBundle.so").c_str()); m_context = WKContextCreateWithInjectedBundlePath(wkStr); WKRelease(wkStr); init(); }
/** * \return Path to the application plugins folder. */ QString RSettings::getPluginPath() { QDir appDir = QDir(getApplicationPath()); #ifdef Q_OS_MAC if (isDeployed()) { appDir.cdUp(); } #endif QString pluginFolder = "plugins"; #ifdef Q_OS_MAC pluginFolder = "PlugIns"; #endif if (!appDir.cd(pluginFolder)) { qWarning() << QString("Folder '%1' does not exist").arg(pluginFolder); return QString(); } return appDir.path(); }
void Application::init(const string &name) { if(glfwInit() == GL_FALSE) { throw runtime_error("Could not initialize GLFW"); } vector<int> hint { GLFW_CONTEXT_VERSION_MAJOR, 3, GLFW_CONTEXT_VERSION_MINOR, 2, GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE, GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE, GLFW_DEPTH_BITS, 16, GLFW_SAMPLES, 4, GLFW_REFRESH_RATE, 60, }; for (size_t h = 0; h < hint.size(); h += 2) glfwWindowHint(hint[h], hint[h+1]); ivec2 size(640, 480); m_window = glfwCreateWindow(size.x, size.y, name.c_str(), nullptr, nullptr); if (!m_window) { throw runtime_error("OpenGL initialization failed, invalid window hints"); } glfwMakeContextCurrent(m_window); #ifndef EMSCRIPTEN if(gl3wInit()) { throw runtime_error("failed to initialize gl3w"); } FMOD_RESULT result = FMOD::System_Create(&m_audio); checkError(result); result = m_audio->init(100, FMOD_INIT_NORMAL, nullptr); checkError(result); printf("ApplicationPath: %s\n", getApplicationPath()->c_str()); printf("ResourcePath: %s\n", getResourcePath()->c_str()); #else audioInit(); #endif // shader test auto handleVertex = glCreateShader(GL_VERTEX_SHADER); auto handleFragment = glCreateShader(GL_FRAGMENT_SHADER); string sourceVertexStr = "#version 150\n in vec3 a_pos; void main() { }"; string sourceFragmentStr = "#version 150\n in vec3 a_pos; out vec4 o_fragColor; void main() { o_fragColor = vec4(1, 0, 1, 1); }"; const GLchar *sv = sourceVertexStr.c_str(); const GLchar *sf = sourceVertexStr.c_str(); auto check = [](GLuint handle) { GLint status; glGetShaderiv(handle, GL_COMPILE_STATUS, &status); if (status == GL_FALSE) { GLint logLength; glGetShaderiv(handle, GL_INFO_LOG_LENGTH, &logLength); GLchar *logStr = new GLchar[logLength + 1]; glGetShaderInfoLog(handle, logLength, nullptr, logStr); fprintf(stderr, "Shader compiler error:\n%s\n", logStr); delete[] logStr; } }; glShaderSource(handleVertex, 1, &sv, nullptr); glShaderSource(handleFragment, 1, &sf, nullptr); glCompileShader(handleVertex); check(handleVertex); glCompileShader(handleFragment); check(handleFragment); GLint status; auto handleProgram = glCreateProgram(); glAttachShader(handleProgram, handleVertex); glAttachShader(handleProgram, handleFragment); glLinkProgram(handleProgram); glGetProgramiv(handleProgram, GL_LINK_STATUS, &status); if (status == GL_FALSE) { GLint logLength; glGetProgramiv(handleProgram, GL_INFO_LOG_LENGTH, &logLength); GLchar *logStr = new GLchar[logLength + 1]; glGetProgramInfoLog(handleProgram, logLength, nullptr, logStr); fprintf(stderr, "Linker error:\n%s\n", logStr); delete[] logStr; return; } glDetachShader(handleProgram, handleVertex); glDetachShader(handleProgram, handleFragment); }
int SimulatorWin::run() { auto player = player::PlayerWin::create(); INITCOMMONCONTROLSEX InitCtrls; InitCtrls.dwSize = sizeof(InitCtrls); InitCtrls.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&InitCtrls); parseCocosProjectConfig(_project); // load project config from command line args vector<string> args; for (int i = 0; i < __argc; ++i) { wstring ws(__wargv[i]); string s; s.assign(ws.begin(), ws.end()); args.push_back(s); } _project.parseCommandLine(args); if (_project.getProjectDir().empty()) { if (args.size() == 2) { // for Code IDE before RC2 _project.setProjectDir(args.at(1)); _project.setDebuggerType(kCCRuntimeDebuggerCodeIDE); } } // create the application instance _app = new AppDelegate(); _app->setProjectConfig(_project); // create console window if (_project.isShowConsole()) { AllocConsole(); _hwndConsole = GetConsoleWindow(); if (_hwndConsole != NULL) { ShowWindow(_hwndConsole, SW_SHOW); BringWindowToTop(_hwndConsole); freopen("CONOUT$", "wt", stdout); freopen("CONOUT$", "wt", stderr); HMENU hmenu = GetSystemMenu(_hwndConsole, FALSE); if (hmenu != NULL) { DeleteMenu(hmenu, SC_CLOSE, MF_BYCOMMAND); } } } // log file if (_project.isWriteDebugLogToFile()) { const string debugLogFilePath = _project.getDebugLogFilePath(); _writeDebugLogFile = fopen(debugLogFilePath.c_str(), "w"); if (!_writeDebugLogFile) { CCLOG("Cannot create debug log file %s", debugLogFilePath.c_str()); } } // set environments SetCurrentDirectoryA(_project.getProjectDir().c_str()); FileUtils::getInstance()->setDefaultResourceRootPath(_project.getProjectDir()); FileUtils::getInstance()->setWritablePath(_project.getWritableRealPath().c_str()); // check screen DPI HDC screen = GetDC(0); int dpi = GetDeviceCaps(screen, LOGPIXELSX); ReleaseDC(0, screen); // set scale with DPI // 96 DPI = 100 % scaling // 120 DPI = 125 % scaling // 144 DPI = 150 % scaling // 192 DPI = 200 % scaling // http://msdn.microsoft.com/en-us/library/windows/desktop/dn469266%28v=vs.85%29.aspx#dpi_and_the_desktop_scaling_factor // // enable DPI-Aware with DeclareDPIAware.manifest // http://msdn.microsoft.com/en-us/library/windows/desktop/dn469266%28v=vs.85%29.aspx#declaring_dpi_awareness float screenScale = 1.0f; if (dpi >= 120 && dpi < 144) { screenScale = 1.25f; } else if (dpi >= 144 && dpi < 192) { screenScale = 1.5f; } else if (dpi >= 192) { screenScale = 2.0f; } CCLOG("SCREEN DPI = %d, SCREEN SCALE = %0.2f", dpi, screenScale); // create opengl view Size frameSize = _project.getFrameSize(); float frameScale = 1.0f; if (_project.isRetinaDisplay()) { frameSize.width *= screenScale; frameSize.height *= screenScale; } else { frameScale = screenScale; } const Rect frameRect = Rect(0, 0, frameSize.width, frameSize.height); const bool isResize = _project.isResizeWindow(); std::stringstream title; title << "Cocos Simulator - " << ConfigParser::getInstance()->getInitViewName(); initGLContextAttrs(); auto glview = GLViewImpl::createWithRect(title.str(), frameRect, frameScale); _hwnd = glview->getWin32Window(); DragAcceptFiles(_hwnd, TRUE); //SendMessage(_hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon); //SendMessage(_hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon); //FreeResource(icon); auto director = Director::getInstance(); director->setOpenGLView(glview); director->setAnimationInterval(1.0 / 60.0); // set window position if (_project.getProjectDir().length()) { setZoom(_project.getFrameScale()); } Vec2 pos = _project.getWindowOffset(); if (pos.x != 0 && pos.y != 0) { RECT rect; GetWindowRect(_hwnd, &rect); MoveWindow(_hwnd, pos.x, pos.y, rect.right - rect.left, rect.bottom - rect.top, FALSE); } // path for looking Lang file, Studio Default images FileUtils::getInstance()->addSearchPath(getApplicationPath().c_str()); // init player services initServices(); setupUI(); DrawMenuBar(_hwnd); // prepare FileUtils::getInstance()->setPopupNotify(false); _project.dump(); auto app = Application::getInstance(); g_oldWindowProc = (WNDPROC)SetWindowLong(_hwnd, GWL_WNDPROC, (LONG)SimulatorWin::windowProc); // update window size RECT rect; GetWindowRect(_hwnd, &rect); MoveWindow(_hwnd, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top + GetSystemMetrics(SM_CYMENU), FALSE); // startup message loop return app->run(); }
TEST(CorePlatformApplicationTests, sanity) { boost::filesystem::path appPath = getApplicationPath(); EXPECT_STREQ("core-unit_test", appPath.stem().generic_string().c_str()); }
Setting::Setting() : Misc<QString>() { // list of parameters to be read/saved at start/end // true -> delete items when they are removed list.setAutoDelete(true); clearList(); // defaults: writeBoolEntry("USE_NMATCH", true); writeBoolEntry("NMATCH_BLACK", true); writeBoolEntry("NMATCH_WHITE", true); writeBoolEntry("NMATCH_NIGIRI", true); writeIntEntry("NMATCH_HANDICAP", 9); writeIntEntry("NMATCH_MAIN_TIME", 100); writeIntEntry("NMATCH_BYO_TIME", 100); writeBoolEntry("SIDEBAR", true); writeBoolEntry("BOARD_COORDS", true); writeBoolEntry("SGF_BOARD_COORDS", false); writeBoolEntry("CURSOR", true); writeBoolEntry("SLIDER", true); writeBoolEntry("FILEBAR", true); writeBoolEntry("TOOLBAR", true); writeBoolEntry("MAINTOOLBAR", true); writeBoolEntry("EDITBAR", true); writeBoolEntry("STATUSBAR", true); writeBoolEntry("MENUBAR", true); writeEntry("SKIN", ""); writeEntry("SKIN_TABLE", ""); writeBoolEntry("TOOLTIPS", true); //writeBoolEntry("STONES_SHADOW", true); //writeBoolEntry("STONES_SHELLS", true); writeBoolEntry("VAR_FONT", true); writeBoolEntry("SOUND_STONE", true); writeBoolEntry("SOUND_AUTOPLAY", true); writeBoolEntry("SOUND_TALK", true); writeBoolEntry("SOUND_MATCH", true); writeBoolEntry("SOUND_GAMEEND", true); writeBoolEntry("SOUND_PASS", true); writeBoolEntry("SOUND_TIME", true); writeBoolEntry("SOUND_SAY", true); writeBoolEntry("SOUND_ENTER", true); writeBoolEntry("SOUND_LEAVE", true); writeBoolEntry("SOUND_DISCONNECT", true); writeBoolEntry("SOUND_CONNECT", true); writeIntEntry("TIMER_INTERVAL", 1); writeBoolEntry("SGF_TIME_TAGS", true); writeIntEntry("DEFAULT_SIZE", 19); writeIntEntry("DEFAULT_TIME", 10); writeIntEntry("DEFAULT_BY", 10); writeIntEntry("BY_TIMER", 10); writeIntEntry("COMPUTER_SIZE", 19); writeEntry("LAST_DIR", QDir::homeDirPath()); //#ifdef Q_OS_MACX writeBoolEntry("REM_DIR", true); writeIntEntry("STONES_LOOK", 3); //#endif // Default ASCII import charset charset = new ASCII_Import(); charset->blackStone = '#'; charset->whiteStone = 'O'; charset->starPoint = ','; charset->emptyPoint = '.'; charset->hBorder = '|'; charset->vBorder = '-'; addImportAsBrother = false; fastLoad = false; language = "Default"; fontStandard = QFont(); fontMarks = QFont(); fontComments = QFont(); fontLists = QFont(); fontClocks = QFont(); fontConsole= QFont("Fixed"); colorBackground = QColor("white"); colorAltBackground = QColor(242,242,242,QColor::Rgb); // init qgo = 0; cw = 0; program_dir = QString(); nmatch_settings_modified=false; #ifdef Q_WS_WIN applicationPath = getApplicationPath(); #endif //#ifdef USE_XPM image0 = QPixmap((const char **)Bowl_xpm); //#else // image0 = QPixmap(ICON_APPICON); //#endif }
namespace core { //===========================================================================// const std::string APPLICATION_PATH = getApplicationPath(); const std::string INSTALL_PATH = getInstallPath(APPLICATION_PATH); const std::string DATA_PATH = path::join(INSTALL_PATH, "data"); const std::string BINARY_PATH = path::join(INSTALL_PATH, "bin"); namespace path { //===========================================================================// std::vector<std::string> split(const std::string& input) { std::vector<std::string> elements; for (const auto& curr : boost::filesystem::path(input)) { elements.push_back(curr.filename().string()); } return elements; } //===========================================================================// std::string join(const std::string& start, const std::string& end) { boost::filesystem::path path(start); path /= end; path.normalize(); return path.string(); } //===========================================================================// bool exists(const std::string& pathname) { return boost::filesystem::exists(pathname); } //===========================================================================// std::vector<std::string> listDirectory(const std::string& pathname) { boost::filesystem::path path(pathname); std::vector<std::string> ret; for (auto iter = boost::filesystem::directory_iterator(path); iter != boost::filesystem::directory_iterator(); ++iter) { if (!boost::filesystem::is_directory(iter->path())) { ret.push_back(iter->path().filename().string()); } } return ret; } //===========================================================================// std::string getExtension(const std::string& pathname, size_t iterations) { std::string extension; std::string fullExtension; boost::filesystem::path base = pathname; size_t iter = 0; do { extension = boost::filesystem::extension(base); fullExtension = extension + fullExtension; base = base.stem(); ++iter; } while (!extension.empty() && (iter < iterations || !iterations)); return fullExtension; } //===========================================================================// std::string getBase(const std::string& pathname) { return boost::filesystem::path(pathname).filename().stem().string(); } //===========================================================================// std::string getDirectory(const std::string& pathname) { boost::filesystem::path boostPath(pathname); if (boost::filesystem::is_directory(boostPath)) { return pathname; } const std::string path = boostPath.parent_path().string(); return path.empty() ? "." : path + "/"; } //===========================================================================// std::string getFilename(const std::string& pathname) { boost::filesystem::path boostPath(pathname); if (boost::filesystem::is_directory(boostPath)) { return ""; } return boostPath.filename().string(); } //===========================================================================// void makeDirectory(const std::string& path) { boost::filesystem::create_directories(path); } //===========================================================================// void removeAll(const std::string& path) { boost::filesystem::remove_all(path); } } }
//-------------------------------------------------------------- string BaseModel::getApplicationName(){ if(applicationName == ""){ getApplicationPath(); } return applicationName; }