checkwadsdlg.cpp
1 //------------------------------------------------------------------------------
2 // checkwadsdlg.cpp
3 //------------------------------------------------------------------------------
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301 USA
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2019 Pol Marcet Sardà <polmarcetsarda@gmail.com>
22 //------------------------------------------------------------------------------
23 #include "checkwadsdlg.h"
24 #include "configuration/doomseekerconfig.h"
25 #include "pathfinder/pathfinder.h"
26 #include "pathfinder/wadpathfinder.h"
28 #include <cassert>
29 #include <QScopedPointer>
30 #include <QTimer>
31 
32 DClass<CheckWadsDlg> : public Ui::CheckWadsDlg
33 {
34 public:
35  QList<PWad> wads;
36  const PathFinder *pathFinder;
37  CheckResult wadsChecked;
38  QScopedPointer<QTimer> checkWadTimer;
39  QScopedPointer<QTimer> showWindow;
40  bool checkIncompatibility;
41 };
42 
43 DPointeredNoCopy(CheckWadsDlg)
44 
45 CheckWadsDlg::CheckWadsDlg(const PathFinder *pathFinder, QWidget *parent) : QDialog(parent)
46 {
47  assert(pathFinder != nullptr);
48  d->pathFinder = pathFinder;
49  d->checkIncompatibility = gConfig.doomseeker.bCheckTheIntegrityOfWads;
50  d->checkWadTimer.reset(new QTimer);
51  d->showWindow.reset(new QTimer);
52 
53  d->setupUi(this);
54  connect(d->checkWadTimer.data(), SIGNAL(timeout()), this, SLOT(performCheckStep()));
55  connect(d->showWindow.data(), SIGNAL(timeout()), this, SLOT(openWindow()));
56  connect(d->buttonBox, SIGNAL(clicked(QAbstractButton*)), SLOT(abortCheck()));
57 }
58 
59 CheckWadsDlg::~CheckWadsDlg()
60 {
61 }
62 
63 void CheckWadsDlg::addWads(const QList<PWad> &wads)
64 {
65  d->wads << wads;
66  d->progressBar->setMaximum(d->progressBar->value() + wads.size());
67 }
68 
70 {
71  d->showWindow->setSingleShot(true);
72  d->showWindow->start(500);
73  d->checkWadTimer->start(0);
74 
75  // we'll wait for the checking to finish.
76  QEventLoop loop;
77  connect(this, SIGNAL(finishedChecking()), &loop, SLOT(quit()));
78  loop.exec();
79 
80  d->showWindow->stop();
81  close();
82  return d->wadsChecked;
83 }
84 
85 void CheckWadsDlg::openWindow()
86 {
87  open();
88 }
89 
90 void CheckWadsDlg::performCheckStep()
91 {
92  if (d->wads.isEmpty())
93  {
94  d->checkWadTimer->stop();
95  emit finishedChecking();
96  return;
97  }
98 
99  const PWad wad = d->wads.first();
100  d->wads.removeFirst();
101  WadPathFinder wadFinder(*d->pathFinder);
102  WadFindResult findResult = wadFinder.find(wad.name());
103 
104  if (!findResult.isValid())
105  d->wadsChecked.missingWads << wad;
106  else if (d->checkIncompatibility && !wad.validFile(findResult.path()))
107  d->wadsChecked.incompatibleWads << wad;
108  else
109  d->wadsChecked.foundWads << wad;
110 
111  d->progressBar->setValue(d->progressBar->value() + 1);
112 }
113 
114 void CheckWadsDlg::abortCheck()
115 {
116  d->checkIncompatibility = false;
117 }
Manages the checking process of wads when trying to enter a server or when executing the "Find missin...
Definition: checkwadsdlg.h:50
Performs a case-insensitive (OS independent) file searches.
Definition: pathfinder.h:81
PWAD hosted on a server.
Contains the results of CheckWadsDlg::CheckWads(), categorized in "incomplete", "missing" and "found"...
Definition: checkwadsdlg.h:37
void addWads(const QList< PWad > &wads)
adds the wads to check.
const CheckResult checkWads()
this function will check for the paths and integrity (if it is turned on in the config). If the process takes more than 500 milliseconds, it will open a loading bar.
bool validFile(const QString &path) const
Verifies if a file has the same checksums as the PWad.
Wrapper for PathFinder that specializes in findings WADs.
Definition: wadpathfinder.h:76
const QString & name() const
File name of the WAD.