bool EkstrApp::OnInit() { // READ PARAMS FROM CMD LINE #if wxUSE_UNICODE libpar_read_cmdline_w(&argc, argv); #else libpar_read_cmdline(&argc, argv); #endif if (!szApp<>::OnInit()) return false; #if BOOST_FILESYSTEM_VERSION == 3 boost::filesystem::wpath::imbue(std::locale("C")); #else boost::filesystem::wpath_traits::imbue(std::locale("C")); #endif SetProgName(_("Ekstraktor 3")); // SET LOCALE wxArrayString catalogs; catalogs.Add(_T("ekstraktor3")); catalogs.Add(_T("common")); catalogs.Add(_T("wx")); InitializeLocale(catalogs, locale); // GET LIBPAR STUFF #ifndef MINGW32 libpar_init(); #else wxString config_str = GetSzarpDir() + wxFileName::GetPathSeparator() + _T("resources") + wxFileName::GetPathSeparator() + _T("szarp.cfg"); libpar_init_with_filename(SC::S2A(config_str).c_str(), 1); #endif std::wstring ipk_prefix; char *_ipk_prefix = libpar_getpar("", "config_prefix", 0); if (_ipk_prefix) { ipk_prefix = SC::L2S(_ipk_prefix); free(_ipk_prefix); } std::map<wxString, std::pair<wxString, wxString> > m_probers_addresses; #ifndef MINGW32 m_probers_addresses = get_probers_addresses(); #endif szFrame::setDefaultIcon(wxICON(extr64)); if (!base.IsEmpty()) { ipk_prefix = base.c_str(); } else { if (ipk_prefix.empty()) { wxArrayString hidden_databases; wxString tmp; wxConfigBase *config = wxConfigBase::Get(true); if (config->Read(_T("HIDDEN_DATABASES"), &tmp)) { wxStringTokenizer tkz(tmp, _T(","), wxTOKEN_STRTOK); while (tkz.HasMoreTokens()) { wxString token = tkz.GetNextToken(); token.Trim(); if (!token.IsEmpty()) hidden_databases.Add(token); } } if (ConfigDialog::SelectDatabase(base, &hidden_databases)) { ipk_prefix = base; } else return false; } } libpar_done(); #ifdef MINGW32 WORD wVersionRequested = MAKEWORD(2, 2); WSADATA wsaData; WSAStartup(wVersionRequested, &wsaData); #endif xmlInitParser(); LIBXML_TEST_VERSION xmlSubstituteEntitiesDefault(1); // .. AND START THE MAIN WIDGET std::pair<wxString, wxString> prober_address; if (m_probers_addresses.find(ipk_prefix) != m_probers_addresses.end()) prober_address = m_probers_addresses[ipk_prefix]; EkstraktorWidget *ew = new EkstraktorWidget(ipk_prefix, geometry.IsEmpty() ? NULL : &geometry, prober_address, sz4); if (ew->IsConfigLoaded() == false) { delete ew; exit(1); } return true; } // onInit()
bool DrawApp::OnInit() { /* Read params from szarp.cfg. */ #if wxUSE_UNICODE libpar_read_cmdline_w(&argc, argv); #else libpar_read_cmdline(&argc, argv); #endif #if BOOST_FILESYSTEM_VERSION == 3 boost::filesystem::wpath::imbue(std::locale("C")); #else boost::filesystem::wpath_traits::imbue(std::locale("C")); #endif if (!DrawGLApp::OnInit()) return false; SetProgName(_T("Draw 3")); //signal(SIGINT, INThandler); if (m_just_print_version) { std::cout << SZARP_VERSION << std::endl; return false; } m_server = NULL; m_db_queue = NULL; m_executor = NULL; m_remarks_handler = NULL; #ifdef __WXGTK__ libpar_init(); char *base = NULL; if (m_base == wxEmptyString) { base = libpar_getpar("", "config_prefix", 1); m_base = SC::L2S(base); free(base); } { if (m_base_type != IKS_BASE) { char *iks_server = libpar_getpar("draw3", "iks_server", 0); if (iks_server) { m_iks_server = SC::L2S(iks_server); m_base_type = IKS_BASE; free(iks_server); } char *iks_port = libpar_getpar("draw3", "iks_server_port", 0); if (iks_port) { m_iks_port = SC::L2S(iks_port); free(iks_port); } } } m_probers_from_szarp_cfg = get_probers_addresses(); #endif #ifdef MINGW32 WORD wVersionRequested = MAKEWORD(2, 2); WSADATA wsaData; WSAStartup(wVersionRequested, &wsaData); #endif /* Set logging to stderr. */ wxLog *logger = new wxLogStderr(); //wxLog *logger = new wxLogGui(); wxLog::SetActiveTarget(logger); m_instance = new szSingleInstanceChecker(_T(".szarp_m_instance_lock"), wxEmptyString, _T("draw3")); if (m_instance->IsAnotherRunning()) { if (!m_url.IsEmpty()) { if (m_url_open_in_existing) SendToRunningInstance(_T("START_URL"), m_url.c_str()); else SendToRunningInstance(_T("START_URL_EXISTING"), m_url.c_str()); } else if (!m_base.IsEmpty()) { SendToRunningInstance(_T("START_BASE"), m_base.c_str()); } else { wxLogError(_T("base not given")); return false; } return false; } InitGL(); SplashScreen *splash = NULL; wxBitmap bitmap; // this loads draw64_xpm under Linux, or draw64 icon resource under Windows szFrame::setDefaultIcon(wxICON(draw64)); wxString splashimage = GetSzarpDir(); #ifndef MINGW32 splashimage += _T("resources/wx/images/szarp-logo.png"); #else splashimage += _T("resources\\wx\\images\\szarp-logo.png"); #endif #if wxUSE_LIBPNG /* Activate PNG image handler. */ wxImage::AddHandler( new wxPNGHandler ); #endif if (bitmap.LoadFile(splashimage, wxBITMAP_TYPE_PNG)) splash = new SplashScreen(&bitmap); else splash = new SplashScreen(); splash->Show(true); splash->PushStatusText(_("Setting locale...")); /* Set locale. */ this->InitializeLocale(_T("draw3"), locale); splash->PushStatusText(_("Reading params from szarp.cfg...")); wxString _lang = wxConfig::Get()->Read(_T("LANGUAGE"), AUTO_LANGUAGE); if (_lang == AUTO_LANGUAGE) _lang = DEFAULT_LANGUAGE; splash->PushStatusText(_("Initializing IPKContainer...")); IPKContainer::Init(GetSzarpDataDir().c_str(), GetSzarpDir().c_str(), _lang.c_str()); m_cfg_mgr = new ConfigManager(GetSzarpDataDir(), IPKContainer::GetObject()); m_cfg_mgr->SetSplashScreen(splash); splash->PushStatusText(_("Initializing szbase...")); splash->PushStatusText(_("Initializing XML Resources...")); InitXmlResource(); splash->PushStatusText(_("Starting database query mechanism...")); m_db_queue = new DatabaseQueryQueue(); m_dbmgr = new DatabaseManager(m_db_queue, m_cfg_mgr); m_db_queue->SetDatabaseManager(m_dbmgr); m_dbmgr->SetProbersAddresses(GetProbersAddresses()); Draw3Base* draw_base; switch (m_base_type) { case SZBASE_BASE: draw_base = new SzbaseBase(m_dbmgr, GetSzarpDataDir().c_str(), &ConfigurationFileChangeHandler::handle, wxConfig::Get()->Read(_T("SZBUFER_IN_MEMORY_CACHE"), 0L)); break; case SZ4_BASE: draw_base = new Sz4Base(m_dbmgr, GetSzarpDataDir().c_str(), IPKContainer::GetObject()); break; case IKS_BASE: draw_base = new Sz4ApiBase(m_dbmgr, m_iks_server.c_str(), m_iks_port.c_str(), IPKContainer::GetObject()); break; } m_executor = new QueryExecutor(m_db_queue, m_dbmgr, draw_base); m_executor->Create(); m_executor->SetPriority((WXTHREAD_MAX_PRIORITY + WXTHREAD_DEFAULT_PRIORITY) / 2); m_executor->Run(); m_cfg_mgr->SetDatabaseManager(m_dbmgr); ConfigurationFileChangeHandler::database_manager = m_dbmgr; /* default config */ wxString defid; DrawsSets *config = NULL; splash->PushStatusText(_("Loading configuration...")); /* init activity logger with base name as server name. This assumes that * server has written basename to /etc/hosts on linux machines and probably * doesn't work on windows. */ UDPLogger::SetAppName( "draw3" ); UDPLogger::SetAddress( (const char*)m_base.mb_str(wxConvUTF8) ); UDPLogger::SetPort ( "7777" ); UDPLogger::LogEvent ( "drawapp:start" ); wxString prefix, window; PeriodType pt = PERIOD_T_YEAR; time_t time = -1; int selected_draw = 0; if (!m_url.IsEmpty()) { if (!decode_url(m_url, prefix, window, pt, time, selected_draw)) { wxLogError(_T("Invalid URL")); StopThreads(); return FALSE; } } else if (!m_base.IsEmpty()) { if ((config = m_cfg_mgr->LoadConfig(m_base,std::wstring(),m_show_logparams)) == NULL) { wxLogError(_("Error occurred while loading default configuration. Check your szarp.cfg file.")); StopThreads(); return FALSE; } prefix = m_base; } else { wxLogError(_("Missing starting base specification.")); StopThreads(); return FALSE; } #ifndef MINGW32 libpar_done(); #endif m_help = new szHelpController; #ifndef MINGW32 m_help->AddBook(wxGetApp().GetSzarpDir() + L"/resources/documentation/new/draw3/html/draw3.hhp"); #else m_help->AddBook(wxGetApp().GetSzarpDir() + L"\\resources\\documentation\\new\\draw3\\html\\draw3.hhp"); #endif szHelpControllerHelpProvider* provider = new szHelpControllerHelpProvider; wxHelpProvider::Set(provider); provider->SetHelpController(m_help); splash->PushStatusText(_("Initizalizing remarks...")); m_remarks_handler = new RemarksHandler(m_cfg_mgr); m_remarks_handler->Start(); splash->PushStatusText(_("Creating Frame Manager...")); VersionChecker* version_checker = new VersionChecker(argv[0]); version_checker->Start(); FrameManager *fm = new FrameManager(m_dbmgr, m_cfg_mgr, m_remarks_handler); /*@michal */ if (!fm->CreateFrame(prefix, window, pt, time, wxSize(width, height), wxPoint(x, y), selected_draw, m_url.IsEmpty(), m_full_screen)) { StopThreads(); wxLogError(_T("Unable to load base: %s"), prefix.c_str()); return FALSE; } StartInstanceServer(fm, m_cfg_mgr); wxToolTip::SetDelay(1000); SetAppName(_T("SZARPDRAW3")); splash->Destroy(); m_cfg_mgr->ResetSplashScreen(); #ifndef NO_GSTREAMER if (!gst_init_check(NULL, NULL, NULL)) return 1; #endif return TRUE; }
bool TestApp::OnInit() { /* Read params from szarp.cfg. */ #if wxUSE_UNICODE libpar_read_cmdline_w(&argc, argv); #else libpar_read_cmdline(&argc, argv); #endif SetProgName(_T("Test app")); m_db_queue = NULL; m_executor = NULL; m_remarks_handler = NULL; #ifdef __WXGTK__ libpar_init(); #endif #ifdef MINGW32 WORD wVersionRequested = MAKEWORD(2, 2); WSADATA wsaData; WSAStartup(wVersionRequested, &wsaData); #endif #if 0 wxPendingEventsLocker = new wxCriticalSection; #endif /* Set logging to stderr. */ wxLog *logger = new wxLogStderr(); wxLog::SetActiveTarget(logger); wxString _lang = wxConfig::Get()->Read(_T("LANGUAGE"), AUTO_LANGUAGE); if (_lang == AUTO_LANGUAGE) _lang = DEFAULT_LANGUAGE; IPKContainer::Init(GetSzarpDataDir().c_str(), GetSzarpDir().c_str(), _lang.c_str(), new szMutex()); m_cfg_mgr = new ConfigManager(GetSzarpDataDir().c_str(), IPKContainer::GetObject()); m_db_queue = new DatabaseQueryQueue(); m_dbmgr = new DatabaseManager(m_db_queue, m_cfg_mgr); m_db_queue->SetDatabaseManager(m_dbmgr); //m_dbmgr->SetProbersAddresses(GetProbersAddresses()); Szbase::Init(GetSzarpDataDir().c_str(), NULL, true, wxConfig::Get()->Read(_T("SZBUFER_IN_MEMORY_CACHE"), 0L)); Szbase* szbase = Szbase::GetObject(); m_executor = new QueryExecutor(m_db_queue, m_dbmgr, szbase); m_executor->Create(); m_executor->SetPriority((WXTHREAD_MAX_PRIORITY + WXTHREAD_DEFAULT_PRIORITY) / 2); m_executor->Run(); m_cfg_mgr->SetDatabaseManager(m_dbmgr); #ifndef MINGW32 libpar_done(); #endif m_remarks_handler = new RemarksHandler(m_cfg_mgr); m_remarks_handler->Start(); SetAppName(_T("SZARPTESTAPP")); m_runner = new TestRunner(m_dbmgr, m_cfg_mgr); m_runner->Run(); return TRUE; }