void CLanguagesDlg::_LoadLanguage(LPCTSTR szLang) { FILE *fp = NULL; CPrivateConfigEx cConfig(TRUE); // GetModuleFileName(NULL, szFile, MAX_PATH * 2); // for(i = _tcslen(szFile)-1; i > 1; i--) // Extract dir // { // if(szFile[i] == _T('\\')) { szFile[i] = 0; break; } // } // _tcscat_s(szFile, _countof(szFile), _T("\\")); // _tcscat_s(szFile, _countof(szFile), szLang); std_string strFile = Executable::instance().getPathOnly(); strFile += szLang; if(_tcscmp(szLang, _T("English")) != 0) { // _tcscat_s(szFile, _countof(szFile), _T(".lng")); strFile += _T(".lng"); _tfopen_s(&fp, strFile.c_str(), _T("rb")); ASSERT(fp != NULL); if(fp == NULL) { MessageBox(TRL("Language file cannot be opened!"), TRL("Loading error"), MB_OK | MB_ICONWARNING); return; } fclose(fp); if(cConfig.Set(PWMKEY_LANG, szLang) == FALSE) { MessageBox(TRL("Language file cannot be registered!"), TRL("Loading error"), MB_OK | MB_ICONWARNING); return; } } else cConfig.Set(PWMKEY_LANG, _T("Standard")); CString str = TRL("The language file has been installed."); str += _T("\r\n\r\n"); str += TRL("You must restart KeePass in order to use the new language."); str += _T("\r\n\r\n"); str += TRL("Do you wish to restart KeePass now?"); const int i = MessageBox(str, TRL("Restart KeePass?"), MB_YESNO | MB_ICONQUESTION); if(i == IDYES) { CDialog::OnOK(); } }
//------------------------------------------ CEngine::~CEngine(){ cConfig()->Save(m_szSettings); delete[] m_szSettings; UNLOAD_SUBCLASS(Filesystem); UNLOAD_SUBCLASS(InputManager); UNLOAD_SUBCLASS(SceneManager); UNLOAD_SUBCLASS(Config); UNLOAD_SUBCLASS(MeshLoader); UNLOAD_SUBCLASS(ObjectManager); UNLOAD_SUBCLASS(ScriptEngine); UNLOAD_SUBCLASS(InternalWindow); UNLOAD_SUBCLASS(InternalInput); UNLOAD_SUBCLASS(Console); // should be last }
void CLanguagesDlg::_LoadLanguage(LPCTSTR szLang) { CPrivateConfigEx cConfig(TRUE); if(_tcscmp(szLang, _T("English")) != 0) { std_string strFile = SU_DriveLetterToUpper(Executable::instance().getPathOnly()); strFile += PWM_DIR_LANGUAGES; strFile += _T("\\"); strFile += szLang; strFile += _T(".lng"); FILE* fp = NULL; _tfopen_s(&fp, strFile.c_str(), _T("rb")); ASSERT(fp != NULL); if(fp == NULL) { MessageBox(TRL("Language file cannot be opened!"), TRL("Loading error"), MB_OK | MB_ICONWARNING); return; } fclose(fp); if(cConfig.Set(PWMKEY_LANG, szLang) == FALSE) { MessageBox(TRL("Language file cannot be activated!"), TRL("Loading error"), MB_OK | MB_ICONWARNING); return; } } else cConfig.Set(PWMKEY_LANG, _T("Standard")); CString str = TRL("The selected language has been activated. KeePass must be restarted in order to load the language."); str += _T("\r\n\r\n"); str += TRL("Do you wish to restart KeePass now?"); int iResult = CVistaTaskDialog::ShowMessageBox(this->m_hWnd, TRL("Restart KeePass?"), str, MTDI_QUESTION, TRL("&Yes"), IDOK, TRL("&No"), IDCANCEL); if(iResult < 0) iResult = MessageBox(str, TRL("Restart KeePass?"), MB_YESNO | MB_ICONQUESTION); if((iResult == IDOK) || (iResult == IDYES)) CDialog::OnOK(); }
//------------------------------------------ bool CEngine::Initialize(const wchar* settings/*="game.ini"*/, bool customWindow/*=false*/, sDisplayProperties *dp/*=NULL*/){ assertd(s_bInit==false, "DOUBLE ENGINE INITIALIZATION!"); s_bInit = true; //predict :-P // initialize random generator srand( (unsigned int)milisec() ); cInternalWindow()->BeginSplash(); // memory leaks detection #if defined(_DEBUG) && defined(_MSC_VER) && _MSC_VER >= 800 _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); //_CrtSetBreakAlloc(23296); #endif // --------------------------------------------------- // QUEUE TESTS CON(MSG_INFO, _W("------- Command Queue Test -------")); CCommandQueue q; DWORD tim; for (int t=0; t<10; t++) { tim = GetTickCount(); // FILL IN QUEUE for (int i=0; i<20000; i++) { sE2RCanvasDesc *cd; q.Enqueue(NULL, CQI_ENGINE2RENDERER_CANVAS_CREATE, (void*&)cd, sizeof(sE2RCanvasDesc)); cd->handle = 0; } CON(MSG_INFO, _W("Iteration #%d: Enqueue %d ms"), t, GetTickCount()-tim ); // DEQUEUE unsigned int cqi; const void* optr; IQueueCommandReceiver *recv; tim = GetTickCount(); while (q.Dequeue(cqi, optr, recv)) { switch(cqi) { case CQI_ENGINE2RENDERER_CANVAS_CREATE: { sE2RCanvasDesc *cd = (sE2RCanvasDesc *)optr; } break; } } CON(MSG_INFO, _W("Iteration #%d: Dequeue %d ms"), t, GetTickCount()-tim ); } CON(MSG_INFO, _W("----------------------------------")); // --------------------------------------------------- // --- WRITE INFO ABOUT LIBRARIES AND MODULES I_DebugPrint( ConsoleMsg ); CON(MSG_INFO, _W("= %s %s build %d initialization ="), _W(P3DNAME), sizeof(void*)==8?_W("x64"):_W("x86"), GetBuildNum()); if (sizeof(wchar)>1) CON(MSG_INFO, _W("Unicode support \x263A")); else CON(MSG_INFO, _W("Multibyte character set")); // --- LOAD SETTINGS m_szSettings = new wchar[wstrlen(settings)+1]; wstrcpy(m_szSettings, settings); cConfig()->Load(m_szSettings); //cConfig()->Save(m_szSettings); // --- INITIALIZE SCRIPT SYSTEM CON(MSG_INFO, _W("Script system initialization")); cScriptEngine()->Initialize(); // --- LOAD KEY BINDINGS cInputManager()->Assign(_W("GUI_CURSOR"), WE_MOUSE_MOTION, 0); cInputManager()->Assign(_W("GUI_SELECT"), WE_MOUSE_DOWN, 0); cInputManager()->Save(_W("keys.ini")); // TODO: FIXME: What about load? :D // --- CREATE MAIN WINDOW Vec2i mainWindowSize(800,600); bool initFullscreen = false; if (customWindow) { // use primary screen resolution for frame buffer // TODO: multiplatform #ifdef _WIN32 mainWindowSize.x = GetSystemMetrics(SM_CXSCREEN); mainWindowSize.y = GetSystemMetrics(SM_CYSCREEN); #endif } else { if (dp) { // use user-defined resolution initFullscreen = dp->Fullscreen; mainWindowSize.x = dp->HorRes; mainWindowSize.y = dp->VertRes; } else { // use settings initFullscreen = svFullscreen.GetBool(); mainWindowSize.x = svResolutionX.GetInt(); mainWindowSize.y = svResolutionY.GetInt(); } } cInternalWindow()->Create(mainWindowSize); //Init the internal input system cInternalInput()->Init( cInternalWindow()->GetHandle() ); //Init the Filesystem cFilesystem()->Init(); // --- LOAD SELECTED MODULES s_pRenderer = (IRenderer*)I_GetModule(_W("renderer"), svRenderer.GetString()); if (!s_pRenderer) CON(MSG_ERR_FATAL, _W("Cannot load renderer module. It is a core module, cannot continue!")); s_pSound = (ISoundEngine*)I_GetModule(_W("sound"), svSound.GetString()); if (!s_pSound) CON(MSG_ERR_FATAL, _W("Cannot load sound module. It is a core module, cannot continue!")); s_pPhys = (IPhysEngine*)I_GetModule(_W("physics"), svPhysics.GetString()); if (!s_pPhys) CON(MSG_ERR_FATAL, _W("Cannot load phys module. It is a core module, cannot continue!")); s_pFS = (IFileSystem*)I_GetModule(_W("filesystem"), svFileSystem.GetString()); if (!s_pFS) CON(MSG_ERR_FATAL, _W("Cannot load filesystem module. It is a core module, cannot continue!")); s_pGUI = (IGUI*)I_GetModule(_W("gui"), svGUI.GetString()); if (!s_pGUI) CON(MSG_ERR_FATAL, _W("Cannot load GUI module. It is a core module, cannot continue!")); m_bModulesLoaded=true; // ==== INITIALIZE MODULES ==== s_pRenderer->Initialize(this, &m_queueRenderer); bool ret = s_pRenderer->iGraphicsDevice()->Initialize(mainWindowSize.x, mainWindowSize.y, initFullscreen, cInternalWindow()->GetHandle()); if (!ret) { CON(MSG_ERR_FATAL, _W("Failed to initialize graphics device!")); } // ===== SERIALIZATION DEBUG AND TEST ======= Scene scene; //scene.Save(s_pFS, _W("scenes/test.robject"), iConsole()); //CModel model; /*model = (Model*)cObjectManager()->CreateObject( _W("Model") ); MeshData md; MeshSubset ms; // Material m; // ms.Material = m; ms.NumTriangles = 1; ms.StartIndex = 0; //ms.StartVertex = 0; md.Subsets.AddEx(ms); md.Indices.AddEx(0); md.Indices.AddEx(1); md.Indices.AddEx(2); md.NumIndices = 3; MeshVertexData mvd; mvd.Usage = _W("P3DVU_POSITION"); mvd.DataSize = 3; mvd.Float3.AddEx(Vec3Param(0.0f, 0.0f, 0.0f)); mvd.Float3.AddEx(Vec3Param(0.0f, 1.0f, 0.0f)); mvd.Float3.AddEx(Vec3Param(1.0f, 1.0f , 0.0f)); md.DataStreams.AddEx(mvd); md.NumVerts = 3; model->LODs.AddEx(md); model->Save(s_pFS, _W("triangle.robject"), iConsole()); model->PreCache();*/ // =========================================== bool initOK=true; initOK &= s_pSound->Initialize(this); initOK &= s_pPhys->Initialize(this); initOK &= s_pFS->Initialize(this); initOK &= s_pGUI->Initialize(this); if (!initOK) CON(MSG_ERR_FATAL, _W("Failed to initialize some core module(s)! Cannot continue. For more details see console.htm.")); cSceneManager()->Create(); cConsole()->InitializeGUI(); // at this time, coz it uses GUI module and it must be initialized ;) // FIXME: register engine to script, temporary here /*using namespace luabind; lua_State* L = cScriptEngine()->GetLVM(); module(L) [ class_<CEngine>("Engine") .scope [ def("GetBuildNum", &CEngine::GetBuildNum ) ] ];*/ // load bootstrap script cScriptEngine()->LoadScript(_W("scripts/bootstrap.rscript")); // DEBUG TESTING OF QUEUE TO RENDERER sE2RCanvasDesc* canvas; EnqueueMessage( MC_RENDERER, this, CQI_ENGINE2RENDERER_CANVAS_CREATE, (void*&)canvas, sizeof(sE2RCanvasDesc) ); canvas->handle = cInternalWindow()->GetHandle(); canvas->size = Vec2i(800,600); canvas->windowed = !initFullscreen; //Sleep(10000); cInternalWindow()->EndSplash(); cInternalWindow()->SetVisible(true); //Filesystem test /*UINT oSize; void *lData=0; if(cFilesystem()->Load(_W("scripts.bootstrap"), &lData, oSize)==P3D_FILERESULT_OK) cFilesystem()->FreeLoadedData(lData); const char* testStr = "this is a test string"; cFilesystem()->Save(_W("scripts.fstest"), testStr, sizeof(char)*strlen(testStr));*/ return true; }
int CMain::Init(DB *a_cDb, char *a_szCfgFile) { bool blnRet = false; int nRet = 0; const char *szTmpCfg[2]; CGlobal *cGlob = NULL; CFileLog *cLog = NULL; if(m_blnInitFlag == true){ return CLA_OK; } m_cDb = a_cDb; nRet = m_cConfig.Initialize(a_szCfgFile); if(nRet != 0){ CLA_LOG(CLA_ERR, true,"Config init failed\n"); return CLA_NOK; } cGlob = CGlobal::GetInstance(); cLog = cGlob->GetLogP(); szTmpCfg[0] = m_cConfig.GetConfigValue("GLOBAL","LOG_PATH"); if(szTmpCfg[0] == NULL){ CLA_LOG(CLA_ERR, true,"LOG_PATH not exist\n"); return CLA_NOK; } cLog->SetThreadLock(); nRet = cLog->Initialize(szTmpCfg[0], NULL, (char*)"CLA", 0, LV_ERROR); if(nRet != 0){ CLA_LOG(CLA_ERR, true,"Log init failed(nRet=%d)\n", nRet); return CLA_NOK; } szTmpCfg[0] = m_cConfig.GetConfigValue("CLC","CLI_HIST_FILE"); if(szTmpCfg[0] != NULL){ m_cHistLog = new CFileLog(); m_cHistLog->Initialize(szTmpCfg[0], NULL, (char*)"CLILOG", 0, LV_INFO); if(nRet != 0){ CLA_LOG(CLA_ERR, true,"Hist Log init failed(nRet=%d)\n", nRet); return CLA_NOK; } m_cHistLog->SetThreadLock(); } szTmpCfg[0] = m_cConfig.GetConfigValue("CLA","MESSAGE_TIMEOUT"); if(szTmpCfg[0] == NULL){ CLA_LOG(CLA_ERR,true,"MESSAGE_TIMEOUT not exist\n"); return CLA_NOK; } m_nTimeOut = atoi(szTmpCfg[0]); szTmpCfg[0] = m_cConfig.GetConfigValue("CLA","LISTEN_IP"); if(szTmpCfg[0] == NULL){ CLA_LOG(CLA_ERR,false,"LISTEN_IP not exist\n"); return CLA_NOK; } szTmpCfg[1] = m_cConfig.GetConfigValue("CLA","LISTEN_PORT"); if(szTmpCfg[1] == NULL){ CLA_LOG(CLA_ERR,false,"LISTEN_PORT not exist\n"); return CLA_NOK; } blnRet = m_cSock.Listen( szTmpCfg[0], atoi(szTmpCfg[1])); if(blnRet == false){ CLA_LOG(CLI_ERR,false, "Socket listen failed\n"); return CLA_NOK; } CClaConfig cConfig(m_cDb, nRet); cConfig.DBLoadCmdDest(&m_cCliRoute); m_blnInitFlag = true; CLA_LOG(CLA_ERR,true,"CLA MODULE START\n"); return CLA_OK; }
Clock::Clock( QWidget * parent, const char *, WFlags f ) : ClockBase( parent, "clock", f ), swatch_splitms(99), init(FALSE) // No tr { alarmDlg = 0; swLayout = 0; alarmProc = 0; alarmCmd = 0; dayBtn = new QToolButton * [7]; Config config( "qpe" ); config.setGroup("Time"); ampm = config.readBoolEntry( "AMPM", TRUE ); onMonday = config.readBoolEntry( "MONDAY" ); connect( tabs, SIGNAL(currentChanged(QWidget*)), this, SLOT(tabChanged(QWidget*)) ); analogStopwatch = new AnalogClock( swFrame ); stopwatchLcd = new QLCDNumber( swFrame ); stopwatchLcd->setFrameStyle( QFrame::NoFrame ); stopwatchLcd->setSegmentStyle( QLCDNumber::Flat ); stopwatchLcd->setSizePolicy( QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred) ); analogClock->display( QTime::currentTime() ); clockLcd->setNumDigits( 5 ); clockLcd->setFixedWidth( clockLcd->sizeHint().width() ); date->setText( TimeString::dateString( QDate::currentDate(), TimeString::currentDateFormat() ) ); if ( qApp->desktop()->width() < 200 ) date->setFont( QFont(date->font().family(), 14, QFont::Bold) ); if ( qApp->desktop()->height() > 240 ) { clockLcd->setFixedHeight( 30 ); stopwatchLcd->setFixedHeight( 30 ); } connect( stopStart, SIGNAL(pressed()), SLOT(stopStartStopWatch()) ); connect( reset, SIGNAL(pressed()), SLOT(resetStopWatch()) ); t = new QTimer( this ); connect( t, SIGNAL(timeout()), SLOT(updateClock()) ); t->start( 1000 ); applyAlarmTimer = new QTimer( this ); connect( applyAlarmTimer, SIGNAL(timeout()), this, SLOT(applyDailyAlarm()) ); alarmt = new QTimer( this ); connect( alarmt, SIGNAL(timeout()), SLOT(alarmTimeout()) ); connect( qApp, SIGNAL(timeChanged()), SLOT(updateClock()) ); connect( qApp, SIGNAL(timeChanged()), SLOT(applyDailyAlarm()) ); swatch_running = FALSE; swatch_totalms = 0; swatch_currLap = 0; swatch_dispLap = 0; stopwatchLcd->setNumDigits( 8+1+sw_prec ); stopwatchLcd->display( "00:00:00.00" ); QVBoxLayout *lvb = new QVBoxLayout( lapFrame ); nextLapBtn = new QToolButton( UpArrow, lapFrame ); connect( nextLapBtn, SIGNAL(clicked()), this, SLOT(nextLap()) ); nextLapBtn->setAccel( Key_Up ); lvb->addWidget( nextLapBtn ); prevLapBtn = new QToolButton( DownArrow, lapFrame ); connect( prevLapBtn, SIGNAL(clicked()), this, SLOT(prevLap()) ); prevLapBtn->setAccel( Key_Down ); prevLapBtn->setMinimumWidth( 15 ); lvb->addWidget( prevLapBtn ); prevLapBtn->setEnabled( FALSE ); nextLapBtn->setEnabled( FALSE ); reset->setEnabled( FALSE ); lapLcd->setNumDigits( 8+1+sw_prec ); lapLcd->display( "00:00:00.00" ); splitLcd->setNumDigits( 8+1+sw_prec ); splitLcd->display( "00:00:00.00" ); lapNumLcd->display( 1 ); lapTimer = new QTimer( this ); connect( lapTimer, SIGNAL(timeout()), this, SLOT(lapTimeout()) ); for (uint s = 0; s < swatch_splitms.count(); s++ ) swatch_splitms[(int)s] = 0; connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(changeClock(bool)) ); cdGroup->hide(); // XXX implement countdown timer. connect( dailyHour, SIGNAL(valueChanged(int)), this, SLOT(scheduleApplyDailyAlarm()) ); connect( dailyMinute, SIGNAL(valueChanged(int)), this, SLOT(setDailyMinute(int)) ); connect( dailyAmPm, SIGNAL(activated(int)), this, SLOT(setDailyAmPm(int)) ); connect( dailyEnabled, SIGNAL(toggled(bool)), this, SLOT(enableDaily(bool)) ); cdLcd->display( "00:00" ); dailyMinute->setValidator(0); Config cConfig( "Clock" ); // No tr cConfig.setGroup( "Daily Alarm" ); QStringList days; days.append( tr("Mon", "Monday") ); days.append( tr("Tue", "Tuesday") ); days.append( tr("Wed", "Wednesday") ); days.append( tr("Thu", "Thursday") ); days.append( tr("Fri", "Friday") ); days.append( tr("Sat", "Saturday") ); days.append( tr("Sun", "Sunday") ); int i; QHBoxLayout *hb = new QHBoxLayout( daysFrame ); for ( i = 0; i < 7; i++ ) { dayBtn[i] = new QToolButton( daysFrame ); hb->addWidget( dayBtn[i] ); dayBtn[i]->setToggleButton( TRUE ); dayBtn[i]->setOn( TRUE ); dayBtn[i]->setFocusPolicy( StrongFocus ); connect( dayBtn[i], SIGNAL(toggled(bool)), this, SLOT(scheduleApplyDailyAlarm()) ); } for ( i = 0; i < 7; i++ ) dayBtn[dayBtnIdx(i+1)]->setText( days[i] ); QStringList exclDays = cConfig.readListEntry( "ExcludeDays", ',' ); QStringList::Iterator it; for ( it = exclDays.begin(); it != exclDays.end(); ++it ) { int d = (*it).toInt(); if ( d >= 1 && d <= 7 ) dayBtn[dayBtnIdx(d)]->setOn( FALSE ); } sbSnoozeTime->setValue( cConfig.readNumEntry( "SnoozeTime", DEFAULT_SNOOZE_TIME ) ); connect( sndOption, SIGNAL( activated(int) ), SLOT( slotSoundChange(int) ) ); sndOption->insertItem(tr("Default alarm")); sndOption->insertItem(tr("Play file in background")); sndOption->insertItem(tr("Play file with OpiePlayer")); sndOption->insertItem(tr("Play file with OpiePlayer 2")); bool alarm = cConfig.readBoolEntry("Enabled", FALSE); dailyEnabled->setChecked( alarm ); sndGroup->setEnabled( alarm ); // FIXME ODP migrate to own config class.. merge config options Config cfg_qpe( "qpe" ); cfg_qpe.setGroup( "Time" ); sndFileName->setText( cfg_qpe.readEntry( "mp3File" ) ); sndOption->setCurrentItem( cfg_qpe.readNumEntry( "mp3Player", DEFAULT_ALARMTYPE ) ); slotSoundChange(sndOption->currentItem()); int m = cConfig.readNumEntry( "Minute", 0 ); dailyMinute->setValue( m ); // dailyMinute->setPrefix( m <= 9 ? "0" : "" ); int h = cConfig.readNumEntry( "Hour", 7 ); if ( ampm ) { if (h > 12) { h -= 12; dailyAmPm->setCurrentItem( 1 ); } if (h == 0) h = 12; dailyHour->setMinValue( 1 ); dailyHour->setMaxValue( 12 ); } else { dailyAmPm->hide(); } dailyHour->setValue( h ); connect( ((MySpinBox*)dailyHour)->lineEdit(), SIGNAL(textChanged(const QString&)), this, SLOT(dailyEdited()) ); connect( ((MySpinBox*)dailyMinute)->lineEdit(), SIGNAL(textChanged(const QString&)), this, SLOT(dailyEdited()) ); #if defined(Q_WS_QWS) && !defined(QT_NO_COP) connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)), this, SLOT(appMessage(const QCString&,const QByteArray&)) ); #endif QTimer::singleShot( 0, this, SLOT(updateClock()) ); swFrame->installEventFilter( this ); init = TRUE; }