From a7d62ddc856e55582e5cd86070abde7d045455c3 Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@4f64403b-2f21-0410-a795-97e2b3489a10> Date: Mon, 22 Nov 2010 01:51:38 +0000 Subject: Added ability to update in directories protected by UAC git-svn-id: https://server.scottellis.com.au/svn/mim_plugs@577 4f64403b-2f21-0410-a795-97e2b3489a10 --- updater/utils.cpp | 52 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 9 deletions(-) (limited to 'updater/utils.cpp') diff --git a/updater/utils.cpp b/updater/utils.cpp index 8448217..cd77678 100644 --- a/updater/utils.cpp +++ b/updater/utils.cpp @@ -1,21 +1,28 @@ #include "common.h" #include "utils.h" -bool VersionFromString(const char *szVer, DWORD *pdwVer) { +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') { + 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 == '.') { + } + else if(*p == '.') + { *pdwVer = *pdwVer << 8; bytes++; digit_count = 0; - } else { + } + else + { if(bytes < 3) // allow other chars on the end (e.g. space) return false; // incompatible version string else @@ -31,16 +38,20 @@ bool VersionFromString(const char *szVer, DWORD *pdwVer) { } -int CheckForFileID(char *update_url, char *version_url, char *name) { - if(strlen(update_url) > 45 && strncmp(update_url, MIM_DOWNLOAD_URL_PREFIX, 45) == 0) { +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) { + 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) { + 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); } @@ -186,6 +197,29 @@ void* memmem (const void *buf1, size_t size1, const void *buf2, size_t size2) return NULL; } +bool IsAdminRequired(void) +{ + TCHAR path[MAX_PATH]; + GetRootDir(path); + _tcscat(path, _T("\\test_tmp.tmp")); + + HANDLE hDatFile = CreateFile(path, GENERIC_WRITE, FILE_SHARE_WRITE, 0, CREATE_ALWAYS, 0, 0); + if (hDatFile != INVALID_HANDLE_VALUE) + { + CloseHandle(hDatFile); + DeleteFile(path); + return false; + } + + return true; +} + +void GetRootDir(TCHAR *szPath) +{ + GetModuleFileName(NULL, szPath, MAX_PATH); + TCHAR *p = _tcsrchr(szPath, '\\'); if (p) *p = 0; +} + void NLog(char *msg) { CallService(MS_NETLIB_LOG, (WPARAM)hNetlibUser, (LPARAM)msg); -- cgit v1.2.3