QStringList CArchiveThread::ListParts(const QString &ArchivePath, bool NamesOnly) { QStringList Parts; StrPair PathName = Split2(ArchivePath, "/", true); StrPair NameEx = Split2(PathName.second, ".", true); QRegExp Pattern; if(NameEx.second == "rar") Pattern = QRegExp(QRegExp::escape(NameEx.first) + "(\\.part[0-9]*)?\\.rar", Qt::CaseInsensitive); else Pattern = QRegExp(QRegExp::escape(NameEx.first + "." + NameEx.second) + "(\\.[0-9]*)?", Qt::CaseInsensitive); QDir Dir(PathName.first); foreach (const QString& File, Dir.entryList()) { if (File.compare(".") == 0 || File.compare("..") == 0) continue; if(Pattern.exactMatch(File)) { if(NamesOnly) Parts.append(File); else Parts.append(PathName.first + "/" + File); } } return Parts; }
map<string, string> CKadScript::ReadHeader(const string& Source) { map<string, string> HeaderFields; string::size_type HeaderBegin = Source.find("/*"); string::size_type HeaderEnd = Source.find("*/"); if(HeaderBegin == -1 || HeaderEnd == -1) return HeaderFields; vector<string> HeaderLines = SplitStr(Source.substr(HeaderBegin + 2, HeaderEnd - (HeaderBegin + 2)), "\n"); for(size_t i=0; i < HeaderLines.size(); i++) { string Line = Trimm(HeaderLines.at(i)); if(Line.substr(0,1) == "*") { Line.erase(0,1); Line = Trimm(Line); } pair<string,string> Field = Split2(Line, ":"); if(Field.first.empty() || Field.first.find(" ") != string::npos) continue; HeaderFields[Field.first] = Trimm(Field.second); } return HeaderFields; }
void CNeoCore::LoadLoginTokens() { QMutexLocker Locker(&m_Mutex); time_t uNow = GetTime(); time_t TimeOut = Cfg(false)->GetUInt("Core/TockenTimeOut"); foreach(const QString& Token, Cfg(false)->GetStringList("Core/ValidTockens")) { StrPair TD = Split2(Token,":"); time_t Time = QDateTime::fromString(TD.second).toTime_t(); if(Time + TimeOut < uNow) continue; m_Logins.insert(TD.first, Time); } }
void CWebAPI::OnRequestCompleted() { CHttpSocket* pRequest = (CHttpSocket*)sender(); ASSERT(pRequest->GetState() == CHttpSocket::eHandling); QString Path = pRequest->GetPath(); TArguments Cookies = GetArguments(pRequest->GetHeader("Cookie")); TArguments Arguments = GetArguments(pRequest->GetQuery().mid(1),'&'); switch(pRequest->GetType()) { case CHttpSocket::eDELETE: pRequest->RespondWithError(501); case CHttpSocket::eHEAD: case CHttpSocket::eOPTIONS: pRequest->SendResponse(); return; } if(Path.compare("/WebAPI/") == 0) pRequest->RespondWithError(403); else if(Path.left(14).compare("/WebAPI/Icons/") == 0) { int Size; if(Arguments["Size"] == "Small") Size = 16; else // if(Arguments["Size"] == "Large") Size = 32; QString Ext = Split2(Path.mid(14), ".").first; QString IconPath = theCore->Cfg()->GetSettingsDir() + "/Cache/Icons/" + Ext + QString::number(Size) + ".png"; if(!QFile::exists(IconPath)) { if(theLoader) QMetaObject::invokeMethod(theLoader, "CreateFileIcon", Qt::BlockingQueuedConnection, Q_ARG(QString, Ext)); else IconPath = ":/Icon" + QString::number(Size) + ".png"; } pRequest->SetCaching(HR2S(48)); pRequest->RespondWithFile(IconPath); } else if(Path.left(11).compare("/WebAPI/FS/") == 0) { StrPair CmdExt = Split2(Path.mid(11),"."); QVariantMap Result; if(CmdExt.first.compare("dir", Qt::CaseInsensitive) == 0) { QVariantList Entrys; QString DirPath = Arguments["Path"]; QDir Dir(DirPath); foreach (const QString& Name, Dir.entryList()) { if (Name.compare(".") == 0 || Name.compare("..") == 0) continue; QVariantMap Entry; QFileInfo Info(DirPath + "/" + Name); Entry["Name"] = Info.fileName(); Entry["Created"] = Info.created(); Entry["Modifyed"] = Info.lastModified(); if (Info.isDir()) Entry["Size"] = "dir"; else Entry["Size"] = Info.size(); Entrys.append(Entry); } Result["List"] = Entrys; }
virtual void HandleResponse(const QVariantMap& Response) { if(m_pView) { m_pView->m_bLockDown = true; QStringList Info; if(Response.contains("Error")) Info.append(tr("Error: %2").arg(Response["Error"].toString())); if(theGUI->Cfg()->GetInt("Gui/AdvancedControls") == 1) Info.append(tr("FileID: %1").arg(Response["ID"].toULongLong())); m_pView->m_pInfo->setText(Info.join(", ")); m_pView->m_pFileName->setText(Response["FileName"].toString()); QVariantList HashMap = Response["HashMap"].toList(); m_pView->m_pHashes->setColumnCount(1); #if QT_VERSION < 0x050000 m_pView->m_pHashes->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch); #else m_pView->m_pHashes->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); #endif m_pView->m_pHashes->setRowCount(HashMap.count()); QStringList Hashes; StrPair MasterHash = Split2(Response["MasterHash"].toString(), ":"); foreach(const QVariant& vHash, HashMap) { QVariantMap Hash = vHash.toMap(); QTableWidgetItem* pItem = new QTableWidgetItem(Hash["Value"].toString()); QFont Font = pItem->font(); if(Hash["Value"].toString() == MasterHash.second) { Font.setBold(true); pItem->setData(Qt::UserRole, "Master"); } else pItem->setData(Qt::UserRole, Hash["State"]); if(!MasterHash.first.isEmpty()) // file complate all hashes just black { if(Hash["State"] == "Parent") Font.setItalic(true); else if(Hash["State"] == "Empty") pItem->setForeground(Qt::gray); else if(Hash["State"] == "Aux") pItem->setForeground(Qt::darkYellow); else if(Hash["State"] == "Bad") pItem->setForeground(Qt::darkRed); else if(Hash["Value"].toString() != MasterHash.second) pItem->setForeground(Qt::darkGreen); } pItem->setFont(Font); m_pView->m_pHashes->setItem(Hashes.count(), 0, pItem); m_pView->m_pHashes->resizeRowToContents(Hashes.count()); Hashes.append(Hash["Type"].toString()); } m_pView->m_pHashes->setVerticalHeaderLabels(Hashes); if(int Count = m_pView->m_pHashes->rowCount()) m_pView->m_pHashes->setMaximumHeight(((m_pView->m_pHashes->rowHeight(0)) * Count) + 2); else m_pView->m_pHashes->setMaximumHeight(30); m_pView->m_IsComplete = Response["FileStatus"] == "Complete"; QVariantMap Properties = Response["Properties"].toMap(); m_pView->m_pRating->setCurrentIndex(Properties["Rating"].toInt()); m_pView->m_pDescription->setPlainText(Properties["Description"].toString()); m_pView->m_pCoverView->ShowCover(m_pView->m_ID, Properties["CoverUrl"].toString()); m_pView->m_pSubmit->setEnabled(false); bool Searching = Response["FileJobs"].toStringList().contains("Searching"); if(m_pView->m_Mode == CFileListView::eFilesSearch || m_pView->m_Mode == CFileListView::eFilesGrabber) { if(!Searching && Properties["Description"].toString().isEmpty()) { Searching = true; CSetRatingJob* pSetRatingJob = new CSetRatingJob(m_pView->m_ID); theGUI->ScheduleJob(pSetRatingJob); } if(Searching) QTimer::singleShot(1000, m_pView, SLOT(UpdateDetails())); } m_pView->m_bLockDown = false; }