7 DownloadFile(const char *filename
, const char *url
, unsigned long size
)
15 unsigned long totalBytes
= 0;
22 #if defined(GPODDER_GUI)
23 dlg
= CreateDialog(NULL
, "PROGRESS", NULL
, NULL
);
25 progress
= GetDlgItem(dlg
, 1);
26 SendMessage(progress
, PBM_SETRANGE
, 0, MAKELPARAM(0, 100));
28 label
= GetDlgItem(dlg
, 3);
29 SendMessage(label
, WM_SETTEXT
, 0, (LPARAM
)filename
);
31 label
= GetDlgItem(dlg
, 4);
34 inet
= InternetOpen("gpodder-dependency-downloader",
35 INTERNET_OPEN_TYPE_PRECONFIG
,
40 connection
= InternetOpenUrl(inet
,
44 INTERNET_FLAG_NO_AUTH
| INTERNET_FLAG_NO_CACHE_WRITE
|
45 INTERNET_FLAG_NO_COOKIES
| INTERNET_FLAG_NO_UI
,
48 out
= fopen(filename
, "wb");
54 if (!InternetReadFile(connection
,
66 fwrite(buf
, readBytes
, 1, out
);
68 totalBytes
+= readBytes
;
70 snprintf(line
, sizeof(line
), "%.2f / %.2f MB",
71 (float)totalBytes
/ (float)(1024*1024),
72 (float)size
/ (float)(1024*1024));
74 #if defined(GPODDER_CLI)
75 fprintf(stderr
, "Downloading: %s\r", line
);
78 #if defined(GPODDER_GUI)
79 SendMessage(label
, WM_SETTEXT
,
80 0, (LPARAM
)TEXT(line
));
82 SendMessage(progress
, PBM_SETPOS
,
83 (int)(100*(float)totalBytes
/(float)size
), 0);
85 while (PeekMessage(&msg
, dlg
, 0, 0, PM_NOREMOVE
)) {
86 if (GetMessage(&msg
, NULL
, 0, 0) > 0) {
87 TranslateMessage(&msg
);
88 DispatchMessage(&msg
);
94 #if defined(GPODDER_GUI)
99 InternetCloseHandle(connection
);
100 InternetCloseHandle(inet
);