@@ -122,7 +122,17 @@ void QmlDownloader::onDownloadEvent(int event)
122122 break ;
123123
124124 case aria2::EVENT_ON_DOWNLOAD_ERROR:
125- emit fatalMessage (" Error received while downloading" );
125+ if (!downloadRestarter_) {
126+ emit fatalMessage (" Error: downloadRestarter unset" );
127+ }
128+ setState (COMPLETED);
129+ setDownloadSpeed (0 );
130+ setUploadSpeed (0 );
131+ setCompletedSize (0 );
132+ stopAria ();
133+ if (!(this ->*downloadRestarter_)()) {
134+ emit fatalMessage (" Error received while downloading" );
135+ }
126136 break ;
127137
128138 case aria2::EVENT_ON_DOWNLOAD_PAUSE:
@@ -143,7 +153,7 @@ void QmlDownloader::onDownloadEvent(int event)
143153 }
144154}
145155
146- void QmlDownloader::startUpdate (const QString& selectedInstallPath)
156+ void QmlDownloader::setInstallPath (const QString& selectedInstallPath)
147157{
148158 qDebug () << " Selected install path:" << selectedInstallPath;
149159 if (!Sys::validateInstallPath (selectedInstallPath)) {
@@ -159,26 +169,38 @@ void QmlDownloader::startUpdate(const QString& selectedInstallPath)
159169 return ;
160170 }
161171 }
172+
162173 if (!QFileInfo (selectedInstallPath).isWritable ()) {
163174 emit fatalMessage (" Install dir not writable. Please select another" );
164175 return ;
165176 }
166177
167- QString gameUrl = splashController_.gameUrl ();
168- qDebug () << " Using torrent file:" << gameUrl;
169178 // Persist the install path only now that download has been initiated and we know the path is good
170179 emit statusMessage (" Installing to " + dir.canonicalPath ());
171180 if (settings_.installPath () != selectedInstallPath) {
172181 qDebug () << " Clearing installed version because path was changed" ;
173182 settings_.setInstalledVersion (" " );
174183 }
175184 settings_.setInstallPath (selectedInstallPath);
185+ }
186+
187+ bool QmlDownloader::startUpdate ()
188+ {
189+ QString gameUrl = splashController_.gameUrl ();
190+ if (gameUrl.isEmpty ()) {
191+ return false ;
192+ }
193+
194+ qDebug () << " Using torrent URL:" << gameUrl;
195+
196+ QDir dir (settings_.installPath ());
176197
177198 setState (DOWNLOADING);
178199 worker_ = new DownloadWorker (ariaLogFilename_);
179200 worker_->setDownloadDirectory (dir.canonicalPath ().toStdString ());
180201 worker_->addTorrent (gameUrl.toStdString ());
181202 worker_->moveToThread (&thread_);
203+ setDownloadRestarter (&QmlDownloader::startUpdate);
182204 connect (&thread_, SIGNAL (finished ()), worker_, SLOT (deleteLater ()));
183205 connect (worker_, SIGNAL (onDownloadEvent (int )), this , SLOT (onDownloadEvent (int )));
184206 connect (worker_, SIGNAL (downloadSpeedChanged (int )), this , SLOT (setDownloadSpeed (int )));
@@ -187,14 +209,17 @@ void QmlDownloader::startUpdate(const QString& selectedInstallPath)
187209 connect (worker_, SIGNAL (completedSizeChanged (int )), this , SLOT (setCompletedSize (int )));
188210 connect (&thread_, SIGNAL (started ()), worker_, SLOT (download ()));
189211 thread_.start ();
212+
213+ return true ;
190214}
191215
192216void QmlDownloader::toggleDownload (QString installPath)
193217{
194218 qDebug () << " QmlDownloader::toggleDownload called" ;
195219 if (state () == COMPLETED) return ;
196220 if (!worker_) {
197- startUpdate (installPath);
221+ setInstallPath (installPath);
222+ startUpdate ();
198223 return ;
199224 }
200225 QMetaObject::invokeMethod (worker_, " toggle" );
@@ -212,14 +237,22 @@ void QmlDownloader::stopAria()
212237 }
213238}
214239
215- void QmlDownloader::startUpdaterUpdate (QString updaterUrl )
240+ bool QmlDownloader::startUpdaterUpdate ()
216241{
242+ QString updaterUrl = splashController_.updaterUrl ();
243+ if (updaterUrl.isEmpty ()) {
244+ return false ;
245+ }
246+
247+ qDebug () << " Using updater URL:" << updaterUrl;
248+
217249 temp_dir_.reset (new QTemporaryDir ());
218250 worker_ = new DownloadWorker (ariaLogFilename_);
219251 worker_->setDownloadDirectory (QDir (temp_dir_->path ()).canonicalPath ().toStdString ());
220252 worker_->setConnectUrl (connectUrl_);
221253 worker_->addUpdaterUri (updaterUrl.toStdString ());
222254 worker_->moveToThread (&thread_);
255+ setDownloadRestarter (&QmlDownloader::startUpdaterUpdate);
223256 connect (&thread_, SIGNAL (finished ()), worker_, SLOT (deleteLater ()));
224257 connect (worker_, SIGNAL (onDownloadEvent (int )), this , SLOT (onDownloadEvent (int )));
225258 connect (worker_, SIGNAL (downloadSpeedChanged (int )), this , SLOT (setDownloadSpeed (int )));
@@ -228,6 +261,8 @@ void QmlDownloader::startUpdaterUpdate(QString updaterUrl)
228261 connect (worker_, SIGNAL (completedSizeChanged (int )), this , SLOT (setCompletedSize (int )));
229262 connect (&thread_, SIGNAL (started ()), worker_, SLOT (download ()));
230263 thread_.start ();
264+
265+ return true ;
231266}
232267
233268QmlDownloader::DownloadState QmlDownloader::state () const
@@ -240,3 +275,8 @@ void QmlDownloader::setState(DownloadState state)
240275 state_ = state;
241276 emit stateChanged (state);
242277}
278+
279+ void QmlDownloader::setDownloadRestarter (DownloadRestarter downloadRestarter)
280+ {
281+ downloadRestarter_ = downloadRestarter;
282+ }
0 commit comments