int main(int argc, char **argv) { int result = -1; Application app(argc, argv); #ifdef Q_OS_LINUX QApplication::setStyle("Plastique"); #endif try { MIMainWindow *mw = MIMainWindow::instance(); QTimer::singleShot(0, &app, SLOT(AfterInit())); QTimer::singleShot(500, mw, SLOT(AfterInit())); mw->show(); result = app.exec(); delete mw; } catch (...) { std::cerr << "MIFit: unknown exception\n"; result = 1; } return result; }
ApplicationFail Application::Init() { BeforeInit(); if ( glfwInit() == false ) { return ApplicationFail::GLFW_INIT; } window_glfw_ = glfwCreateWindow( 1280, 720, name_string_.c_str(), nullptr, nullptr ); if ( window_glfw_ == nullptr ) { glfwTerminate(); return ApplicationFail::GLFW_CREATE_WINDOW; } glfwMakeContextCurrent( window_glfw_ ); if ( ogl_LoadFunctions() == ogl_LOAD_FAILED ) { glfwDestroyWindow( window_glfw_ ); glfwTerminate(); return ApplicationFail::OGL_LOAD_FUNCTIONS; } const int OGL_MAJOR = ogl_GetMajorVersion(); const int OGL_MINOR = ogl_GetMinorVersion(); printf( "OpenGL Version: %i.%i\n", OGL_MAJOR, OGL_MINOR ); glClearColor( 0.25f, 0.25f, 0.25f, 1.0f ); glEnable( GL_DEPTH_TEST ); time_previous_d_ = glfwGetTime(); InputDevice::Init( window_glfw_ ); AfterInit(); return ApplicationFail::NONE; }
bool DolphinApp::OnInit() { std::lock_guard<std::mutex> lk(s_init_mutex); if (!wxApp::OnInit()) return false; Bind(wxEVT_QUERY_END_SESSION, &DolphinApp::OnEndSession, this); Bind(wxEVT_END_SESSION, &DolphinApp::OnEndSession, this); Bind(wxEVT_IDLE, &DolphinApp::OnIdle, this); Bind(wxEVT_ACTIVATE_APP, &DolphinApp::OnActivate, this); // Register message box and translation handlers RegisterMsgAlertHandler(&wxMsgAlert); RegisterStringTranslator(&wxStringTranslator); #if wxUSE_ON_FATAL_EXCEPTION wxHandleFatalExceptions(true); #endif UICommon::SetUserDirectory(m_user_path.ToStdString()); UICommon::CreateDirectories(); InitLanguageSupport(); // The language setting is loaded from the user directory UICommon::Init(); if (m_select_video_backend && !m_video_backend_name.empty()) SConfig::GetInstance().m_strVideoBackend = WxStrToStr(m_video_backend_name); if (m_select_audio_emulation) SConfig::GetInstance().bDSPHLE = (m_audio_emulation_name.Upper() == "HLE"); VideoBackendBase::ActivateBackend(SConfig::GetInstance().m_strVideoBackend); DolphinAnalytics::Instance()->ReportDolphinStart("wx"); wxToolTip::Enable(!SConfig::GetInstance().m_DisableTooltips); // Enable the PNG image handler for screenshots wxImage::AddHandler(new wxPNGHandler); // We have to copy the size and position out of SConfig now because CFrame's OnMove // handler will corrupt them during window creation (various APIs like SetMenuBar cause // event dispatch including WM_MOVE/WM_SIZE) wxRect window_geometry(SConfig::GetInstance().iPosX, SConfig::GetInstance().iPosY, SConfig::GetInstance().iWidth, SConfig::GetInstance().iHeight); main_frame = new CFrame(nullptr, wxID_ANY, StrToWxStr(scm_rev_str), window_geometry, m_use_debugger, m_batch_mode, m_use_logger); SetTopWindow(main_frame); AfterInit(); return true; }
bool DolphinApp::OnInit() { Bind(wxEVT_QUERY_END_SESSION, &DolphinApp::OnEndSession, this); Bind(wxEVT_END_SESSION, &DolphinApp::OnEndSession, this); // Declarations and definitions bool UseDebugger = false; bool UseLogger = false; bool selectVideoBackend = false; bool selectAudioEmulation = false; bool selectPerfDir = false; wxString videoBackendName; wxString audioEmulationName; wxString userPath; wxString perfDir; #if wxUSE_CMDLINE_PARSER // Parse command lines wxCmdLineEntryDesc cmdLineDesc[] = { { wxCMD_LINE_SWITCH, "h", "help", "Show this help message", wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP }, { wxCMD_LINE_SWITCH, "d", "debugger", "Opens the debugger", wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL }, { wxCMD_LINE_SWITCH, "l", "logger", "Opens the logger", wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL }, { wxCMD_LINE_OPTION, "e", "exec", "Loads the specified file (ELF, DOL, GCM, ISO, WBFS, CISO, GCZ, WAD)", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL }, { wxCMD_LINE_SWITCH, "b", "batch", "Exit Dolphin with emulator", wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL }, { wxCMD_LINE_OPTION, "V", "video_backend", "Specify a video backend", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL }, { wxCMD_LINE_OPTION, "A", "audio_emulation", "Low level (LLE) or high level (HLE) audio", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL }, { wxCMD_LINE_OPTION, "m", "movie", "Play a movie file", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL }, { wxCMD_LINE_OPTION, "U", "user", "User folder path", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL }, { wxCMD_LINE_OPTION, "P", "perf_dir", "Directory for Linux perf perf-$pid.map file", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL }, { wxCMD_LINE_NONE, nullptr, nullptr, nullptr, wxCMD_LINE_VAL_NONE, 0 } }; // Gets the command line parameters wxCmdLineParser parser(cmdLineDesc, argc, argv); LoadFile = false; if (argc == 2 && File::Exists(argv[1].ToUTF8().data())) { LoadFile = true; FileToLoad = argv[1]; } else if (parser.Parse() != 0) { return false; } UseDebugger = parser.Found("debugger"); UseLogger = parser.Found("logger"); if (!LoadFile) LoadFile = parser.Found("exec", &FileToLoad); BatchMode = parser.Found("batch"); selectVideoBackend = parser.Found("video_backend", &videoBackendName); selectAudioEmulation = parser.Found("audio_emulation", &audioEmulationName); selectPerfDir = parser.Found("perf_dir", &perfDir); playMovie = parser.Found("movie", &movieFile); parser.Found("user", &userPath); #endif // wxUSE_CMDLINE_PARSER // Register message box and translation handlers RegisterMsgAlertHandler(&wxMsgAlert); RegisterStringTranslator(&wxStringTranslator); #if wxUSE_ON_FATAL_EXCEPTION wxHandleFatalExceptions(true); #endif UICommon::SetUserDirectory(userPath.ToStdString()); UICommon::CreateDirectories(); InitLanguageSupport(); // The language setting is loaded from the user directory UICommon::Init(); if (selectPerfDir) { SConfig::GetInstance().m_LocalCoreStartupParameter.m_perfDir = WxStrToStr(perfDir); } if (selectVideoBackend && videoBackendName != wxEmptyString) SConfig::GetInstance().m_LocalCoreStartupParameter.m_strVideoBackend = WxStrToStr(videoBackendName); if (selectAudioEmulation) { if (audioEmulationName == "HLE") SConfig::GetInstance().m_LocalCoreStartupParameter.bDSPHLE = true; else if (audioEmulationName == "LLE") SConfig::GetInstance().m_LocalCoreStartupParameter.bDSPHLE = false; } VideoBackend::ActivateBackend(SConfig::GetInstance().m_LocalCoreStartupParameter.m_strVideoBackend); // Enable the PNG image handler for screenshots wxImage::AddHandler(new wxPNGHandler); int x = SConfig::GetInstance().m_LocalCoreStartupParameter.iPosX; int y = SConfig::GetInstance().m_LocalCoreStartupParameter.iPosY; int w = SConfig::GetInstance().m_LocalCoreStartupParameter.iWidth; int h = SConfig::GetInstance().m_LocalCoreStartupParameter.iHeight; if (File::Exists("www.dolphin-emulator.com.txt")) { File::Delete("www.dolphin-emulator.com.txt"); wxMessageDialog dlg(nullptr, _( "This version of Dolphin was downloaded from a website stealing money from developers of the emulator. Please " "download Dolphin from the official website instead: https://dolphin-emu.org/"), _("Unofficial version detected"), wxOK | wxICON_WARNING); dlg.ShowModal(); wxLaunchDefaultBrowser("https://dolphin-emu.org/?ref=badver"); exit(0); } // The following is not needed with X11, where window managers // do not allow windows to be created off the desktop. #ifdef _WIN32 // Out of desktop check int leftPos = GetSystemMetrics(SM_XVIRTUALSCREEN); int topPos = GetSystemMetrics(SM_YVIRTUALSCREEN); int width = GetSystemMetrics(SM_CXVIRTUALSCREEN); int height = GetSystemMetrics(SM_CYVIRTUALSCREEN); if ((leftPos + width) < (x + w) || leftPos > x || (topPos + height) < (y + h) || topPos > y) x = y = wxDefaultCoord; #elif defined __APPLE__ if (y < 1) y = wxDefaultCoord; #endif main_frame = new CFrame(nullptr, wxID_ANY, StrToWxStr(scm_rev_str), wxPoint(x, y), wxSize(w, h), UseDebugger, BatchMode, UseLogger); SetTopWindow(main_frame); main_frame->SetMinSize(wxSize(400, 300)); AfterInit(); return true; }
bool DolphinApp::OnInit() { if (!wxApp::OnInit()) return false; Bind(wxEVT_QUERY_END_SESSION, &DolphinApp::OnEndSession, this); Bind(wxEVT_END_SESSION, &DolphinApp::OnEndSession, this); // Register message box and translation handlers RegisterMsgAlertHandler(&wxMsgAlert); RegisterStringTranslator(&wxStringTranslator); #if wxUSE_ON_FATAL_EXCEPTION wxHandleFatalExceptions(true); #endif UICommon::SetUserDirectory(m_user_path.ToStdString()); UICommon::CreateDirectories(); InitLanguageSupport(); // The language setting is loaded from the user directory UICommon::Init(); if (m_select_video_backend && !m_video_backend_name.empty()) SConfig::GetInstance().m_strVideoBackend = WxStrToStr(m_video_backend_name); if (m_select_audio_emulation) SConfig::GetInstance().bDSPHLE = (m_audio_emulation_name.Upper() == "HLE"); VideoBackend::ActivateBackend(SConfig::GetInstance().m_strVideoBackend); // Enable the PNG image handler for screenshots wxImage::AddHandler(new wxPNGHandler); int x = SConfig::GetInstance().iPosX; int y = SConfig::GetInstance().iPosY; int w = SConfig::GetInstance().iWidth; int h = SConfig::GetInstance().iHeight; // The following is not needed with X11, where window managers // do not allow windows to be created off the desktop. #ifdef _WIN32 // Out of desktop check int leftPos = GetSystemMetrics(SM_XVIRTUALSCREEN); int topPos = GetSystemMetrics(SM_YVIRTUALSCREEN); int width = GetSystemMetrics(SM_CXVIRTUALSCREEN); int height = GetSystemMetrics(SM_CYVIRTUALSCREEN); if ((leftPos + width) < (x + w) || leftPos > x || (topPos + height) < (y + h) || topPos > y) x = y = wxDefaultCoord; #elif defined __APPLE__ if (y < 1) y = wxDefaultCoord; #endif main_frame = new CFrame(nullptr, wxID_ANY, StrToWxStr(scm_rev_str), wxPoint(x, y), wxSize(w, h), m_use_debugger, m_batch_mode, m_use_logger); SetTopWindow(main_frame); main_frame->SetMinSize(wxSize(400, 300)); AfterInit(); return true; }
void CRequest::Run() { if(BeforeInit()) { m_State = HTTP_ERROR; return; } CURL *pHandle = curl_easy_init(); if(!pHandle) { m_State = HTTP_ERROR; return; } if(g_Config.m_DbgCurl) { curl_easy_setopt(pHandle, CURLOPT_VERBOSE, 1L); } char aErr[CURL_ERROR_SIZE]; curl_easy_setopt(pHandle, CURLOPT_ERRORBUFFER, aErr); if(m_CanTimeout) { curl_easy_setopt(pHandle, CURLOPT_CONNECTTIMEOUT_MS, (long)g_Config.m_ClHTTPConnectTimeoutMs); curl_easy_setopt(pHandle, CURLOPT_LOW_SPEED_LIMIT, (long)g_Config.m_ClHTTPLowSpeedLimit); curl_easy_setopt(pHandle, CURLOPT_LOW_SPEED_TIME, (long)g_Config.m_ClHTTPLowSpeedTime); } else { curl_easy_setopt(pHandle, CURLOPT_CONNECTTIMEOUT_MS, 0L); curl_easy_setopt(pHandle, CURLOPT_LOW_SPEED_LIMIT, 0L); curl_easy_setopt(pHandle, CURLOPT_LOW_SPEED_TIME, 0L); } curl_easy_setopt(pHandle, CURLOPT_SHARE, gs_Share); curl_easy_setopt(pHandle, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS); curl_easy_setopt(pHandle, CURLOPT_FOLLOWLOCATION, 1L); curl_easy_setopt(pHandle, CURLOPT_MAXREDIRS, 4L); curl_easy_setopt(pHandle, CURLOPT_FAILONERROR, 1L); curl_easy_setopt(pHandle, CURLOPT_URL, m_aUrl); curl_easy_setopt(pHandle, CURLOPT_NOSIGNAL, 1L); curl_easy_setopt(pHandle, CURLOPT_USERAGENT, "DDNet " GAME_RELEASE_VERSION " (" CONF_PLATFORM_STRING "; " CONF_ARCH_STRING ")"); // We only trust our own custom-selected CAs for our own servers. // Other servers can use any CA trusted by the system. if(false || str_comp_nocase_num("maps.ddnet.tw/", m_aUrl, 14) == 0 || str_comp_nocase_num("http://maps.ddnet.tw/", m_aUrl, 21) == 0 || str_comp_nocase_num("https://maps.ddnet.tw/", m_aUrl, 22) == 0 || str_comp_nocase_num("http://info.ddnet.tw/", m_aUrl, 21) == 0 || str_comp_nocase_num("https://info.ddnet.tw/", m_aUrl, 22) == 0 || str_comp_nocase_num("https://update4.ddnet.tw/", m_aUrl, 25) == 0) { curl_easy_setopt(pHandle, CURLOPT_CAINFO, CA_FILE_PATH); } curl_easy_setopt(pHandle, CURLOPT_WRITEDATA, this); curl_easy_setopt(pHandle, CURLOPT_WRITEFUNCTION, WriteCallback); curl_easy_setopt(pHandle, CURLOPT_NOPROGRESS, 0L); curl_easy_setopt(pHandle, CURLOPT_PROGRESSDATA, this); curl_easy_setopt(pHandle, CURLOPT_PROGRESSFUNCTION, ProgressCallback); if(AfterInit(pHandle)) { curl_easy_cleanup(pHandle); m_State = HTTP_ERROR; return; } dbg_msg("http", "http %s", m_aUrl); m_State = HTTP_RUNNING; int Ret = curl_easy_perform(pHandle); BeforeCompletion(); if(Ret != CURLE_OK) { dbg_msg("http", "task failed. libcurl error: %s", aErr); m_State = (Ret == CURLE_ABORTED_BY_CALLBACK) ? HTTP_ABORTED : HTTP_ERROR; } else { dbg_msg("http", "task done %s", m_aUrl); m_State = HTTP_DONE; } curl_easy_cleanup(pHandle); OnCompletion(); }