static QByteArray qt_create_environment(const QProcessEnvironmentPrivate::Hash &environment) { QByteArray envlist; if (!environment.isEmpty()) { QProcessEnvironmentPrivate::Hash copy = environment; // add PATH if necessary (for DLL loading) QProcessEnvironmentPrivate::Key pathKey(QLatin1String("PATH")); if (!copy.contains(pathKey)) { QByteArray path = qgetenv("PATH"); if (!path.isEmpty()) copy.insert(pathKey, QString::fromLocal8Bit(path)); } // add systemroot if needed QProcessEnvironmentPrivate::Key rootKey(QLatin1String("SystemRoot")); if (!copy.contains(rootKey)) { QByteArray systemRoot = qgetenv("SystemRoot"); if (!systemRoot.isEmpty()) copy.insert(rootKey, QString::fromLocal8Bit(systemRoot)); } int pos = 0; QProcessEnvironmentPrivate::Hash::ConstIterator it = copy.constBegin(), end = copy.constEnd(); static const wchar_t equal = L'='; static const wchar_t nul = L'\0'; for ( ; it != end; ++it) { uint tmpSize = sizeof(wchar_t) * (it.key().length() + it.value().length() + 2); // ignore empty strings if (tmpSize == sizeof(wchar_t) * 2) continue; envlist.resize(envlist.size() + tmpSize); tmpSize = it.key().length() * sizeof(wchar_t); memcpy(envlist.data()+pos, it.key().utf16(), tmpSize); pos += tmpSize; memcpy(envlist.data()+pos, &equal, sizeof(wchar_t)); pos += sizeof(wchar_t); tmpSize = it.value().length() * sizeof(wchar_t); memcpy(envlist.data()+pos, it.value().utf16(), tmpSize); pos += tmpSize; memcpy(envlist.data()+pos, &nul, sizeof(wchar_t)); pos += sizeof(wchar_t); } // add the 2 terminating 0 (actually 4, just to be on the safe side) envlist.resize( envlist.size()+4 ); envlist[pos++] = 0; envlist[pos++] = 0; envlist[pos++] = 0; envlist[pos++] = 0; } return envlist; }
void TestHelpSelectingDialog::addKey(QTreeWidgetItem *root, const Key &key, const QString &title, const uint nodeId, const int role) { Key rootKey(root->text(0).split(" ").at(0), ((role == Qt::UserRole) ? Key::InnerCode : Key::OuterCode)); if (rootKey == key) { QTreeWidgetItem *newNode = new QTreeWidgetItem(root); newNode->setText(0, key.getKey() + " - " + title); newNode->setData(0, role, nodeId); return; } for (int i = 0; i < root->childCount(); i++) { if (root->child(i)->text(0).contains(" ")) { continue; } Key currentKey(root->child(i)->text(0).split(" ").at(0), ((role == Qt::UserRole) ? Key::InnerCode : Key::OuterCode)); if ((currentKey.isParentFor(key)) || (currentKey == key)) { QTreeWidgetItem *newRoot = root->child(i); addKey(newRoot, key, title, nodeId, role); return; } } // иначе - среди узлов нет родителей, нужно создать свой ключ QList<int> rootLevels = rootKey.getLevels(); QList<int> keyLevels = key.getLevels(); QString newKey; if (!((rootLevels.length() == 1) && (rootLevels.at(0) == 0))) { newKey = rootKey.getKey(); newKey += "." + QString::number(keyLevels.at(rootLevels.length()), 10); } else { newKey = QString::number(keyLevels.at(0), 10); } QTreeWidgetItem *newNode = new QTreeWidgetItem(root); newNode->setText(0, newKey); newNode->setData(0, role, -1); addKey(newNode, key, title, nodeId, role); }
void nsProxyObjectManager::LockedRemove(nsProxyObject *aProxy) { nsCOMPtr<nsISupports> realEQ = do_QueryInterface(aProxy->GetTarget()); nsProxyEventKey rootKey(aProxy->GetRealObject(), realEQ, aProxy->GetProxyType()); if (!mProxyObjectMap.Remove(&rootKey)) { NS_ERROR("nsProxyObject not found in global hash."); } }
// Explore the registry to find a suitable version of Java. // Returns an int which is the version of Java found (e.g. 1006 for 1.6) and the // matching path in outJavaPath. // Returns 0 if nothing suitable was found. static int exploreJavaRegistry(const char *entry, REGSAM access, CPath *outJavaPath) { // Let's visit HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment [CurrentVersion] CPath rootKey("SOFTWARE\\JavaSoft\\"); rootKey.addPath(entry); int versionInt = 0; CString currentVersion; CPath subKey(rootKey); if (getRegValue(subKey.cstr(), "CurrentVersion", access, ¤tVersion)) { // CurrentVersion should be something like "1.7". // We want to read HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\1.7 [JavaHome] subKey.addPath(currentVersion); CPath javaHome; if (getRegValue(subKey.cstr(), "JavaHome", access, &javaHome)) { versionInt = checkBinPath(&javaHome); if (versionInt >= 0) { if (gIsDebug) { fprintf(stderr, "Java %d found via registry: %s\n", versionInt, javaHome.cstr()); } *outJavaPath = javaHome; } if (versionInt >= MIN_JAVA_VERSION) { // Heuristic: if the current version is good enough, stop here return versionInt; } } } // Try again, but this time look at all the versions available HKEY javaHomeKey; LSTATUS status = RegOpenKeyExA( HKEY_LOCAL_MACHINE, // hKey "SOFTWARE\\JavaSoft", // lpSubKey 0, // ulOptions KEY_READ | access, // samDesired &javaHomeKey); // phkResult if (status == ERROR_SUCCESS) { char name[256]; DWORD index = 0; CPath javaHome; for (LONG result = ERROR_SUCCESS; result == ERROR_SUCCESS; index++) { DWORD nameLen = 255; name[nameLen] = 0; result = RegEnumKeyExA( javaHomeKey, // hKey index, // dwIndex name, // lpName &nameLen, // lpcName NULL, // lpReserved NULL, // lpClass NULL, // lpcClass, NULL); // lpftLastWriteTime if (result == ERROR_SUCCESS && nameLen < 256) { name[nameLen] = 0; CPath subKey(rootKey); subKey.addPath(name); if (getRegValue(subKey.cstr(), "JavaHome", access, &javaHome)) { int v = checkBinPath(&javaHome); if (v > versionInt) { if (gIsDebug) { fprintf(stderr, "Java %d found via registry: %s\n", versionInt, javaHome.cstr()); } *outJavaPath = javaHome; versionInt = v; } } } } RegCloseKey(javaHomeKey); } return 0; }
Node::NodePtr Node::root() const { return clone(rootKey()); }
NS_IMETHODIMP nsProxyObjectManager::GetProxyForObject(nsIEventTarget* aTarget, REFNSIID aIID, nsISupports* aObj, PRInt32 proxyType, void** aProxyObject) { NS_ENSURE_ARG_POINTER(aObj); *aProxyObject = nsnull; // handle special values nsCOMPtr<nsIThread> thread; if (aTarget == NS_PROXY_TO_CURRENT_THREAD) { aTarget = NS_GetCurrentThread(); } else if (aTarget == NS_PROXY_TO_MAIN_THREAD) { thread = do_GetMainThread(); aTarget = thread.get(); } // check to see if the target is on our thread. If so, just return the // real object. if (!(proxyType & NS_PROXY_ASYNC) && !(proxyType & NS_PROXY_ALWAYS)) { PRBool result; aTarget->IsOnCurrentThread(&result); if (result) return aObj->QueryInterface(aIID, aProxyObject); } nsCOMPtr<nsISupports> realObj = do_QueryInterface(aObj); // Make sure the object passed in is not a proxy; if it is, be nice and // build the proxy for the real object. nsCOMPtr<nsProxyObject> po = do_QueryInterface(aObj); if (po) { realObj = po->GetRealObject(); } nsCOMPtr<nsISupports> realEQ = do_QueryInterface(aTarget); nsProxyEventKey rootKey(realObj, realEQ, proxyType); { nsAutoLock lock(mProxyCreationLock); nsProxyLockedRefPtr root = (nsProxyObject*) mProxyObjectMap.Get(&rootKey); if (root) return root->LockedFind(aIID, aProxyObject); } // don't lock while creating the nsProxyObject nsProxyObject *newRoot = new nsProxyObject(aTarget, proxyType, realObj); if (!newRoot) return NS_ERROR_OUT_OF_MEMORY; // lock again, and check for a race putting into mProxyObjectMap { nsAutoLock lock(mProxyCreationLock); nsProxyLockedRefPtr root = (nsProxyObject*) mProxyObjectMap.Get(&rootKey); if (root) { delete newRoot; return root->LockedFind(aIID, aProxyObject); } mProxyObjectMap.Put(&rootKey, newRoot); nsProxyLockedRefPtr kungFuDeathGrip(newRoot); return newRoot->LockedFind(aIID, aProxyObject); } }