/// Get the full path of the current process. The given filename should be the value of argv[0]. std::string SetDirectory::GetProcessFullPath(const char* filename) { #if defined (WIN32) if (!filename || !filename[0]) { // //return __argv[0]; // int n=0; //LPWSTR wpath = *CommandLineToArgvW(GetCommandLineW(),&n); //if (wpath) //{ // char path[1024]; // memset(path,0,sizeof(path)); // wcstombs(path, wpath, sizeof(path)-1); // if (path[0]) return path; // } TCHAR tpath[1024]; GetModuleFileName(NULL,tpath,1024); std::wstring wprocessPath = tpath; std::string processPath; processPath.assign(wprocessPath.begin(), wprocessPath.end() ); return processPath; } /// \TODO use GetCommandLineW and/or CommandLineToArgvW. This is however not strictly necessary, as argv[0] already contains the full path in most cases. #elif defined (__linux__) if (!filename || filename[0]!='/') { char path[1024]; memset(path,0,sizeof(path)); if (readlink("/proc/self/exe",path,sizeof(path)-1) == -1) msg_error("SetDirectory") << "can't read the contents of the link."; if (path[0]) return path; else msg_error("SetDirectory") << "can't get current process path..." ; } #elif defined (__APPLE__) if (!filename || filename[0]!='/') { char* path = new char[4096]; uint32_t size; if ( _NSGetExecutablePath( path, &size ) != 0) { //realloc delete [] path; path = new char[size]; _NSGetExecutablePath( path, &size ); } std::string finalPath(path); delete [] path; return finalPath; } #endif if(filename) return filename; else return std::string(""); }
void FileLayer::setCurrentPath(string path) { #ifdef _WIN32 char* currentPath = (char*)path.c_str(); char newPath[MAX_PATH]; // check that valid path (and resolve if relative path was passed if (_fullpath(newPath, currentPath, MAX_PATH) == NULL) { throw FileLayerPathNotFound(); } string finalPath(newPath); m_currentPath = finalPath; if (!this->isDirectory(m_currentPath)) { throw FileLayerNotDirectory(); } #endif // _WIN32 #ifdef linux #endif // linux }
FileName getUserSettingsDirectory() { FileName finalPath("./"); #ifdef _WIN32 char homeDir[MAX_PATH] = {0}; if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, homeDir))) { finalPath = FileName::append(homeDir, PROJECT_NAME); } #else /* Expects game settings to be located in ~/.{PROJECT_NAME} (This is a hidden directory within the user's home directory) TODO: Follow the standard universal file hierarchy better */ struct passwd *pwd = getpwuid(getuid()); if(pwd == 0) { perror("Failed to retrieve user information"); finalPath = string("./.") + PROJECT_NAME; } else { finalPath = FileName::append(pwd->pw_dir, string(".") + PROJECT_NAME); } #endif // Ensure that the directory exists createDirectory(finalPath); return finalPath; }
FilePath FileDir::find( const FilePath& fileName ) const { _OC3_DEBUG_BREAK_IF( !isExist() ); if( !fileName.toString().size() ) { return ""; } if( fileName.isExist() ) { return fileName; } FilePath finalPath( addEndSlash().toString() + fileName.toString() ); if( finalPath.isExist() ) { return finalPath; } return fileName; }
bool PluginPackage::load() { if (m_isLoaded) { m_loadCount++; return true; } GOwnPtr<gchar> finalPath(g_strdup(m_path.utf8().data())); while (g_file_test(finalPath.get(), G_FILE_TEST_IS_SYMLINK)) { GOwnPtr<GFile> file(g_file_new_for_path(finalPath.get())); GOwnPtr<GFile> dir(g_file_get_parent(file.get())); GOwnPtr<gchar> linkPath(g_file_read_link(finalPath.get(), 0)); GOwnPtr<GFile> resolvedFile(g_file_resolve_relative_path(dir.get(), linkPath.get())); finalPath.set(g_file_get_path(resolvedFile.get())); } // No joke. If there is a netscape component in the path, go back // to the symlink, as flash breaks otherwise. // See http://src.chromium.org/viewvc/chrome/trunk/src/webkit/glue/plugins/plugin_list_posix.cc GOwnPtr<gchar> baseName(g_path_get_basename(finalPath.get())); if (!g_strcmp0(baseName.get(), "libflashplayer.so") && g_strstr_len(finalPath.get(), -1, "/netscape/")) finalPath.set(g_strdup(m_path.utf8().data())); m_module = g_module_open(finalPath.get(), G_MODULE_BIND_LOCAL); if (!m_module) { LOG(Plugins,"Module Load Failed :%s, Error:%s\n", (m_path.utf8()).data(), g_module_error()); return false; } m_isLoaded = true; NP_InitializeFuncPtr NP_Initialize = 0; m_NPP_Shutdown = 0; NPError npErr; g_module_symbol(m_module, "NP_Initialize", (void**)&NP_Initialize); g_module_symbol(m_module, "NP_Shutdown", (void**)&m_NPP_Shutdown); if (!NP_Initialize || !m_NPP_Shutdown) goto abort; memset(&m_pluginFuncs, 0, sizeof(m_pluginFuncs)); m_pluginFuncs.size = sizeof(m_pluginFuncs); initializeBrowserFuncs(); #if defined(XP_UNIX) npErr = NP_Initialize(&m_browserFuncs, &m_pluginFuncs); #else npErr = NP_Initialize(&m_browserFuncs); #endif if (npErr != NPERR_NO_ERROR) goto abort; m_loadCount++; return true; abort: unloadWithoutShutdown(); return false; }
bool PluginPackage::load() { if (m_isLoaded) { m_loadCount++; return true; } GOwnPtr<gchar> finalPath(g_strdup(m_path.utf8().data())); while (g_file_test(finalPath.get(), G_FILE_TEST_IS_SYMLINK)) { GRefPtr<GFile> file = adoptGRef(g_file_new_for_path(finalPath.get())); GRefPtr<GFile> dir = adoptGRef(g_file_get_parent(file.get())); GOwnPtr<gchar> linkPath(g_file_read_link(finalPath.get(), 0)); GRefPtr<GFile> resolvedFile = adoptGRef(g_file_resolve_relative_path(dir.get(), linkPath.get())); finalPath.set(g_file_get_path(resolvedFile.get())); } // No joke. If there is a netscape component in the path, go back // to the symlink, as flash breaks otherwise. // See http://src.chromium.org/viewvc/chrome/trunk/src/webkit/glue/plugins/plugin_list_posix.cc GOwnPtr<gchar> baseName(g_path_get_basename(finalPath.get())); if (!g_strcmp0(baseName.get(), "libflashplayer.so") && g_strstr_len(finalPath.get(), -1, "/netscape/")) finalPath.set(g_strdup(m_path.utf8().data())); m_module = g_module_open(finalPath.get(), G_MODULE_BIND_LOCAL); if (!m_module) { LOG(Plugins,"Module Load Failed :%s, Error:%s\n", (m_path.utf8()).data(), g_module_error()); return false; } if (moduleMixesGtkSymbols(m_module)) { LOG(Plugins, "Ignoring module '%s' to avoid mixing GTK+ 2 and GTK+ 3 symbols.\n", m_path.utf8().data()); return false; } m_isLoaded = true; if (!g_strcmp0(baseName.get(), "libflashplayer.so")) { // Flash plugin can produce X errors that are handled by the GDK X error handler, which // exits the process. Since we don't want to crash due to flash bugs, we install a // custom error handler to show a warning when a X error happens without aborting. XSetErrorHandler(webkitgtkXError); } NP_InitializeFuncPtr NP_Initialize = 0; m_NPP_Shutdown = 0; NPError npErr; g_module_symbol(m_module, "NP_Initialize", (void**)&NP_Initialize); g_module_symbol(m_module, "NP_Shutdown", (void**)&m_NPP_Shutdown); if (!NP_Initialize || !m_NPP_Shutdown) goto abort; memset(&m_pluginFuncs, 0, sizeof(m_pluginFuncs)); m_pluginFuncs.size = sizeof(m_pluginFuncs); initializeBrowserFuncs(); npErr = NP_Initialize(&m_browserFuncs, &m_pluginFuncs); if (npErr != NPERR_NO_ERROR) goto abort; m_loadCount++; return true; abort: unloadWithoutShutdown(); return false; }