CL_CheckOrDownloadFile returns true if the file exists, otherwise it attempts to start a download from the server.
(String filename)
| 83 | * download from the server. |
| 84 | */ |
| 85 | public static boolean CheckOrDownloadFile(String filename) { |
| 86 | if (filename.indexOf("..") != -1) { |
| 87 | Com.Printf("Refusing to download a path with ..\n"); |
| 88 | return true; |
| 89 | } |
| 90 | |
| 91 | if (FS.FileExists(filename)) { |
| 92 | // it exists, no need to download |
| 93 | return true; |
| 94 | } else if (FS.FileExists(filename.toLowerCase())) { |
| 95 | // some mods mess up the case |
| 96 | Com.Printf("Found file by lowercase: " + filename + "\n"); |
| 97 | return true; |
| 98 | } |
| 99 | |
| 100 | ClientGlobals.cls.downloadname = filename; |
| 101 | |
| 102 | // download to a temp name, and only rename |
| 103 | // to the real name when done, so if interrupted |
| 104 | // a runt file wont be left |
| 105 | ClientGlobals.cls.downloadtempname = Com |
| 106 | .StripExtension(ClientGlobals.cls.downloadname); |
| 107 | ClientGlobals.cls.downloadtempname += ".tmp"; |
| 108 | |
| 109 | // ZOID |
| 110 | // check to see if we already have a tmp for this file, if so, try to |
| 111 | // resume |
| 112 | // open the file if not opened yet |
| 113 | String name = DownloadFileName(ClientGlobals.cls.downloadtempname); |
| 114 | |
| 115 | RandomAccessFile fp = Lib.fopen(name, "r+b"); |
| 116 | |
| 117 | if (fp != null) { |
| 118 | |
| 119 | // it exists |
| 120 | long len = 0; |
| 121 | |
| 122 | try { |
| 123 | len = fp.length(); |
| 124 | } |
| 125 | catch (IOException e) { |
| 126 | } |
| 127 | |
| 128 | |
| 129 | ClientGlobals.cls.download = fp; |
| 130 | |
| 131 | // give the server an offset to start the download |
| 132 | Com.Printf("Resuming " + ClientGlobals.cls.downloadname + "\n"); |
| 133 | ClientGlobals.cls.netchan.reliablePending.add(new StringCmdMessage(StringCmdMessage.DOWNLOAD + " " + ClientGlobals.cls.downloadname + " " + len)); |
| 134 | } else { |
| 135 | Com.Printf("Downloading " + ClientGlobals.cls.downloadname + "\n"); |
| 136 | ClientGlobals.cls.netchan.reliablePending.add(new StringCmdMessage(StringCmdMessage.DOWNLOAD + " " + ClientGlobals.cls.downloadname)); |
| 137 | } |
| 138 | |
| 139 | ClientGlobals.cls.downloadnumber++; |
| 140 | |
| 141 | return false; |
| 142 | } |
no test coverage detected