// Callback when a registry key is changed void GameManager::keyChanged (const std::string& key, const std::string& val) { const std::string path = GlobalRegistry().get(RKEY_ENGINE_PATH); if (_enginePath != path) { _enginePathObservers.unrealise(); _enginePath = path; _cleanedEnginePath = DirectoryCleaned(_enginePath); _enginePathObservers.realise(); } }
void FileSystem::initDirectory (const std::string& directory) { ArchiveModules& archiveModules = FileSystemAPI_getArchiveModules(); std::string path = DirectoryCleaned(directory); g_strDirs.push_back(path); { ArchiveEntry entry; entry.name = path; entry.archive = OpenDirArchive(path); entry.is_pakfile = false; g_archives.push_back(entry); } if (g_bUsePak) { GDir* dir = g_dir_open(path.c_str(), 0, 0); if (dir != 0) { g_message("vfs directory: %s\n", path.c_str()); Archives archives; Archives archivesOverride; for (;;) { const char* name = g_dir_read_name(dir); if (name == 0) break; const char *ext = strrchr(name, '.'); if ((ext == 0) || *(++ext) == '\0' || GetArchiveTable(archiveModules, ext) == 0) continue; archives.insert(name); } g_dir_close(dir); // add the entries to the vfs for (Archives::iterator i = archivesOverride.begin(); i != archivesOverride.end(); ++i) { std::string filename = path + *i; initPK3File(filename); } for (Archives::iterator i = archives.begin(); i != archives.end(); ++i) { std::string filename = path + *i; initPK3File(filename); } } else { g_message("vfs directory not found: '%s'\n", path.c_str()); } } }
/** * @brief Loads the game description file */ void GameManager::initialise () { #ifdef PKGDATADIR if (!settingsValid()) { _enginePath = PKGDATADIR; _cleanedEnginePath = DirectoryCleaned(_enginePath); GlobalRegistry().set(RKEY_ENGINE_PATH, _enginePath); } #endif if (!settingsValid()) { _enginePath = Win32Registry::getKeyValue("Software\\UFOAI", "ufo.exe"); _cleanedEnginePath = DirectoryCleaned(_enginePath); GlobalRegistry().set(RKEY_ENGINE_PATH, _enginePath); } // Check loop, continue, till the user specifies a valid setting while (!settingsValid()) { // Engine path doesn't exist, ask the user ui::PathsDialog dialog; if (!settingsValid()) { std::string msg(_("<b>Warning:</b>\n")); if (!file_exists(_enginePath)) { msg += _("Engine path does not exist."); msg += "\n"; } msg += _("Do you want to correct these settings?"); EMessageBoxReturn ret = gtk_MessageBox(NULL, msg, _("Invalid Settings"), eMB_YESNO); if (ret == eIDNO) { break; } } } }
void ModelSelector::loadDirectory(const std::string& path) { if (path.empty()) return; // Modal dialog window to display progress gtkutil::ModalProgressDialog dialog(GlobalRadiant().getMainWindow(), string::format(_("Loading models %s"), path.c_str())); // Populate the treestore using the VFS callback functor ModelFileFunctor functor(_treeStore, dialog, DirectoryCleaned(path), _dirIterMap); functor.setDirectory(true); GlobalFileSystem().forEachDirectory(path, makeCallback1(functor), 1); functor.setDirectory(false); GlobalFileSystem().forEachFile(path, "*", makeCallback1(functor), 1); }
void Environment::init(int argc, char* argv[]) { _homePath = getHomeDir(); #ifdef PKGDATADIR _appPath = std::string(PKGDATADIR) + "/" + RADIANT_DIRECTORY; if (!(g_file_test(_appPath.c_str(), (GFileTest)G_FILE_TEST_IS_DIR) && g_path_is_absolute(_appPath.c_str()))) #endif { gchar *currentDir = g_get_current_dir(); _appPath = DirectoryCleaned(currentDir); g_free(currentDir); } initPaths(); }
std::string Environment::getHomeDir () { const gchar *home; #ifdef _WIN32 home = g_get_user_config_dir(); const std::string RADIANT_HOME = "UFOAI/"; #else home = g_get_home_dir(); const std::string RADIANT_HOME = ".ufoai/"; #endif const std::string cleaned = DirectoryCleaned(home); return cleaned + RADIANT_HOME + RADIANT_DIRECTORY; }
std::size_t FileSystem::loadFile (const std::string& filename, void **buffer) { AutoPtr<ArchiveFile> file(openFile(DirectoryCleaned(filename))); if (file) { *buffer = malloc(file->size() + 1); // we need to end the buffer with a 0 ((char*) (*buffer))[file->size()] = 0; std::size_t length = file->getInputStream().read((InputStream::byte_type*) *buffer, file->size()); return length; } *buffer = 0; return 0; }
GameManager::GameManager () : _currentGameDescription(0), _enginePath(GlobalRegistry().get(RKEY_ENGINE_PATH)), _cleanedEnginePath( DirectoryCleaned(_enginePath)), _emptyString("") { GlobalRegistry().addKeyObserver(this, RKEY_ENGINE_PATH); // greebo: Register this class in the preference system so that the constructPreferencePage() gets called. GlobalPreferenceSystem().addConstructor(this); // TODO Remove this and read the game.xml data from the xmlregistry, too std::string strGameFilename = Environment::Instance().getAppPath() + "game.xml"; xmlDocPtr pDoc = xmlParseFile(strGameFilename.c_str()); if (pDoc) { _currentGameDescription = new GameDescription(pDoc, strGameFilename); // Import this information into the registry //GlobalRegistry().importFromFile(strGameFilename, ""); xmlFreeDoc(pDoc); } else { gtkutil::errorDialog(_("XML parser failed to parse game.xml")); } initialise(); }