forked from rileytestut/AltServer-Windows
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathDeveloperDiskManager.h
More file actions
executable file
·79 lines (60 loc) · 2.07 KB
/
Copy pathDeveloperDiskManager.h
File metadata and controls
executable file
·79 lines (60 loc) · 2.07 KB
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
//
// DeveloperDiskManager.hpp
// AltServer-Windows
//
// Created by Riley Testut on 7/1/21.
// Copyright © 2021 Riley Testut. All rights reserved.
//
#pragma once
#include <pplx/pplxtasks.h>
#include <filesystem>
#include <cpprest/http_client.h>
#include <cpprest/json.h>
#include "Device.hpp"
#include "Error.hpp"
enum class DeveloperDiskErrorCode
{
UnknownDownloadURL,
UnsupportedOperatingSystem,
DownloadedDiskNotFound
};
class DeveloperDiskError : public Error
{
public:
DeveloperDiskError(DeveloperDiskErrorCode code) : Error((int)code)
{
}
virtual std::string domain() const
{
return "AltServer.DeveloperDiskError";
}
virtual std::optional<std::string> localizedFailureReason() const
{
switch ((DeveloperDiskErrorCode)this->code())
{
case DeveloperDiskErrorCode::UnknownDownloadURL:
return "The URL to download the Developer disk image could not be determined.";
case DeveloperDiskErrorCode::UnsupportedOperatingSystem:
return "The device's operating system does not support installing Developer disk images.";
case DeveloperDiskErrorCode::DownloadedDiskNotFound:
return "DeveloperDiskImage.dmg and its signature could not be found in the downloaded archive.";
}
}
};
class DeveloperDiskManager
{
public:
DeveloperDiskManager();
~DeveloperDiskManager();
pplx::task<std::pair<std::string, std::string>> DownloadDeveloperDisk(std::shared_ptr<Device> device);
bool IsDeveloperDiskCompatible(std::shared_ptr<Device> device);
void SetDeveloperDiskCompatible(bool compatible, std::shared_ptr<Device> device);
private:
web::http::client::http_client _client;
web::http::client::http_client client() const;
pplx::task<web::json::value> FetchDeveloperDiskURLs();
pplx::task<size_t> DownloadFile(std::string downloadURL, std::filesystem::path destinationPath);
pplx::task<std::pair<std::string, std::string>> DownloadDiskArchive(std::string archiveURL);
pplx::task<std::pair<std::string, std::string>> DownloadDisk(std::string diskURL, std::string signatureURL);
std::optional<std::string> DeveloperDiskCompatibilityID(std::shared_ptr<Device> device);
};