diff options
author | George Hazan <george.hazan@gmail.com> | 2012-08-08 15:32:54 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2012-08-08 15:32:54 +0000 |
commit | 3f3b29cdf466a9865d9e831ce7a2d0fe00995364 (patch) | |
tree | aa1fecd509c816857bc917884e1e5553e76e31e0 /plugins/PluginUpdater/src | |
parent | b073e215612eda97d9182bc951bf01058585b910 (diff) |
- icons are being downloaded ok now
- STL removed
git-svn-id: http://svn.miranda-ng.org/main/trunk@1404 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/PluginUpdater/src')
-rw-r--r-- | plugins/PluginUpdater/src/Common.h | 7 | ||||
-rw-r--r-- | plugins/PluginUpdater/src/Notifications.cpp | 22 | ||||
-rw-r--r-- | plugins/PluginUpdater/src/Scanner.cpp | 75 |
3 files changed, 62 insertions, 42 deletions
diff --git a/plugins/PluginUpdater/src/Common.h b/plugins/PluginUpdater/src/Common.h index a3a88da424..d61a75ac2c 100644 --- a/plugins/PluginUpdater/src/Common.h +++ b/plugins/PluginUpdater/src/Common.h @@ -24,11 +24,10 @@ Boston, MA 02111-1307, USA. // Windows Header Files:
#include <time.h>
#include <stdio.h>
+#include <malloc.h>
+#include <stddef.h>
#include <windows.h>
#include <Windowsx.h>
-#include <vector> // stl vector header
-#include <map>
-#include <string>
#include <Shlobj.h>
// Miranda header files
@@ -78,6 +77,8 @@ struct FILEINFO BYTE Force;
};
+typedef OBJLIST<FILEINFO> FILELIST;
+
struct PopupDataText
{
TCHAR* Title;
diff --git a/plugins/PluginUpdater/src/Notifications.cpp b/plugins/PluginUpdater/src/Notifications.cpp index 63d95d7892..04b24b56e2 100644 --- a/plugins/PluginUpdater/src/Notifications.cpp +++ b/plugins/PluginUpdater/src/Notifications.cpp @@ -208,10 +208,10 @@ void DlgDownloadProc(FILEURL *pFileUrl, PopupDataText temp) void SelectAll(HWND hDlg, bool bEnable)
{
- vector<FILEINFO> &todo = *(vector<FILEINFO> *)GetWindowLongPtr(hDlg, GWLP_USERDATA);
+ OBJLIST<FILEINFO> &todo = *(OBJLIST<FILEINFO> *)GetWindowLongPtr(hDlg, GWLP_USERDATA);
HWND hwndList = GetDlgItem(hDlg, IDC_LIST_UPDATES);
- for (size_t i=0; i < todo.size(); i++) {
+ for (int i=0; i < todo.getCount(); i++) {
ListView_SetCheckState(hwndList, i, bEnable);
todo[i].enabled = bEnable;
}
@@ -226,7 +226,7 @@ static void ApplyUpdates(void* param) {
HWND hDlg = (HWND)param;
HWND hwndList = GetDlgItem(hDlg, IDC_LIST_UPDATES);
- vector<FILEINFO> &todo = *(vector<FILEINFO> *)GetWindowLongPtr(hDlg, GWLP_USERDATA);
+ OBJLIST<FILEINFO> &todo = *(OBJLIST<FILEINFO> *)GetWindowLongPtr(hDlg, GWLP_USERDATA);
TCHAR tszBuff[2048], tszFileTemp[MAX_PATH], tszFileBack[MAX_PATH];
mir_sntprintf(tszFileBack, SIZEOF(tszFileBack), _T("%s\\Backups"), tszRoot);
@@ -235,7 +235,7 @@ static void ApplyUpdates(void* param) mir_sntprintf(tszFileTemp, SIZEOF(tszFileTemp), _T("%s\\Temp"), tszRoot);
CreateDirectory(tszFileTemp, NULL);
- for (size_t i=0; i < todo.size(); ++i) {
+ for (int i=0; i < todo.getCount(); ++i) {
ListView_EnsureVisible(hwndList, i, FALSE);
if ( !todo[i].enabled) {
SetStringText(hwndList, i, TranslateT("Skipped"));
@@ -252,7 +252,7 @@ static void ApplyUpdates(void* param) SetStringText(hwndList, i, TranslateT("Succeeded."));
}
- if (todo.size() == 0) {
+ if (todo.getCount() == 0) {
DestroyWindow(hDlg);
return;
}
@@ -275,7 +275,7 @@ static void ApplyUpdates(void* param) TCHAR* tszMirandaPath = Utils_ReplaceVarsT(_T("%miranda_path%"));
- for (size_t i = 0; i < todo.size(); i++) {
+ for (int i = 0; i < todo.getCount(); i++) {
if ( !todo[i].enabled)
continue;
@@ -329,8 +329,8 @@ INT_PTR CALLBACK DlgUpdate(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam LVITEM lvI = {0};
lvI.mask = LVIF_TEXT | LVIF_PARAM | LVIF_NORECOMPUTE;// | LVIF_IMAGE;
- vector<FILEINFO> &todo = *(vector<FILEINFO> *)lParam;
- for (int i = 0; i < (int)todo.size(); ++i) {
+ OBJLIST<FILEINFO> &todo = *(OBJLIST<FILEINFO> *)lParam;
+ for (int i = 0; i < todo.getCount(); ++i) {
lvI.mask = LVIF_TEXT | LVIF_PARAM;// | LVIF_IMAGE;
lvI.iSubItem = 0;
lvI.lParam = (LPARAM)&todo[i];
@@ -363,12 +363,12 @@ INT_PTR CALLBACK DlgUpdate(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam lvI.mask = LVIF_PARAM;
ListView_GetItem(hwndList, &lvI);
- vector<FILEINFO> &todo = *(vector<FILEINFO> *)GetWindowLongPtr(hDlg, GWLP_USERDATA);
+ OBJLIST<FILEINFO> &todo = *(OBJLIST<FILEINFO> *)GetWindowLongPtr(hDlg, GWLP_USERDATA);
if ((nmlv->uNewState ^ nmlv->uOldState) & LVIS_STATEIMAGEMASK) {
todo[lvI.iItem].enabled = ListView_GetCheckState(hwndList, nmlv->iItem);
bool enableOk = false;
- for(int i=0; i<(int)todo.size(); ++i) {
+ for(int i=0; i < todo.getCount(); ++i) {
if(todo[i].enabled) {
enableOk = true;
break;
@@ -409,7 +409,7 @@ INT_PTR CALLBACK DlgUpdate(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam case WM_DESTROY:
Utils_SaveWindowPosition(hDlg, NULL, MODNAME, "ConfirmWindow");
hwndDialog = NULL;
- delete (vector<FILEINFO> *)GetWindowLongPtr(hDlg, GWLP_USERDATA);
+ delete (OBJLIST<FILEINFO> *)GetWindowLongPtr(hDlg, GWLP_USERDATA);
SetWindowLongPtr(hDlg, GWLP_USERDATA, 0);
break;
}
diff --git a/plugins/PluginUpdater/src/Scanner.cpp b/plugins/PluginUpdater/src/Scanner.cpp index 391c1ff7fc..5787cd16b1 100644 --- a/plugins/PluginUpdater/src/Scanner.cpp +++ b/plugins/PluginUpdater/src/Scanner.cpp @@ -33,10 +33,24 @@ static bool Exists(LPCTSTR strName) /////////////////////////////////////////////////////////////////////////////////////////
-typedef map<string, string> hashMap;
-typedef pair<string, string> hashItem;
+struct ServListEntry
+{
+ ~ServListEntry()
+ { mir_free(m_name);
+ }
+
+ char *m_name, *m_searchName;
+ char m_szHash[32+1];
+};
-static void ScanFolder(const TCHAR* tszFolder, const TCHAR* tszBaseUrl, hashMap& hashes, vector<FILEINFO>* UpdateFiles)
+static int CompareHashes(const ServListEntry* p1, const ServListEntry* p2)
+{
+ return strcmp(p1->m_searchName, p2->m_searchName);
+}
+
+typedef OBJLIST<ServListEntry> SERVLIST;
+
+static void ScanFolder(const TCHAR* tszFolder, const TCHAR* tszBaseUrl, SERVLIST& hashes, OBJLIST<FILEINFO>* UpdateFiles)
{
TCHAR tszMask[MAX_PATH], tszFileTemp[MAX_PATH];
mir_sntprintf(tszMask, SIZEOF(tszMask), _T("%s\\*"), tszFolder);
@@ -71,29 +85,30 @@ static void ScanFolder(const TCHAR* tszFolder, const TCHAR* tszBaseUrl, hashMap& continue;
// Read version info
- hashMap::iterator boo = hashes.find(szFileName);
- if (boo == hashes.end())
+ ServListEntry tmp = { NULL, szFileName };
+ int idx = hashes.getIndex( &tmp );
+ if (idx == -1)
continue;
- TCHAR *plugname = ffd.cFileName;
- FILEINFO FileInfo = { 0 };
-
+ char szMyHash[33];
mir_sntprintf(tszMask, SIZEOF(tszMask), _T("%s\\%s"), tszFolder, ffd.cFileName);
- CalculateModuleHash(tszMask, FileInfo.curhash);
-
- strncpy(FileInfo.newhash, boo->second.c_str(), SIZEOF(FileInfo.newhash));
+ CalculateModuleHash(tszMask, szMyHash);
// Compare versions
- if ( strcmp(FileInfo.curhash, FileInfo.newhash)) { // Yeah, we've got new version.
- _tcscpy(FileInfo.tszDescr, ffd.cFileName);
+ if ( strcmp(szMyHash, hashes[idx].m_szHash)) { // Yeah, we've got new version.
+ FILEINFO* FileInfo = new FILEINFO;
+ strncpy(FileInfo->newhash, hashes[idx].m_szHash, SIZEOF(FileInfo->newhash));
+ strncpy(FileInfo->curhash, szMyHash, SIZEOF(FileInfo->newhash));
+ _tcscpy(FileInfo->tszDescr, ffd.cFileName);
*p = 0;
- mir_sntprintf(FileInfo.File.tszDownloadURL, SIZEOF(FileInfo.File.tszDownloadURL), _T("%s/%s.zip"), tszBaseUrl, ffd.cFileName);
- _tcslwr(FileInfo.File.tszDownloadURL);
+ mir_sntprintf(FileInfo->File.tszDiskPath, SIZEOF(FileInfo->File.tszDiskPath), _T("%s\\%s.zip"), tszFileTemp, ffd.cFileName);
- mir_sntprintf(FileInfo.File.tszDiskPath, SIZEOF(FileInfo.File.tszDiskPath), _T("%s\\%s.zip"), tszFileTemp, ffd.cFileName);
+ mir_sntprintf(FileInfo->File.tszDownloadURL, SIZEOF(FileInfo->File.tszDownloadURL), _T("%s/%S"), tszBaseUrl, hashes[idx].m_name);
+ if ((p = _tcsrchr(FileInfo->File.tszDownloadURL, '.')) != NULL)
+ _tcscpy(p, _T(".zip"));
- UpdateFiles->push_back(FileInfo);
+ UpdateFiles->insert(FileInfo);
} // end compare versions
}
while (FindNextFile(hFind, &ffd) != 0);
@@ -143,7 +158,7 @@ static void CheckUpdates(void *) if (!fp)
return;
- hashMap hashes;
+ SERVLIST hashes(50, CompareHashes);
char str[200];
while(fgets(str, SIZEOF(str), fp) != NULL) {
rtrim(str);
@@ -152,29 +167,33 @@ static void CheckUpdates(void *) continue;
*p++ = 0;
- _strlwr(str);
- if ( !opts.bUpdateIcons && !strncmp(str, "icons\\", 6))
+ if ( !opts.bUpdateIcons && !_strnicmp(str, "icons\\", 6))
continue;
- char* szName = strrchr(str, '\\');
- if (szName == NULL)
- szName = str;
- else
- szName++;
+ ServListEntry* newItem = new ServListEntry;
+ newItem->m_name = mir_strdup(str);
_strlwr(p);
- hashes[szName] = p;
+ strncpy(newItem->m_szHash, p, sizeof(newItem->m_szHash));
+
+ for (p = strchr(newItem->m_name, '\\'); p != NULL; p = strchr(p+1, '\\'))
+ *p = '/';
+
+ char* szName = strrchr(newItem->m_name, '/');
+ newItem->m_searchName = (szName == NULL) ? newItem->m_name : szName+1;
+ _strlwr(newItem->m_searchName);
+ hashes.insert(newItem);
}
fclose(fp);
DeleteFile(tszTmpIni);
- vector<FILEINFO>* UpdateFiles = new vector<FILEINFO>;
+ FILELIST *UpdateFiles = new FILELIST(20);
TCHAR *dirname = Utils_ReplaceVarsT(_T("%miranda_path%"));
ScanFolder(dirname, tszBaseUrl, hashes, UpdateFiles);
mir_free(dirname);
// Show dialog
- if (UpdateFiles->size() == 0) {
+ if (UpdateFiles->getCount() == 0) {
if ( !opts.bSilent)
ShowPopup(0, LPGENT("Plugin Updater"), LPGENT("No updates found."), 2, 0);
}
|