1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
|
/** (c) Nullsoft, Inc. C O N F I D E N T I A L
** Filename:
** Project:
** Description:
** Author:
** Created:
**/
#include "Main.h"
#include <cstdint>
#if 1
#include <sys/types.h>
#include <winsock.h>
#include "../nu/threadname.h"
#include "Wa_dlg.h"
#include "../nu/AutoWide.h"
static void createDirForFileW(wchar_t *str)
{
wchar_t *p = str;
if ((p[0] ==L'\\' || p[0] ==L'/') && (p[1] ==L'\\' || p[1] ==L'/'))
{
p += 2;
while (p && *p && *p !=L'\\' && *p !=L'/') p++;
if (!*p) return ;
p++;
while (p && *p && *p !=L'\\' && *p !=L'/') p++;
}
else
{
while (p && *p && *p !=L'\\' && *p !=L'/') p++;
}
while (p && *p)
{
while (p && *p !=L'\\' && *p !=L'/' && *p) p = CharNextW(p);
if (*p)
{
wchar_t lp = *p;
*p = 0;
CreateDirectoryW(str, NULL);
*p++ = lp;
}
}
}
static const wchar_t *rf_file, *rf_dlgtitle;
static const char *rf_url;
static int rf_in;
static HWND rf_dlgWnd, rf_statusWnd;
static volatile int rf_rv=-1;
static volatile int rf_abort;
static int g_rv;
static int _rftabort(int r, char *s)
{
if (s) SetWindowTextA(rf_statusWnd,s);
if (rf_dlgWnd) SendMessageW(rf_dlgWnd,WM_USER+1,r,0);
else rf_rv=r;
return r;
}
#define rfta(s) return _rftabort(!success,s)
#define sets(s) SetWindowTextA(rf_statusWnd,s)
typedef int (__stdcall *waP_RECV)(SOCKET s, char FAR* buf, int len, int flags);
waP_RECV p_recv;
static void encodeMimeStr(char *in, char *out)
{
char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
int shift = 0;
int accum = 0;
while (in && *in)
{
if (*in)
{
accum <<= 8;
shift += 8;
accum |= *in++;
}
while ( shift >= 6 )
{
shift -= 6;
*out++ = alphabet[(accum >> shift) & 0x3F];
}
}
if (shift == 4)
{
*out++ = alphabet[(accum & 0xF)<<2];
*out++='=';
}
else if (shift == 2)
{
*out++ = alphabet[(accum & 0x3)<<4];
*out++='=';
*out++='=';
}
*out++=0;
}
static int recv_string(SOCKET s, char *str, int maxlen)
{
int p=0;
do
{
int t=0;
while (t!=1)
{
t=p_recv(s,str+p,1,0);
if (t != 1)
{
if (rf_abort || !t) { str[0]=0; return -1; }
Sleep(100);
}
if (str[p] == '\r') t=0;
}
} while (str[p] != '\n' && ++p < maxlen-1);
str[p--]=0;
while (str[p] == '\n' && p > 0)
{
str[p--]=0;
}
if (p < 0) p = 0;
return p;
}
static int g_in_resolve;
static DWORD WINAPI rf_ThreadProc(LPVOID p666)
{
char locbuf[1024]={0};
int redirect=0;
HINSTANCE hws = LoadLibraryA("wsock32.dll");
int total_bytes;
uint64_t content_length;
SOCKET sock;
char proxytmp[256]={0};
char *proxy;
char connect_host[MAX_PATH]={0};
unsigned short connect_port;
int success=0;
typedef int (__stdcall *waSELECT)(int nfds,fd_set FAR * readfds,fd_set FAR * writefds,fd_set FAR * exceptfds,const struct timeval FAR * timeout);
typedef int (__stdcall *waWSAGETLASTERROR)(void);
typedef int (__stdcall *waWSACLEANUP)(void);
typedef int (__stdcall *waWSASTARTUP)(WORD wVersionRequested,LPWSADATA lpWSAData);
typedef int (__stdcall *waCLOSESOCKET)(SOCKET s);
typedef int (__stdcall *waSEND)(SOCKET s,const char FAR *buf,int len,int flags);
typedef SOCKET (__stdcall *waSOCKET)(int af, int type,int protocol);
typedef int (__stdcall *waCONNECT)( SOCKET s, const struct sockaddr FAR *name, int namelen );
typedef unsigned long (__stdcall *waINET_ADDR)(const char FAR *cp );
typedef struct hostent FAR * (__stdcall *waGETHOSTBYNAME)(const char FAR *name);
typedef int (__stdcall *waIOCTLSOCKET)(SOCKET s,long cmd,u_long FAR *argp);
typedef u_short (__stdcall *waHTONS)(u_short hostshort);
waSELECT select;
waWSAGETLASTERROR WSAGetLastError;
waWSACLEANUP WSACleanup;
waWSASTARTUP WSAStartup;
waCLOSESOCKET closesocket;
waSEND send;
waSOCKET socket;
waCONNECT connect;
waINET_ADDR inet_addr;
waGETHOSTBYNAME gethostbyname;
waIOCTLSOCKET ioctlsocket;
waHTONS htons;
char buf[ 4096 ] = { 0 };
char errorStr[ 1024 ] = { 0 };
char *p;
char url_buf[ 1024 ] = { 0 };
char *url_lp = NULL;
char *url_host = NULL;
int url_port = 80;
char *url_url = NULL;
char authstr[ 1024 ] = { 0 };
char proxy_lp[ 1024 ] = { 0 };
const char *t;
SetThreadName((DWORD)-1, "HTTP Retrieve File");
if ( hws )
{
WSAGetLastError = (waWSAGETLASTERROR)GetProcAddress( hws, "WSAGetLastError" );
WSACleanup = (waWSACLEANUP)GetProcAddress( hws, "WSACleanup" );
WSAStartup = (waWSASTARTUP)GetProcAddress( hws, "WSAStartup" );
closesocket = (waCLOSESOCKET)GetProcAddress( hws, "closesocket" );
send = (waSEND)GetProcAddress( hws, "send" );
p_recv = (waP_RECV)GetProcAddress( hws, "recv" );
select = (waSELECT)GetProcAddress( hws, "select" );
connect = (waCONNECT)GetProcAddress( hws, "connect" );
socket = (waSOCKET)GetProcAddress( hws, "socket" );
inet_addr = (waINET_ADDR)GetProcAddress( hws, "inet_addr" );
gethostbyname = (waGETHOSTBYNAME)GetProcAddress( hws, "gethostbyname" );
ioctlsocket = (waIOCTLSOCKET)GetProcAddress( hws, "ioctlsocket" );
htons = (waHTONS)GetProcAddress( hws, "htons" );
}
if (!hws || !p_recv || !WSACleanup ||
!WSAStartup || !closesocket || !send ||
!connect || !socket || !inet_addr ||
!gethostbyname || !ioctlsocket || !htons || !select || !WSAGetLastError)
{
if (hws)
FreeLibrary(hws);
rfta(getString(IDS_HTTP_LOAD_ERROR,errorStr,1024));
}
sets(getString(IDS_HTTP_INIT_SOCKET,errorStr,1024));
{
WSADATA wsaData;
if (WSAStartup(MAKEWORD(1, 1), &wsaData))
{
FreeLibrary(hws);
rfta(getString(IDS_HTTP_INIT_SOCKET_ERROR,errorStr,1024));
}
}
_redirect_goto:
total_bytes=0;
content_length=0;
// parse out l/p, host, port, and url from loc
authstr[0]=0;
url_lp=NULL;
url_host=NULL;
url_port=80;
url_url=NULL;
t= strstr(rf_url,"://");
if (t)
{
StringCchCopyA(url_buf,1024,t+3);
}
else
{
StringCchCopyA(url_buf,1024,rf_url);
}
p=url_buf;
while (p && *p != '/' && *p) p++;
if (p && *p) *p++=0;
url_url=p;
p=url_buf;
while (p && *p) p++;
while (p>=url_buf && *p != '@') p--;
if (p>=url_buf)
{
*p++=0;
url_host=p;
url_lp=url_buf;
if (lstrlenA(url_lp)>0)
{
StringCchCopyA(authstr,1024,"Authorization: Basic ");
encodeMimeStr(url_lp,authstr+lstrlenA(authstr));
StringCchCatA(authstr,1024,"\r\n");
}
}
else url_host=url_buf;
p=url_host;
while (p && *p != ':' && *p) p++;
if (p && *p)
{
*p++=0;
if (*p) url_port=atoi(p);
}
// determine if proxy server used
{
StringCchCopyA(proxytmp,256,config_proxy);
proxy=proxytmp;
while (proxy && (*proxy == ' ' || *proxy == '\t')) proxy++;
if (url_port != 80 && GetPrivateProfileIntW(L"Winamp",L"proxyonly80",0,INI_FILE))
proxy="";
}
if (*proxy)
{
p=proxy;
while (p && *p && *p != '@') p++;
if (p && *p)
{
*p++=0;
StringCchCopyA(proxy_lp,1024,"Proxy-Authorization: Basic ");
encodeMimeStr(proxy,proxy_lp+lstrlenA(proxy_lp));
StringCchCatA(proxy_lp,1024,"\r\n");
proxy=p;
}
lstrcpynA(connect_host,proxy,sizeof(connect_host)/sizeof(*connect_host));
p=connect_host;
while (p && *p && *p != ':') p++;
if (p && *p)
{
*p++=0;
if (*p) connect_port=(unsigned short)atoi(p);
else connect_port=80;
}
}
else
{
lstrcpynA(connect_host,url_host,sizeof(connect_host)/sizeof(*connect_host));
connect_port=(unsigned short)url_port;
}
sets(getString(IDS_HTTP_SOCKET_CREATE,errorStr,1024));
if (rf_abort || (sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP))==INVALID_SOCKET)
{
WSACleanup();
FreeLibrary(hws);
rfta(getString(IDS_HTTP_SOCKET_ERROR,errorStr,1024));
}
{
int t;
struct sockaddr_in blah;
memset((char *)&blah,0,sizeof(blah));
blah.sin_family=AF_INET;
blah.sin_addr.s_addr=inet_addr(connect_host);
blah.sin_port=htons(connect_port);
if ( blah.sin_addr.s_addr == INADDR_NONE )
{
struct hostent *he;
g_in_resolve = 1;
sets( *proxy ? getString( IDS_HTTP_RESOLVE_PROXY, errorStr, 1024 ) : getString( IDS_HTTP_RESOLVE_HOST, errorStr, 1024 ) );
if ( ( he = gethostbyname( connect_host ) ) != NULL )
memcpy( (char *)&blah.sin_addr, he->h_addr, he->h_length );
else if ( ( blah.sin_addr.s_addr = inet_addr( connect_host ) ) == INADDR_NONE )
{
g_in_resolve = 0;
closesocket( sock );
WSACleanup();
FreeLibrary( hws );
rfta( *proxy ? getString( IDS_HTTP_RESOLVE_PROXY_ERROR, errorStr, 1024 ) : getString( IDS_HTTP_RESOLVE_HOST_ERROR, errorStr, 1024 ) );
}
g_in_resolve = 0;
}
sets(*proxy?getString(IDS_HTTP_CONNECT_PROXY,errorStr,1024):getString(IDS_HTTP_CONNECT_HOST,errorStr,1024));
{
unsigned long arg=1;
ioctlsocket(sock,FIONBIO,&arg);
}
t=connect(sock,(struct sockaddr *)&blah,16);
if (t == -1 && WSAGetLastError()==WSAEWOULDBLOCK)
{
int a=0;
while (!rf_abort && t==-1)
{
TIMEVAL to={0,250*1000};
fd_set f;
FD_ZERO(&f);
FD_SET(sock,&f);
switch (select(0,NULL,&f,NULL,&to))
{
case 1: t=0; break;
case 0: if (a++ > 40) rf_abort =1; break;
case -1: rf_abort =1; break;
}
}
}
if (rf_abort || t==-1)
{
closesocket(sock);
WSACleanup();
FreeLibrary(hws);
rfta(*proxy?getString(IDS_HTTP_CONNECT_PROXY_ERROR,errorStr,1024):getString(IDS_HTTP_CONNECT_HOST_ERROR,errorStr,1024));
}
}
sets(getString(IDS_HTTP_SEND_REQUEST,errorStr,1024));
{
if ( *proxy )
StringCchPrintfA( buf, 4096, "GET http://%s:%d/%s", url_host, url_port, url_url );
else
StringCchPrintfA( buf, 4096, "GET /%s", url_url );
if (url_port != 80)
StringCchPrintfA( buf + lstrlenA( buf ), 4096 - lstrlenA( buf ), " HTTP/1.0\r\nHost: %s:%d\r\n", url_host, url_port );
else
StringCchPrintfA( buf + lstrlenA( buf ), 4096 - lstrlenA( buf ), " HTTP/1.0\r\nHost: %s\r\n", url_host );
StringCchPrintfA( buf + lstrlenA( buf ), 4096 - lstrlenA( buf ),
"User-Agent: Winamp/%s%s\r\n"
"%s%s"
"Accept: */*\r\n\r\n",
app_version,
( redirect == 2 ? " (Mozilla)" : "" ),
proxy_lp, authstr );
//MessageBox(NULL,buf,"SENDING:",0);
{
unsigned long arg = 0;
ioctlsocket( sock, FIONBIO, &arg );
}
send(sock,buf,lstrlenA(buf),0);
{
unsigned long arg = 1;
ioctlsocket( sock, FIONBIO, &arg );
}
}
sets( getString( IDS_HTTP_READ_REQUEST, errorStr, 1024 ) );
{ // get the standard HTTP 1.0 200 OK
char buf[1024] = {0};
int x = recv_string(sock,buf,sizeof(buf));
//MessageBox(0, buf, "RECEIVING:", 0);
if (x < 0 || rf_abort)
{
closesocket(sock);
WSACleanup();
FreeLibrary(hws);
rfta(getString(IDS_HTTP_CONNECTION_LOST,errorStr,1024));
}
if (strstr(buf," 302") || strstr(buf,"301"))
{
redirect=1;
}
else
{
// this is a very specific handling to allow for /listen.m3u with v1.x DNAS to work correctly
// as we need alter the user-agent so it will provide us with the needed response (a DNAS bug)
if ((redirect != 2) && strstr(buf,"ICY 404 Resource Not Found") && strstr(url_url,"listen.m3u")) {
redirect=2;
closesocket(sock);
goto _redirect_goto;
}
else
{
redirect=0;
}
}
if (!strstr(buf,"OK") && !redirect)
{
StringCchCatA(buf,1024,getString(IDS_HTTP_CONNECTION_CLOSED,errorStr,1024));
closesocket(sock);
WSACleanup();
FreeLibrary(hws);
rfta(buf);
}
sets(buf);
}
while (1)
{
char buf[1024] = {0}, *p;
int x = recv_string(sock,buf,sizeof(buf));
if (x < 0 || rf_abort)
{
closesocket(sock);
WSACleanup();
FreeLibrary(hws);
rfta(getString(IDS_HTTP_CONNECTION_LOST,errorStr,1024));
}
if (buf[0] == '\r' || !buf[0])
break;
{
p=buf;
while (p && *p && *p != ':') p++;
if (p && *p == ':')
{
*p++=0;
while (p && (*p == ' ' || *p == '\t'))
p++;
}
else
p=NULL;
}
if (!lstrcmpiA(buf,"Content-Length") && (*p >= '0' && *p <= '9'))
{
content_length=0;
while (p && *p >= '0' && *p <= '9')
{
content_length *= 10;
content_length += *p++-'0';
}
}
if (!lstrcmpiA(buf,"Location") && redirect)
{
StringCchCopyA(locbuf,1024,p);
rf_url=locbuf;
closesocket(sock);
//blah
goto _redirect_goto;
}
}
{
createDirForFileW((wchar_t *)rf_file);
HANDLE h = CreateFileW(rf_file,GENERIC_WRITE,FILE_SHARE_READ,NULL,CREATE_ALWAYS,0,NULL);
if (h == INVALID_HANDLE_VALUE)
{
closesocket(sock);
WSACleanup();
FreeLibrary(hws);
rfta(getString(IDS_HTTP_ERROR_OPEN_FILE,errorStr,1024));
}
{
unsigned int start_time=GetTickCount();
char buf[4096] = {0};
while (1)
{
int x=p_recv(sock,buf,sizeof(buf),0);
if (x == 0 || rf_abort)
break;
else if (x < 0)
{
if (WSAGetLastError()!=WSAEWOULDBLOCK) break;
Sleep(50);
}
else // x > 0
{
DWORD t = 0;
int lb=total_bytes;
WriteFile(h,buf,x,&t,NULL);
total_bytes += x;
if ( lb / 16384 != total_bytes / 16384 )
{
int bps;
int t = ( GetTickCount() - start_time );
if ( t < 1000 ) t = 1000;
bps = total_bytes / ( ( t + 999 ) / 1000 );
if ( content_length )
StringCchPrintfA( buf, 4096, getString( IDS_HTTP_RETRIEVE_FILE_LENGTH, errorStr, 1024 ), ( total_bytes * 100 ) / content_length, total_bytes, content_length, bps / 1000, ( bps / 10 ) % 100 );
else
StringCchPrintfA( buf, 4096, getString( IDS_HTTP_RETRIEVE_FILE, errorStr, 1024 ), total_bytes, bps / 1000, ( bps / 10 ) % 100 );
sets( buf );
}
}
}
}
CloseHandle(h);
}
if (!content_length || total_bytes == content_length)
success=1;
else
sets(getString(IDS_HTTP_FILE_INCOMPLETE,errorStr,1024));
closesocket(sock);
WSACleanup();
FreeLibrary(hws);
rfta(success?getString(IDS_HTTP_SUCCESS,errorStr,1024):NULL);
}
#undef rfta
#undef sets
static BOOL CALLBACK rf_DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
{
static HANDLE hThread;
static int r;
if (WADlg_initted())
{
INT_PTR a = WADlg_handleDialogMsgs(hwndDlg, uMsg, wParam, lParam);
if (a)
return a;
}
switch (uMsg)
{
case WM_USER+1:
if (hThread != INVALID_HANDLE_VALUE)
{
CloseHandle(hThread);
hThread=INVALID_HANDLE_VALUE;
}
if (!wParam)
{
g_rv=0;
PostMessageW(hwndDlg,WM_USER,0,0); // make it go quick
}
else
{
SetDlgItemTextA(hwndDlg,IDCANCEL,getString(IDS_HTTP_CLOSE,NULL,0));
r=5;
SetTimer(hwndDlg,123,1000,NULL);
}
return 0;
case WM_TIMER:
if (wParam == 123)
{
if ( r == 0 )
{
KillTimer( hwndDlg, wParam );
g_rv = 1;
}
else
{
char s[ 32 ] = { 0 };
StringCchPrintfA( s, 32, getString( IDS_CLOSE_COUNTDOWN, NULL, 0 ), r-- );
SetDlgItemTextA( hwndDlg, IDCANCEL, s );
}
}
return 0;
case WM_ERASEBKGND:
if (WADlg_initted())
return 1; //handled by WADlg_DrawChildWindowBorders in WM_PAINT
break;
case WM_PAINT:
{
if (WADlg_initted())
{
int tab[] = { IDC_STATUS | DCW_SUNKENBORDER};
WADlg_DrawChildWindowBorders(hwndDlg, tab, sizeof(tab) / sizeof(tab[0]));
return 0;
}
}
break;
case WM_INITDIALOG:
{
DWORD id;
char errorStr[ 1024 ] = { 0 };
if ( WADlg_initted() )
SetWindowLong( GetDlgItem( hwndDlg, IDCANCEL ), GWL_STYLE, GetWindowLongW( GetDlgItem( hwndDlg, IDCANCEL ), GWL_STYLE ) | BS_OWNERDRAW );
rf_dlgWnd = hwndDlg;
rf_statusWnd = GetDlgItem( hwndDlg, IDC_STATUS );
SetWindowTextW( hwndDlg, rf_dlgtitle );
if ( strstr( rf_url, "client.winamp.com/update" ) )
SetDlgItemTextA( hwndDlg, IDC_URL, getString( IDS_HTTP_WINAMP_UPDATE_SITE, errorStr, 1024 ) );
else
SetDlgItemTextA( hwndDlg, IDC_URL, rf_url );
SetDlgItemTextA( hwndDlg, IDC_STATUS, getString( IDS_HTTP_INIT, errorStr, 1024 ) );
rf_abort = 0;
hThread = CreateThread( NULL, 0, rf_ThreadProc, 0, 0, &id );
}
return FALSE;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDCANCEL:
if (hThread!=INVALID_HANDLE_VALUE)
{
char errorStr[1024] = {0};
rf_abort=1;
#if 0
if (g_in_resolve) g_in_resolve++;
if (0 && g_in_resolve==3) // lame terminatethread shouldnt be used
{
TerminateThread(hThread,0);
CloseHandle(hThread);
hThread=INVALID_HANDLE_VALUE;
g_rv=1;
}
else
#endif
SetDlgItemTextA(hwndDlg,IDCANCEL,getString(IDS_HTTP_ABORT,errorStr,1024));
}
else
{
g_rv=1;
}
return 0;
}
return 0;
}
return 0;
}
int httpRetrieveFileW(HWND hwnd, const char *url, const wchar_t *file, const wchar_t *dlgtitle)
{
int i;
int activated=0;
RECT r;
HWND dlgWnd;
if (rf_in) return 1;
rf_in=1;
g_rv=-1;
rf_url=url;
rf_file=file;
rf_dlgtitle=dlgtitle;
g_in_resolve=0;
if (!hwnd) hwnd=hMainWindow;
if (hwnd == hMainWindow && g_dialog_box_parent)
hwnd=g_dialog_box_parent;
{
if (_strnicmp(url,"http://",7))
{
// MessageBox(hwnd,getString(IDS_ONLYHTTP,NULL,0),"Winamp",MB_OK|MB_ICONSTOP);
rf_in=0;
return 1;
}
}
GetWindowRect(hwnd,&r);
dlgWnd=LPCreateDialogW(IDD_HTTPGET, hwnd, (WNDPROC)rf_DlgProc);
if (r.bottom > GetSystemMetrics(SM_CXSCREEN)/2 && r.bottom-r.top < 100)
{
RECT r2;
GetWindowRect(dlgWnd,&r2);
r.top=r.bottom-(r2.bottom-r2.top);
}
SetWindowPos(dlgWnd,NULL,r.left,r.top,0,0,SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE);
if (GetForegroundWindow()==hwnd)
{
activated=1;
ShowWindow(dlgWnd,SW_SHOW);
}
else
ShowWindow(dlgWnd,SW_SHOWNA);
if (hwnd == hMainWindow)
{
if (hMainWindow) EnableWindow(hMainWindow,0);
if (hPLWindow) EnableWindow(hPLWindow,0);
if (hEQWindow) EnableWindow(hEQWindow,0);
//if (hMBWindow) EnableWindow(hMBWindow,0);
}
else
EnableWindow(hwnd,0);
while (1)
{
MSG msg;
if (g_rv != -1) break;
GetMessage(&msg,NULL,0,0);
DispatchMessage(&msg);
}
if ( activated && GetForegroundWindow() == dlgWnd )
{
}
else
activated = 0;
if ( hwnd == hMainWindow )
{
if ( hMainWindow )
EnableWindow( hMainWindow, 1 );
if ( hPLWindow )
EnableWindow( hPLWindow, 1 );
if ( hEQWindow )
EnableWindow( hEQWindow, 1 );
//if (hMBWindow) EnableWindow(hMBWindow,1);
}
else
EnableWindow( hwnd, 1 );
DestroyWindow(dlgWnd);
if (activated)
SetForegroundWindow(hwnd);
i = g_rv;
rf_in=0;
return i;
}
int httpRetrieveFile(HWND hwnd, const char *url, char *file, char *dlgtitle)
{
return httpRetrieveFileW(hwnd, url, AutoWide(file), AutoWide(dlgtitle));
}
#endif
|