| 1 |
#ifdef _WIN32
|
| 2 |
#include "menu.h"
|
| 3 |
#include <urlmon.h>
|
| 4 |
#define ALLPINGERS "allpingers.txt"
|
| 5 |
#define URL "http://www.noreply.org/allpingers/allpingers.txt"
|
| 6 |
#pragma comment(lib,"urlmon.lib")
|
| 7 |
|
| 8 |
static const char *files[]={"mlist","rlist","mixring","pgpring","type2list"};
|
| 9 |
#define NUMFILES sizeof(files)/sizeof(*files)
|
| 10 |
|
| 11 |
/* Download all the needed files from the specified source */
|
| 12 |
static BOOL download(char *source, char *allpingers) {
|
| 13 |
const char *localfiles[]={"mlist.txt","rlist.txt","pubring.mix","pgpring.asc","type2.list"};
|
| 14 |
char buffer[1024],path[PATHMAX];
|
| 15 |
int i,ret = TRUE;
|
| 16 |
|
| 17 |
clear();
|
| 18 |
standout();
|
| 19 |
GetPrivateProfileString(source,"base","",buffer,sizeof(buffer),allpingers);
|
| 20 |
if (buffer[0]=='\0')
|
| 21 |
return FALSE;
|
| 22 |
printw("%s",buffer);
|
| 23 |
standend();
|
| 24 |
|
| 25 |
for (i = 0;i < NUMFILES;i++) {
|
| 26 |
GetPrivateProfileString(source,files[i],"",buffer,sizeof(buffer),allpingers);
|
| 27 |
if (buffer[0]=='\0')
|
| 28 |
break;
|
| 29 |
mixfile(path, localfiles[i]);
|
| 30 |
mvprintw(i+3,0,"downloading %s...",localfiles[i]);
|
| 31 |
refresh();
|
| 32 |
if (URLDownloadToFile(NULL,buffer,path,BINDF_GETNEWESTVERSION,NULL) != S_OK) {
|
| 33 |
printw("failed to download.\n\rTry using another stats source.");
|
| 34 |
ret = FALSE;
|
| 35 |
break;
|
| 36 |
}
|
| 37 |
printw("done");
|
| 38 |
}
|
| 39 |
|
| 40 |
printw("\n\n\rPress any key to continue");
|
| 41 |
getch();
|
| 42 |
clear();
|
| 43 |
return ret;
|
| 44 |
}
|
| 45 |
/* Checks whether the stats source has all the required files */
|
| 46 |
static BOOL good_source(char *source,char *allpingers) {
|
| 47 |
char buffer[1024];
|
| 48 |
int i;
|
| 49 |
|
| 50 |
for (i = 0;i < NUMFILES;i++)
|
| 51 |
{
|
| 52 |
GetPrivateProfileString(source,files[i],"",buffer,sizeof(buffer),allpingers);
|
| 53 |
if (buffer[0]=='\0')
|
| 54 |
return FALSE;
|
| 55 |
}
|
| 56 |
|
| 57 |
return TRUE;
|
| 58 |
}
|
| 59 |
/* Download allpingers.txt */
|
| 60 |
static BOOL download_list(void) {
|
| 61 |
char path[PATHMAX];
|
| 62 |
mixfile(path,ALLPINGERS);
|
| 63 |
|
| 64 |
clear();
|
| 65 |
standout();
|
| 66 |
printw(URL);
|
| 67 |
standend();
|
| 68 |
|
| 69 |
mvprintw(3,0,"downloading %s...", ALLPINGERS);
|
| 70 |
refresh();
|
| 71 |
if (URLDownloadToFile(NULL,URL,path,BINDF_GETNEWESTVERSION,NULL) != S_OK) {
|
| 72 |
printw("failed to download.\n\rTry again later.");
|
| 73 |
printw("\n\n\rPress any key to continue");
|
| 74 |
getch();
|
| 75 |
return FALSE;
|
| 76 |
}
|
| 77 |
return TRUE;
|
| 78 |
}
|
| 79 |
/* Displays the choice of stats sources */
|
| 80 |
void update_stats(void) {
|
| 81 |
char buffer[1024],*ptr,*stats[MAXREM];
|
| 82 |
int i=0,x,y,num=0;
|
| 83 |
char path[PATHMAX],c;
|
| 84 |
mixfile(path, ALLPINGERS);
|
| 85 |
|
| 86 |
while (1) {
|
| 87 |
x = 0;
|
| 88 |
clear();
|
| 89 |
standout();
|
| 90 |
printw("Select stats source:\n\n");
|
| 91 |
standend();
|
| 92 |
if (num == 0) {
|
| 93 |
GetPrivateProfileSectionNames(buffer,sizeof(buffer),path);
|
| 94 |
ptr = buffer;
|
| 95 |
while ((*ptr != '\0') && (num < MAXREM)) {
|
| 96 |
if (good_source(ptr,path) == TRUE)
|
| 97 |
stats[num++] = ptr;
|
| 98 |
ptr+=strlen(ptr)+1;
|
| 99 |
}
|
| 100 |
}
|
| 101 |
|
| 102 |
for (i = 0;i < num;i++) {
|
| 103 |
y = i;
|
| 104 |
if (y >= LINES - 6)
|
| 105 |
y -= LINES - 6, x = 40;
|
| 106 |
mvprintw(y + 2, x, "%c", i < 26 ? i + 'a' : i - 26 + 'A');
|
| 107 |
mvprintw(y + 2, x + 2, "%s", stats[i]);
|
| 108 |
}
|
| 109 |
y = i + 3;
|
| 110 |
if (y > LINES - 4)
|
| 111 |
y = LINES - 4;
|
| 112 |
mvprintw(y, 0, "* update list of pingers");
|
| 113 |
c = getch();
|
| 114 |
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
|
| 115 |
if (c >= 'a')
|
| 116 |
c -= 'a';
|
| 117 |
else
|
| 118 |
c = c - 'A' + 26;
|
| 119 |
if (c < num) {
|
| 120 |
if (download(stats[c],path) == TRUE)
|
| 121 |
break;
|
| 122 |
}
|
| 123 |
}
|
| 124 |
else if (c == '*') {
|
| 125 |
download_list();
|
| 126 |
}
|
| 127 |
else break;
|
| 128 |
}
|
| 129 |
clear();
|
| 130 |
}
|
| 131 |
|
| 132 |
#endif /* _WIN32 */
|