From c12debcb441a2078c30372ba77cfcf6bdb219bfd Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@4f64403b-2f21-0410-a795-97e2b3489a10> Date: Wed, 21 Apr 2010 13:01:53 +0000 Subject: Added beta indication when update More performance improvements git-svn-id: https://server.scottellis.com.au/svn/mim_plugs@509 4f64403b-2f21-0410-a795-97e2b3489a10 --- updater/common.h | 3 + updater/conf_dialog.cpp | 64 +++++--- updater/popups.cpp | 1 + updater/services.cpp | 2 +- updater/socket.cpp | 317 +++++++++++++++++---------------------- updater/unzipfile.cpp | 14 +- updater/updater.dsp | 13 +- updater/updater.rc | 14 +- updater/updater_9.vcproj | 6 +- updater/utils.cpp | 29 ++++ updater/version.h | 2 +- updater/xmldata.cpp | 1 - updater/zbin/minizip/ioapi.h | 2 +- updater/zbin/minizip/ioapi_mem.c | 219 +++++++++++++++++++++++++++ 14 files changed, 446 insertions(+), 241 deletions(-) create mode 100644 updater/zbin/minizip/ioapi_mem.c diff --git a/updater/common.h b/updater/common.h index 45519a9..2387c94 100644 --- a/updater/common.h +++ b/updater/common.h @@ -108,7 +108,10 @@ extern bool is_idle; extern HANDLE hNetlibUser, hNetlibHttp; +void* memmem (const void *buf1, size_t size1, const void *buf2, size_t size2); + void NLog(char *msg); +void NLogF(const char *fmt, ...); #ifdef _UNICODE void NLog(wchar_t *msg); diff --git a/updater/conf_dialog.cpp b/updater/conf_dialog.cpp index cbd6887..8ccaedf 100644 --- a/updater/conf_dialog.cpp +++ b/updater/conf_dialog.cpp @@ -1,13 +1,15 @@ #include "common.h" #include "conf_dialog.h" -INT_PTR CALLBACK DlgProcConfirm(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { +INT_PTR CALLBACK DlgProcConfirm(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + HWND hwndList = GetDlgItem(hwndDlg, IDC_LIST_UPDATES); switch ( msg ) { case WM_INITDIALOG: TranslateDialogDefault( hwndDlg ); SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0); - SendMessage(GetDlgItem(hwndDlg, IDC_LIST_UPDATES),LVM_SETEXTENDEDLISTVIEWSTYLE, 0,LVS_EX_FULLROWSELECT | LVS_EX_CHECKBOXES); + SendMessage(hwndList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT | LVS_EX_CHECKBOXES); if(options.save_zips && options.no_unzip) { CheckDlgButton(hwndDlg, IDC_CHK_CONFALL, FALSE); @@ -39,23 +41,28 @@ INT_PTR CALLBACK DlgProcConfirm(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP lvc.iSubItem = 0; lvc.pszText = TranslateT("Component Name"); lvc.cx = 145; // width of column in pixels - ListView_InsertColumn(GetDlgItem(hwndDlg, IDC_LIST_UPDATES), 0, &lvc); + ListView_InsertColumn(hwndList, 0, &lvc); lvc.iSubItem = 1; lvc.pszText = TranslateT("New Version"); lvc.cx = 80; // width of column in pixels - ListView_InsertColumn(GetDlgItem(hwndDlg, IDC_LIST_UPDATES), 1, &lvc); + ListView_InsertColumn(hwndList, 1, &lvc); lvc.iSubItem = 2; lvc.pszText = TranslateT("Current Version"); lvc.cx = 90; // width of column in pixels - ListView_InsertColumn(GetDlgItem(hwndDlg, IDC_LIST_UPDATES), 2, &lvc); + ListView_InsertColumn(hwndList, 2, &lvc); + + lvc.iSubItem = 3; + lvc.pszText = TranslateT("Beta"); + lvc.cx = 90; // width of column in pixels + ListView_InsertColumn(hwndList, 3, &lvc); } //enumerate plugins, fill in list { bool one_enabled = false; - ListView_DeleteAllItems(GetDlgItem(hwndDlg, IDC_LIST_UPDATES)); + ListView_DeleteAllItems(hwndList); LVITEM lvI = {0}; TCHAR *temp_str; @@ -66,37 +73,44 @@ INT_PTR CALLBACK DlgProcConfirm(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP lvI.mask = LVIF_TEXT | LVIF_PARAM | LVIF_NORECOMPUTE;// | LVIF_IMAGE; UpdateList &todo = *(UpdateList *)lParam; - for(int i=0; inewVersion; - lvI.pszText = (temp_str = GetTString(((UpdateInternal *)lvI.lParam)->newVersion)); - ListView_SetItem(GetDlgItem(hwndDlg, IDC_LIST_UPDATES), &lvI); + lvI.pszText = (temp_str = mir_a2t(((UpdateInternal *)lvI.lParam)->newVersion)); + ListView_SetItem(hwndList, &lvI); mir_free(temp_str); lvI.iSubItem = 2; //lvI.pszText = LPSTR_TEXTCALLBACK; //i->newVersion; - lvI.pszText = (temp_str = GetTString((char *)((UpdateInternal *)lvI.lParam)->update.pbVersion)); - ListView_SetItem(GetDlgItem(hwndDlg, IDC_LIST_UPDATES), &lvI); + lvI.pszText = (temp_str = mir_a2t((char *)((UpdateInternal *)lvI.lParam)->update.pbVersion)); + ListView_SetItem(hwndList, &lvI); mir_free(temp_str); - //MessageBox(0, i->newVersion, + + lvI.iSubItem = 3; + lvI.pszText = ((UpdateInternal *)lvI.lParam)->update_options.use_beta ? + TranslateT("Yes") : TranslateT("No"); + ListView_SetItem(hwndList, &lvI); + + //MessageBox(0, todo[i].newVersion, //"Version", MB_OK); - //i->update.szComponentName, MB_OK); + //todo[i].update.szComponentName, MB_OK); // remember whether the user has decided not to update this component with this particular new version char stored_setting[256]; mir_snprintf(stored_setting, 256, "DisabledVer%s", todo[i].update.szComponentName); DBVARIANT dbv; bool check = todo[i].update_options.enabled; - if(!DBGetContactSetting(0, "Updater", stored_setting, &dbv)) { + if(!DBGetContactSettingString(0, "Updater", stored_setting, &dbv)) { if(dbv.pszVal && strcmp(dbv.pszVal, ((UpdateInternal *)lvI.lParam)->newVersion) == 0) check = false; else @@ -104,7 +118,7 @@ INT_PTR CALLBACK DlgProcConfirm(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP DBFreeVariant(&dbv); } one_enabled |= check; - ListView_SetCheckState(GetDlgItem(hwndDlg, IDC_LIST_UPDATES), lvI.iItem, check); + ListView_SetCheckState(hwndList, lvI.iItem, check); } HWND hwOk = GetDlgItem(hwndDlg, IDOK); @@ -118,7 +132,7 @@ INT_PTR CALLBACK DlgProcConfirm(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP return TRUE; case WM_NOTIFY: - if(((LPNMHDR) lParam)->hwndFrom == GetDlgItem(hwndDlg, IDC_LIST_UPDATES)) { + if(((LPNMHDR) lParam)->hwndFrom == hwndList) { switch (((LPNMHDR) lParam)->code) { case LVN_ITEMCHANGED: @@ -130,11 +144,11 @@ INT_PTR CALLBACK DlgProcConfirm(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP lvI.iItem = nmlv->iItem; lvI.iSubItem = 0; lvI.mask = LVIF_PARAM; - ListView_GetItem(GetDlgItem(hwndDlg, IDC_LIST_UPDATES), &lvI); + ListView_GetItem(hwndList, &lvI); - //if(IsWindowVisible(GetDlgItem(hwndDlg, IDC_LIST_UPDATES)) && ((nmlv->uNewState ^ nmlv->uOldState) & LVIS_STATEIMAGEMASK)) { + //if(IsWindowVisible(hwndList) && ((nmlv->uNewState ^ nmlv->uOldState) & LVIS_STATEIMAGEMASK)) { if((nmlv->uNewState ^ nmlv->uOldState) & LVIS_STATEIMAGEMASK) { - ((UpdateInternal *)lvI.lParam)->update_options.enabled = ListView_GetCheckState(GetDlgItem(hwndDlg, IDC_LIST_UPDATES), nmlv->iItem) ? true : false; + ((UpdateInternal *)lvI.lParam)->update_options.enabled = ListView_GetCheckState(hwndList, nmlv->iItem) != 0; char stored_setting[256]; mir_snprintf(stored_setting, 256, "DisabledVer%s", ((UpdateInternal *)lvI.lParam)->update.szComponentName); @@ -143,7 +157,7 @@ INT_PTR CALLBACK DlgProcConfirm(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP DBDeleteContactSetting(0, "Updater", stored_setting); // user has re-enabled update to this version - remove setting from db else DBWriteContactSettingString(0, "Updater", stored_setting, ((UpdateInternal *)lvI.lParam)->newVersion); - //ListView_SetItem(GetDlgItem(hwndDlg, IDC_LIST_UPDATES), &lvI); + //ListView_SetItem(hwndList, &lvI); UpdateList &todo = *(UpdateList *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); @@ -175,7 +189,7 @@ INT_PTR CALLBACK DlgProcConfirm(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP lvi.mask = LVIF_PARAM; lvi.iItem = ((NMLVDISPINFO *)lParam)->item.iItem; lvi.iSubItem = 0; - SendMessage(GetDlgItem(hwndDlg, IDC_LIST_UPDATES), LVM_GETITEM, 0, (LPARAM)&lvi); + SendMessage(hwndList, LVM_GETITEM, 0, (LPARAM)&lvi); switch (((NMLVDISPINFO *)lParam)->item.iSubItem) { case 0: MessageBox(0, _T("LVN_GETDISPINFO (0)"), _T("msg"), MB_OK); @@ -199,13 +213,13 @@ INT_PTR CALLBACK DlgProcConfirm(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP case IDC_BTN_CHANGELOG: { char url[256]; - int sel = ListView_GetSelectionMark(GetDlgItem(hwndDlg, IDC_LIST_UPDATES)); + int sel = ListView_GetSelectionMark(hwndList); LVITEM lvI = {0}; lvI.iItem = sel; lvI.iSubItem = 0; lvI.mask = LVIF_PARAM; - ListView_GetItem(GetDlgItem(hwndDlg, IDC_LIST_UPDATES), &lvI); + ListView_GetItem(hwndList, &lvI); if(!((UpdateInternal *)lvI.lParam)->update_options.use_beta && ((UpdateInternal *)lvI.lParam)->file_id != -1) { sprintf(url, MIM_CHANGELOG_URL_PREFIX "%d", ((UpdateInternal *)lvI.lParam)->file_id); diff --git a/updater/popups.cpp b/updater/popups.cpp index 95911f4..c4e2edf 100644 --- a/updater/popups.cpp +++ b/updater/popups.cpp @@ -161,6 +161,7 @@ void ShowWarning(TCHAR *msg) void ShowError(TCHAR *msg) { static const TCHAR title[512] = _T(MODULE) _T(" Error"); + NLog(msg); if(ServiceExists(MS_POPUP_SHOWMESSAGE)) { diff --git a/updater/services.cpp b/updater/services.cpp index 90215b1..62e88b9 100644 --- a/updater/services.cpp +++ b/updater/services.cpp @@ -54,7 +54,7 @@ bool DownloadUpdates(UpdateList &todo, FilenameMap *map, bool dlls_only) { mir_snprintf(stored_setting, SIZEOF(stored_setting), "DisabledVer%s", todo[index].update.szComponentName); DBVARIANT dbv; bool download = todo[index].update_options.enabled; - if(!DBGetContactSetting(0, "Updater", stored_setting, &dbv)) { + if(!DBGetContactSettingString(0, "Updater", stored_setting, &dbv)) { if(dbv.pszVal && strcmp(dbv.pszVal, todo[index].newVersion) == 0) download = false; else diff --git a/updater/socket.cpp b/updater/socket.cpp index 3447efd..3e52914 100644 --- a/updater/socket.cpp +++ b/updater/socket.cpp @@ -1,7 +1,7 @@ #include "common.h" #include "socket.h" -void unzip_file(TCHAR* zipfile, TCHAR* dest); +void unzip_mem(char* buf, int len, TCHAR* dest); bool GetFile(char *url, TCHAR *temp_folder, char *plugin_name, char *version, bool dlls_only, int recurse_count /*=0*/) { if(recurse_count > MAX_REDIRECT_RECURSE) { @@ -16,19 +16,13 @@ bool GetFile(char *url, TCHAR *temp_folder, char *plugin_name, char *version, bo // ensure temp_folder exists if(!CreatePath(options.temp_folder)) { - DWORD err = GetLastError(); - char buff[128]; - mir_snprintf(buff, SIZEOF(buff), "GetFile: error creating temp folder, code %u", err); - NLog(buff); + NLogF("GetFile: error creating temp folder, code %u", GetLastError()); return false; } // ensure zip_folder exists, if necessary if(options.save_zips && !CreatePath(options.zip_folder)) { - DWORD err = GetLastError(); - char buff[128]; - mir_snprintf(buff, SIZEOF(buff), "GetFile: error creating zip folder, code %u", err); - NLog(buff); + NLogF("GetFile: error creating zip folder, code %u", GetLastError()); return false; } @@ -83,129 +77,102 @@ bool GetFile(char *url, TCHAR *temp_folder, char *plugin_name, char *version, bo NETLIBHTTPREQUEST *resp = (NETLIBHTTPREQUEST *)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)hNetlibUser, (LPARAM)&req); - if(resp) { + if (resp) + { hNetlibHttp = resp->nlc; - if(resp->resultCode == 200) { - HANDLE hSaveFile = CreateFile(save_file, GENERIC_WRITE, FILE_SHARE_WRITE, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); - if(hSaveFile != INVALID_HANDLE_VALUE) { - unsigned long bytes_written = 0; - if(WriteFile(hSaveFile, resp->pData, resp->dataLength, &bytes_written, NULL) == TRUE) { - CloseHandle(hSaveFile); - CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)resp); - resp = 0; - - if(ext && *ext && strcmp(ext, ".zip") == 0) + if (resp->resultCode == 200) + { + if (ext && *ext && _stricmp(ext, ".zip") == 0) + { + if (!options.no_unzip) + unzip_mem(resp->pData, resp->dataLength, temp_folder); + + if (options.save_zips) + { + TCHAR save_archive[MAX_PATH]; + mir_sntprintf(save_archive, SIZEOF(save_archive), _T("%s%s"), options.zip_folder, _tcsrchr(save_file, '\\')); + + HANDLE hSaveFile = CreateFile(save_archive, GENERIC_WRITE, FILE_SHARE_WRITE, 0, + CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); + if (hSaveFile != INVALID_HANDLE_VALUE) { - if(!options.no_unzip) - unzip_file(save_file, temp_folder); - - if(options.save_zips) - { - TCHAR save_archive[MAX_PATH]; - mir_sntprintf(save_archive, SIZEOF(save_archive), _T("%s%s"), options.zip_folder, _tcsrchr(save_file, '\\')); - - DeleteFile(save_archive); - if (!MoveFile(save_file, save_archive)) - { - char buff[128]; - mir_snprintf(buff, SIZEOF(buff), "GetFile: could not move file, code: %u", GetLastError()); - NLog(buff); - if(!DeleteFile(save_file)) { - char buff[128]; - mir_snprintf(buff, SIZEOF(buff), "GetFile: error deleting file, code: %u", GetLastError()); - NLog(buff); - } - } - - } else { - if(!DeleteFile(save_file)) { - char buff[128]; - mir_snprintf(buff, SIZEOF(buff), "GetFile: error deleting file, code: %u", GetLastError()); - NLog(buff); - } - } - - if(dlls_only) { - NLog("Deleting non-dlls"); - DeleteNonDlls(temp_folder); - } - + unsigned long bytes_written; + WriteFile(hSaveFile, resp->pData, resp->dataLength, &bytes_written, NULL); + CloseHandle(hSaveFile); } - return true; + else + NLogF("GetFile: error creating file, code %u", GetLastError()); + } + + if(dlls_only) + { + NLog("Deleting non-dlls"); + DeleteNonDlls(temp_folder); + } - } else { - char buff[128]; - mir_snprintf(buff, SIZEOF(buff), "GetFile: error writing file, code %u", GetLastError()); - NLog(buff); + } + else + { + HANDLE hSaveFile = CreateFile(save_file, GENERIC_WRITE, FILE_SHARE_WRITE, 0, + CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); + if (hSaveFile != INVALID_HANDLE_VALUE) + { + unsigned long bytes_written; + WriteFile(hSaveFile, resp->pData, resp->dataLength, &bytes_written, NULL); + CloseHandle(hSaveFile); } - CloseHandle(hSaveFile); - } else { - char buff[128]; - mir_snprintf(buff, SIZEOF(buff), "GetFile: error creating file, code %u", GetLastError()); - NLog(buff); + else + NLogF("GetFile: error creating file, code %u", GetLastError()); } - } else if(resp->resultCode >= 300 && resp->resultCode < 400) { + + CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)resp); + return true; + } + else if (resp->resultCode >= 300 && resp->resultCode < 400) + { // get new location bool ret = false; - for(int i = 0; i < resp->headersCount; i++) { - //MessageBox(0, resp->headers[i].szValue, resp->headers[i].szName, MB_OK); - if(strcmp(resp->headers[i].szName, "Location") == 0) { + for (int i = 0; i < resp->headersCount; i++) + { + if (_stricmp(resp->headers[i].szName, "Location") == 0) + { ret = GetFile(resp->headers[i].szValue, temp_folder, plugin_name, version, dlls_only, recurse_count + 1); break; } } CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)resp); - resp = 0; return ret; - } else { + } + else + { TCHAR buff[1024]; mir_sntprintf(buff, SIZEOF(buff), TranslateT("Failed to download \"%s\" - Invalid response, code %d"), plugin_name, resp->resultCode); - ShowError(buff); - NLog(buff); - } CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)resp); - resp = 0; - } else { + } + else + { hNetlibHttp = NULL; int err = GetLastError(); - if(err) { + if(err) + { TCHAR buff[1024]; int len = mir_sntprintf(buff, SIZEOF(buff), TranslateT("Failed to download \"%s\": "), plugin_name); FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, err, 0, buff + len, 512 - len, 0); - ShowError(buff); - NLog(buff); } } return false; } -char *CheckVersionURL(char *url, BYTE *pbPrefixBytes, int cpbPrefixBytes, BYTE *pbVersionBytes, int cpbVersionBytes) { - - /* - bool check = false; - - if(strncmp((char *)pbPrefixBytes, "My Details ", cpbPrefixBytes) == 0) { - //MessageBox(0, "Checking version URL", "Updater -> My Details", MB_OK); - check = true; - } - */ - - if(url == 0 || pbPrefixBytes == 0 || cpbPrefixBytes == 0 || pbVersionBytes == 0 || cpbVersionBytes == 0) +char *CheckVersionURL(char *url, BYTE *pbPrefixBytes, int cpbPrefixBytes, BYTE *pbVersionBytes, int cpbVersionBytes) +{ + if (url == 0 || pbPrefixBytes == 0 || cpbPrefixBytes == 0 || pbVersionBytes == 0 || cpbVersionBytes == 0) return 0; - /* - if(check) { - MessageBox(0, "Real URL check", "CheckVersionURL", MB_OK); - MessageBox(0, url, "URL", MB_OK); - MessageBox(0, (char *)pbPrefixBytes, "Prefix", MB_OK); - MessageBox(0, (char *)pbVersionBytes, "Version", MB_OK); - } - */ - + char *ret = NULL; NETLIBHTTPREQUEST req = {0}; req.cbSize = sizeof(req); @@ -214,106 +181,92 @@ char *CheckVersionURL(char *url, BYTE *pbPrefixBytes, int cpbPrefixBytes, BYTE * req.flags = NLHRF_DUMPASTEXT | NLHRF_HTTP11 | NLHRF_PERSISTENT | NLHRF_REDIRECT; req.nlc = hNetlibHttp; - NETLIBHTTPREQUEST *resp = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)hNetlibUser, (LPARAM)&req); + NETLIBHTTPREQUEST *resp = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, + (WPARAM)hNetlibUser, (LPARAM)&req); - if(resp) { + if (resp) + { hNetlibHttp = resp->nlc; - if(resp->resultCode == 200) { + if (resp->resultCode == 200) + { // find the location of the prefix - int index, index2; - for(int i = 0; i < resp->dataLength; i++) { - index = 0; - while(index < cpbPrefixBytes && i + index < resp->dataLength && (BYTE)resp->pData[i + index] == pbPrefixBytes[index]) index++; - if(index == cpbPrefixBytes) { - // we found the prefix - now compare the following bytes - // i + index the first byte after the prefix - index2 = 0; - while(index2 + i + index < resp->dataLength && index2 < cpbVersionBytes && resp->pData[i + index + index2] == pbVersionBytes[index2]) index2++; - if(index2 == cpbVersionBytes) { - // same version as current - //if(check) - //MessageBox(0, "same version", "check url", MB_OK); - CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)resp); - resp = 0; - return 0; - } else { - DWORD ver_current, ver_potential; - char *buff = (char *)malloc(cpbVersionBytes + 1); - strncpy(buff, (char *)pbVersionBytes, cpbVersionBytes); - buff[cpbVersionBytes] = 0; - - // this is safe because pData finishes with a zero always (according to m_netlib.h docs) - if(VersionFromString(buff, &ver_current) && VersionFromString(&resp->pData[i + index], &ver_potential)) + char* ver = (char*)memmem(resp->pData, resp->dataLength, pbPrefixBytes, cpbPrefixBytes); + if (ver) + { + int len = resp->dataLength - ((ver += cpbPrefixBytes) - resp->pData); + if (cpbVersionBytes <= len && memcmp(ver, pbVersionBytes, cpbVersionBytes) == 0) + { + // same version as current + CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)resp); + return 0; + } + else + { + DWORD ver_current, ver_potential; + char *buff = (char *)alloca(cpbVersionBytes + 1); + memcpy(buff, (char *)pbVersionBytes, cpbVersionBytes); + buff[cpbVersionBytes] = 0; + + // this is safe because pData finishes with a zero always (according to m_netlib.h docs) + if (VersionFromString(buff, &ver_current) && VersionFromString(ver, &ver_potential)) + { + switch(options.ver_req) { - switch(options.ver_req) { - case VR_MAJOR: - ver_current &= 0xFF000000; - ver_potential &= 0xFF000000; - break; - case VR_MINOR: - ver_current &= 0xFFFF0000; - ver_potential &= 0xFFFF0000; - break; - case VR_RELEASE: - ver_current &= 0xFFFFFF00; - ver_potential &= 0xFFFFFF00; - break; - case VR_BUILD: - break; - } - //if(check) MessageBox(0, (char *)resp->pData[i + index], buff, MB_OK); - free(buff); - CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)resp); - resp = 0; - // we can covert the versions to DWORDS, so compare... - if(ver_current < ver_potential) { - char buff2[16]; - CreateVersionString(ver_potential, buff2); - return _strdup(buff2); - } else - return 0; - } else { // invalid version(s), but different from current - assume it's an update - free(buff); - CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)resp); - resp = 0; - return _strdup(Translate("Yes")); + case VR_MAJOR: + ver_current &= 0xFF000000; + ver_potential &= 0xFF000000; + break; + case VR_MINOR: + ver_current &= 0xFFFF0000; + ver_potential &= 0xFFFF0000; + break; + case VR_RELEASE: + ver_current &= 0xFFFFFF00; + ver_potential &= 0xFFFFFF00; + break; + case VR_BUILD: + break; } - } + + // we can covert the versions to DWORDS, so compare... + if (ver_current < ver_potential) + { + char buff2[16]; + CreateVersionString(ver_potential, buff2); + ret = _strdup(buff2); + } + } + else // invalid version(s), but different from current - assume it's an update + ret = _strdup(Translate("Yes")); } } - } else if(resp->resultCode == 302) { // redirect - char *ret = 0; + } + else if (resp->resultCode == 302) // redirect + { // get new location - for(int i = 0; i < resp->headersCount; i++) { - //MessageBox(0, resp->headers[i].szValue, resp->headers[i].szName, MB_OK); - if(strcmp(resp->headers[i].szName, "Location") == 0) { + for (int i = 0; i < resp->headersCount; i++) + { + if(_stricmp(resp->headers[i].szName, "Location") == 0) + { ret = CheckVersionURL(resp->headers[i].szValue, pbPrefixBytes, cpbPrefixBytes, pbVersionBytes, cpbVersionBytes); break; } } - CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)resp); - resp = 0; + } + else + NLogF("CheckVersionURL: error, http result code %d", resp->resultCode); - return ret; - } else { - char buff[128]; - sprintf(buff, "CheckVersionURL: error, http result code %d", resp->resultCode); - NLog(buff); - } CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)resp); - resp = 0; - } else { + } + else + { hNetlibHttp = NULL; int err = GetLastError(); - if(err) { - char buff[128]; - sprintf(buff, "CheckVersionURL: error code %d", err); - NLog(buff); - return 0; - } + if (err) + NLogF("CheckVersionURL: error code %d", err); } - return 0; + return ret; } char *UpdateRequired(UpdateInternal &update_internal, bool *beta) { @@ -364,8 +317,6 @@ char *UpdateRequired(UpdateInternal &update_internal, bool *beta) { } else if(ret && ret_beta) { // find highest version of ret and ret_beta - //MessageBox(0, ret, ret_beta, MB_OK); - DWORD vRet, vRetBeta; VersionFromString(ret, &vRet); VersionFromString(ret_beta, &vRetBeta); diff --git a/updater/unzipfile.cpp b/updater/unzipfile.cpp index a449ceb..b14bf97 100644 --- a/updater/unzipfile.cpp +++ b/updater/unzipfile.cpp @@ -2,7 +2,8 @@ #include "utils.h" #include -#include + +extern "C" void fill_memory_filefunc (zlib_filefunc_def* pzlib_filefunc_def); bool extractCurrentFile(unzFile uf, TCHAR *path) { @@ -87,12 +88,15 @@ bool extractCurrentFile(unzFile uf, TCHAR *path) return true; } -void unzip_file(TCHAR* zipfile, TCHAR* dest) +void unzip_mem(char* buf, int len, TCHAR* dest) { - zlib_filefunc64_def ffunc; - fill_win32_filefunc64(&ffunc); + zlib_filefunc_def ffunc; + fill_memory_filefunc(&ffunc); + + char zipfile[128]; + mir_snprintf(zipfile, sizeof(zipfile), "%p+%x", buf, len); - unzFile uf = unzOpen2_64(zipfile, &ffunc); + unzFile uf = unzOpen2(zipfile, &ffunc); if (uf) { do { diff --git a/updater/updater.dsp b/updater/updater.dsp index 8e855b4..40bac6b 100644 --- a/updater/updater.dsp +++ b/updater/updater.dsp @@ -162,17 +162,6 @@ SOURCE=.\conf_comp_dialog.cpp # Begin Source File SOURCE=.\conf_dialog.cpp - -!IF "$(CFG)" == "updater - Win32 Release" - -!ELSEIF "$(CFG)" == "updater - Win32 Debug" - -!ELSEIF "$(CFG)" == "updater - Win32 Release Unicode" - -!ELSEIF "$(CFG)" == "updater - Win32 Debug Unicode" - -!ENDIF - # End Source File # Begin Source File @@ -398,7 +387,7 @@ SOURCE=.\zbin\minizip\ioapi.c # End Source File # Begin Source File -SOURCE=.\zbin\minizip\iowin32.c +SOURCE=.\zbin\minizip\ioapi_mem.c # End Source File # Begin Source File diff --git a/updater/updater.rc b/updater/updater.rc index c00769f..63ceb26 100644 --- a/updater/updater.rc +++ b/updater/updater.rc @@ -107,20 +107,20 @@ BEGIN CONTROL "Don't unzip",IDC_CHK_NOUNZIP,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,158,161,127,10 END -IDD_CONFIRMUPDATES DIALOGEX 0, 0, 241, 209 +IDD_CONFIRMUPDATES DIALOGEX 0, 0, 266, 209 STYLE DS_SETFONT | DS_MODALFRAME | DS_SETFOREGROUND | DS_FIXEDSYS | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "Updates Found" FONT 8, "MS Shell Dlg", 0, 0, 0x0 BEGIN - DEFPUSHBUTTON "Update",IDOK,70,188,50,14 - PUSHBUTTON "Cancel",IDCANCEL,128,188,50,14 + DEFPUSHBUTTON "Update",IDOK,67,188,50,14 + PUSHBUTTON "Cancel",IDCANCEL,143,188,50,14 CTEXT "Updater has detected updated versions\nof the following Miranda components:",IDC_STATIC,9,9,222,22 - CONTROL "List1",IDC_LIST_UPDATES,"SysListView32",LVS_REPORT | LVS_SINGLESEL | LVS_SORTASCENDING | WS_BORDER | WS_TABSTOP,13,37,213,105 - GROUPBOX "",IDC_STATIC,13,144,214,39 + CONTROL "List1",IDC_LIST_UPDATES,"SysListView32",LVS_REPORT | LVS_SINGLESEL | LVS_SORTASCENDING | WS_BORDER | WS_TABSTOP,13,37,238,105 + GROUPBOX "",IDC_STATIC,13,144,239,39 CONTROL "Confirm install for individual files",IDC_CHK_CONFALL, "Button",BS_AUTOCHECKBOX | WS_TABSTOP,21,153,143,10 CONTROL "Download but do not install",IDC_CHK_NOINSTALL,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,21,166,143,10 - DEFPUSHBUTTON "Changelog",IDC_BTN_CHANGELOG,169,159,53,14,WS_DISABLED | NOT WS_TABSTOP + DEFPUSHBUTTON "Changelog",IDC_BTN_CHANGELOG,192,158,53,14,WS_DISABLED | NOT WS_TABSTOP END IDD_PROGRESS DIALOGEX 0, 0, 187, 41 @@ -160,7 +160,7 @@ BEGIN IDD_CONFIRMUPDATES, DIALOG BEGIN LEFTMARGIN, 7 - RIGHTMARGIN, 234 + RIGHTMARGIN, 259 TOPMARGIN, 7 BOTTOMMARGIN, 202 END diff --git a/updater/updater_9.vcproj b/updater/updater_9.vcproj index f4c05c9..7eea5c0 100644 --- a/updater/updater_9.vcproj +++ b/updater/updater_9.vcproj @@ -1202,11 +1202,7 @@ > - - +#include +#include + +#include "zlib.h" +#include "ioapi.h" + + + +voidpf ZCALLBACK fopen_mem_func OF(( + voidpf opaque, + const char* filename, + int mode)); + +uLong ZCALLBACK fread_mem_func OF(( + voidpf opaque, + voidpf stream, + void* buf, + uLong size)); + +uLong ZCALLBACK fwrite_mem_func OF(( + voidpf opaque, + voidpf stream, + const void* buf, + uLong size)); + +long ZCALLBACK ftell_mem_func OF(( + voidpf opaque, + voidpf stream)); + +long ZCALLBACK fseek_mem_func OF(( + voidpf opaque, + voidpf stream, + uLong offset, + int origin)); + +int ZCALLBACK fclose_mem_func OF(( + voidpf opaque, + voidpf stream)); + +int ZCALLBACK ferror_mem_func OF(( + voidpf opaque, + voidpf stream)); + + +typedef struct ourmemory_s { + char *base; /* Base of the region of memory we're using */ + uLong size; /* Size of the region of memory we're using */ + uLong limit; /* Furthest we've written */ + uLong cur_offset; /* Current offset in the area */ +} ourmemory_t; + +voidpf ZCALLBACK fopen_mem_func (opaque, filename, mode) + voidpf opaque; + const char* filename; + int mode; +{ + ourmemory_t *mem = malloc(sizeof(*mem)); + if (mem==NULL) + return NULL; /* Can't allocate space, so failed */ + + /* Filenames are specified in the form : + * + + * This may not work where memory addresses are longer than the + * size of an int and therefore may need addressing for 64bit + * architectures + */ + if (sscanf(filename,"%p+%x",&mem->base,&mem->size)!=2) + return NULL; + + if (mode & ZLIB_FILEFUNC_MODE_CREATE) + mem->limit=0; /* When writing we start with 0 bytes written */ + else + mem->limit=mem->size; + + mem->cur_offset = 0; + + return mem; +} + + +uLong ZCALLBACK fread_mem_func (opaque, stream, buf, size) + voidpf opaque; + voidpf stream; + void* buf; + uLong size; +{ + ourmemory_t *mem = (ourmemory_t *)stream; + + if (size > mem->size - mem->cur_offset) + size = mem->size - mem->cur_offset; + + memcpy(buf, mem->base + mem->cur_offset, size); + mem->cur_offset+=size; + + return size; +} + + +uLong ZCALLBACK fwrite_mem_func (opaque, stream, buf, size) + voidpf opaque; + voidpf stream; + const void* buf; + uLong size; +{ + ourmemory_t *mem = (ourmemory_t *)stream; + + if (size > mem->size - mem->cur_offset) + size = mem->size - mem->cur_offset; + + memcpy(mem->base + mem->cur_offset, buf, size); + mem->cur_offset+=size; + if (mem->cur_offset > mem->limit) + mem->limit = mem->cur_offset; + + return size; +} + +long ZCALLBACK ftell_mem_func (opaque, stream) + voidpf opaque; + voidpf stream; +{ + ourmemory_t *mem = (ourmemory_t *)stream; + + return mem->cur_offset; +} + +long ZCALLBACK fseek_mem_func (opaque, stream, offset, origin) + voidpf opaque; + voidpf stream; + uLong offset; + int origin; +{ + ourmemory_t *mem = (ourmemory_t *)stream; + uLong new_pos; + switch (origin) + { + case ZLIB_FILEFUNC_SEEK_CUR : + new_pos = mem->cur_offset + offset; + break; + case ZLIB_FILEFUNC_SEEK_END : + new_pos = mem->limit + offset; + break; + case ZLIB_FILEFUNC_SEEK_SET : + new_pos = offset; + break; + default: return -1; + } + + if (new_pos > mem->size) + return 1; /* Failed to seek that far */ + + if (new_pos > mem->limit) + memset(mem->base + mem->limit, 0, new_pos - mem->limit); + + mem->cur_offset = new_pos; + return 0; +} + +int ZCALLBACK fclose_mem_func (opaque, stream) + voidpf opaque; + voidpf stream; +{ + ourmemory_t *mem = (ourmemory_t *)stream; + + /* Note that once we've written to the buffer we don't tell anyone + about it here. Probably the opaque handle could be used to inform + some other component of how much data was written. + + This, and other aspects of writing through this interface, has + not been tested. + */ + + free (mem); + return 0; +} + +int ZCALLBACK ferror_mem_func (opaque, stream) + voidpf opaque; + voidpf stream; +{ + ourmemory_t *mem = (ourmemory_t *)stream; + /* We never return errors */ + return 0; +} + +void fill_memory_filefunc (pzlib_filefunc_def) + zlib_filefunc_def* pzlib_filefunc_def; +{ + pzlib_filefunc_def->zopen_file = fopen_mem_func; + pzlib_filefunc_def->zread_file = fread_mem_func; + pzlib_filefunc_def->zwrite_file = fwrite_mem_func; + pzlib_filefunc_def->ztell_file = ftell_mem_func; + pzlib_filefunc_def->zseek_file = fseek_mem_func; + pzlib_filefunc_def->zclose_file = fclose_mem_func; + pzlib_filefunc_def->zerror_file = ferror_mem_func; + pzlib_filefunc_def->opaque = NULL; +} -- cgit v1.2.3