-
Marton Ady authoredMarton Ady authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
AppUpdater.cpp 50.66 KiB
#include "AppUpdater.h"
#include "AppUpdaterRemoteFeed.hpp"
#include <ZipLib/ZipArchive.h>
#include <ZipLib/ZipArchiveEntry.h>
#include <ZipLib/ZipFile.h>
#include "File.h"
#include <sstream>
#include <filesystem>
#include "Helper/MathTools.h" //Contains
#include "Helper/StringHelper.h"
#include "GLApp/GLToolkit.h"
#include "GLApp/GLList.h"
#include "GLApp/GLMessageBox.h"
#include "GLApp/GLButton.h"
#include "GLApp/GLLabel.h"
#include "MatomoAnalytics.h"
#ifndef _WIN32
#include <unistd.h> //Get user name
#endif
/**
* \brief Constructor with initialisation for the App Updater
* \param appName hardcoded name of the app (@see versionId.h)
* \param versionId hardcoded version ID of the app (@see versionId.h)
* \param configFile xml file with the updater config (usually in bin folder)
*/
AppUpdater::AppUpdater(const std::string& appName, const int versionId, const std::string& configFile) {
applicationName = appName;
currentVersionId = versionId;
configFileName = configFile;
updateWarning = nullptr;
os = GLToolkit::GetOSName();
if(!std::filesystem::exists(configFileName))
MakeDefaultConfig();
LoadConfig();
}
/**
* \brief Creates a default config from MatomoAnalytics.h info
*/
void AppUpdater::MakeDefaultConfig(){
xml_document configDoc;
xml_node rootNode = configDoc.append_child("UpdaterConfigFile"); //XML specifications require a root node
xml_node serverNode = rootNode.append_child("ServerConfig");
//serverNode.append_child("RemoteFeed").append_attribute("url") = REMOTE_FEED; //Hard-code to avoid tampering
serverNode.append_child("PublicWebsite").append_attribute("url") = PUBLIC_WEBSITE;
serverNode.child("PublicWebsite").append_attribute("downloadsPage") = DOWNLOAD_PAGE;
auto matomoNode = serverNode.append_child("MatomoAnalytics");
matomoNode.append_attribute("siteId") = MATOMO_SITE_ID;
matomoNode.append_attribute("requestTarget") = MATOMO_REQUEST_TARGET;
xml_node localConfigNode = rootNode.append_child("LocalConfig");
localConfigNode.append_child("Permission").append_attribute("allowUpdateCheck") = "false";
localConfigNode.child("Permission").append_attribute("appLaunchedBeforeAsking") = "0";
localConfigNode.child("Permission").append_attribute("askAfterNbLaunches") = "3";
localConfigNode.child("Permission").append_attribute("nbUpdateFailsInRow") = "0";
localConfigNode.child("Permission").append_attribute("askAfterNbUpdateFails") = "5";
localConfigNode.append_child("Branch").append_attribute("name") = BRANCH_NAME BRANCH_OS_SUFFIX; //molflow_public or synrad_public + suffix (_win, _mac, _mac_arm, _linux_debian, _linux_fedora)
localConfigNode.append_child("MatomoAnalytics").append_attribute("userHash") = "";
localConfigNode.append_child("SkippedVersions");
configDoc.save_file(configFileName.c_str());