FS2_Open
Open source remastering of the Freespace 2 engine
inetgetfile.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) Volition, Inc. 1999. All rights reserved.
3  *
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 the
6  * source.
7  *
8 */
9 
10 
11 
12 #ifndef _INET_GETFILE_HEADER_
13 #define _INET_GETFILE_HEADER_
14 
15 //At the end of this file is an example of usage
16 
17 #include "inetfile/cftp.h"
18 #include "inetfile/chttpget.h"
19 
20 #define INET_ERROR_NO_ERROR 0
21 #define INET_ERROR_BADPARMS 1
22 #define INET_ERROR_CANT_WRITE_FILE 2
23 #define INET_ERROR_CANT_PARSE_URL 3
24 #define INET_ERROR_BAD_FILE_OR_DIR 4
25 #define INET_ERROR_HOST_NOT_FOUND 5
26 #define INET_ERROR_UNKNOWN_ERROR 6
27 #define INET_ERROR_NO_MEMORY 7
28 
30 {
31 public:
32  InetGetFile(char *URL,char *localfile);
33  ~InetGetFile();
34  bool IsFileReceived();
35  bool IsFileError();
36  bool IsConnecting();
37  bool IsReceiving();
38  int GetErrorCode();
39  int GetBytesIn();
40  int GetTotalBytes();
41  void AbortGet();
42 
43 protected:
46  bool m_bUseHTTP;
48  int m_State;
50 
51 };
52 
53 #endif
54 
55 /*
56 
57 #include <stdio.h>
58 #include <windows.h>
59 #include <conio.h>
60 #include <time.h>
61 
62 #include "inetfile/inetgetfile.h"
63 
64 int main(int argc,char **argv)
65 {
66  unsigned int LastPrintbytes = time(NULL);
67  InetGetFile *inetfile;
68  WSADATA ws_data;
69  WORD ver=MAKEWORD(1,1);
70 
71  int error=WSAStartup(ver,&ws_data);
72  inetfile = new InetGetFile("http://www.volition-inc.com/images/download/freespace/fsdemo1x-12u.exe","e:\\fsdemo1x-12u.exe");
73  do
74  {
75  if(inetfile->IsFileReceived())
76  {
77  printf("File received\n");
78  break;
79  }
80  if(inetfile->IsFileError())
81  {
82  printf("File not received. Error code: %d\n",inetfile->GetErrorCode());
83  break;
84  }
85  if(time(NULL)-LastPrintbytes>=1)
86  {
87  int ipct = 0;
88  if(inetfile->GetTotalBytes())
89  {
90  ipct = 100*(float)((float)inetfile->GetBytesIn()/(float)inetfile->GetTotalBytes());
91  }
92  printf("Received %d Bytes out of %d (%d%%).\n",inetfile->GetBytesIn(),inetfile->GetTotalBytes(),ipct);
93  LastPrintbytes = time(NULL);
94  }
95 
96 
97  }while(!kbhit());
98  return 0;
99 
100 }
101 
102 
103 
104  */
bool m_bUseHTTP
Definition: inetgetfile.h:46
int m_ErrorCode
Definition: inetgetfile.h:47
int GetTotalBytes()
bool IsConnecting()
int GetBytesIn()
bool IsFileReceived()
bool IsReceiving()
bool IsFileError()
Definition: cftp.h:48
int GetErrorCode()
int m_HardError
Definition: inetgetfile.h:49
InetGetFile(char *URL, char *localfile)
Definition: inetgetfile.cpp:45
void AbortGet()
Definition: inetgetfile.cpp:34
ChttpGet * http
Definition: inetgetfile.h:45
CFtpGet * ftp
Definition: inetgetfile.h:44