Skip to content

Commit

Permalink
fixed problem with sorting PackageVersions that was dropping versions…
Browse files Browse the repository at this point in the history
… entirely
  • Loading branch information
Justin Byers committed Jan 28, 2018
1 parent 5e00dfc commit 8a43a86
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 20 deletions.
20 changes: 15 additions & 5 deletions helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,9 @@ Package helpers::getLatestPackage(PackageVersions packageVers)
PackageVersions::iterator it;
for (it=packageVers.begin();it != packageVers.end(); it++)
{
QString curVer = it->first;
QString maxVer = ret.version;
curVer.remove(".");
maxVer.remove(".");
float ver = atof(curVer.toStdString().c_str());
if (ver > atof(maxVer.toStdString().c_str()))
float ver = helpers::numberize(it->first);
if (ver > helpers::numberize(maxVer))
ret = it->second;
}

Expand Down Expand Up @@ -230,3 +227,16 @@ void helpers::delRepoFromFile(QString url, QString file)
//close the file
f.close();
}

int helpers::numberize (QString str)
{
QString s = str;
const char* cstr = str.toStdString().c_str();
char* tmp;
for (unsigned long i=0;i<strlen(cstr);i++)
{
if (cstr[i] != '0' && strtol(&(cstr[i]), &tmp, 10) == 0)
s.remove(i, 1);
}
return atoi(s.toStdString().c_str());
}
1 change: 1 addition & 0 deletions helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class helpers
static QString bytesToHuman(qint64 sz);
static void addRepoToFile(QString url, QString file);
static void delRepoFromFile(QString url, QString file);
static int numberize (QString str);
private:
static bool decompress_bz2(QString inFile, QString outFile);
static bool decompress_gz(QString inFile, QString outFile);
Expand Down
1 change: 0 additions & 1 deletion mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,6 @@ void MainWindow::repoInfoDownloaded()
if (m_sections[secName].find(m_packages[i].name) != m_sections[secName].end())
{ //package was already added
m_sections[secName][m_packages[i].name][m_packages[i].version] = m_packages[i];
int t = m_sections[secName][m_packages[i].name].size();
}
else
{ //package was not already added, need to create a PackageVersions
Expand Down
2 changes: 1 addition & 1 deletion repodialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ void RepoDialog::initialize(Repo repo, SectionList sections)
PackageList::iterator itt;
for (itt = it->second.begin();itt != it->second.end();itt++)
{
int t = itt->second.size();
Package latestPackage = helpers::getLatestPackage(itt->second);
QTreeWidgetItem *itm2 = new QTreeWidgetItem(QStringList(latestPackage.name + " (" + latestPackage.version + ")"));
itm->insertChild(0, itm2);
Expand Down Expand Up @@ -159,6 +158,7 @@ void RepoDialog::on_btn_download_clicked()
QString url = "";
for (it=clickedPackage.begin();it != clickedPackage.end();it++)
{
Logger::log("Checking "+it->first+" against "+ui->cmb_pkg_version->currentText());
if (it->first == ui->cmb_pkg_version->currentText())
{
//found it! get the package filename
Expand Down
14 changes: 1 addition & 13 deletions types.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,7 @@ struct strCmp {
}
};

struct strVerCmp {
bool operator()(QString const &a, QString const &b) const {
QString A = a;
QString B = b;
A.remove(".");
A.remove("-");
B.remove(".");
B.remove("-");
return atof(A.toStdString().c_str()) < atof(B.toStdString().c_str());
}
};

typedef std::map<QString, Package, strVerCmp> PackageVersions;
typedef std::map<QString, Package> PackageVersions;
typedef std::map<QString, PackageVersions, strCmp> PackageList;
typedef std::map<QString, PackageList, strCmp> SectionList;

Expand Down

0 comments on commit 8a43a86

Please sign in to comment.