//------------------------------------------------------------------------ //! Removes the current configuration //------------------------------------------------------------------------ void CViewConfigSectionProfiles::RemoveCurrentConfig() { if (GetSectionName() == m_ViewName) { // Backup strProfile-settings and reset the other settings const CString& strProfiles = ReadSetting(m_ViewName, _T("CurrentProfiles"), _T("")); const CString& activeProfile = ReadSetting(m_ViewName, _T("ActiveProfile"), _T("")); CViewConfigSectionDefault::RemoveCurrentConfig(); WriteSetting(m_ViewName, _T("CurrentProfiles"), strProfiles); WriteSetting(m_ViewName, _T("ActiveProfile"), activeProfile); } else { CViewConfigSectionDefault::RemoveCurrentConfig(); } }
///////////////////////////////////////////////////////////////////// // makeKanBeWin ///////////////////////////////////////////////////////////////////// void kanBeApp::makeKanBeWin(void) { BFont aFont; font_height h_info; float h, w; char basepath[B_FILE_NAME_LENGTH]; ReadSetting(basepath, &aFont); setBasePath(basepath); w = aFont.StringWidth(B_UTF8_HIROSHI); // kanji width aFont.GetHeight(&h_info); h = h_info.ascent + h_info.descent + h_info.leading; mWindow = new BWindow(InitFrame(w, h), "kanBe ver. 0.52", B_TITLED_WINDOW, B_NOT_RESIZABLE|B_NOT_CLOSABLE|B_NOT_MINIMIZABLE|B_NOT_ZOOMABLE); mWindow->Lock(); mView = new FEPView(mWindow->Bounds()); mView->SetFont(&aFont); mWindow->AddChild(mView); mWindow->Unlock(); mWindow->Show(); }
/* * Main... * */ int main(int argc, char **argv) { const char *me = (const char *)basename(argv[0]); bool SwitchesAllowed = true; bool WriteMode = false; int ReturnCode = 0; const char *preloadfile = DEFAULT_PRELOAD; PrintName = true; if (argc < 2) { return Usage(me); } /* endif */ argv++; for (; argv && *argv && **argv; argv++) { if (SwitchesAllowed && **argv == '-') { /* we have a switch */ switch((*argv)[1]) { case 'n': PrintName = false; break; case 'w': SwitchesAllowed = false; WriteMode = true; break; case 'p': argv++; if (argv && *argv && **argv) { preloadfile = *argv; } /* endif */ Preload(preloadfile); return(0); break; case 'a': case 'A': SwitchesAllowed = false; return DisplayAll(PROC_PATH, ((*argv)[1] == 'a') ? false : true); case 'h': case '?': return Usage(me); default: fprintf(stderr, ERR_UNKNOWN_PARAMETER, *argv); return Usage(me); } /* end switch */ } else { SwitchesAllowed = false; if (WriteMode) ReturnCode = WriteSetting(*argv); else ReadSetting(*argv); } /* end if */ } /* end for */ return ReturnCode; } /* end main */
bool SettingsFile::ReadSetting( char *section, int sectionSize, char *param, int paramSize, char *subparam, int subparamSize, char *value, int valueSize ) { bool rc = ReadSetting(); if (rc) { strncpy(section, m_strSection, sectionSize); strncpy(param, m_strParam, paramSize); strncpy(subparam, m_strSubParam, subparamSize); strncpy(value, m_strValue, valueSize); } return rc; }
//------------------------------------------------------------------------ //! Retrieves the section name of the currently active configuration profile //! //! @return Current section name //------------------------------------------------------------------------ const CString& CViewConfigSectionProfiles::GetSectionName() const { if (m_CurrentSection == m_ViewName) { CString strProfile = ReadSetting(m_ViewName, _T("ActiveProfile"), _T("")); if (strProfile.IsEmpty()) { CSimpleArray<CString> profiles; GetProfiles(profiles); if (profiles.GetSize()>0) strProfile = profiles[0]; } m_CurrentSection = JoinSectionName(m_ViewName, strProfile); } return m_CurrentSection; }
unsigned int CSettings::ReadSetting(TDBTSetting & Setting) { CBlockManager * file = &m_BlockManagerPri; if (Setting.Descriptor->Entity == 0) file = &m_BlockManagerSet; CBlockManager::ReadTransaction trans(*file); TDBTSettingHandle hset = FindSetting(*Setting.Descriptor); if ((hset == 0) || (hset == DBT_INVALIDPARAM)) return DBT_INVALIDPARAM; PDBTSettingDescriptor back = Setting.Descriptor; Setting.Descriptor = NULL; if (ReadSetting(Setting, hset) == DBT_INVALIDPARAM) hset = DBT_INVALIDPARAM; Setting.Descriptor = back; return hset; }
/* * Display all the sysctl settings * */ int DisplayAll(const char *path, bool ShowTableUtil) { int rc = 0; int rc2; DIR *dp; struct dirent *de; char *tmpdir; struct stat ts; dp = opendir(path); if (!dp) { fprintf(stderr, ERR_OPENING_DIR, path); rc = -1; } else { readdir(dp); readdir(dp); /* skip . and .. */ while (de = readdir(dp)) { tmpdir = (char *)malloc(strlen(path)+strlen(de->d_name)+2); sprintf(tmpdir, "%s%s", path, de->d_name); rc2 = stat(tmpdir, &ts); /* should check this return code */ if (rc2 != 0) { perror(tmpdir); } else { if (S_ISDIR(ts.st_mode)) { strcat(tmpdir, "/"); DisplayAll(tmpdir, ShowTableUtil); } else { rc |= ReadSetting(tmpdir+strlen(PROC_PATH)); } /* endif */ } /* endif */ free(tmpdir); } /* end while */ closedir(dp); } /* endif */ return rc; } /* end DisplayAll() */
QString PathManager::GetDecPackPath() { ReadSetting(); return DECPACKPATH; }
int PathManager::GetThreadNum() { ReadSetting(); return THREADNUM; }
QString PathManager::GetAliasesPasswd() { ReadSetting(); return ALIASESPASSWD; }
QString PathManager::GetKeyAliases() { ReadSetting(); return KEYALIASES; }
QString PathManager::GetPasswd() { ReadSetting(); return PASSWD; }
QString PathManager::GetSdkPath() { ReadSetting(); return SDKPATH; }
QString PathManager::GetSrcPath() { ReadSetting(); return SRCPATH; }
QString PathManager::GetKeyPath() { ReadSetting(); return KEYPATH; }
TDBTSettingHandle CSettings::IterationNext(TDBTSettingIterationHandle Iteration) { PSettingIteration iter = reinterpret_cast<PSettingIteration>(Iteration); CBlockManager::ReadTransaction transset; CBlockManager::ReadTransaction transpri; if (iter->LockSetting) transset = CBlockManager::ReadTransaction(m_BlockManagerSet); if (iter->LockPrivate) transpri = CBlockManager::ReadTransaction(m_BlockManagerPri); while (iter->Frame->empty() && iter->Heap->Top()) { while (iter->Heap->Top() && iter->Heap->Top().wasDeleted()) iter->Heap->Pop(); if (iter->Heap->Top()) { uint32_t h = iter->Heap->Top()->Hash; std::queue<TSettingIterationHelper> q; TSettingIterationHelper help; help.NameLen = 0; help.Name = NULL; help.Handle = iter->Heap->Top()->Setting; help.Tree = (CSettingsTree *) iter->Heap->Top().Tree(); if (help.Tree) q.push(help); iter->Heap->Pop(); // add all candidates while (iter->Heap->Top() && (iter->Heap->Top()->Hash == h)) { if (!iter->Heap->Top().wasDeleted()) { help.Handle = iter->Heap->Top()->Setting; help.Tree = (CSettingsTree *) iter->Heap->Top().Tree(); q.push(help); } iter->Heap->Pop(); } while (!q.empty()) { help = q.front(); q.pop(); if (help.Name == NULL) { if (help.Tree->Entity() == 0) _ReadSettingName(m_BlockManagerSet, help.Handle, help.NameLen, help.Name); else _ReadSettingName(m_BlockManagerPri, help.Handle, help.NameLen, help.Name); } q.push(help); while (q.front().Handle != help.Handle) // remove all queued settings with same name { bool namereadres = false; TSettingIterationHelper tmp; tmp = q.front(); q.pop(); if (tmp.Name == NULL) { if (tmp.Tree->Entity() == 0) namereadres = _ReadSettingName(m_BlockManagerSet, tmp.Handle, tmp.NameLen, tmp.Name); else namereadres = _ReadSettingName(m_BlockManagerPri, tmp.Handle, tmp.NameLen, tmp.Name); } if (!namereadres) { q.push(tmp); } else { if (strcmp(tmp.Name, help.Name) != 0) { q.push(tmp); } else { free(tmp.Name); } } } // namefilter if ((iter->Filter.NameStart == NULL) || ((iter->FilterNameStartLength <= help.NameLen) && (memcmp(iter->Filter.NameStart, help.Name, iter->FilterNameStartLength) == 0))) { TSettingIterationResult tmp; if (help.Tree->Entity() == 0) help.Handle |= cSettingsFileFlag; tmp.Handle = help.Handle; tmp.Entity = help.Tree->Entity(); tmp.Name = help.Name; tmp.NameLen = help.NameLen; iter->Frame->push(tmp); } else { free(help.Name); } q.pop(); } } } TSettingIterationResult res = {0,0,0,0}; if (!iter->Frame->empty()) { res = iter->Frame->front(); iter->Frame->pop(); if ((iter->Filter.Descriptor) && ((iter->Filter.Setting == NULL) || (iter->Filter.Setting->Descriptor != iter->Filter.Descriptor))) { iter->Filter.Descriptor->Entity = res.Entity; iter->Filter.Descriptor->pszSettingName = (char *) mir_realloc(iter->Filter.Descriptor->pszSettingName, res.NameLen + 1); memcpy(iter->Filter.Descriptor->pszSettingName, res.Name, res.NameLen + 1); iter->Filter.Descriptor->FoundInEntity = res.Entity; } if (iter->Filter.Setting) { if ((iter->Filter.Setting->Type & DBT_STF_VariableLength) && (iter->Filter.Setting->Value.pBlob)) { mir_free(iter->Filter.Setting->Value.pBlob); iter->Filter.Setting->Value.pBlob = NULL; } iter->Filter.Setting->Type = 0; ReadSetting(*iter->Filter.Setting, res.Handle); } free(res.Name); } return res.Handle; }
QString PathManager::GetVersion() { ReadSetting(); return VERSION; }
int PathManager::GetPackWay() { ReadSetting(); return PACKWAY; }
//------------------------------------------------------------------------ //! Retrieves a setting value for the view //! //! @param strName Name of setting //! @param strDefval Default value to return if no value was found //! @return Value of the setting //------------------------------------------------------------------------ CString CViewConfigSection::GetSetting(const CString& strName, const CString& strDefval) const { return ReadSetting(GetSectionName(), strName, strDefval); }
QString PathManager::GetSigalg() { ReadSetting(); return SIGALG; }
//------------------------------------------------------------------------ //! Retrieves the list of currently available configuration profiles //! //! @param profiles List of profile names //------------------------------------------------------------------------ void CViewConfigSectionProfiles::GetProfiles(CSimpleArray<CString>& profiles) const { const CString& strProfiles = ReadSetting(m_ViewName, _T("CurrentProfiles"), _T("")); SplitArraySetting(strProfiles, profiles, _T(", ")); }
QString PathManager::GetDigestalg() { ReadSetting(); return DIGESTALG; }
//************************************************ //*主程序 //************************************************ int APIENTRY t1::_tWinMain(HINSTANCE &hInstance, HINSTANCE &hPrevInstance, LPTSTR &lpCmdLine, int &nCmdShow, HWND &_hWnd, std::string winClassName, std::string winName) { // 初始化句柄和状态 bool bUnClosedLastWin = true; hWnd = _hWnd; gHinstance = hInstance; ShowCursor(FALSE); //g_nThreadExitCount = 0; //获得传递的命令行参数,得到被试着名字和任务编号 char *pdest; int result; int pos1; pdest = strrchr(lpCmdLine, ' '); pos1 = pdest - lpCmdLine; if (pos1>0) { strncpy(m_TaskNumStr, lpCmdLine, pos1); } else { strcpy(m_TaskNumStr, ""); } pdest = strrchr(lpCmdLine, '-'); result = pdest - lpCmdLine; if (result>0) { strncpy(m_TesterName, lpCmdLine + pos1 + 1, result - pos1 - 1); } else { strcpy(m_TesterName, ""); } if (pos1>0) { strcpy(m_DataName, lpCmdLine + pos1 + 1); } else { strcpy(m_DataName, ""); } //读取任务设置 if (!ReadSetting()) { MessageBox(hWnd, "任务设置文件格式错误!", "测试任务", MB_OK); return 0; } //注册窗口类 WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS, MsgProc, 0L, 0L, hInstance, NULL, NULL, NULL, NULL, std::to_string(nCmdShow).c_str(), NULL }; RegisterClassEx(&wc); x_resolution = GetSystemMetrics(SM_CXSCREEN); y_resolution = GetSystemMetrics(SM_CYSCREEN); rec_x_begin = (x_resolution - 1024) / 2; rec_y_begin = (y_resolution - 768) / 2; rec_x_end = (x_resolution + 1024) / 2; rec_y_end = (y_resolution + 768) / 2; _hWnd = hWnd = CreateWindow(std::to_string(nCmdShow).c_str(), std::to_string(nCmdShow).c_str(), WS_VISIBLE | WS_POPUP, 0, 0, x_resolution, y_resolution, NULL, NULL, hInstance, NULL); //显示主窗口 SetFocus(hWnd); //创建DirectX设备 if (FAILED(DirectInput8Create(hInstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&m_lpkDInput, NULL))) { return 0; } float m_JoySpeedMax; if (m_HardSetting.m_JoySpeedMax > 0) { m_JoySpeedMax = m_HardSetting.m_JoySpeedMax; } else { m_JoySpeedMax = 200; } //关闭输入法 HKL hkl; hkl = LoadKeyboardLayout("00000804", KLF_ACTIVATE); if (hkl != NULL) { ActivateKeyboardLayout(hkl, KLF_SETFORPROCESS); } //ShowCursor(FALSE); //设置操纵杆变化范围 if (JoystickInit(hWnd, -m_JoySpeedMax, m_JoySpeedMax, 1)) { JoystickUpdate(); } else { MessageBox(hWnd, "请检查操纵杆连接是否正确!", "测试任务", MB_OK); return 0; } // declare a variable of our data structure to pass to the ThreadProcedure MYDATA MyThreadData; MyThreadData.nTime = 7509843; MyThreadData.nNumber = 39; //创建操纵杆输入线程 // declare a DWORD to hold our thread's new generated ID HANDLE h = CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)InputThreadProcedure, (LPVOID)&MyThreadData, NULL, &dwInputThreadID); // SetPriorityClass(h,NORMAL_PRIORITY_CLASS); // SetThreadPriority(h,THREAD_PRIORITY_ABOVE_NORMAL); // actually create and start the thread now! // the thread will run until we send it our own WM_THREADSTOP message srand((unsigned)time(NULL)); //初始化随机种子 //初始化Direct3D bool b_InitD3d = SUCCEEDED(InitD3D(hWnd)); if (b_InitD3d) { //进入消息循环 MSG msg; ZeroMemory(&msg, sizeof(msg)); while (msg.message != WM_QUIT) { if (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE)) { //处理外部消息 TranslateMessage(&msg); DispatchMessage(&msg); } else { //执行测试过程 UpdateState(); if (m_bDisplayReady) { //渲染图形 Render(); hideLastWindow(bUnClosedLastWin, winClassName, winName, hInstance); } } Sleep(1); // 当按下“下一个任务”或“退出”时,终止消息循环 if (m_TestState == STATE_NEXT || m_TestState == STATE_EXIT) { break; } } } ShowCursor(TRUE); CloseHandle(h); return rtn; }
QString PathManager::GetOutPath() { ReadSetting(); return OUTPATH; }