]> git.sur5r.net Git - minitube/blob - src/updateutils.cpp
New upstream version 3.8
[minitube] / src / updateutils.cpp
1 #include "updateutils.h"
2
3 #include <QtCore>
4
5 #include "constants.h"
6 #include "iconutils.h"
7 #include "mainwindow.h"
8
9 #ifdef UPDATER
10 #include "updater.h"
11 #ifdef UPDATER_SPARKLE
12 #include "sparkleupdater.h"
13 #else
14 #include "defaultupdater.h"
15 #include "runinstaller.h"
16 #include "simplexmlparser.h"
17 #endif
18 #endif
19
20 namespace UpdateUtils {
21
22 void init() {
23 #ifdef UPDATER
24
25 #ifdef UPDATER_SPARKLE
26     Updater::setInstance(new updater::SparkleUpdater());
27 #else
28     auto updater = new updater::DefaultUpdater();
29
30     QUrl manifestUrl(QLatin1String(Constants::WEBSITE) + "-ws/release.xml");
31     updater->setManifestUrl(manifestUrl);
32     updater->setParser(new updater::SimpleXmlParser());
33
34     QString ext;
35 #ifdef APP_MAC
36     ext = ".dmg";
37 #elif defined APP_WIN
38     ext = ".exe";
39 #else
40     ext = ".deb";
41 #endif
42     QUrl downloadUrl("https://" + QLatin1String(Constants::ORG_DOMAIN) + "/files/" +
43                      Constants::UNIX_NAME + "/" + Constants::UNIX_NAME + ext);
44     updater->setDownloadUrl(downloadUrl);
45
46     auto installer = new updater::RunInstaller;
47 #ifdef APP_WIN
48     installer->setArguments({"/S"});
49     installer->setRelaunchArguments({"/run"});
50 #endif
51 #ifdef APP_LINUX
52     installer->setCommand({"dpkg"});
53     installer->setArguments({"-i", "%filename%"});
54     installer->setRunAsAdmin(true);
55     installer->setAutoRestart(true);
56 #endif
57     updater->setInstaller(installer);
58
59     Updater::setInstance(updater);
60 #endif
61
62 #endif
63 }
64
65 } // namespace UpdateUtils