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
|
#include "common.h"
#include "utils.h"
bool VersionFromString(const char *szVer, DWORD *pdwVer) {
char *p = (char *)szVer;
*pdwVer = 0;
int bytes = 1; // we start in the first 'byte'
int digit_count = 0;
while(*p && bytes <= 4 && digit_count <= 3) {
if(*p >= '0' && *p <= '9') {
*pdwVer = (*pdwVer & 0xFFFFFF00) + (*pdwVer & 0xFF) * 10 + (*p - '0');
digit_count++;
} else if(*p == '.') {
*pdwVer = *pdwVer << 8;
bytes++;
digit_count = 0;
} else {
if(bytes < 3) // allow other chars on the end (e.g. space)
return false; // incompatible version string
else
return true;
}
p++;
}
// version must be x.x.x.x format (for now - until a convention is established
// whereby we assume '0' bytes as either prefix or suffix)
// 15/3/06 - allowing 3 digit version numbers (ostensibly for spamfilter definition files which use date for version)
return (bytes >= 3);
}
int CheckForFileID(char *update_url, char *version_url, char *name) {
if(strlen(update_url) > 45 && strncmp(update_url, MIM_DOWNLOAD_URL_PREFIX, 45) == 0) {
char *p = update_url + 45;
return atoi(p);
}
if(strlen(update_url) > 51 && strncmp(update_url, "http://www.miranda-im.org/download/feed.php?dlfile=", 51) == 0) {
char *p = update_url + 51;
return atoi(p);
}
if(strlen(update_url) > 47 && strncmp(update_url, "http://miranda-im.org/download/feed.php?dlfile=", 47) == 0) {
char *p = update_url + 47;
return atoi(p);
}
return -1;
}
bool CreatePath(const TCHAR *path)
{
if (!path) return false;
CallService(MS_UTILS_CREATEDIRTREET, 0, (LPARAM)path);
return true;
}
// must 'mir_free' return val
TCHAR *GetTString(const char *asc)
{
if (!asc) return NULL;
return (TCHAR*)CallService(MS_LANGPACK_PCHARTOTCHAR, 0, (LPARAM)asc);
}
void RemoveFolder(const TCHAR *src_folder)
{
TCHAR szFilesPath[MAX_PATH];
mir_sntprintf(szFilesPath, SIZEOF(szFilesPath), _T("%s\\*.*"), src_folder);
TCHAR *p = _tcsrchr(szFilesPath, '\\') + 1;
WIN32_FIND_DATA findData;
HANDLE hFileSearch = FindFirstFile(szFilesPath, &findData);
if (hFileSearch != INVALID_HANDLE_VALUE)
{
do
{
if(findData.cFileName[0] != _T('.'))
{
_tcscpy(p, findData.cFileName);
if(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
// recurse
RemoveFolder(szFilesPath);
else
DeleteFile(szFilesPath);
}
} while(FindNextFile(hFileSearch, &findData));
FindClose(hFileSearch);
}
RemoveDirectory(src_folder);
}
bool FolderIsEmpty(const TCHAR *folder)
{
TCHAR szFilesPath[MAX_PATH];
mir_sntprintf(szFilesPath, SIZEOF(szFilesPath), _T("%s\\*.*"), folder);
WIN32_FIND_DATA findData;
HANDLE hFileSearch = FindFirstFile(szFilesPath, &findData);
if (hFileSearch != INVALID_HANDLE_VALUE)
{
do {
if (_tcscmp(findData.cFileName, _T(".")) && _tcscmp(findData.cFileName, _T("..")))
{
FindClose(hFileSearch);
return false;
}
} while(FindNextFile(hFileSearch, &findData));
FindClose(hFileSearch);
}
return true;
}
bool DeleteNonDlls(const TCHAR *folder)
{
TCHAR szFilesPath[MAX_PATH];
{
TCHAR buff[200];
mir_sntprintf(buff, SIZEOF(buff), _T("Deleting non-dlls in %s"), folder);
NLog(buff);
}
mir_sntprintf(szFilesPath, SIZEOF(szFilesPath), _T("%s\\*.*"), folder);
TCHAR *p = _tcsrchr(szFilesPath, '\\') + 1;
WIN32_FIND_DATA findData;
HANDLE hFileSearch = FindFirstFile(szFilesPath, &findData);
if (hFileSearch != INVALID_HANDLE_VALUE) {
do {
if (_tcscmp(findData.cFileName, _T(".")) && _tcscmp(findData.cFileName, _T("..")))
{
_tcscpy(p, findData.cFileName);
if(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
DeleteNonDlls(szFilesPath);
} else {
if (_tcsstr(findData.cFileName, _T(".dll")) == 0)
{
{
TCHAR buff[200];
mir_sntprintf(buff, SIZEOF(buff), _T("Deleting %s"), folder);
NLog(buff);
}
DeleteFile(szFilesPath);
}
}
}
} while(FindNextFile(hFileSearch, &findData));
FindClose(hFileSearch);
}
return true;
}
void NLog(char *msg)
{
CallService(MS_NETLIB_LOG, (WPARAM)hNetlibUser, (LPARAM)msg);
}
#ifdef _UNICODE
void NLog(wchar_t *msg)
{
char* a = mir_u2a(msg);
CallService(MS_NETLIB_LOG, (WPARAM)hNetlibUser, (LPARAM)a);
mir_free(a);
}
#endif
|