This repository has been archived by the owner on Oct 2, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathimagewriter.h
162 lines (127 loc) · 5.38 KB
/
imagewriter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#ifndef IMAGEWRITER_H
#define IMAGEWRITER_H
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright (C) 2020 Raspberry Pi (Trading) Limited
*/
#include <QObject>
#include <QTimer>
#include <QUrl>
#include <QSettings>
#include <QVariant>
#include "config.h"
#include "powersaveblocker.h"
#include "drivelistmodel.h"
class QQmlApplicationEngine;
class DownloadThread;
class QNetworkReply;
class QWinTaskbarButton;
class ImageWriter : public QObject
{
Q_OBJECT
public:
explicit ImageWriter(QObject *parent = nullptr);
~ImageWriter() override;
void setEngine(QQmlApplicationEngine *engine);
/* Set URL to download from, and if known download length and uncompressed length */
Q_INVOKABLE void setSrc(const QUrl &url, quint64 downloadLen = 0, quint64 extrLen = 0, QByteArray expectedHash = "", bool multifilesinzip = false, QString parentcategory = "", QString osname = "");
/* Set device to write to */
Q_INVOKABLE void setDst(const QString &device, quint64 deviceSize = 0);
/* Enable/disable verification */
Q_INVOKABLE void setVerifyEnabled(bool verify);
/* Returns true if src and dst are set */
Q_INVOKABLE bool readyToWrite();
/* Start writing */
Q_INVOKABLE void startWrite();
/* Cancel write */
Q_INVOKABLE void cancelWrite();
/* Return true if url is in our local disk cache */
Q_INVOKABLE bool isCached(const QUrl &url, const QByteArray &sha256);
/* Start polling the list of available drives */
Q_INVOKABLE void startDriveListPolling();
/* Stop polling the list of available drives */
Q_INVOKABLE void stopDriveListPolling();
/* Return list of available drives. Call startDriveListPolling() first */
DriveListModel *getDriveList();
/* Utility function to return filename part from URL */
Q_INVOKABLE QString fileNameFromUrl(const QUrl &url);
/* Function to return OS list URL */
Q_INVOKABLE QUrl constantOsListUrl() const;
/* Function to return version */
Q_INVOKABLE static QString constantVersion();
/* Returns true if version argument is newer than current program */
Q_INVOKABLE bool isVersionNewer(const QString &version);
/* Set custom repository */
Q_INVOKABLE void setCustomOsListUrl(const QUrl &url);
/* Utility function to open OS file dialog */
Q_INVOKABLE void openFileDialog();
/* Return filename part of URL set */
Q_INVOKABLE QString srcFileName();
/* Returns true if online */
Q_INVOKABLE bool isOnline();
/* Returns true if run on embedded Linux platform */
Q_INVOKABLE bool isEmbeddedMode();
/* Mount any USB sticks that can contain source images under /media
Returns true if at least one device was mounted */
Q_INVOKABLE bool mountUsbSourceMedia();
/* Returns a json formatted list of the OS images found on USB stick */
Q_INVOKABLE QByteArray getUsbSourceOSlist();
/* Functions to collect information from computer running imager to make image customization easier */
Q_INVOKABLE QString getDefaultPubKey();
Q_INVOKABLE QString getTimezone();
Q_INVOKABLE QStringList getTimezoneList();
Q_INVOKABLE QStringList getCountryList();
Q_INVOKABLE QString getSSID();
Q_INVOKABLE QString getPSK(const QString &ssid);
Q_INVOKABLE bool getBoolSetting(const QString &key);
Q_INVOKABLE void setSetting(const QString &key, const QVariant &value);
Q_INVOKABLE void setImageCustomization(const QByteArray &config, const QByteArray &cmdline, const QByteArray &firstrun);
Q_INVOKABLE void setSavedCustomizationSettings(const QVariantMap &map);
Q_INVOKABLE QVariantMap getSavedCustomizationSettings();
Q_INVOKABLE void clearSavedCustomizationSettings();
Q_INVOKABLE bool hasSavedCustomizationSettings();
Q_INVOKABLE QString crypt(const QByteArray &password);
Q_INVOKABLE QString pbkdf2(const QByteArray &psk, const QByteArray &ssid);
signals:
/* We are emiting signals with QVariant as parameters because QML likes it that way */
void downloadProgress(QVariant _t1, QVariant _t2);
void verifyProgress(QVariant _t1, QVariant _t2);
void error(QVariant _t1);
void success();
void fileSelected(QVariant _t1);
void cancelled();
void finalizing();
void networkOnline();
void preparationStatusUpdate(QVariant _t1);
protected slots:
void startProgressPolling();
void stopProgressPolling();
void pollProgress();
void pollNetwork();
void syncTime();
void onSuccess();
void onError(const QString& msg);
void onFileSelected(const QString& filename);
void onCancelled();
void onCacheFileUpdated(const QByteArray& sha256);
void onFinalizing();
void onTimeSyncReply(QNetworkReply *reply);
void onPreparationStatusUpdate(const QString& msg);
protected:
QUrl _src, _repo;
QString _dst, _cacheFileName, _parentCategory, _osName;
QByteArray _expectedHash, _cachedFileHash, _cmdline, _config, _firstrun;
quint64 _downloadLen, _extrLen, _devLen, _dlnow{0}, _verifynow{0};
DriveListModel _drivelist;
QQmlApplicationEngine *_engine{nullptr};
QTimer _polltimer, _networkchecktimer;
PowerSaveBlocker _powersave;
DownloadThread *_thread{nullptr};
bool _verifyEnabled{false}, _multipleFilesInZip, _cachingEnabled{false}, _embeddedMode{false}, _online{false};
QSettings _settings;
#ifdef Q_OS_WIN
QWinTaskbarButton *_taskbarButton;
#endif
void _parseCompressedFile();
};
#endif // IMAGEWRITER_H