2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
4 * All source code herein is the property of Volition, Inc. You may not sell
5 * or otherwise commercially exploit the source or things you created based on
10 * $Logfile: /Freespace2/code/Inetfile/inetgetfile.cpp $
15 * InternetGetFile Class
18 * Revision 1.6 2005/08/12 08:50:09 taylor
19 * recursively create directories (hurt more on OSX) and update all _mkdir() calls accordingly
21 * Revision 1.5 2002/06/09 04:41:21 relnev
22 * added copyright header
24 * Revision 1.4 2002/05/26 20:32:24 theoddone33
25 * Fix some minor stuff
27 * Revision 1.3 2002/05/26 20:20:54 relnev
32 * Revision 1.2 2002/05/07 03:16:45 theoddone33
33 * The Great Newline Fix
35 * Revision 1.1.1.1 2002/05/03 03:28:09 root
39 * 4 8/22/99 1:19p Dave
40 * Fixed up http proxy code. Cleaned up scoring code. Reverse the order in
41 * which d3d cards are detected.
43 * 3 6/16/99 10:27a Andsager
44 * Make directory if it does not already exist.
46 * 2 4/20/99 6:39p Dave
47 * Almost done with artillery targeting. Added support for downloading
48 * images on the PXO screen.
50 * 1 4/20/99 4:37p Dave
68 #include "cfilesystem.h"
72 #include "inetgetfile.h"
75 #define INET_STATE_CONNECTING 1
76 #define INET_STATE_ERROR 2
77 #define INET_STATE_RECEIVING 3
78 #define INET_STATE_GOT_FILE 4
80 void InetGetFile::AbortGet()
92 InetGetFile::InetGetFile(char *URL, char *filename, int cf_type)
97 if ( (URL == NULL) || (filename == NULL) || !CF_TYPE_SPECIFIED(cf_type) ) {
98 m_HardError = INET_ERROR_BADPARMS;
102 // create directory if not already there.
103 cf_create_directory(cf_type);
105 // create full path for file
106 char localfile[MAX_PATH_LEN] = "";
107 cf_create_default_path_string(localfile, cf_type, filename);
109 if (strstr(URL,"http:")) {
113 extern char Multi_options_proxy[512];
114 extern ushort Multi_options_proxy_port;
115 if(strlen(Multi_options_proxy) > 0){
116 http = new ChttpGet(URL, localfile, Multi_options_proxy, Multi_options_proxy_port);
118 http = new ChttpGet(URL, localfile);
122 m_HardError = INET_ERROR_NO_MEMORY;
124 } else if (strstr(URL,"ftp:")) {
126 ftp = new CFtpGet(URL,localfile);
128 m_HardError = INET_ERROR_NO_MEMORY;
131 m_HardError = INET_ERROR_CANT_PARSE_URL;
136 InetGetFile::~InetGetFile()
138 if(http!=NULL) delete http;
139 if(ftp!=NULL) delete ftp;
142 bool InetGetFile::IsConnecting()
147 state = http->GetStatus();
151 state = ftp->GetStatus();
153 if(state == FTP_STATE_CONNECTING)
164 bool InetGetFile::IsReceiving()
169 state = http->GetStatus();
173 state = ftp->GetStatus();
175 if(state == FTP_STATE_RECEIVING)
185 bool InetGetFile::IsFileReceived()
190 state = http->GetStatus();
194 state = ftp->GetStatus();
196 if(state == FTP_STATE_FILE_RECEIVED)
206 bool InetGetFile::IsFileError()
209 if(m_HardError) return true;
212 state = http->GetStatus();
216 state = ftp->GetStatus();
221 case FTP_STATE_URL_PARSING_ERROR:
222 case FTP_STATE_HOST_NOT_FOUND:
223 case FTP_STATE_DIRECTORY_INVALID:
224 case FTP_STATE_FILE_NOT_FOUND:
225 case FTP_STATE_CANT_CONNECT:
226 case FTP_STATE_LOGIN_ERROR:
227 case FTP_STATE_INTERNAL_ERROR:
228 case FTP_STATE_SOCKET_ERROR:
229 case FTP_STATE_UNKNOWN_ERROR:
230 case FTP_STATE_RECV_FAILED:
231 case FTP_STATE_CANT_WRITE_FILE:
233 case FTP_STATE_CONNECTING:
240 int InetGetFile::GetErrorCode()
243 if(m_HardError) return m_HardError;
246 state = http->GetStatus();
250 state = ftp->GetStatus();
255 case FTP_STATE_URL_PARSING_ERROR:
256 return INET_ERROR_CANT_PARSE_URL;
258 case FTP_STATE_HOST_NOT_FOUND:
259 return INET_ERROR_HOST_NOT_FOUND;
262 case FTP_STATE_DIRECTORY_INVALID:
263 case FTP_STATE_FILE_NOT_FOUND:
264 return INET_ERROR_BAD_FILE_OR_DIR;
266 case FTP_STATE_CANT_CONNECT:
267 case FTP_STATE_LOGIN_ERROR:
268 case FTP_STATE_INTERNAL_ERROR:
269 case FTP_STATE_SOCKET_ERROR:
270 case FTP_STATE_UNKNOWN_ERROR:
271 case FTP_STATE_RECV_FAILED:
273 return INET_ERROR_UNKNOWN_ERROR;
275 case FTP_STATE_CANT_WRITE_FILE:
276 return INET_ERROR_CANT_WRITE_FILE;
278 return INET_ERROR_NO_ERROR;
282 int InetGetFile::GetTotalBytes()
286 return http->GetTotalBytes();
290 return ftp->GetTotalBytes();
294 int InetGetFile::GetBytesIn()
298 return http->GetBytesIn();
302 return ftp->GetBytesIn();