forked from rileytestut/AltServer-Windows
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathServerError.hpp
More file actions
executable file
·339 lines (273 loc) · 9.95 KB
/
Copy pathServerError.hpp
File metadata and controls
executable file
·339 lines (273 loc) · 9.95 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
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
//
// ServerError.hpp
// AltServer-Windows
//
// Created by Riley Testut on 8/13/19.
// Copyright © 2019 Riley Testut. All rights reserved.
//
#ifndef ServerError_hpp
#define ServerError_hpp
#include "Error.hpp"
#include <sstream>
extern std::string UnderlyingErrorDomainErrorKey;
extern std::string UnderlyingErrorCodeErrorKey;
extern std::string ProvisioningProfileBundleIDErrorKey;
extern std::string AppNameErrorKey;
extern std::string DeviceNameErrorKey;
extern std::string OperatingSystemNameErrorKey;
extern std::string OperatingSystemVersionErrorKey;
extern std::string NSFilePathErrorKey;
enum class ServerErrorCode
{
UnderlyingError = -1,
Unknown = 0,
ConnectionFailed = 1,
LostConnection = 2,
DeviceNotFound = 3,
DeviceWriteFailed = 4,
InvalidRequest = 5,
InvalidResponse = 6,
InvalidApp = 7,
InstallationFailed = 8,
MaximumFreeAppLimitReached = 9,
UnsupportediOSVersion = 10,
UnknownRequest = 11,
UnknownResponse = 12,
InvalidAnisetteData = 13,
PluginNotFound = 14,
ProfileNotFound = 15,
AppDeletionFailed = 16,
RequestedAppNotRunning = 100,
IncompatibleDeveloperDisk = 101,
};
class ServerError: public Error
{
public:
ServerError(ServerErrorCode code, std::map<std::string, std::any> userInfo = {}) : Error((int)code, userInfo)
{
}
virtual std::string domain() const
{
return "AltServer.ServerError";
}
virtual int displayCode() const
{
// We want ServerError codes to start at 2000,
// but we can't change them without breaking AltServer compatibility.
// Instead, we just add 2000 when displaying code to user
// to make it appear as if codes start at 2000 normally.
int displayCode = 2000 + this->code();
return displayCode;
}
virtual std::optional<std::string> localizedFailureReason() const
{
switch ((ServerErrorCode)this->code())
{
case ServerErrorCode::UnderlyingError:
if (this->userInfo().count(NSUnderlyingErrorKey) > 0)
{
auto underlyingError = std::any_cast<std::shared_ptr<Error>>(this->userInfo()[NSUnderlyingErrorKey]);
if (underlyingError->localizedFailureReason().has_value())
{
return *(underlyingError->localizedFailureReason());
}
}
if (this->userInfo().count(UnderlyingErrorCodeErrorKey) > 0)
{
auto errorCode = AnyStringValue(this->userInfo()[UnderlyingErrorCodeErrorKey]);
auto failureReason = "Error code: " + errorCode;
return failureReason;
}
else if (this->userInfo().count(NSLocalizedFailureReasonErrorKey) > 0)
{
auto localizedFailureReason = AnyStringValue(this->userInfo()[NSLocalizedFailureReasonErrorKey]);
return localizedFailureReason;
}
else
{
return std::nullopt;
}
case ServerErrorCode::Unknown:
return "An unknown error occured.";
case ServerErrorCode::ConnectionFailed:
{
if (this->userInfo().count(NSUnderlyingErrorKey) > 0)
{
auto underlyingError = std::any_cast<std::shared_ptr<Error>>(this->userInfo()[NSUnderlyingErrorKey]);
if (underlyingError->localizedFailureReason().has_value())
{
return *(underlyingError->localizedFailureReason());
}
}
return "There was an error connecting to the device.";
}
case ServerErrorCode::LostConnection:
return "The connection to AltServer was lost.";
case ServerErrorCode::DeviceNotFound:
return "AltServer could not find the device.";
case ServerErrorCode::DeviceWriteFailed:
return "AltServer could not write app data to the device.";
case ServerErrorCode::InvalidRequest:
{
if (this->userInfo().count(NSUnderlyingErrorKey) > 0)
{
auto underlyingError = std::any_cast<std::shared_ptr<Error>>(this->userInfo()[NSUnderlyingErrorKey]);
if (underlyingError->localizedFailureReason().has_value())
{
return *(underlyingError->localizedFailureReason());
}
}
return "AltServer received an invalid request.";
}
case ServerErrorCode::InvalidResponse:
{
if (this->userInfo().count(NSUnderlyingErrorKey) > 0)
{
auto underlyingError = std::any_cast<std::shared_ptr<Error>>(this->userInfo()[NSUnderlyingErrorKey]);
if (underlyingError->localizedFailureReason().has_value())
{
return *(underlyingError->localizedFailureReason());
}
}
return "AltServer sent an invalid response.";
}
case ServerErrorCode::InvalidApp:
return "The app is in an invalid format.";
case ServerErrorCode::InstallationFailed:
{
if (this->userInfo().count(NSUnderlyingErrorKey) > 0)
{
auto underlyingError = std::any_cast<std::shared_ptr<Error>>(this->userInfo()[NSUnderlyingErrorKey]);
if (underlyingError->localizedFailureReason().has_value())
{
return *(underlyingError->localizedFailureReason());
}
else
{
return underlyingError->localizedDescription();
}
}
return "An error occured while installing the app.";
}
case ServerErrorCode::MaximumFreeAppLimitReached:
return "You cannot activate more than 3 apps with a non-developer Apple ID.";
case ServerErrorCode::UnsupportediOSVersion:
{
auto osVersion = this->osVersion();
if (!osVersion.has_value())
{
return "Your device must be running iOS 12.2 or later to install AltStore.";
}
std::string appName = this->userInfo().count(AppNameErrorKey) > 0 ? AnyStringValue(this->userInfo()[AppNameErrorKey]) : "The app";
std::string failureReason = appName + " requires " + *osVersion + " or later.";
return failureReason;
}
case ServerErrorCode::UnknownRequest:
return "SideServer does not support this request.";
case ServerErrorCode::UnknownResponse:
return "SideStore received an unknown response from SideServer.";
case ServerErrorCode::InvalidAnisetteData:
return "The provided anisette data is invalid.";
case ServerErrorCode::PluginNotFound:
return "SideServer could not connect to Mail plug-in.";
case ServerErrorCode::ProfileNotFound:
return "The provisioning profile could not be found.";
case ServerErrorCode::AppDeletionFailed:
return "An error occured while removing the app.";
case ServerErrorCode::RequestedAppNotRunning:
{
std::string appName = this->userInfo().count(AppNameErrorKey) > 0 ? AnyStringValue(this->userInfo()[AppNameErrorKey]) : "The requested app";
std::string deviceName = this->userInfo().count(DeviceNameErrorKey) > 0 ? AnyStringValue(this->userInfo()[DeviceNameErrorKey]) : "the device";
std::ostringstream oss;
oss << appName << " is not currently running on " << deviceName << ".";
return oss.str();
}
case ServerErrorCode::IncompatibleDeveloperDisk:
{
auto osVersion = this->osVersion();
std::string failureReason = "The disk is incompatible with " + (osVersion.has_value() ? *osVersion : "this device's OS version") + ".";
return failureReason;
}
}
return std::nullopt;
}
virtual std::optional<std::string> localizedRecoverySuggestion() const
{
switch ((ServerErrorCode)this->code())
{
case ServerErrorCode::UnderlyingError:
{
if (this->userInfo().count(NSUnderlyingErrorKey) > 0)
{
auto underlyingError = std::any_cast<std::shared_ptr<Error>>(this->userInfo()[NSUnderlyingErrorKey]);
return underlyingError->localizedRecoverySuggestion();
}
else
{
return std::nullopt;
}
}
case ServerErrorCode::ConnectionFailed:
{
if (this->userInfo().count(NSUnderlyingErrorKey) > 0)
{
auto underlyingError = std::any_cast<std::shared_ptr<Error>>(this->userInfo()[NSUnderlyingErrorKey]);
if (underlyingError->localizedRecoverySuggestion().has_value())
{
return underlyingError->localizedRecoverySuggestion();
}
}
// If there is no underlying error, fall through to ::DeviceNotFound
[[fallthrough]];
}
case ServerErrorCode::DeviceNotFound:
return "Make sure you have trusted this device with your computer and WiFi sync is enabled.";
case ServerErrorCode::MaximumFreeAppLimitReached:
return "Please deactivate a sideloaded app with AltStore in order to install another app. If you're running iOS 13.5 or later, make sure 'Offload Unused Apps' is disabled in Settings > iTunes & App Stores, then install or delete all offloaded apps to prevent them from erroneously counting towards this limit.";
case ServerErrorCode::InvalidAnisetteData:
return "Please download the latest versions of iTunes and iCloud directly from Apple, and not from the Microsoft Store.";
case ServerErrorCode::RequestedAppNotRunning:
{
std::string deviceName = this->userInfo().count(DeviceNameErrorKey) > 0 ? AnyStringValue(this->userInfo()[DeviceNameErrorKey]) : "your device";
std::string localizedRecoverySuggestion = "Make sure the app is running in the foreground on " + deviceName + " then try again.";
return localizedRecoverySuggestion;
}
default: return Error::localizedRecoverySuggestion();
}
}
virtual std::optional<std::string> localizedDebugDescription() const
{
switch ((ServerErrorCode)this->code())
{
case ServerErrorCode::UnderlyingError:
case ServerErrorCode::InvalidRequest:
case ServerErrorCode::InvalidResponse:
{
if (this->userInfo().count(NSUnderlyingErrorKey) > 0)
{
auto underlyingError = std::any_cast<std::shared_ptr<Error>>(this->userInfo()[NSUnderlyingErrorKey]);
return underlyingError->localizedDebugDescription();
}
else
{
break;
}
}
case ServerErrorCode::IncompatibleDeveloperDisk:
{
if (this->userInfo().count(NSFilePathErrorKey) == 0)
{
break;
}
auto path = AnyStringValue(this->userInfo()[NSFilePathErrorKey]);
auto osVersion = this->osVersion().has_value() ? (*this->osVersion()) : "this device's OS version";
std::string failureReason = std::string("The Developer disk located at ") + path + " is incompatible with " + osVersion + ".";
return failureReason;
}
}
return Error::localizedDebugDescription();
}
private:
std::optional<std::string> osVersion() const;
};
#endif /* ServerError_hpp */