UString Platform::getUserDataDirectory() { UString directory; #if defined(WIN32) // Windows: Same as getConfigDirectory() directory = getConfigDirectory(); #elif defined(MACOSX) // Mac OS X: ~/Library/Application\ Support/xoreos/ directory = getHomeDirectory(); if (!directory.empty()) directory += "/Library/Application Support/xoreos"; if (directory.empty()) directory = "."; #elif defined(UNIX) // Default Unixoid: $XDG_DATA_HOME/xoreos/ or ~/.local/share/xoreos/ const char *pathStr = getenv("XDG_DATA_HOME"); if (pathStr) { directory = UString(pathStr) + "/xoreos"; } else { directory = getHomeDirectory(); if (!directory.empty()) directory += "/.local/share/xoreos"; } if (directory.empty()) directory = "."; #else // Fallback: Same as getConfigDirectory() directory = getConfigDirectory(); #endif return FilePath::canonicalize(directory); }
std::string getSaveAsPath(const ScraperSearchParams& params, const std::string& suffix, const std::string& url) { const std::string subdirectory = params.system->getName(); const std::string name = params.game.getPath().stem().generic_string() + "-" + suffix; std::string path = getConfigDirectory() + "/downloaded_images/"; if(!boost::filesystem::exists(path)) boost::filesystem::create_directory(path); path += subdirectory + "/"; if(!boost::filesystem::exists(path)) boost::filesystem::create_directory(path); size_t dot = url.find_last_of('.'); std::string ext; if(dot != std::string::npos) ext = url.substr(dot, std::string::npos); path += name + ext; return path; }
Application::Application(const std::vector<CL_String> &args, lua_State *luaState) : mUpdated(false), mCompanyName(""), mApplicationName("bmgui"), mApplicationVersion(""), mQuit(false) { GAME_ASSERT(!args.empty()); #ifdef WIN32 // bind main thread to the first core for correct timings on some multicore systems SetThreadAffinityMask(GetCurrentThread(), 0x01); #endif // parse the command line arguments std::vector<char *> argv; for (std::vector<CL_String>::const_iterator it = args.begin(); it != args.end(); ++it) argv.push_back(const_cast<char *>(it->c_str())); CL_CommandLine commandLine; commandLine.set_help_indent(40); commandLine.add_doc("Graphical interface for Sibek balance machines"); commandLine.add_usage("[OPTION...]\n"); commandLine.add_option('g', "gateway", "ADDR", "Default gateway address"); commandLine.add_option('a', "local_addr", "ADDR", "Local address"); commandLine.add_option('m', "netmask", "ADDR", "Subnet mask"); commandLine.add_option('d', "dns", "ADDR", "DNS server address"); commandLine.add_option('i', "input_dev", "TYPE", "Input device type"); commandLine.add_option('s', "server_status", "FLAG", "Server status"); commandLine.add_option('u', "available_update_version", "VERSION", "Available update version"); commandLine.add_option('U', "updated", "FLAG", "Software update flag"); commandLine.add_option('W', "updatedfw", "FLAG", "Firmware update flag"); commandLine.add_option('D', "datadir", "PATH", "Path to the data directory"); commandLine.add_option('h', "help", "", "Show this help"); commandLine.parse_args(argv.size(), &argv[0]); #if defined(WIN32) || defined(__APPLE__) mDataDirectory = CL_Directory::get_resourcedata("bmgui", "data"); #else mDataDirectory = CL_PathHelp::add_trailing_slash(GAME_DATA_DIR); #endif while (commandLine.next()) { switch (commandLine.get_key()) { case 'g': mGateway = commandLine.get_argument(); break; case 'a': mLocalAddr = commandLine.get_argument(); break; case 'm': mNetmask = commandLine.get_argument(); break; case 'd': mDNS = commandLine.get_argument(); break; case 'i': mInputDev = commandLine.get_argument(); break; case 's': mServerStatus = commandLine.get_argument(); break; case 'u': mAvailableUpdateVersion = commandLine.get_argument(); break; case 'U': mUpdated = CL_StringHelp::text_to_bool(commandLine.get_argument()); break; case 'W': mFirmwareUpdated = commandLine.get_argument(); break; case 'D': mDataDirectory = CL_PathHelp::add_trailing_slash(commandLine.get_argument()); break; case 'h': commandLine.print_help(); quit(); return; } } /*CL_Console::write_line(cl_format("mGateway = %1", mGateway)); CL_Console::write_line(cl_format("mLocalAddr = %1", mLocalAddr)); CL_Console::write_line(cl_format("mNetmask = %1", mNetmask)); CL_Console::write_line(cl_format("mDNS = %1", mDNS)); CL_Console::write_line(cl_format("mInputDev = %1", mInputDev)); CL_Console::write_line(cl_format("mServerStatus = %1", mServerStatus)); CL_Console::write_line(cl_format("mAvailableUpdateVersion = %1", mAvailableUpdateVersion)); CL_Console::write_line(cl_format("mDataDirectory = %1", mDataDirectory));*/ // load the system profile Profile profile(""); CL_Console::write_line(cl_format("gateway = %1", profile.getString("gateway"))); CL_Console::write_line(cl_format("local_addr = %1", profile.getString("local_addr"))); CL_Console::write_line(cl_format("netmask = %1", profile.getString("netmask"))); CL_Console::write_line(cl_format("dns = %1", profile.getString("dns"))); CL_Console::write_line(cl_format("input_dev = %1", profile.getInt("input_dev"))); CL_Console::write_line(cl_format("server_status = %1", profile.getBool("server_status"))); CL_Console::write_line(cl_format("available_update_version = %1", profile.getString("available_update_version"))); CL_Console::write_line(cl_format("server_addr = %1", profile.getString("server_addr"))); CL_Console::write_line(cl_format("remote_control = %1", profile.getBool("remote_control"))); CL_Console::write_line(cl_format("ignored_update_version = %1", profile.getString("ignored_update_version"))); CL_Console::write_line(cl_format("cal_command = %1", profile.getString("cal_command"))); CL_Console::write_line(cl_format("language = %1", profile.getInt("language"))); CL_Console::write_line(cl_format("fullscreen = %1", profile.getBool("fullscreen"))); CL_Console::write_line(cl_format("width = %1", profile.getInt("width"))); CL_Console::write_line(cl_format("height = %1", profile.getInt("height"))); CL_Console::write_line(cl_format("sound_level = %1", profile.getInt("sound_level"))); // initialize all game subsystems mBalance = CL_SharedPtr<Balance>(new Balance(profile)); mDatabase = CL_SharedPtr<Database>(new Database(getConfigDirectory() + getApplicationName() + ".db")); mResourceManager = CL_SharedPtr<ResourceManager>(new ResourceManager()); mResourceQueue = CL_SharedPtr<ResourceQueue>(new ResourceQueue()); mGraphics = CL_SharedPtr<Graphics>(new Graphics(profile)); mKeyboard = CL_SharedPtr<Keyboard>(new Keyboard()); mMouse = CL_SharedPtr<Mouse>(new Mouse()); mSoundOutput = CL_SoundOutput(44100); mLuaScript = CL_SharedPtr<LuaScript>(new LuaScript("main.lua", luaState)); }
int main(int argc, char* argv[]) { unsigned int width = 0; unsigned int height = 0; std::locale::global(boost::locale::generator().generate("")); boost::filesystem::path::imbue(std::locale()); if(!parseArgs(argc, argv, &width, &height)) return 0; // only show the console on Windows if HideConsole is false #ifdef WIN32 // MSVC has a "SubSystem" option, with two primary options: "WINDOWS" and "CONSOLE". // In "WINDOWS" mode, no console is automatically created for us. This is good, // because we can choose to only create the console window if the user explicitly // asks for it, preventing it from flashing open and then closing. // In "CONSOLE" mode, a console is always automatically created for us before we // enter main. In this case, we can only hide the console after the fact, which // will leave a brief flash. // TL;DR: You should compile ES under the "WINDOWS" subsystem. // I have no idea how this works with non-MSVC compilers. if(!Settings::getInstance()->getBool("HideConsole")) { // we want to show the console // if we're compiled in "CONSOLE" mode, this is already done. // if we're compiled in "WINDOWS" mode, no console is created for us automatically; // the user asked for one, so make one and then hook stdin/stdout/sterr up to it if(AllocConsole()) // should only pass in "WINDOWS" mode { freopen("CONIN$", "r", stdin); freopen("CONOUT$", "wb", stdout); freopen("CONOUT$", "wb", stderr); } }else{ // we want to hide the console // if we're compiled with the "WINDOWS" subsystem, this is already done. // if we're compiled with the "CONSOLE" subsystem, a console is already created; // it'll flash open, but we hide it nearly immediately if(GetConsoleWindow()) // should only pass in "CONSOLE" mode ShowWindow(GetConsoleWindow(), SW_HIDE); } #endif if(Settings::getInstance()->getString("ConfigDirectory") == ""){ if(checkForOldConfigDirectory()){ std::cerr << "Using old config directory, please migrate your files to \"" << getDefaultConfigDirectory() << "\" and delete the .emulationstation folder."; Settings::getInstance()->setString("ConfigDirectory", getHomePath() + "/.emulationstation"); } else { if(!createNewConfigDirectory()) return 1; Settings::getInstance()->setString("ConfigDirectory", getDefaultConfigDirectory()); } } if(!Settings::getInstance()->loadFile()){ std::cerr << "Couldn't load settings from \"" << getConfigDirectory(); return 1; } Log::open(); LOG(LogInfo) << "EmulationStation - v" << PROGRAM_VERSION_STRING << ", built " << PROGRAM_BUILT_STRING; //always close the log on exit atexit(&onExit); Window window; ViewController::init(&window); window.pushGui(ViewController::get()); if(!scrape_cmdline) { if(!window.init(width, height)) { LOG(LogError) << "Window failed to initialize!"; return 1; } std::string glExts = (const char*)glGetString(GL_EXTENSIONS); LOG(LogInfo) << "Checking available OpenGL extensions..."; LOG(LogInfo) << " ARB_texture_non_power_of_two: " << (glExts.find("ARB_texture_non_power_of_two") != std::string::npos ? "ok" : "MISSING"); if(Settings::getInstance()->getBool("SplashScreen")) window.renderLoadingScreen(); } const char* errorMsg = NULL; if(!loadSystemConfigFile(&errorMsg)) { // something went terribly wrong if(errorMsg == NULL) { LOG(LogError) << "Unknown error occured while parsing system config file."; if(!scrape_cmdline) Renderer::deinit(); return 1; } // we can't handle es_systems.cfg file problems inside ES itself, so display the error message then quit window.pushGui(new GuiMsgBox(&window, errorMsg, "QUIT", [] { SDL_Event* quit = new SDL_Event(); quit->type = SDL_QUIT; SDL_PushEvent(quit); })); } //run the command line scraper then quit if(scrape_cmdline) { return run_scraper_cmdline(); } //dont generate joystick events while we're loading (hopefully fixes "automatically started emulator" bug) SDL_JoystickEventState(SDL_DISABLE); // preload what we can right away instead of waiting for the user to select it // this makes for no delays when accessing content, but a longer startup time ViewController::get()->preload(); //choose which GUI to open depending on if an input configuration already exists if(errorMsg == NULL) { if(fs::exists(InputManager::getConfigPath()) && InputManager::getInstance()->getNumConfiguredDevices() > 0) { ViewController::get()->goToStart(); }else{ window.pushGui(new GuiDetectDevice(&window, true, [] { ViewController::get()->goToStart(); })); } } //generate joystick events since we're done loading SDL_JoystickEventState(SDL_ENABLE); int lastTime = SDL_GetTicks(); bool running = true; Uint32 CecEventType = InputManager::getInstance()->getCecEventType(); while(running) { SDL_Event event; while(SDL_PollEvent(&event)) { if(CecEventType != ((Uint32)-1) && event.type == CecEventType) { InputManager::getInstance()->parseEvent(event, &window); }else{ switch(event.type) { case SDL_JOYHATMOTION: case SDL_JOYBUTTONDOWN: case SDL_JOYBUTTONUP: case SDL_KEYDOWN: case SDL_KEYUP: case SDL_JOYAXISMOTION: case SDL_TEXTINPUT: case SDL_TEXTEDITING: case SDL_JOYDEVICEADDED: case SDL_JOYDEVICEREMOVED: InputManager::getInstance()->parseEvent(event, &window); break; case SDL_QUIT: running = false; break; } } } if(window.isSleeping()) { lastTime = SDL_GetTicks(); SDL_Delay(1); // this doesn't need to be accurate, we're just giving up our CPU time until something wakes us up continue; } int curTime = SDL_GetTicks(); int deltaTime = curTime - lastTime; lastTime = curTime; // cap deltaTime at 1000 if(deltaTime > 1000 || deltaTime < 0) deltaTime = 1000; window.update(deltaTime); window.render(); Renderer::swapBuffers(); Log::flush(); } while(window.peekGui() != ViewController::get()) delete window.peekGui(); window.deinit(); SystemData::deleteSystems(); LOG(LogInfo) << "EmulationStation cleanly shutting down."; return 0; }