|
|
@ -565,13 +565,6 @@ int options_imp::getMaxConnec() const{ |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void options_imp::showLoad(){ |
|
|
|
|
|
|
|
if(!loadOptions()){ |
|
|
|
|
|
|
|
std::cout << "Warning: Couldn't load options" << '\n'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this->show(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void options_imp::on_okButton_clicked(){ |
|
|
|
void options_imp::on_okButton_clicked(){ |
|
|
|
if(applyButton->isEnabled()){ |
|
|
|
if(applyButton->isEnabled()){ |
|
|
|
saveOptions(); |
|
|
|
saveOptions(); |
|
|
@ -784,6 +777,7 @@ void options_imp::on_browse_button_clicked(){ |
|
|
|
//
|
|
|
|
//
|
|
|
|
// Lines may be commented using '#' or '//'
|
|
|
|
// Lines may be commented using '#' or '//'
|
|
|
|
void options_imp::processFilterFile(const QString& filePath){ |
|
|
|
void options_imp::processFilterFile(const QString& filePath){ |
|
|
|
|
|
|
|
qDebug("Processing filter files"); |
|
|
|
filtersList->clear(); |
|
|
|
filtersList->clear(); |
|
|
|
QString manualFilters= misc::qBittorrentPath() + "ipfilter.dat"; |
|
|
|
QString manualFilters= misc::qBittorrentPath() + "ipfilter.dat"; |
|
|
|
QStringList filterFiles(manualFilters); |
|
|
|
QStringList filterFiles(manualFilters); |
|
|
@ -794,27 +788,26 @@ void options_imp::processFilterFile(const QString& filePath){ |
|
|
|
if (file.exists()){ |
|
|
|
if (file.exists()){ |
|
|
|
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){ |
|
|
|
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){ |
|
|
|
QMessageBox::critical(0, tr("I/O Error"), tr("Couldn't open:")+" "+filePath+" "+tr("in read mode.")); |
|
|
|
QMessageBox::critical(0, tr("I/O Error"), tr("Couldn't open:")+" "+filePath+" "+tr("in read mode.")); |
|
|
|
return; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
unsigned int nbLine = 0; |
|
|
|
unsigned int nbLine = 0; |
|
|
|
while (!file.atEnd()) { |
|
|
|
while (!file.atEnd()) { |
|
|
|
++nbLine; |
|
|
|
++nbLine; |
|
|
|
QByteArray line = file.readLine(); |
|
|
|
QByteArray line = file.readLine(); |
|
|
|
QString strLine = QString(line.data()); |
|
|
|
if(!line.startsWith('#') && !line.startsWith("//")){ |
|
|
|
if(!strLine.startsWith('#') && !strLine.startsWith("//")){ |
|
|
|
|
|
|
|
// Line is not commented
|
|
|
|
// Line is not commented
|
|
|
|
QStringList partsList = strLine.split(','); |
|
|
|
QList<QByteArray> partsList = line.split(','); |
|
|
|
unsigned int nbElem = partsList.size(); |
|
|
|
unsigned int nbElem = partsList.size(); |
|
|
|
if(nbElem != 2 && nbElem != 3){ |
|
|
|
if(nbElem < 2){ |
|
|
|
QMessageBox::critical(0, tr("Invalid Line"), tr("Line")+" "+QString(misc::toString(nbLine).c_str())+" "+tr("is malformed.")); |
|
|
|
std::cout << "Ipfilter.dat: line " << nbLine << " is malformed.\n"; |
|
|
|
return; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
int nbAccess = partsList.at(1).trimmed().toInt(); |
|
|
|
int nbAccess = partsList.at(1).trimmed().toInt(); |
|
|
|
if(nbAccess <= 127){ |
|
|
|
if(nbAccess <= 127){ |
|
|
|
QString strComment; |
|
|
|
QString strComment; |
|
|
|
QString strStartIP = partsList.at(0).split('-').at(0).trimmed(); |
|
|
|
QString strStartIP = partsList.at(0).split('-').at(0).trimmed(); |
|
|
|
QString strEndIP = partsList.at(0).split('-').at(1).trimmed(); |
|
|
|
QString strEndIP = partsList.at(0).split('-').at(1).trimmed(); |
|
|
|
if(partsList.size() == 3){ |
|
|
|
if(nbElem > 2){ |
|
|
|
strComment = partsList.at(2).trimmed(); |
|
|
|
strComment = partsList.at(2).trimmed(); |
|
|
|
}else{ |
|
|
|
}else{ |
|
|
|
strComment = QString(); |
|
|
|
strComment = QString(); |
|
|
@ -822,17 +815,19 @@ void options_imp::processFilterFile(const QString& filePath){ |
|
|
|
// Split IP
|
|
|
|
// Split IP
|
|
|
|
IP = strStartIP.split('.'); |
|
|
|
IP = strStartIP.split('.'); |
|
|
|
if(IP.size() != 4){ |
|
|
|
if(IP.size() != 4){ |
|
|
|
|
|
|
|
std::cout << "Ipfilter.dat: line " << nbLine << ", first IP is malformed.\n"; |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
address start(address::from_string(strStartIP.toStdString())); |
|
|
|
address_v4 start((IP.at(0).toInt() << 24) + (IP.at(1).toInt() << 16) + (IP.at(2).toInt() << 8) + IP.at(3).toInt()); |
|
|
|
IP = strEndIP.split('.'); |
|
|
|
IP = strEndIP.split('.'); |
|
|
|
if(IP.size() != 4){ |
|
|
|
if(IP.size() != 4){ |
|
|
|
|
|
|
|
std::cout << "Ipfilter.dat: line " << nbLine << ", second IP is malformed.\n"; |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
address last(address::from_string(strEndIP.toStdString())); |
|
|
|
address_v4 last((IP.at(0).toInt() << 24) + (IP.at(1).toInt() << 16) + (IP.at(2).toInt() << 8) + IP.at(3).toInt()); |
|
|
|
// add it to list
|
|
|
|
// add it to list
|
|
|
|
QStringList item(strStartIP); |
|
|
|
QStringList item(QString(start.to_string().c_str())); |
|
|
|
item.append(strEndIP); |
|
|
|
item.append(QString(last.to_string().c_str())); |
|
|
|
if(!i){ |
|
|
|
if(!i){ |
|
|
|
item.append("Manual"); |
|
|
|
item.append("Manual"); |
|
|
|
}else{ |
|
|
|
}else{ |
|
|
|