@@ -10,9 +10,11 @@ import std.math;
10
10
import std.net.curl ;
11
11
import std.parallelism ;
12
12
import std.path ;
13
- import std.stdio ;
14
13
import std.zip ;
15
14
15
+ import slf4d;
16
+ import slf4d.default_provider;
17
+
16
18
import provision;
17
19
18
20
import constants;
@@ -34,7 +36,14 @@ __gshared ADI adi;
34
36
__gshared Device device;
35
37
36
38
void main (string [] args) {
37
- writeln(anisetteServerBranding, " v" , provisionVersion);
39
+ debug {
40
+ configureLoggingProvider(new shared DefaultProvider(true , Levels.DEBUG ));
41
+ } else {
42
+ configureLoggingProvider(new shared DefaultProvider(true , Levels.INFO ));
43
+ }
44
+
45
+ Logger log = getLogger();
46
+ log.infoF! " %s v%s" (anisetteServerBranding, provisionVersion);
38
47
auto serverConfig = ServerConfig.defaultValues;
39
48
serverConfig.hostname = " 0.0.0.0" ;
40
49
serverConfig.port = 6969 ;
@@ -70,27 +79,9 @@ void main(string[] args) {
70
79
71
80
if (! (file.exists(coreADIPath) && file.exists(SSCPath)) && apkDownloadAllowed) {
72
81
auto http = HTTP ();
73
- http.onProgress = (size_t dlTotal, size_t dlNow, size_t ulTotal, size_t ulNow) {
74
- write(" Downloading libraries from Apple servers... " );
75
- if (dlTotal != 0 ) {
76
- write((dlNow * 100 )/ dlTotal, " % \r " );
77
- } else {
78
- // Convert dlNow (in bytes) to a human readable string
79
- float downloadedSize = dlNow;
80
-
81
- enum units = [" B" , " kB" , " MB" , " GB" , " TB" ];
82
- int i = 0 ;
83
- while (downloadedSize > 1000 && i < units.length - 1 ) {
84
- downloadedSize = floor(downloadedSize) / 1000 ;
85
- ++ i;
86
- }
87
-
88
- write(downloadedSize, units[i], " \r " );
89
- }
90
- return 0 ;
91
- };
82
+ log.info(" Downloading libraries from Apple servers..." );
92
83
auto apkData = get ! (HTTP , ubyte )(nativesUrl, http);
93
- writeln( " Downloading libraries from Apple servers... done! \r " );
84
+ log.info( " Done ! " );
94
85
auto apk = new ZipArchive (apkData);
95
86
auto dir = apk.directory();
96
87
@@ -111,7 +102,7 @@ void main(string[] args) {
111
102
adi.provisioningPath = configurationPath;
112
103
113
104
if (! device.initialized) {
114
- stderr.write (" Creating machine... " );
105
+ log.info (" Creating machine... " );
115
106
116
107
import std.digest ;
117
108
import std.random ;
@@ -123,27 +114,29 @@ void main(string[] args) {
123
114
device.adiIdentifier = (cast (ubyte []) rndGen.take(2 ).array()).toHexString().toLower();
124
115
device.localUserUUID = (cast (ubyte []) rndGen.take(8 ).array()).toHexString().toUpper();
125
116
126
- stderr.writeln( " done !" );
117
+ log.info( " Machine creation done !" );
127
118
}
128
119
129
120
enum dsId = - 2 ;
130
121
131
122
adi.identifier = device.adiIdentifier;
132
123
if (! adi.isMachineProvisioned(dsId)) {
133
- stderr.write (" Machine requires provisioning... " );
124
+ log.info (" Machine requires provisioning... " );
134
125
135
126
ProvisioningSession provisioningSession = new ProvisioningSession(adi, device);
136
127
provisioningSession.provision(dsId);
137
- stderr.writeln( " done !" );
128
+ log.info( " Provisioning done !" );
138
129
}
139
130
140
131
auto s = new HttpServer((ref ctx) {
132
+ Logger log = getLogger();
133
+
141
134
auto req = ctx.request;
142
135
ctx.response.addHeader(" Implementation-Version" , anisetteServerBranding ~ " " ~ provisionVersion);
143
136
144
- writeln( " [<<] " , req.method, " " , req.url);
137
+ log.infoF ! " [<<] %s %s " ( req.method, req.url);
145
138
if (req.method != " GET" ) {
146
- writefln (" [>>] 405 Method Not Allowed" );
139
+ log.info (" [>>] 405 Method Not Allowed" );
147
140
ctx.response.setStatus(405 ).setStatusText(" Method Not Allowed" );
148
141
return ;
149
142
}
@@ -152,17 +145,17 @@ void main(string[] args) {
152
145
if (allowRemoteProvisioning) {
153
146
ProvisioningSession provisioningSession = new ProvisioningSession(adi, device);
154
147
provisioningSession.provision(dsId);
155
- writeln (" [>>] 200 OK" );
148
+ log.info (" [>>] 200 OK" );
156
149
ctx.response.setStatus(200 );
157
150
} else {
158
- writeln (" [>>] 403 Forbidden" );
151
+ log.info (" [>>] 403 Forbidden" );
159
152
ctx.response.setStatus(403 ).setStatusText(" Forbidden" );
160
153
}
161
154
return ;
162
155
}
163
156
164
157
if (req.url != " " ) {
165
- writeln (" [>>] 404 Not Found" );
158
+ log.info (" [>>] 404 Not Found" );
166
159
ctx.response.setStatus(404 ).setStatusText(" Not Found" );
167
160
return ;
168
161
}
@@ -191,16 +184,16 @@ void main(string[] args) {
191
184
" X-Mme-Device-Id" : device.uniqueDeviceIdentifier,
192
185
];
193
186
ctx.response.writeBodyString(response.toString(JSONOptions.doNotEscapeSlashes), " application/json" );
194
- writefln ! " [>>] 200 OK %s" (response);
187
+ log.infoF ! " [>>] 200 OK %s" (response);
195
188
} catch (Throwable t) {
196
189
string exception = t.toString();
197
- writeln( " Encountered an error: " , exception);
198
- writeln (" [>>] 500 Internal Server Error" );
190
+ log.errorF ! " Encountered an error: %s " ( exception);
191
+ log.info (" [>>] 500 Internal Server Error" );
199
192
ctx.response.writeBodyString(exception);
200
193
ctx.response.setStatus(500 ).setStatusText(" Internal Server Error" );
201
194
}
202
195
}, serverConfig);
203
196
204
- writeln (" Ready! Serving data." );
197
+ log.info (" Ready! Serving data." );
205
198
s.start();
206
199
}
0 commit comments