From 8c32170e2712fe88671cad08a392a0872684ad6c Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Thu, 13 Aug 2015 20:54:08 +0000 Subject: PluginUpdater: ability to download files via AccosMgr git-svn-id: http://svn.miranda-ng.org/main/trunk@14945 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/PluginUpdater/src/DlgListNew.cpp | 105 ++++++++++++++++++++++++------- plugins/PluginUpdater/src/Events.cpp | 8 +++ plugins/PluginUpdater/src/Services.cpp | 2 +- plugins/PluginUpdater/src/Version.h | 2 +- plugins/PluginUpdater/src/stdafx.h | 3 + 5 files changed, 95 insertions(+), 25 deletions(-) (limited to 'plugins/PluginUpdater') diff --git a/plugins/PluginUpdater/src/DlgListNew.cpp b/plugins/PluginUpdater/src/DlgListNew.cpp index fda1defc54..6dc0558cc8 100644 --- a/plugins/PluginUpdater/src/DlgListNew.cpp +++ b/plugins/PluginUpdater/src/DlgListNew.cpp @@ -337,6 +337,34 @@ static void __stdcall LaunchListDialog(void *param) ///////////////////////////////////////////////////////////////////////////////////////// // building file list in the separate thread +static FILEINFO* ServerEntryToFileInfo(const ServListEntry &hash, const TCHAR* tszBaseUrl, const TCHAR* tszPath) +{ + FILEINFO *FileInfo = new FILEINFO; + FileInfo->bDeleteOnly = FALSE; + // copy the relative old name + _tcsncpy(FileInfo->tszOldName, hash.m_name, _countof(FileInfo->tszOldName)); + _tcsncpy(FileInfo->tszNewName, hash.m_name, _countof(FileInfo->tszNewName)); + + TCHAR tszFileName[MAX_PATH]; + _tcsncpy(tszFileName, _tcsrchr(tszPath, L'\\') + 1, _countof(tszFileName)); + TCHAR *tp = _tcschr(tszFileName, L'.'); *tp = 0; + + TCHAR tszRelFileName[MAX_PATH]; + _tcsncpy(tszRelFileName, hash.m_name, MAX_PATH); + tp = _tcsrchr(tszRelFileName, L'.'); if (tp) *tp = 0; + tp = _tcschr(tszRelFileName, L'\\'); if (tp) tp++; else tp = tszRelFileName; + _tcslwr(tp); + + mir_sntprintf(FileInfo->File.tszDiskPath, _countof(FileInfo->File.tszDiskPath), _T("%s\\Temp\\%s.zip"), tszRoot, tszFileName); + mir_sntprintf(FileInfo->File.tszDownloadURL, _countof(FileInfo->File.tszDownloadURL), _T("%s/%s.zip"), tszBaseUrl, tszRelFileName); + for (tp = _tcschr(FileInfo->File.tszDownloadURL, '\\'); tp != 0; tp = _tcschr(tp, '\\')) + *tp++ = '/'; + FileInfo->File.CRCsum = hash.m_crc; + // Deselect all plugins by default + FileInfo->bEnabled = false; + return FileInfo; +} + static void GetList(void *) { TCHAR tszTempPath[MAX_PATH]; @@ -361,29 +389,7 @@ static void GetList(void *) mir_sntprintf(tszPath, _countof(tszPath), _T("%s\\%s"), dirname, hash.m_name); if (GetFileAttributes(tszPath) == INVALID_FILE_ATTRIBUTES) { - FILEINFO *FileInfo = new FILEINFO; - FileInfo->bDeleteOnly = FALSE; - // copy the relative old name - _tcsncpy(FileInfo->tszOldName, hash.m_name, _countof(FileInfo->tszOldName)); - _tcsncpy(FileInfo->tszNewName, hash.m_name, _countof(FileInfo->tszNewName)); - - TCHAR tszFileName[MAX_PATH]; - _tcsncpy(tszFileName, _tcsrchr(tszPath, L'\\') + 1, _countof(tszFileName)); - TCHAR *tp = _tcschr(tszFileName, L'.'); *tp = 0; - - TCHAR tszRelFileName[MAX_PATH]; - _tcsncpy(tszRelFileName, hash.m_name, MAX_PATH); - tp = _tcsrchr(tszRelFileName, L'.'); if (tp) *tp = 0; - tp = _tcschr(tszRelFileName, L'\\'); if (tp) tp++; else tp = tszRelFileName; - _tcslwr(tp); - - mir_sntprintf(FileInfo->File.tszDiskPath, _countof(FileInfo->File.tszDiskPath), _T("%s\\Temp\\%s.zip"), tszRoot, tszFileName); - mir_sntprintf(FileInfo->File.tszDownloadURL, _countof(FileInfo->File.tszDownloadURL), _T("%s/%s.zip"), baseUrl, tszRelFileName); - for (tp = _tcschr(FileInfo->File.tszDownloadURL, '\\'); tp != 0; tp = _tcschr(tp, '\\')) - *tp++ = '/'; - FileInfo->File.CRCsum = hash.m_crc; - // Deselect all plugins by default - FileInfo->bEnabled = false; + FILEINFO *FileInfo = ServerEntryToFileInfo(hash, baseUrl, tszPath); UpdateFiles->insert(FileInfo); } } @@ -432,4 +438,57 @@ void UnloadListNew() { if (hListThread) hListThread = NULL; +} + +INT_PTR ParseUriService(WPARAM wParam, LPARAM lParam) +{ + TCHAR *arg = (TCHAR *)lParam; + if (arg == NULL) + return 1; + + TCHAR uri[1024]; + _tcsncpy_s(uri, arg, _TRUNCATE); + + TCHAR *p = _tcschr(uri, _T(':')); + if (p == NULL) + return 1; + + TCHAR pluginPath[MAX_PATH]; + mir_tstrcpy(pluginPath, p + 1); + p = _tcschr(pluginPath, _T('/')); + if (p) *p = _T('\\'); + + ptrT updateUrl(GetDefaultUrl()), baseUrl; + SERVLIST hashes(50, CompareHashes); + if (!ParseHashes(updateUrl, baseUrl, hashes)) { + hListThread = NULL; + return 1; + } + + FILELIST *fileList = new FILELIST(1); + + VARST dirName(_T("%miranda_path%")); + for (int i = 0; i < hashes.getCount(); i++) + { + ServListEntry &hash = hashes[i]; + + if (mir_tstrcmpi(hash.m_name, pluginPath) == 0) + { + TCHAR tszPath[MAX_PATH]; + mir_sntprintf(tszPath, _countof(tszPath), _T("%s\\%s"), dirName, hash.m_name); + + FILEINFO *fileInfo = ServerEntryToFileInfo(hash, baseUrl, tszPath); + fileList->insert(fileInfo); + + break; + } + } + + if (fileList->getCount() == 0) { + ShowPopup(TranslateT("Plugin Updater"), TranslateT("List is empty."), POPUP_TYPE_INFO); + delete fileList; + } + else CallFunctionAsync(LaunchListDialog, fileList); + + return 0; } \ No newline at end of file diff --git a/plugins/PluginUpdater/src/Events.cpp b/plugins/PluginUpdater/src/Events.cpp index f97d384bf5..6781bc4a88 100644 --- a/plugins/PluginUpdater/src/Events.cpp +++ b/plugins/PluginUpdater/src/Events.cpp @@ -53,6 +53,14 @@ int ModulesLoaded(WPARAM, LPARAM) else lstrcpyn(tszRoot, VARST( _T("%miranda_path%\\" DEFAULT_UPDATES_FOLDER)), _countof(tszRoot)); +#if MIRANDA_VER >= 0x0A00 + if (ServiceExists(MS_ASSOCMGR_ADDNEWURLTYPE)) + { + CreateServiceFunction(MODNAME "/ParseUri", ParseUriService); + AssocMgr_AddNewUrlTypeT("mirpu:", TranslateT("Plugin updater URI scheme"), hInst, IDI_PLGLIST, MODNAME "/ParseUri", 0); + } +#endif + int iRestartCount = db_get_b(NULL, MODNAME, DB_SETTING_RESTART_COUNT, 2); if (iRestartCount > 0) db_set_b(NULL, MODNAME, DB_SETTING_RESTART_COUNT, iRestartCount - 1); diff --git a/plugins/PluginUpdater/src/Services.cpp b/plugins/PluginUpdater/src/Services.cpp index ef70e7edb8..4111fca483 100644 --- a/plugins/PluginUpdater/src/Services.cpp +++ b/plugins/PluginUpdater/src/Services.cpp @@ -63,4 +63,4 @@ void InitServices() CreateServiceFunction(MS_PU_FREEHASHES, srvFreeHashes); CreateServiceFunction(MS_PU_GETHASHCOUNT, srvGetHashCount); CreateServiceFunction(MS_PU_GETNTHHASH, srvGetNthHash); -} +} \ No newline at end of file diff --git a/plugins/PluginUpdater/src/Version.h b/plugins/PluginUpdater/src/Version.h index 09efeac785..d32a307f54 100644 --- a/plugins/PluginUpdater/src/Version.h +++ b/plugins/PluginUpdater/src/Version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 1 #define __RELEASE_NUM 2 -#define __BUILD_NUM 4 +#define __BUILD_NUM 3 #include diff --git a/plugins/PluginUpdater/src/stdafx.h b/plugins/PluginUpdater/src/stdafx.h index dc903f1033..eda11fe2b8 100644 --- a/plugins/PluginUpdater/src/stdafx.h +++ b/plugins/PluginUpdater/src/stdafx.h @@ -36,6 +36,7 @@ Boston, MA 02111-1307, USA. #include #include #include +#include #include #include @@ -215,6 +216,8 @@ void InitTimer(void *type); bool unzip(const TCHAR *ptszZipFile, TCHAR *ptszDestPath, TCHAR *ptszBackPath,bool ch); void strdel(TCHAR *parBuffer, int len); +INT_PTR ParseUriService(WPARAM wParam, LPARAM lParam); + /////////////////////////////////////////////////////////////////////////////// int CalculateModuleHash(const TCHAR *tszFileName, char *dest); -- cgit v1.2.3