]> icculus.org git repositories - taylor/freespace2.git/blob - include/inetgetfile.h
Initial revision
[taylor/freespace2.git] / include / inetgetfile.h
1 /*
2 * $Logfile: /Freespace2/code/Inetfile/inetgetfile.h $
3 * $Revision$
4 * $Date$
5 * $Author$
6 *
7 * InternetGetFile Class header
8 *
9 * $Log$
10 * Revision 1.1  2002/05/03 03:28:12  root
11 * Initial revision
12 *
13  * 
14  * 2     4/20/99 6:39p Dave
15  * Almost done with artillery targeting. Added support for downloading
16  * images on the PXO screen.
17  * 
18  * 1     4/20/99 4:37p Dave
19  *  
20  * Initial version
21 *
22 * $NoKeywords: $
23 */
24 #ifndef _INET_GETFILE_HEADER_
25 #define _INET_GETFILE_HEADER_
26
27 //At the end of this file is an example of usage
28
29 #include "cftp.h"
30 #include "chttpget.h"
31
32 #define INET_ERROR_NO_ERROR                     0
33 #define INET_ERROR_BADPARMS                     1
34 #define INET_ERROR_CANT_WRITE_FILE      2
35 #define INET_ERROR_CANT_PARSE_URL       3
36 #define INET_ERROR_BAD_FILE_OR_DIR      4
37 #define INET_ERROR_HOST_NOT_FOUND       5
38 #define INET_ERROR_UNKNOWN_ERROR                6
39 #define INET_ERROR_NO_MEMORY        7
40
41 class InetGetFile
42 {
43 public:
44         InetGetFile(char *URL,char *localfile);
45         ~InetGetFile();
46         BOOL IsFileReceived();
47         BOOL IsFileError();
48         BOOL IsConnecting();
49         BOOL IsReceiving();
50         int GetErrorCode();
51         int GetBytesIn();
52         int GetTotalBytes();
53         void AbortGet();
54
55 protected:
56         CFtpGet *ftp;
57         ChttpGet *http;
58         BOOL m_bUseHTTP;
59         int m_ErrorCode;
60         int m_State;
61         int m_HardError;
62
63 };
64
65 #endif
66
67 /*
68
69 #include <stdio.h>
70 #include <windows.h>
71 #include <conio.h>
72 #include <time.h>
73
74 #include "inetgetfile.h"
75
76 int main(int argc,char **argv)
77 {
78         unsigned int LastPrintbytes = time(NULL);
79         InetGetFile *inetfile;
80         WSADATA ws_data;
81         WORD ver=MAKEWORD(1,1);
82         
83         int error=WSAStartup(ver,&ws_data);
84         inetfile = new InetGetFile("http://www.volition-inc.com/images/download/freespace/fsdemo1x-12u.exe","e:\\fsdemo1x-12u.exe");
85         do
86         {
87                 if(inetfile->IsFileReceived())
88                 {
89                         printf("File received\n");
90                         break;
91                 }
92                 if(inetfile->IsFileError())
93                 {
94                         printf("File not received. Error code: %d\n",inetfile->GetErrorCode());
95                         break;
96                 }
97                 if(time(NULL)-LastPrintbytes>=1)
98                 {
99                         int ipct = 0;
100                         if(inetfile->GetTotalBytes())
101                         {
102                                 ipct = 100*(float)((float)inetfile->GetBytesIn()/(float)inetfile->GetTotalBytes());
103                         }
104                         printf("Received %d Bytes out of %d (%d%%).\n",inetfile->GetBytesIn(),inetfile->GetTotalBytes(),ipct);
105                         LastPrintbytes = time(NULL);
106                 }
107
108
109         }while(!kbhit());
110         return 0;
111
112 }
113
114
115
116  */
117