void CEngine::scanNetworkNode(const boost::filesystem::path& nodePath, std::map<std::string, boost::shared_ptr<device::IDevice> >& devices) { try { if (!boost::filesystem::exists(nodePath)) return; if (!boost::filesystem::is_directory(nodePath)) return; static const boost::filesystem::directory_iterator endDirectoryIterator; for (boost::filesystem::directory_iterator dir(nodePath); dir != endDirectoryIterator; ++dir) { // Check dir if (!isValidDir(*dir)) continue; // Get the device from it's path and add it to list try { boost::shared_ptr<device::IDevice> device(createDevice(*dir)); devices[device->ident()->deviceName()] = device; // If device is a hub, scan for all hub connected devices (recursively) if (device->ident()->family() == kMicrolanCoupler) { // Scan in "main" and "aux" dir scanNetworkNode(nodePath / boost::filesystem::path("main"), devices); scanNetworkNode(nodePath / boost::filesystem::path("aux"), devices); } } catch (shared::exception::CInvalidParameter&) { const std::string unsupportedFamily(dir->path().filename().string().substr(0, 2)); if (m_unsupporterFamilies.find(unsupportedFamily) == m_unsupporterFamilies.end()) { std::cout << "1-Wire, Device family 0x" << unsupportedFamily << " is not actually supported" << std::endl; m_unsupporterFamilies.insert(unsupportedFamily); } } } } catch (const boost::filesystem::filesystem_error& ex) { std::cerr << "1-Wire, OWFS mode, unable to scan 1-wire network : " << ex.what() << std::endl; } }
void CUrlBufferModule::OnModCommand(const CString& sCommand) { CString command = sCommand.Token(0).AsLower().Trim_n(); if (command == "help") { CTable CmdTable; CmdTable.AddColumn("Command"); CmdTable.AddColumn("Description"); CmdTable.AddRow(); CmdTable.SetCell("Command", "ENABLE"); CmdTable.SetCell("Description", "Activates link buffering."); CmdTable.AddRow(); CmdTable.SetCell("Command", "DISABLE"); CmdTable.SetCell("Description", "Deactivates link buffering."); CmdTable.AddRow(); CmdTable.SetCell("Command", "ENABLELOCAL"); CmdTable.SetCell("Description", "Enables downloading of each link to local directory."); CmdTable.AddRow(); CmdTable.SetCell("Command", "DISABLELOCAL"); CmdTable.SetCell("Description", "Disables downloading of each link to local directory."); CmdTable.AddRow(); CmdTable.SetCell("Command","ENABLEPUBLIC"); CmdTable.SetCell("Description", "Enables the usage of !showlinks publicly, by other users."); CmdTable.AddRow(); CmdTable.SetCell("Command","DISABLEPUBLIC"); CmdTable.SetCell("Description", "Disables the usage of !showlinks publicly, by other users."); CmdTable.AddRow(); CmdTable.SetCell("Command", "DIRECTORY <#directory>"); CmdTable.SetCell("Description", "Sets the local directory where the links will be saved."); CmdTable.AddRow(); CmdTable.SetCell("Command", "CLEARBUFFER"); CmdTable.SetCell("Description", "Empties the link buffer."); CmdTable.AddRow(); CmdTable.SetCell("Command", "BUFFERSIZE <#size>"); CmdTable.SetCell("Description", "Sets the size of the link buffer. Only integers >=0."); CmdTable.AddRow(); CmdTable.SetCell("Command", "SHOWSETTINGS"); CmdTable.SetCell("Description", "Prints all the settings."); CmdTable.AddRow(); CmdTable.SetCell("Command", "BUFFERALLLINKS"); CmdTable.SetCell("Description", "Toggles the buffering of all links or only image links."); CmdTable.AddRow(); CmdTable.SetCell("Command", "REUPLOAD"); CmdTable.SetCell("Description", "Toggles the reuploading of image links to imgur."); CmdTable.AddRow(); CmdTable.SetCell("Command", "SHOWLINKS <#number>"); CmdTable.SetCell("Description", "Prints <#number> or <#buffersize> number of cached links."); CmdTable.AddRow(); CmdTable.SetCell("Command", "HELP"); CmdTable.SetCell("Description", "This help."); PutModule(CmdTable); return; } else if (command == "enable") { SetNV("enable","true",true); PutModule("Enabled buffering"); } else if (command == "disable") { SetNV("enable","false",true); PutModule("Disabled buffering"); } else if (command == "enablelocal") { if(GetNV("directory") == "") { PutModule("Directory is not set. First set a directory and then enable local caching"); return; } SetNV("enablelocal","true",true); PutModule("Enabled local caching"); } else if (command == "disablelocal") { SetNV("enablelocal", "false", true); PutModule("Disabled local caching"); } else if (command == "enablepublic") { SetNV("enablepublic", "true", true); PutModule("Enabled public usage of showlinks."); } else if (command == "disablepublic") { SetNV("enablepublic", "false", true); PutModule("Disabled public usage of showlinks."); } else if (command == "directory") { CString dir=sCommand.Token(1).Replace_n("//", "/").TrimRight_n("/") + "/"; if (!isValidDir(dir)) { PutModule("Error in directory name. Avoid using: | ; ! @ # ( ) < > \" ' ` ~ = & ^ <space> <tab>"); return; } // Check if file exists and is directory if (dir.empty() || !CFile::Exists(dir) || !CFile::IsDir(dir, false)) { PutModule("Invalid path or no write access to ["+ sCommand.Token(1) +"]."); return; } SetNV("directory", dir, true); PutModule("Directory for local caching set to " + GetNV("directory")); } else if (command == "clearbuffer") { lastUrls.clear(); nicks.clear(); } else if (command == "buffersize") { unsigned int bufSize = sCommand.Token(1).ToUInt(); if(bufSize==0 || bufSize==UINT_MAX) { PutModule("Error in buffer size. Use only integers >= 0."); return; } SetNV("buffersize", CString(bufSize), true); PutModule("Buffer size set to " + GetNV("buffersize")); } else if (command == "showsettings") { for(MCString::iterator it = BeginNV(); it != EndNV(); it++) { PutModule(it->first.AsUpper() + " : " + it->second); } } else if(command == "bufferalllinks"){ SetNV("bufferalllinks", CString(!GetNV("bufferalllinks").ToBool()), true); PutModule( CString(GetNV("bufferalllinks").ToBool()?"Enabled":"Disabled") + " buffering of all links."); } else if(command == "reupload"){ SetNV("reupload", CString(!GetNV("reupload").ToBool()), true); PutModule( CString(GetNV("reupload").ToBool()?"Enabled":"Disabled") + " reuploading of images."); } else if (command == "showlinks") { if(lastUrls.empty()) PutModule("No links were found..."); else { unsigned int maxLinks = GetNV("buffersize").ToUInt(); unsigned int size = sCommand.Token(1).ToUInt(); if(size!=0 && size<UINT_MAX) //if it was a valid number maxLinks = size; unsigned int maxSize = lastUrls.size()-1; for(unsigned int i=0; i<=maxSize && i< maxLinks; i++) { PutModule(nicks[maxSize-i] + ": " + lastUrls[maxSize-i]); } } } else { PutModule("Unknown command! Try HELP."); } }