Gpt4all Custom Updater

This PR establishes the initial infrastructure required to migrate gpt4all away from reliance on the IFW framwork by implementing a custom updater.
This custom updater (currently headless only) can perform the same operations as the existing updater with the option for more functionality to be added and most importantly, is installer agnostic, meaning gpt4all can start to leverage platform specific installers.

Implements both offline and online installation and update mechanisms.

Initial implementation of: https://github.com/nomic-ai/gpt4all/issues/2878

Signed-off-by: John Parent <john.parent@kitware.com>
This commit is contained in:
John Parent
2024-10-19 01:06:36 -04:00
parent 9cafd38dcf
commit 0765f917a9
34 changed files with 1252 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
#pragma once
#include <QCoreApplication>
#include <QProcess>
#include <QStringList>
#include <QFile>
namespace gpt4all {
namespace command{
class Command
{
public:
virtual bool execute();
QStringList arguments;
QFile* installer;
};
}
}

View File

@@ -0,0 +1,12 @@
#pragma once
#include "Command.h"
#include "CommandLine.h"
class CommandFactory : public QObject
{
public:
std::shared_ptr<gpt4all::command::Command> GetCommand(gpt4all::command::CommandType type);
};

View File

@@ -0,0 +1,30 @@
#pragma once
#include <QCommandLineParser>
namespace gpt4all {
namespace command {
enum CommandType {
UPDATE,
MODIFY,
DOWNGRADE,
UNINSTALL
};
class CommandLine : public QObject
{
public:
CommandLine();
~CommandLine();
void parse(QCoreApplication &app);
CommandType command();
private:
CommandType type;
QCommandLineParser * parser;
};
}
}

View File

@@ -0,0 +1,17 @@
#pragma once
#include "Command.h"
namespace gpt4all {
namespace downgrade {
class Downgrade : public gpt4all::command::Command
{
public:
Downgrade(QFile &installer);
};
}
}

View File

@@ -0,0 +1,65 @@
#pragma once
#include "Manifest.h"
#include "State.h"
#include <QCryptographicHash>
#include <QDateTime>
#include <QFile>
#include <QHash>
#include <QList>
#include <QMap>
#include <QObject>
#include <QtGlobal>
#include <QVersionNumber>
#include <QSslError>
#include <QThread>
#include <QString>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QCoreApplication>
namespace gpt4all {
namespace download {
class HashFile : public QObject
{
public:
HashFile() : QObject(nullptr) {}
void hashAndInstall(const QString &expected, QCryptographicHash::Algorithm algo, QFile *temp, const QString &file, QNetworkReply *reply);
};
class Download : public QObject
{
public:
static Download *instance();
Q_INVOKABLE void driveFetchAndInstall();
Q_INVOKABLE void downloadManifest();
Q_INVOKABLE void downloadInstaller();
Q_INVOKABLE void cancelDownload();
Q_INVOKABLE void installInstaller(QString &expected, QFile *temp, QNetworkReply *installerResponse);
private Q_SLOTS:
void handleSslErrors(QNetworkReply *reply, const QList<QSslError> &errors);
void handleErrorOccurred(QNetworkReply::NetworkError code);
void handleInstallerDownloadFinished();
void handleReadyRead();
private:
explicit Download();
~Download();
QNetworkReply * downloadInMemory(QUrl &url);
QNetworkReply * downloadLargeFile(QUrl &url);
QIODevice * handleManifestRequestResponse(QNetworkReply * reply);
gpt4all::manifest::ManifestFile *manifest;
QNetworkAccessManager m_networkManager;
QMap<QNetworkReply*, QFile*> download_tracking;
HashFile *saver;
QDateTime m_startTime;
QString platform_ext;
QFile *downloadPath;
friend class Downloader;
};
}
}

View File

