diff --git a/reference/GuiWebDownload/GuiWebDownload.upp b/reference/GuiWebDownload/GuiWebDownload.upp new file mode 100644 index 000000000..78afc12a4 --- /dev/null +++ b/reference/GuiWebDownload/GuiWebDownload.upp @@ -0,0 +1,9 @@ +uses + CtrlLib; + +file + main.cpp; + +mainconfig + "" = "GUI SSE2"; + diff --git a/reference/GuiWebDownload/init b/reference/GuiWebDownload/init new file mode 100644 index 000000000..600f93ec4 --- /dev/null +++ b/reference/GuiWebDownload/init @@ -0,0 +1,4 @@ +#ifndef _SocketProgress_icpp_init_stub +#define _SocketProgress_icpp_init_stub +#include "CtrlLib/init" +#endif diff --git a/reference/GuiWebDownload/main.cpp b/reference/GuiWebDownload/main.cpp new file mode 100644 index 000000000..8258af1d9 --- /dev/null +++ b/reference/GuiWebDownload/main.cpp @@ -0,0 +1,55 @@ +#include + +using namespace Upp; + +struct Loader { + Progress pi; + HttpRequest http; + int64 loaded; + + typedef Loader CLASSNAME; + + void ProcessContent(const void *ptr, int size); + void Perform(); + void ShowProgress(); +}; + +void Loader::Perform() +{ + String url = "http://www.samgrob.ch/images/video/m60/m60_mtzion-nw-music1.divx"; + for(;;) { + if(!EditText(url, "Download", "URL")) + break; + loaded = 0; + HttpRequest http(url); + http.MaxContentSize(INT_MAX); + http.WhenContent = THISBACK(ProcessContent); + http.WhenWait = THISBACK(ShowProgress); + http.Execute(); + if(!http.IsSuccess()) + Exclamation("Failed !"); + } +} + +void Loader::ProcessContent(const void *ptr, int size) +{ + loaded += size; +} + +void Loader::ShowProgress() +{ +DDUMP(http.GetPeerAddr()); + if(http.GetContentLength() >= 0) + pi.Set((int)loaded, (int)http.GetContentLength()); + else + pi.Set(0, 0); + pi.SetText(http.GetPhaseName()); + if(pi.Canceled()) + http.Abort(); +} + +GUI_APP_MAIN +{ + HttpRequest::Trace(); + Loader().Perform(); +}