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
|
#ifdef _WIN32
#include "menu.h"
#include <urlmon.h>
#define ALLPINGERS "allpingers.txt"
#define URL "http://www.noreply.org/allpingers/allpingers.txt"
#pragma comment(lib,"urlmon.lib")
static const char *files[]={"mlist","rlist","mixring","pgpring","type2list"};
#define NUMFILES sizeof(files)/sizeof(*files)
/* Download all the needed files from the specified source */
static BOOL download(char *source, char *allpingers) {
const char *localfiles[]={"mlist.txt","rlist.txt","pubring.mix","pgpring.asc","type2.list"};
char buffer[1024],path[PATHMAX];
int i,ret = TRUE;
clear();
standout();
GetPrivateProfileString(source,"base","",buffer,sizeof(buffer),allpingers);
if (buffer[0]!='\0')
printw("%s",buffer);
standend();
for (i = 0;i < NUMFILES;i++) {
GetPrivateProfileString(source,files[i],"",buffer,sizeof(buffer),allpingers);
if (buffer[0]=='\0')
break;
mixfile(path, localfiles[i]);
mvprintw(i+3,0,"downloading %s...",localfiles[i]);
refresh();
if (URLDownloadToFile(NULL,buffer,path,BINDF_GETNEWESTVERSION,NULL) != S_OK) {
printw("failed to download.\n\rTry using another stats source.");
ret = FALSE;
break;
}
printw("done");
}
printw("\n\n\rPress any key to continue");
getch();
clear();
return ret;
}
/* Checks whether the stats source has all the required files */
static BOOL good_source(char *source,char *allpingers) {
char buffer[1024],*ptr;
int i;
GetPrivateProfileString(source,NULL,"",buffer,sizeof(buffer),allpingers);
for (i = 0;i < NUMFILES;i++) {
ptr = buffer;
while (*ptr != '\0') {
if (!strcmp(ptr,files[i]))
break;
ptr+=strlen(ptr)+1;
}
if (*ptr == '\0')
return FALSE;
}
return TRUE;
}
/* Download allpingers.txt */
static BOOL download_list(char *allpingers) {
clear();
standout();
printw(URL);
standend();
mvprintw(3,0,"downloading %s...", ALLPINGERS);
refresh();
if (URLDownloadToFile(NULL,URL,allpingers,BINDF_GETNEWESTVERSION,NULL) != S_OK) {
printw("failed to download.\n\rTry again later.");
printw("\n\n\rPress any key to continue");
getch();
return FALSE;
}
return TRUE;
}
/* Displays the choice of stats sources */
void update_stats(void) {
char buffer[1024],*ptr,*stats[MAXREM];
int i=0,x,y,num=0;
char path[PATHMAX],c;
mixfile(path, ALLPINGERS);
while (1) {
x = 0;
clear();
standout();
printw("Select stats source:\n\n");
standend();
if (num == 0) {
GetPrivateProfileSectionNames(buffer,sizeof(buffer),path);
ptr = buffer;
while ((*ptr != '\0') && (num < MAXREM)) {
if (good_source(ptr,path) == TRUE)
stats[num++] = ptr;
ptr+=strlen(ptr)+1;
}
}
for (i = 0;i < num;i++) {
y = i;
if (y >= LINES - 6)
y -= LINES - 6, x = 40;
mvprintw(y + 2, x, "%c", i < 26 ? i + 'a' : i - 26 + 'A');
mvprintw(y + 2, x + 2, "%s", stats[i]);
}
y = i + 3;
if (y > LINES - 4)
y = LINES - 4;
mvprintw(y, 0, "* update list of pingers");
c = getch();
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
if (c >= 'a')
c -= 'a';
else
c = c - 'A' + 26;
if (c < num) {
if (download(stats[c],path) == TRUE)
break;
}
}
else if (c == '*') {
download_list(path);
}
else break;
}
clear();
}
#endif /* _WIN32 */
|