@@ -0,0 +1,37 @@
#pragma once
#include <iostream>
#include <fstream>
#include <sstream>
#include <QCoreApplication>
#include <QFile>
#include <QByteArray>
// Symbols indicating beginning and end of embedded installer
extern "C" {
extern char data_start_gpt4all_installer, data_stop_gpt4all_installer;
extern int gpt4all_installer_size;
}
namespace gpt4all {
namespace embedded {
class EmbeddedInstaller : public QObject
{
public:
EmbeddedInstaller();
void extractAndDecode();
void installInstaller();
private:
char * start;
char * end;
int size;
QByteArray data;
};
}
}

View File

@@ -0,0 +1,46 @@
#pragma once
#include "Package.h"
#include <QVersionNumber>
#include <QDate>
#include <QFile>
#include <QXmlStreamReader>
#include <QString>
#include <QStringList>
namespace gpt4all{
namespace manifest {
enum releaseType{
RELEASE,
DEBUG
};
class ManifestFile {
public:
static ManifestFile * parseManifest(QIODevice *manifestInput);
QUrl & getInstallerEndpoint();
QString & getExpectedHash();
private:
ManifestFile() {}
QString name;
QVersionNumber release_ver;
QString notes;
QStringList authors;
QDate release_date;
releaseType config;
QVersionNumber last_supported_version;
QString entity;
QStringList component_list;
Package pkg;
void parsePkgDescription();
void parsePkgManifest();
QXmlStreamReader xml;
};
}
}

View File

@@ -0,0 +1,15 @@
#pragma once
#include "Command.h"
namespace gpt4all {
namespace modify {
class Modify : public gpt4all::command::Command
{
public:
Modify(QFile &installer);
};
}
}

View File

@@ -0,0 +1,29 @@
#pragma once
#include <string>
#include <vector>
#include <QCryptographicHash>
#include <QXmlStreamReader>
#include <QString>
#include <QStringList>
#include <QUrl>
namespace gpt4all {
namespace manifest {
class Package {
public:
Package() {}
static Package parsePackage(QXmlStreamReader &xml);
QString checksum_sha256;
bool is_signed;
QUrl installer_endpoint;
QUrl sbom_manifest;
QStringList installer_args;
};
}
}

View File

@@ -0,0 +1,18 @@
#pragma once
#include <stdio.h>
#include <windows.h>
#include <QCoreApplication>
namespace gpt4all {
namespace resource {
class WinInstallerResources : public QObject
{
public:
static int extractAndInstall();
}
}
}

View File

@@ -0,0 +1,38 @@
#pragma once
#include <QDir>
#include <QVersionNumber>
#include <QString>
#include <QStringList>
#include <QFile>
#include <QCoreApplication>
namespace gpt4all {
namespace state {
class Gpt4AllState : public QObject {
public:
virtual ~Gpt4AllState() = default;
static Gpt4AllState & getInstance();
QVersionNumber &getCurrentGpt4AllVersion();
QFile &getCurrentGpt4AllConfig();
QDir &getCurrentGpt4AllInstallRoot();
bool checkForExistingInstall();
QFile &getInstaller();
void setInstaller(QFile *installer);
void removeCurrentInstallation();
bool getExistingInstaller();
#ifdef OFFLINE
void driveOffline();
#endif
private:
explicit Gpt4AllState(QObject *parent = nullptr) {}
QFile *installer;
QFile currentGpt4AllConfig;
QDir currentGpt4AllInstallPath;
QVersionNumber currentGpt4AllVersion;
};
}
}

View File

@@ -0,0 +1,16 @@
#pragma once
#include "Command.h"
namespace gpt4all {
namespace uninstall {
class Uninstall : public gpt4all::command::Command
{
public:
Uninstall(QFile &uninstaller);
};
}
}

View File

@@ -0,0 +1,15 @@
#pragma once
#include "Command.h"
namespace gpt4all {
namespace updater {
class Update : public gpt4all::command::Command
{
public:
Update(QFile &installer);
};
}
}

View File

@@ -0,0 +1,7 @@
#pragma once
#include <stdlib.h>
#include <QString>
constexpr uint32_t hash(const char* data) noexcept;
void mountAndExtract(const QString &mountPoint, const QString &saveFilePath, const QString &appBundlePath);