summaryrefslogtreecommitdiff
path: root/win/upgrade_wizard
diff options
context:
space:
mode:
authorVladislav Vaintroub <wlad@montyprogram.com>2011-01-30 22:27:59 +0100
committerVladislav Vaintroub <wlad@montyprogram.com>2011-01-30 22:27:59 +0100
commit366ee3c791ca6b5e7688a5138dfe347860772d2a (patch)
tree382224bbff0ec202ac76390e209c286a069b4bda /win/upgrade_wizard
parente353bc80f721fc415ab2977f503878d69b43e63e (diff)
downloadmariadb-git-366ee3c791ca6b5e7688a5138dfe347860772d2a.tar.gz
Move common functionality (analyze service configuration) into winservice library
Diffstat (limited to 'win/upgrade_wizard')
-rw-r--r--win/upgrade_wizard/CMakeLists.txt6
-rw-r--r--win/upgrade_wizard/upgradeDlg.cpp110
2 files changed, 36 insertions, 80 deletions
diff --git a/win/upgrade_wizard/CMakeLists.txt b/win/upgrade_wizard/CMakeLists.txt
index d23c6b0a607..fad67a207de 100644
--- a/win/upgrade_wizard/CMakeLists.txt
+++ b/win/upgrade_wizard/CMakeLists.txt
@@ -18,9 +18,11 @@ SET(CMAKE_MFC_FLAG 1)
# Enable exception handling (avoids warnings)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
-MYSQL_ADD_EXECUTABLE(upgrade_wizard upgrade.cpp upgradeDlg.cpp upgrade.rc
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/sql)
+MYSQL_ADD_EXECUTABLE(upgrade_wizard
+ upgrade.cpp upgradeDlg.cpp upgrade.rc
COMPONENT Server)
-
+TARGET_LINK_LIBRARIES(upgrade_wizard winservice)
# upgrade_wizard is Windows executable, set WIN32_EXECUTABLE so it does not
# create a console.
SET_TARGET_PROPERTIES(upgrade_wizard PROPERTIES WIN32_EXECUTABLE 1)
diff --git a/win/upgrade_wizard/upgradeDlg.cpp b/win/upgrade_wizard/upgradeDlg.cpp
index 97c40f53d94..f650407f245 100644
--- a/win/upgrade_wizard/upgradeDlg.cpp
+++ b/win/upgrade_wizard/upgradeDlg.cpp
@@ -14,6 +14,8 @@
#include <string>
#include <vector>
+#include <winservice.h>
+
using namespace std;
#ifdef _DEBUG
@@ -75,7 +77,7 @@ vector<ServiceProperties> services;
<unknown> , of executable does not have any version
info embedded (like MySQL 5.1 for example)
*/
-string GetExeVersion(const string& filename, int *major, int *minor, int *patch)
+void GetExeVersion(const string& filename, int *major, int *minor, int *patch)
{
DWORD handle;
*major= *minor= *patch= 0;
@@ -85,20 +87,17 @@ string GetExeVersion(const string& filename, int *major, int *minor, int *patch)
if (!GetFileVersionInfo(filename.c_str(), handle, size, versionInfo))
{
delete[] versionInfo;
- return "<unknown>";
+ return;
}
// we have version information
UINT len = 0;
VS_FIXEDFILEINFO* vsfi = NULL;
VerQueryValue(versionInfo, "\\", (void**)&vsfi, &len);
- char arr[64];
*major= (int)HIWORD(vsfi->dwFileVersionMS);
*minor= (int)LOWORD(vsfi->dwFileVersionMS);
*patch= (int)HIWORD(vsfi->dwFileVersionLS);
- sprintf_s(arr,"%d.%d.%d", *major, *minor, *patch);
delete[] versionInfo;
- return string(arr);
}
@@ -122,19 +121,6 @@ void CUpgradeDlg::SelectService(int index)
}
-/* Remove quotes from string */
-static char *RemoveQuotes(char *s)
-{
- if(s[0]=='"')
- {
- s++;
- char *p= strchr(s, '"');
- if(p)
- *p= 0;
- }
- return s;
-}
-
/*
Iterate over services, lookup for mysqld.exe ones.
@@ -157,8 +143,7 @@ void CUpgradeDlg::PopulateServicesList()
static BYTE buf[64*1024];
static BYTE configBuffer[8*1024];
- char datadirBuf[MAX_PATH];
- char datadirNormalized[MAX_PATH];
+
DWORD bufsize= sizeof(buf);
DWORD bufneed;
DWORD num_services;
@@ -184,70 +169,39 @@ void CUpgradeDlg::PopulateServicesList()
CloseServiceHandle(service);
if (ok)
{
- int argc;
- wchar_t **wargv = CommandLineToArgvW(config->lpBinaryPathName, &argc);
+ mysqld_service_properties service_props;
+
+ if (get_mysql_service_properties(config->lpBinaryPathName,
+ &service_props))
+ continue;
- // We expect path\to\mysqld --defaults-file=<path> <servicename>
- if(argc == 3)
+ /* Check if service uses mysqld in installation directory */
+ if (_strnicmp(service_props.mysqld_exe, m_InstallDir.c_str(),
+ m_InstallDir.size()) == 0)
+ continue;
+
+ if(m_MajorVersion > service_props.version_major ||
+ (m_MajorVersion == service_props.version_major && m_MinorVersion >=
+ service_props.version_minor))
{
-
- // Convert wide strings to ANSI
- char *argv[3];
- for(int k=0; k < 3;k++)
+ ServiceProperties props;
+ props.myini= service_props.inifile;
+ props.datadir= service_props.datadir;
+ props.servicename = info[i].lpServiceName;
+ if (service_props.version_major)
{
- size_t nbytes = 2*wcslen(wargv[k])+1;
- argv[k]= new char[nbytes];
- wcstombs(argv[k], wargv[k], nbytes);
+ char ver[64];
+ sprintf(ver, "%d.%d.%d", service_props.version_major,
+ service_props.version_minor, service_props.version_patch);
+ props.version= ver;
}
+ else
+ props.version= "<unknown>";
- size_t len= strlen(argv[0]);
- char path[MAX_PATH]={0};
- char *filepart;
- GetFullPathName(argv[0],MAX_PATH, path, &filepart);
- if(_stricmp(filepart, "mysqld.exe") == 0 ||
- _stricmp(filepart, "mysqld") == 0)
- {
- if(_strnicmp(argv[1],"--defaults-file=",16) == 0)
- {
- /* Remove quotes around defaults-file */
- char *inifile= argv[1] + 16;
- inifile = RemoveQuotes(inifile);
-
- char *datadir=datadirBuf;
- GetPrivateProfileString("mysqld", "datadir", NULL, datadirBuf,
- MAX_PATH, inifile);
-
- /* Remove quotes from datadir */
- datadir= RemoveQuotes(datadir);
-
- GetFullPathName(datadir, MAX_PATH, datadirNormalized, NULL);
- ServiceProperties props;
-
- props.myini = inifile;
- props.servicename = info[i].lpServiceName;
- string exefilename(argv[0]);
- if(!strstr(argv[0], ".exe"))
- exefilename += ".exe";
- int major, minor, patch;
- props.version= GetExeVersion(exefilename, &major, &minor, &patch);
- if(m_MajorVersion > major ||
- (m_MajorVersion == major && m_MinorVersion >= minor))
- {
- if (_strnicmp(exefilename.c_str(), m_InstallDir.c_str(),
- m_InstallDir.size()) != 0)
- {
- props.datadir = datadirNormalized;
- index = m_Services.AddString(info[i].lpServiceName);
- services.resize(index+1);
- services[index] = props;
- }
- }
- }
- }
- for(int k=0; k< 3;k++)
- delete[] argv[k];
+ index = m_Services.AddString(info[i].lpServiceName);
+ services.resize(index+1);
+ services[index] = props;
}
- LocalFree((HLOCAL)wargv);
}
if (index != -1)
{