void PlayerWin::loadLuaConfig() { LuaEngine* pEngine = LuaEngine::getInstance(); ScriptEngineManager::getInstance()->setScriptEngine(pEngine); // load player lua core luaopen_PlayerLuaCore(pEngine->getLuaStack()->getLuaState()); luaopen_PlayerLuaCore_Manual(pEngine->getLuaStack()->getLuaState()); // set env string quickRootPath = _project.getQuickCocos2dxRootPath(); quickRootPath = convertPathFormatToUnixStyle(quickRootPath); string env = "__G_QUICK_V3_ROOT__=\""; env.append(quickRootPath); env.append("\""); pEngine->executeString(env.c_str()); // set user home dir lua_pushstring(pEngine->getLuaStack()->getLuaState(), getUserDocumentPath().c_str()); lua_setglobal(pEngine->getLuaStack()->getLuaState(), "__USER_HOME__"); // // ugly: Add the opening project to the "Open Recents" list // lua_pushstring(pEngine->getLuaStack()->getLuaState(), _project.getProjectDir().c_str()); lua_setglobal(pEngine->getLuaStack()->getLuaState(), "__PLAYER_OPEN_TITLE__"); lua_pushstring(pEngine->getLuaStack()->getLuaState(), _project.makeCommandLine().c_str()); lua_setglobal(pEngine->getLuaStack()->getLuaState(), "__PLAYER_OPEN_COMMAND__"); // load player.lua string playerCoreFilePath = quickRootPath + "quick/welcome/src/player.lua"; pEngine->executeScriptFile(playerCoreFilePath.c_str()); }
void FileUtils::setDefaultResourceRootPath(const std::string& path) { LOG_ASSERT(!path.empty(), "setDefaultResourceRootPath:Invalid path."); _resourceRootPath = path; if (_resourceRootPath.back() != '/' || _resourceRootPath.back() != '\\') { _resourceRootPath.push_back('/'); } _resourceRootPath = convertPathFormatToUnixStyle(_resourceRootPath); }
std::string FileUtils::getDirName(const std::string& dirPath)const { std::string tempPath = convertPathFormatToUnixStyle(dirPath); std::string dirName; size_t pos = tempPath.find_last_of('/'); if (pos != std::string::npos) { dirName = tempPath.substr(pos+1, tempPath.length()); } return dirName; }
// // @return: C:/Users/win8/Documents/ // std::string SimulatorWin::getUserDocumentPath() { TCHAR filePath[MAX_PATH]; SHGetSpecialFolderPath(NULL, filePath, CSIDL_PERSONAL, FALSE); int length = 2 * wcslen(filePath); char* tempstring = new char[length + 1]; wcstombs(tempstring, filePath, length + 1); string userDocumentPath(tempstring); delete [] tempstring; userDocumentPath = convertPathFormatToUnixStyle(userDocumentPath); userDocumentPath.append("/"); return userDocumentPath; }
// // @return: C:/Users/win8/Documents/ // std::string PlayerWin::getUserDocumentPath() { TCHAR filePath[MAX_PATH]; SHGetSpecialFolderPath(NULL, filePath, CSIDL_PERSONAL, FALSE); int length = 2 * wcslen(filePath); char *pWideCharStr = convertTCharToANSI(filePath); if (!pWideCharStr) { return string("==Get User Document Path Fail=="); } string userDocumentPath(pWideCharStr); HeapFree(GetProcessHeap(), 0, pWideCharStr); pWideCharStr = NULL; userDocumentPath = convertPathFormatToUnixStyle(userDocumentPath); userDocumentPath.append("/"); return userDocumentPath; }