MCPcopy Create free account
hub / github.com/demoth/jake2 / ParseDownload

Method ParseDownload

client/src/main/java/jake2/client/CL_parse.java:171–236  ·  view source on GitHub ↗
(DownloadMessage msg)

Source from the content-addressed store, hash-verified

169 * =====================
170 */
171 public static void ParseDownload(DownloadMessage msg) {
172
173 // read the data
174 int percent = msg.percentage;
175 if (msg.data == null) {
176 Com.Printf("Server does not have this file.\n");
177 if (ClientGlobals.cls.download != null) {
178 // if here, we tried to resume a file but the server said no
179 try {
180 ClientGlobals.cls.download.close();
181 } catch (IOException e) {
182 }
183 ClientGlobals.cls.download = null;
184 }
185 CL.RequestNextDownload();
186 return;
187 }
188
189 // open the file if not opened yet
190 if (ClientGlobals.cls.download == null) {
191 String name = DownloadFileName(ClientGlobals.cls.downloadtempname).toLowerCase();
192
193 FS.CreatePath(name);
194
195 ClientGlobals.cls.download = Lib.fopen(name, "rw");
196 if (ClientGlobals.cls.download == null) {
197 Com.Printf("Failed to open " + ClientGlobals.cls.downloadtempname + "\n");
198 CL.RequestNextDownload();
199 return;
200 }
201 }
202
203
204 try {
205 ClientGlobals.cls.download.write(msg.data);
206 } catch (Exception e) {
207 Com.dprintln("Could not write downloaded data to file: " + e.getMessage());
208 }
209
210 if (percent != 100) {
211 // request next block
212 // change display routines by zoid
213 ClientGlobals.cls.downloadpercent = percent;
214 ClientGlobals.cls.netchan.reliablePending.add(new StringCmdMessage(StringCmdMessage.NEXT_DOWNLOAD));
215 } else {
216 try {
217 ClientGlobals.cls.download.close();
218 }
219 catch (IOException e) {
220 }
221
222 // rename the temp file to it's final name
223 String oldn = DownloadFileName(ClientGlobals.cls.downloadtempname);
224 String newn = DownloadFileName(ClientGlobals.cls.downloadname);
225 int r = Lib.rename(oldn, newn);
226 if (r != 0)
227 Com.Printf("failed to rename.\n");
228

Callers 1

ParseServerMessageMethod · 0.95

Calls 9

PrintfMethod · 0.95
RequestNextDownloadMethod · 0.95
DownloadFileNameMethod · 0.95
CreatePathMethod · 0.95
fopenMethod · 0.95
dprintlnMethod · 0.95
renameMethod · 0.95
writeMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected