|
Odamex
Setting the Standard in Multiplayer Doom
|
00001 // Emacs style mode select -*- C++ -*- 00002 //----------------------------------------------------------------------------- 00003 // 00004 // $Id: frm_odaget.h 1788 2010-08-24 04:42:57Z russellrice $ 00005 // 00006 // Copyright (C) 2006-2010 by The Odamex Team. 00007 // 00008 // This program is free software; you can redistribute it and/or 00009 // modify it under the terms of the GNU General Public License 00010 // as published by the Free Software Foundation; either version 2 00011 // of the License, or (at your option) any later version. 00012 // 00013 // This program is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 // GNU General Public License for more details. 00017 // 00018 // DESCRIPTION: OdaGet file download utility 00019 // 00020 //----------------------------------------------------------------------------- 00021 00022 #ifndef __FRM_ODAGET__ 00023 #define __FRM_ODAGET__ 00024 00025 #include <wx/frame.h> 00026 #include <wx/gauge.h> 00027 #include <wx/textctrl.h> 00028 00029 #include <wx/protocol/http.h> 00030 #include <wx/protocol/ftp.h> 00031 #include <wx/thread.h> 00032 00033 enum URIResult 00034 { 00035 MIN_URIRESULTS 00036 ,URI_SUCCESS 00037 ,URI_BADDOMAIN 00038 ,URI_BADPATH 00039 ,URI_BADFILE 00040 ,MAX_URIRESULTS 00041 }; 00042 00043 // This class handles parsing of uniform resource identifiers (URI's) for 00044 // our http and ftp thread classes 00045 class URIHandler 00046 { 00047 public: 00048 URIHandler(const wxString &File) : 00049 m_User(wxT("")), m_Password(wxT("")), m_Server(wxT("")), m_Port(0), 00050 m_Path(wxT("")), m_Directory(wxT("")), m_File(File) 00051 { 00052 00053 } 00054 ~URIHandler() { } 00055 00056 URIResult ParseURL(const wxString &URL); 00057 00058 const wxString &GetUser() const { return m_User; } 00059 const wxString &GetPassword() const { return m_Password; } 00060 const wxString &GetServer() const { return m_Server; } 00061 const wxUint16 &GetPort() const { return m_Port; } 00062 const wxString &GetPath() const { return m_Path; } 00063 const wxString &GetDirectory() const { return m_Directory; } 00064 const wxString &GetFile() const { return m_File; } 00065 00066 protected: 00067 wxString m_User; 00068 wxString m_Password; 00069 wxString m_Server; 00070 wxUint16 m_Port; 00071 wxString m_Path; 00072 wxString m_Directory; 00073 wxString m_File; 00074 }; 00075 00076 // FTP Stuff 00077 00078 DECLARE_EVENT_TYPE(EVENT_FTP_THREAD, -1); 00079 00080 enum FTPEvent 00081 { 00082 MIN_FTPEVENTS 00083 ,FTP_BADURL 00084 ,FTP_CONNECTED 00085 ,FTP_DISCONNECTED 00086 ,FTP_GOTFILEINFO 00087 ,FTP_DOWNLOADING 00088 ,FTP_DOWNLOADERROR 00089 ,FTP_DOWNLOADTERMINATED 00090 ,FTP_POSITION 00091 ,FTP_DOWNLOADCOMPLETE 00092 ,MAX_FTPEVENTS 00093 }; 00094 00095 class FTPThread : public wxThread 00096 { 00097 public: 00098 FTPThread(wxEvtHandler *EventHandler, wxString URL, wxString SaveLocation, wxString File = wxT("")) : 00099 wxThread(wxTHREAD_JOINABLE), m_EventHandler(EventHandler), m_URL(URL), m_SaveLocation(SaveLocation) 00100 { 00101 m_File = File; 00102 } 00103 00104 ~FTPThread() { } 00105 00106 private: 00107 virtual void *Entry(); 00108 00109 wxFTP m_FTP; 00110 wxEvtHandler *m_EventHandler; 00111 wxString m_URL; 00112 wxString m_SaveLocation; 00113 wxString m_File; 00114 }; 00115 00116 // HTTP Stuff 00117 00118 DECLARE_EVENT_TYPE(EVENT_HTTP_THREAD, -1); 00119 00120 enum HTTPEvent 00121 { 00122 MIN_HTTPEVENTS 00123 ,HTTP_BADURL 00124 ,HTTP_CONNECTED 00125 ,HTTP_DISCONNECTED 00126 ,HTTP_GOTFILEINFO 00127 ,HTTP_DOWNLOADING 00128 ,HTTP_DOWNLOADERROR 00129 ,HTTP_DOWNLOADTERMINATED 00130 ,HTTP_POSITION 00131 ,HTTP_DOWNLOADCOMPLETE 00132 ,MAX_HTTPEVENTS 00133 }; 00134 00135 class HTTPThread : public wxThread 00136 { 00137 public: 00138 HTTPThread(wxEvtHandler *EventHandler, wxString URL, wxString SaveLocation, wxString File = wxT("")) : 00139 wxThread(wxTHREAD_JOINABLE), m_EventHandler(EventHandler), m_URL(URL), m_SaveLocation(SaveLocation) 00140 { 00141 m_File = File; 00142 00143 m_HTTP.SetHeader(wxT("Accept"), wxT("text/*")); 00144 m_HTTP.SetHeader(wxT("User-Agent"), wxT("OdaGet 0.1")); 00145 00146 m_HTTP.SetTimeout(60); 00147 } 00148 00149 ~HTTPThread() { } 00150 00151 private: 00152 virtual void *Entry(); 00153 00154 wxHTTP m_HTTP; 00155 wxEvtHandler *m_EventHandler; 00156 wxString m_URL; 00157 wxString m_SaveLocation; 00158 wxString m_File; 00159 }; 00160 00161 class frmOdaGet : public wxFrame 00162 { 00163 public: 00164 frmOdaGet(wxTopLevelWindow* parent, wxWindowID id = -1, wxString SaveLocation = wxT("")); 00165 virtual ~frmOdaGet(); 00166 private: 00167 void OnClose(wxCloseEvent &event); 00168 void OnCancel(wxCommandEvent &event); 00169 void OnDownload(wxCommandEvent &event); 00170 00171 void OnHttpThreadMessage(wxCommandEvent &event); 00172 void OnFtpThreadMessage(wxCommandEvent &event); 00173 00174 FTPThread *m_FTPThread; 00175 HTTPThread *m_HTTPThread; 00176 00177 wxTextCtrl *m_DownloadURL; 00178 wxTextCtrl *m_LocationDisplay; 00179 wxGauge *m_DownloadGauge; 00180 00181 wxString m_SaveLocation; 00182 00183 DECLARE_EVENT_TABLE() 00184 }; 00185 00186 #endif