void MemWin::readLoop() { while (run) { MEMORYSTATUSEX memInfo; memInfo.dwLength = sizeof(MEMORYSTATUSEX); GlobalMemoryStatusEx(&memInfo); updateUsage(memInfo.ullTotalPhys - memInfo.ullAvailPhys); boost::this_thread::sleep_for(refresh); } }
int UDPAllocation::send(const char* data, std::size_t size, const net::Address& peerAddress) { updateUsage(size); // Check that we have not exceeded our lifetime and bandwidth quota. if (IAllocation::deleted()) { WarnL << "Send indication dropped: Allocation quota reached" << endl; return -1; } return _relaySocket./*base().*/send(data, size, peerAddress); }
/* MapTextureBrowser::doSort * Sort the current items depending on [sort_type] *******************************************************************/ void MapTextureBrowser::doSort(unsigned sort_type) { map_tex_sort = sort_type; // Default sorts if (sort_type < 2) return BrowserWindow::doSort(sort_type); // Sort by usage else if (sort_type == 2) { updateUsage(); vector<BrowserItem*>& items = canvas->itemList(); std::sort(items.begin(), items.end(), sortBIUsage); } }
void UDPAllocation::onPeerDataReceived(void*, const MutableBuffer& buffer, const net::Address& peerAddress) { //auto source = reinterpret_cast<net::PacketInfo*>(packet.info); TraceL << "Received UDP Datagram from " << peerAddress << endl; if (!hasPermission(peerAddress.host())) { TraceL << "No Permission: " << peerAddress.host() << endl; return; } updateUsage(buffer.size()); // Check that we have not exceeded out lifetime and bandwidth quota. if (IAllocation::deleted()) return; stun::Message message(stun::Message::Indication, stun::Message::DataIndication); // Try to use the externalIP value for the XorPeerAddress // attribute to overcome proxy and NAT issues. std::string peerHost(server().options().externalIP); if (peerHost.empty()) { peerHost.assign(peerAddress.host()); assert(0 && "external IP not set"); } auto peerAttr = new stun::XorPeerAddress; peerAttr->setAddress(net::Address(peerHost, peerAddress.port())); message.add(peerAttr); auto dataAttr = new stun::Data; dataAttr->copyBytes(bufferCast<const char*>(buffer), buffer.size()); message.add(dataAttr); //Mutex::ScopedLock lock(_mutex); TraceL << "Send data indication:" << "\n\tFrom: " << peerAddress << "\n\tTo: " << _tuple.remote() //<< "\n\tData: " << std::string(packet.data(), packet.size()) << endl; server().udpSocket().sendPacket(message, _tuple.remote()); //net::Address tempAddress("58.7.41.244", _tuple.remote().port()); //server().udpSocket().send(message, tempAddress); }
int VerbyPlugin::launchItem(QList<InputData>* inputData, CatItem* item) { item = item; // Compiler Warning if (inputData->count() != 2) { // Tell Launchy to handle the command return MSG_CONTROL_LAUNCHITEM; } QString noun = inputData->first().getTopResult().fullPath; CatItem& verbItem = inputData->last().getTopResult(); QString verb = verbItem.shortName; qDebug() << "Verby launchItem" << verb; if (verb == "Run") { runProgram(noun, ""); } else if (verb == "Open containing folder") { QFileInfo info(noun); if (info.isSymLink()) { info.setFile(info.symLinkTarget()); } #ifdef Q_WS_WIN runProgram("explorer.exe", "\"" + QDir::toNativeSeparators(info.absolutePath()) + "\""); #endif } else if (verb == "Open shortcut folder") { QFileInfo info(noun); #ifdef Q_WS_WIN runProgram("explorer.exe", "\"" + QDir::toNativeSeparators(info.absolutePath()) + "\""); #endif } else if (verb == "Run as") { #ifdef Q_WS_WIN SHELLEXECUTEINFO shellExecInfo; shellExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); shellExecInfo.fMask = SEE_MASK_FLAG_NO_UI; shellExecInfo.hwnd = NULL; shellExecInfo.lpVerb = L"runas"; shellExecInfo.lpFile = (LPCTSTR)noun.utf16(); shellExecInfo.lpParameters = NULL; QDir dir(noun); QFileInfo info(noun); if (!info.isDir() && info.isFile()) dir.cdUp(); QString filePath = QDir::toNativeSeparators(dir.absolutePath()); shellExecInfo.lpDirectory = (LPCTSTR)filePath.utf16(); shellExecInfo.nShow = SW_NORMAL; shellExecInfo.hInstApp = NULL; ShellExecuteEx(&shellExecInfo); #endif } else if (verb == "File properties") { #ifdef Q_WS_WIN SHELLEXECUTEINFO shellExecInfo; shellExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); shellExecInfo.fMask = SEE_MASK_FLAG_NO_UI | SEE_MASK_INVOKEIDLIST; shellExecInfo.hwnd = NULL; shellExecInfo.lpVerb = L"properties"; QString filePath = QDir::toNativeSeparators(noun); shellExecInfo.lpFile = (LPCTSTR)filePath.utf16(); shellExecInfo.lpIDList = NULL; shellExecInfo.lpParameters = NULL; shellExecInfo.lpDirectory = NULL; shellExecInfo.nShow = SW_NORMAL; shellExecInfo.hInstApp = NULL; ShellExecuteEx(&shellExecInfo); #endif } else if (verb == "Copy path to clipboard") { QFileInfo info(noun); if (info.isSymLink()) { info.setFile(info.symLinkTarget()); } QClipboard *clipboard = QApplication::clipboard(); clipboard->setText(QDir::toNativeSeparators(info.canonicalFilePath())); } else { // Tell Launchy to handle the command return MSG_CONTROL_LAUNCHITEM; } updateUsage(verbItem); return true; }
int controlyPlugin::launchItem(QList<InputData>* inputData, CatItem* item) { item = item; // Compiler warning if (inputData->count() == 1) { // no parameters, just the item itsef QString path = item->fullPath; if (path.contains(",@")) { // dll cpl item indexing containing items, e.g. 'main.cpl,@1' runProgram("control.exe", item->fullPath); //runProgram(cmd, args); // use toNativeSeparators()? } else if ((path.startsWith("csidl:", Qt::CaseInsensitive)) && (path.endsWith(".controly", Qt::CaseSensitive))) { // Constant special item ID list (CSIDL) // shell instance object (special shell extension folder), e.g. 'csidl:0x0014.controly' ('shellinstance:0x0014') QString folderId = path.mid(strlen("csidl:"), strlen(path.toLocal8Bit())-strlen("csidl:")-strlen(".controly")); // e.g. 0x0014 = CSIDL_FONTS; bool ok; int folderIdx = folderId.toLong(&ok, 16); if (ok) { LPITEMIDLIST pidl; HRESULT hres = SHGetFolderLocation(NULL, folderIdx, NULL, 0, &pidl); if (hres == S_OK) { SHELLEXECUTEINFO sei; memset(&sei, 0, sizeof(sei)); sei.cbSize = sizeof(SHELLEXECUTEINFO); sei.fMask = SEE_MASK_IDLIST; sei.hwnd = NULL; sei.lpVerb = NULL; sei.lpFile = NULL; sei.lpParameters = NULL; sei.lpDirectory = NULL; sei.nShow = SW_SHOW; sei.hInstApp = NULL; sei.lpIDList = pidl; sei.hProcess = NULL; //it seems we don't need CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); ShellExecuteEx(&sei); CoTaskMemFree((void*)pidl); // needs objbase.h/ole32.lib } } } else { // exe cpl item with command line parameters, e.g. 'rundll32.exe shell32.dll,Options_RunDLL 1' // or item defined via application name, e.g. 'control.exe /name Microsoft.WindowsUpdate' QStringList spl = path.split(".exe "); if (spl.size() == 2) { // split size currently is always 2, as assured above QString executable = spl[0] + ".exe"; QString parameters = spl[1]; runProgram(executable, parameters); } else { runProgram(path, ""); } } return 1; } if (inputData->count() != 2) return 1; CatItem last = inputData->last().getTopResult(); if (last.shortName == "Options") { updateUsage(last); return MSG_CONTROL_OPTIONS; } else if (last.shortName == "Rebuild Catalog") { updateUsage(last); return MSG_CONTROL_REBUILD; } else if (last.shortName == "Exit") { updateUsage(last); return MSG_CONTROL_EXIT; } return 1; }