void QWinSettingsPrivate::remove(const QString &uKey) { if (writeHandle() == 0) { setStatus(QSettings::AccessError); return; } QString rKey = escapedKey(uKey); // try to delete value bar in key foo LONG res; HKEY handle = openKey(writeHandle(), registryPermissions, keyPath(rKey)); if (handle != 0) { res = RegDeleteValue(handle, reinterpret_cast<const wchar_t *>(keyName(rKey).utf16())); RegCloseKey(handle); } // try to delete key foo/bar and all subkeys handle = openKey(writeHandle(), registryPermissions, rKey); if (handle != 0) { deleteChildGroups(handle); if (rKey.isEmpty()) { QStringList childKeys = childKeysOrGroups(handle, QSettingsPrivate::ChildKeys); for (int i = 0; i < childKeys.size(); ++i) { QString group = childKeys.at(i); LONG res = RegDeleteValue(handle, reinterpret_cast<const wchar_t *>(group.utf16())); if (res != ERROR_SUCCESS) { qWarning("QSettings: RegDeleteValue failed on subkey \"%s\": %s", group.toLatin1().data(), errorCodeToString(res).toLatin1().data()); } } } else { #if defined(Q_OS_WINCE) // For WinCE always Close the handle first. RegCloseKey(handle); #endif res = RegDeleteKey(writeHandle(), reinterpret_cast<const wchar_t *>(rKey.utf16())); if (res != ERROR_SUCCESS) { qWarning("QSettings: RegDeleteKey failed on key \"%s\": %s", rKey.toLatin1().data(), errorCodeToString(res).toLatin1().data()); } } RegCloseKey(handle); } }
NTSTATUS getKeyFullInformation(KEY_FULL_INFORMATION **info, WCHAR *key) { HANDLE hreg; ULONG resultlen; NTSTATUS status; hreg = openKey(key, KEY_READ); if (!hreg) return STATUS_OBJECT_PATH_NOT_FOUND; resultlen = sizeof(KEY_FULL_INFORMATION) + 100*sizeof(WCHAR); *info = ExAllocatePoolWithTag ( PagedPool, resultlen, CRASH_TAG); if (!*info) { ZwClose(hreg); return STATUS_NO_MEMORY; } status = ZwQueryKey(hreg, KeyFullInformation, *info, resultlen, &resultlen); if (status == STATUS_BUFFER_OVERFLOW) { ExFreePool(*info); *info = ExAllocatePoolWithTag ( PagedPool, resultlen, CRASH_TAG); if (*info) status = ZwQueryKey(hreg, KeyFullInformation, *info, resultlen, &resultlen); } if (status != STATUS_SUCCESS && *info) { ExFreePool(*info); *info = NULL; } ZwClose(hreg); return status; }
QStringList QWinSettingsPrivate::children(const QString &uKey, ChildSpec spec) const { NameSet result; QString rKey = escapedKey(uKey); for (int i = 0; i < regList.size(); ++i) { HKEY parent_handle = regList.at(i).handle(); if (parent_handle == 0) continue; HKEY handle = openKey(parent_handle, KEY_READ, rKey); if (handle == 0) continue; if (spec == AllKeys) { NameSet keys; allKeys(handle, QLatin1String(""), &keys); mergeKeySets(&result, keys); } else { // ChildGroups or ChildKeys QStringList names = childKeysOrGroups(handle, spec); mergeKeySets(&result, names); } RegCloseKey(handle); if (!fallbacks) return result.keys(); } return result.keys(); }
/****************************************************************************** * This funtion is the main entry point to the queryValue type of action. It * receives the currently read line and dispatch the work depending on the * context. */ void doQueryValue(LPTSTR stdInput) { /* * We encoutered the end of the file, make sure we * close the opened key and exit */ if (stdInput == NULL) { if (bTheKeyIsOpen != FALSE) closeKey(); return; } if (stdInput[0] == _T('[')) { /* We are reading a new key */ if (bTheKeyIsOpen != FALSE) closeKey(); /* Close the previous key before */ if (openKey(stdInput) != ERROR_SUCCESS ) { _tprintf(_T("doQueryValue failed to open key %s\n"), stdInput); } } else if( (bTheKeyIsOpen) && ((stdInput[0] == _T('@')) || /* reading a default @=data pair */ (stdInput[0] == _T('\"')))) { /* reading a new value=data pair */ processQueryValue(stdInput); } else { /* since we are assuming that the file format is */ if (bTheKeyIsOpen) /* valid we must be reading a blank line which */ closeKey(); /* indicate end of this key processing */ } }
static void allKeys(HKEY parentHandle, const QString &rSubKey, NameSet *result) { HKEY handle = openKey(parentHandle, KEY_READ, rSubKey); if (handle == 0) return; QStringList childKeys = childKeysOrGroups(handle, QSettingsPrivate::ChildKeys); QStringList childGroups = childKeysOrGroups(handle, QSettingsPrivate::ChildGroups); RegCloseKey(handle); for (int i = 0; i < childKeys.size(); ++i) { QString s = rSubKey; if (!s.isEmpty()) s += QLatin1Char('\\'); s += childKeys.at(i); result->insert(s, QString()); } for (int i = 0; i < childGroups.size(); ++i) { QString s = rSubKey; if (!s.isEmpty()) s += QLatin1Char('\\'); s += childGroups.at(i); allKeys(parentHandle, s, result); } }
HKEY ArchMiscWindows::openKey(HKEY key, const TCHAR* const* keyNames, bool create) { for (size_t i = 0; key != NULL && keyNames[i] != NULL; ++i) { // open next key key = openKey(key, keyNames[i], create); } return key; }
void RegElement::remove() { HKEY parent_key; LONG result = openKey(root_, path_, &parent_key, KEY_ALL_ACCESS); if (result != ERROR_SUCCESS) { return; } result = RegDeleteValueW (parent_key, name_.toStdWString().c_str()); RegCloseKey(parent_key); }
HKEY RegistryKey::handle() const { if (m_handle != 0) return m_handle; if (m_read_only) m_handle = openKey(m_parent_handle, KEY_READ, m_key); else m_handle = createOrOpenKey(m_parent_handle, m_key, &m_read_only); return m_handle; }
// Open a key with the specified perms, create it if it does not exist static HKEY createOrOpenKey(HKEY parentHandle, REGSAM perms, const QString &rSubKey) { // try to open it HKEY resultHandle = openKey(parentHandle, perms, rSubKey); if (resultHandle != 0) return resultHandle; // try to create it LONG res = RegCreateKeyEx(parentHandle, reinterpret_cast<const wchar_t *>(rSubKey.utf16()), 0, 0, REG_OPTION_NON_VOLATILE, perms, 0, &resultHandle, 0); if (res == ERROR_SUCCESS) return resultHandle; //qWarning("QSettings: Failed to create subkey \"%s\": %s", // rSubKey.toLatin1().data(), errorCodeToString(res).toLatin1().data()); return 0; }
bool RegElement::exists() { HKEY parent_key; LONG result = openKey(root_, path_, &parent_key, KEY_READ); if (result != ERROR_SUCCESS) { return false; } result = RegQueryValueExW (parent_key, name_.toStdWString().c_str(), NULL, /* reserved */ NULL, /* output type */ NULL, /* output data */ NULL); /* output length */ RegCloseKey(parent_key); if (result != ERROR_SUCCESS) { return false; } return true; }
static void deleteChildGroups(HKEY parentHandle) { QStringList childGroups = childKeysOrGroups(parentHandle, QSettingsPrivate::ChildGroups); for (int i = 0; i < childGroups.size(); ++i) { QString group = childGroups.at(i); // delete subgroups in group HKEY childGroupHandle = openKey(parentHandle, registryPermissions, group); if (childGroupHandle == 0) continue; deleteChildGroups(childGroupHandle); RegCloseKey(childGroupHandle); // delete group itself LONG res = RegDeleteKey(parentHandle, reinterpret_cast<const wchar_t *>(group.utf16())); if (res != ERROR_SUCCESS) { qWarning("QSettings: RegDeleteKey failed on subkey \"%s\": %s", group.toLatin1().data(), errorCodeToString(res).toLatin1().data()); return; } } }
bool RegElement::exists() { HKEY parent_key; LONG result = openKey(root_, path_, &parent_key); if (result != ERROR_SUCCESS) { return false; } char buf[MAX_PATH] = {0}; DWORD len = sizeof(buf); result = RegQueryValueExW (parent_key, name_.toStdWString().c_str(), NULL, /* reserved */ NULL, /* output type */ (LPBYTE)buf, /* output data */ &len); /* output length */ RegCloseKey(parent_key); if (result != ERROR_SUCCESS) { return false; } return true; }
HKEY CArchMiscWindows::openKey(HKEY key, const TCHAR* keyName) { return openKey(key, keyName, false); }
bool QWinSettingsPrivate::readKey(HKEY parentHandle, const QString &rSubKey, QVariant *value) const { QString rSubkeyName = keyName(rSubKey); QString rSubkeyPath = keyPath(rSubKey); // open a handle on the subkey HKEY handle = openKey(parentHandle, KEY_READ, rSubkeyPath); if (handle == 0) return false; // get the size and type of the value DWORD dataType; DWORD dataSize; LONG res = RegQueryValueEx(handle, reinterpret_cast<const wchar_t *>(rSubkeyName.utf16()), 0, &dataType, 0, &dataSize); if (res != ERROR_SUCCESS) { RegCloseKey(handle); return false; } // get the value QByteArray data(dataSize, 0); res = RegQueryValueEx(handle, reinterpret_cast<const wchar_t *>(rSubkeyName.utf16()), 0, 0, reinterpret_cast<unsigned char*>(data.data()), &dataSize); if (res != ERROR_SUCCESS) { RegCloseKey(handle); return false; } switch (dataType) { case REG_EXPAND_SZ: case REG_SZ: { QString s; if (dataSize) { s = QString::fromWCharArray(((const wchar_t *)data.constData())); } if (value != 0) *value = stringToVariant(s); break; } case REG_MULTI_SZ: { QStringList l; if (dataSize) { int i = 0; for (;;) { QString s = QString::fromWCharArray((const wchar_t *)data.constData() + i); i += s.length() + 1; if (s.isEmpty()) break; l.append(s); } } if (value != 0) *value = stringListToVariantList(l); break; } case REG_NONE: case REG_BINARY: { QString s; if (dataSize) { s = QString::fromWCharArray((const wchar_t *)data.constData(), data.size() / 2); } if (value != 0) *value = stringToVariant(s); break; } case REG_DWORD_BIG_ENDIAN: case REG_DWORD: { Q_ASSERT(data.size() == sizeof(int)); int i; memcpy((char*)&i, data.constData(), sizeof(int)); if (value != 0) *value = i; break; } case REG_QWORD: { Q_ASSERT(data.size() == sizeof(qint64)); qint64 i; memcpy((char*)&i, data.constData(), sizeof(qint64)); if (value != 0) *value = i; break; } default: qWarning("QSettings: Unknown data %d type in Windows registry", static_cast<int>(dataType)); if (value != 0) *value = QVariant(); break; } RegCloseKey(handle); return true; }
/*! This is the main routine of measurement. @param[in,out] prms A pointer to a #AK8975PRMS structure. */ void MeasureSNGLoop(AK8975PRMS* prms) { BYTE i2cData[AKSC_BDATA_SIZE]; int16 i; int16 bData[AKSC_BDATA_SIZE]; // Measuring block data int16 ret; int32 ch; int32 doze; int32_t delay; AKMD_INTERVAL interval; struct timespec tsstart, tsend; if (openKey() < 0) { DBGPRINT(DBG_LEVEL1, "%s:%d Error.\n", __FUNCTION__, __LINE__); return; } if (openFormation() < 0) { DBGPRINT(DBG_LEVEL1, "%s:%d Error.\n", __FUNCTION__, __LINE__); return; } // Get initial interval GetValidInterval(CSPEC_INTERVAL_SNG, &interval); // Initialize if(InitAK8975_Measure(prms) != AKD_SUCCESS){ return; } while(TRUE){ // Get start time if (clock_gettime(CLOCK_REALTIME, &tsstart) < 0) { DBGPRINT(DBG_LEVEL1, "%s:%d Error.\n", __FUNCTION__, __LINE__); return; } // Set to SNG measurement pattern (Set CNTL register) if (AKD_SetMode(AK8975_MODE_SNG_MEASURE) != AKD_SUCCESS) { DBGPRINT(DBG_LEVEL1, "%s:%d Error.\n", __FUNCTION__, __LINE__); return; } // .! : 获取 M snesor 的原始数据. 这里可能阻塞. // Get measurement data from AK8975 // ST1 + (HXL + HXH) + (HYL + HYH) + (HZL + HZH) + ST2 // = 1 + (1 + 1) + (1 + 1) + (1 + 1) + 1 = 8 bytes if (AKD_GetMagneticData(i2cData) != AKD_SUCCESS) { DBGPRINT(DBG_LEVEL1, "%s:%d Error.\n", __FUNCTION__, __LINE__); return; } // Copy to local variable // DBGPRINT(DBG_LEVEL3, "%s: bData(Hex)=", __FUNCTION__); for(i=0; i<AKSC_BDATA_SIZE; i++){ bData[i] = i2cData[i]; // DBGPRINT(DBG_LEVEL3, "%02x,", bData[i]); } // DBGPRINT(DBG_LEVEL3, "\n"); D_WHEN_REPEAT(100, "raw mag x : %d, raw mag y : %d, raw mag z : %d.", (signed short)(bData[1] + (bData[2] << 8) ), (signed short)(bData[3] + (bData[4] << 8) ), (signed short)(bData[5] + (bData[6] << 8) ) ); // .! : // Get acceelration sensor's measurement data. if (GetAccVec(prms) != AKRET_PROC_SUCCEED) { return; } /* DBGPRINT(DBG_LEVEL3, "%s: acc(Hex)=%02x,%02x,%02x\n", __FUNCTION__, prms->m_avec.u.x, prms->m_avec.u.y, prms->m_avec.u.z); */ ret = MeasuringEventProcess( bData, prms, getFormation(), interval.decimator, CSPEC_CNTSUSPEND_SNG ); // Check the return value if(ret == AKRET_PROC_SUCCEED){ if(prms->m_cntSuspend > 0){ // Show message DBGPRINT(DBG_LEVEL2, "Suspend cycle count = %d\n", prms->m_cntSuspend); } else if (prms->m_callcnt <= 1){ // Check interval if (AKD_GetDelay(&delay) != AKD_SUCCESS) { DBGPRINT(DBG_LEVEL1, "%s:%d Error.\n", __FUNCTION__, __LINE__); } else { GetValidInterval(delay, &interval); } } // Display(or dispatch) the result. Disp_MeasurementResultHook(prms); } else if(ret == AKRET_FORMATION_CHANGED){ // Switch formation. SwitchFormation(prms); } else if(ret == AKRET_DATA_READERROR){ DBGPRINT(DBG_LEVEL2, "Data read error occurred.\n\n"); } else if(ret == AKRET_DATA_OVERFLOW){ DBGPRINT(DBG_LEVEL2, "Data overflow occurred.\n\n"); } else if(ret == AKRET_HFLUC_OCCURRED){ DBGPRINT(DBG_LEVEL2, "AKSC_HFlucCheck did not return 1.\n\n"); } else{ // Does not reach here LOGE("MeasuringEventProcess has failed.\n"); break; } // Check user order ch = checkKey(); if (ch == AKKEY_STOP_MEASURE) { break; } else if(ch < 0){ LOGD("Bad key code.\n"); break; } // Get end time if (clock_gettime(CLOCK_REALTIME, &tsend) < 0) { DBGPRINT(DBG_LEVEL1, "%s:%d Error.\n", __FUNCTION__, __LINE__); return; } // calculate wait time doze = interval.interval - ((tsend.tv_sec - tsstart.tv_sec)*1000000 + (tsend.tv_nsec - tsstart.tv_nsec)/1000); if (doze < 0) { doze = 0; } // Adjust sampling frequency // DBGPRINT(DBG_LEVEL3, "Sleep %d usec.\n", doze); usleep(doze); } // Set to PowerDown mode if (AKD_SetMode(AK8975_MODE_POWERDOWN) != AKD_SUCCESS) { DBGPRINT(DBG_LEVEL1, "%s:%d Error.\n", __FUNCTION__, __LINE__); } closeFormation(); closeKey(); }
HKEY CArchMiscWindows::addKey(HKEY key, const TCHAR* keyName) { return openKey(key, keyName, true); }
HKEY ArchMiscWindows::addKey(HKEY key, const TCHAR* const* keyNames) { return openKey(key, keyNames, true); }
HKEY ArchMiscWindows::openKey(HKEY key, const TCHAR* const* keyNames) { return openKey(key, keyNames, false); }
void RegElement::read() { string_value_.clear(); dword_value_ = 0; HKEY parent_key; LONG result = openKey(root_, path_, &parent_key, KEY_READ); if (result != ERROR_SUCCESS) { return; } const std::wstring std_name = name_.toStdWString(); DWORD len; // get value size result = RegQueryValueExW (parent_key, std_name.c_str(), NULL, /* reserved */ &type_, /* output type */ NULL, /* output data */ &len); /* output length */ if (result != ERROR_SUCCESS) { RegCloseKey(parent_key); return; } // get value #ifndef UTILS_CXX11_MODE std::vector<wchar_t> buf; #else utils::WBufferArray buf; #endif buf.resize(len); result = RegQueryValueExW (parent_key, std_name.c_str(), NULL, /* reserved */ &type_, /* output type */ (LPBYTE)&buf[0], /* output data */ &len); /* output length */ buf.resize(len); if (result != ERROR_SUCCESS) { RegCloseKey(parent_key); return; } switch (type_) { case REG_EXPAND_SZ: case REG_SZ: { // expand environment strings wchar_t expanded_buf[MAX_PATH]; DWORD size = ExpandEnvironmentStringsW(&buf[0], expanded_buf, MAX_PATH); if (size == 0 || size > MAX_PATH) string_value_ = QString::fromWCharArray(&buf[0], buf.size()); else string_value_ = QString::fromWCharArray(expanded_buf, size); } break; case REG_NONE: case REG_BINARY: string_value_ = QString::fromWCharArray(&buf[0], buf.size() / 2); break; case REG_DWORD_BIG_ENDIAN: case REG_DWORD: if (buf.size() != sizeof(int)) return; memcpy((char*)&dword_value_, buf.data(), sizeof(int)); break; case REG_QWORD: { if (buf.size() != sizeof(int)) return; qint64 value; memcpy((char*)&value, buf.data(), sizeof(int)); dword_value_ = (int)value; break; } case REG_MULTI_SZ: default: break; } RegCloseKey(parent_key); // workaround with a bug string_value_ = QString::fromUtf8(string_value_.toUtf8()); return; }