Commit b6f7ec6a authored by Rasmus Johansson's avatar Rasmus Johansson

MDEV-19781 Create MariaDB named commands on Windows

Added CreateSymlinks and DeleteSymlinks functions to
CustomAction.cpp. Extra.wxs.in calls them.
parent f9ceb0a6
......@@ -21,8 +21,6 @@ IF(MSVC_VERSION LESS 1600)
RETURN()
ENDIF()
SET(MANUFACTURER "MariaDB Corporation Ab")
SET(WIX_BIN_PATHS)
FOREACH(WIX_VER 3.9 3.10 3.11)
......
......@@ -32,6 +32,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */
#include <shellapi.h>
#include <stdlib.h>
#include <winservice.h>
#include <string>
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <map>
using namespace std;
#define ONE_MB 1048576
UINT ExecRemoveDataDirectory(wchar_t *dir)
......@@ -467,6 +475,7 @@ extern "C" UINT CheckDBInUse(MSIHANDLE hInstall)
WcaGetProperty(L"SERVICENAME", &servicename);
WcaGetProperty(L"DATADIR", &datadir);
WcaGetFormattedString(L"[INSTALLDIR]bin\\", &bindir);
WcaLog(LOGMSG_STANDARD,"SERVICENAME=%S, DATADIR=%S, bindir=%S",
servicename, datadir, bindir);
......@@ -1003,3 +1012,305 @@ extern "C" BOOL WINAPI DllMain(
return TRUE;
}
// check if file exists
inline bool checkIfFileExists (wstring& name) {
string sLog = "checkIfFileExists, ";
string sName(name.begin(), name.end() );
ifstream f(sName);
sLog.append(sName);
sLog.append(", result: ");
bool fileExists = f.good();
if (f.good())
sLog.append("true");
else
sLog.append("false");
WcaLog(LOGMSG_STANDARD, sLog.c_str());
return f.good();
}
// string to wstring
std::wstring s2ws(const std::string& s)
{
int len;
int slength = (int)s.length() + 1;
len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0);
wchar_t* buf = new wchar_t[len];
MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, buf, len);
std::wstring r(buf);
delete[] buf;
return r;
}
/* MDEV-19781 MariaDB symlinks on Windows */
extern "C" UINT __stdcall CreateSymlinks(MSIHANDLE hInstall)
{
HRESULT hr = S_OK;
UINT er = ERROR_SUCCESS;
wchar_t customActionData[10000];
wchar_t installDir[MAX_PATH];
DWORD len = 10000;
wchar_t installerVersion[MAX_VERSION_PROPERTY_SIZE];
DWORD size = MAX_VERSION_PROPERTY_SIZE;
wchar_t binDir[MAX_PATH];
size_t blen = NULL;
hr = WcaInitialize(hInstall, __FUNCTION__);
WcaLog(LOGMSG_STANDARD, "Initialized.");
if (MsiGetPropertyW(hInstall, L"CustomActionData", customActionData, &len) != ERROR_SUCCESS)
{
hr = HRESULT_FROM_WIN32(GetLastError());
MsiProcessMessage(hInstall, INSTALLMESSAGE_INFO, hr);
}
if (MsiGetPropertyW(hInstall, L"ProductVersion", installerVersion, &size) != ERROR_SUCCESS)
{
hr = HRESULT_FROM_WIN32(GetLastError());
MsiProcessMessage(hInstall, INSTALLMESSAGE_INFO, hr);
}
MsiProcessMessage(hInstall, INSTALLMESSAGE_INFO, hr);
wstring wsCustomActionData(customActionData);
string sCustomActionData(wsCustomActionData.begin(), wsCustomActionData.end());
WcaLog(LOGMSG_STANDARD, sCustomActionData.c_str());
stringstream ss;
ss << sCustomActionData;
vector<string> vCustomActionData;
while( ss.good() )
{
string substr;
getline( ss, substr, '|' );
WcaLog(LOGMSG_STANDARD, substr.c_str());
vCustomActionData.push_back( substr );
}
int i = 0;
string sBinPath = "";
string sPathFrom = "";
string sPathTo = "";
for(auto const& value: vCustomActionData) {
if (i == 0) {
sBinPath = value;
sBinPath.append("bin\\");
} else if (i == 1) {
sPathFrom = value;
} else if (i == 2) {
sPathTo = value;
}
WcaLog(LOGMSG_STANDARD, value.c_str());
i++;
}
WcaLog(LOGMSG_STANDARD, sBinPath.c_str());
WcaLog(LOGMSG_STANDARD, sPathFrom.c_str());
WcaLog(LOGMSG_STANDARD, sPathTo.c_str());
stringstream ssPathFrom, ssPathTo;
ssPathFrom << sPathFrom;
ssPathTo << sPathTo;
vector<string> vPathFrom;
vector<string> vPathTo;
while(ssPathFrom.good()) {
string substr = "";
getline(ssPathFrom, substr, ';');
substr = substr.insert(0, sBinPath);
WcaLog(LOGMSG_STANDARD, substr.c_str());
vPathFrom.push_back(substr);
}
while(ssPathTo.good()) {
string substr = "";
getline(ssPathTo, substr, ';');
substr = substr.insert(0, sBinPath);
WcaLog(LOGMSG_STANDARD, substr.c_str());
vPathTo.push_back(substr);
}
i = 0;
for(auto const& value: vPathTo) {
string &sTmpPathFrom = vPathFrom[i];
string &sTmpPathTo = vPathTo[i];
sTmpPathFrom.append(".exe");
sTmpPathTo.append(".exe");
wstring wsPathFrom = s2ws(sTmpPathFrom);
LPCWSTR lPathFrom = wsPathFrom.c_str();
wstring wsPathTo = s2ws(sTmpPathTo);
LPCWSTR lPathTo = wsPathTo.c_str();
int createdSymlink = -1;
if (checkIfFileExists(wsPathFrom))
createdSymlink = CreateSymbolicLinkW(wsPathTo.c_str(), wsPathFrom.c_str(), 0);
string created = "Created symlink: ";
created.append(sTmpPathTo);
created.append(" --> ");
created.append(sTmpPathFrom);
created.append(", result= ");
created.append(to_string(createdSymlink));
WcaLog(LOGMSG_STANDARD, created.c_str());
i++;
}
ReleaseStr(installDir);
ReleaseStr(installerVersion);
ReleaseStr(binDir);
return WcaFinalize(er);
}
/* MDEV-19781 MariaDB symlinks on Windows */
extern "C" UINT __stdcall DeleteSymlinks(MSIHANDLE hInstall)
{
HRESULT hr = S_OK;
UINT er = ERROR_SUCCESS;
wchar_t customActionData[10000];
wchar_t installDir[MAX_PATH];
DWORD len = 10000;
DWORD size = MAX_VERSION_PROPERTY_SIZE;
wchar_t binDir[MAX_PATH];
size_t blen = NULL;
hr = WcaInitialize(hInstall, __FUNCTION__);
WcaLog(LOGMSG_STANDARD, "DeleteSymlinks initialized.");
if (MsiGetPropertyW(hInstall, L"CustomActionData", customActionData, &len) != ERROR_SUCCESS)
{
hr = HRESULT_FROM_WIN32(GetLastError());
MsiProcessMessage(hInstall, INSTALLMESSAGE_INFO, hr);
}
wstring wsCustomActionData(customActionData);
string sCustomActionData(wsCustomActionData.begin(), wsCustomActionData.end());
WcaLog(LOGMSG_STANDARD, sCustomActionData.c_str());
stringstream ss;
ss << sCustomActionData;
vector<string> vCustomActionData;
while( ss.good() )
{
string substr;
getline( ss, substr, '|' );
WcaLog(LOGMSG_STANDARD, substr.c_str());
vCustomActionData.push_back( substr );
}
int i = 0;
string sBinPath = "";
string sPathFrom = "";
string sPathTo = "";
for(auto const& value: vCustomActionData) {
if (i == 0) {
sBinPath = value;
sBinPath.append("bin\\");
} else if (i == 1) {
sPathFrom = value;
} else if (i == 2) {
sPathTo = value;
}
WcaLog(LOGMSG_STANDARD, value.c_str());
i++;
}
WcaLog(LOGMSG_STANDARD, sBinPath.c_str());
WcaLog(LOGMSG_STANDARD, sPathFrom.c_str());
WcaLog(LOGMSG_STANDARD, sPathTo.c_str());
stringstream ssPathFrom, ssPathTo;
ssPathFrom << sPathFrom;
ssPathTo << sPathTo;
vector<string> vPathFrom;
vector<string> vPathTo;
while(ssPathFrom.good()) {
string substr = "";
getline(ssPathFrom, substr, ';');
substr = substr.insert(0, sBinPath);
WcaLog(LOGMSG_STANDARD, substr.c_str());
vPathFrom.push_back(substr);
}
while(ssPathTo.good()) {
string substr = "";
getline(ssPathTo, substr, ';');
substr = substr.insert(0, sBinPath);
WcaLog(LOGMSG_STANDARD, substr.c_str());
vPathTo.push_back(substr);
}
i = 0;
for(auto const& value: vPathTo) {
string &sTmpPathFrom = vPathFrom[i];
string &sTmpPathTo = vPathTo[i];
sTmpPathFrom.append(".exe");
sTmpPathTo.append(".exe");
wstring wsPathFrom = s2ws(sTmpPathFrom);
LPCWSTR lPathFrom = wsPathFrom.c_str();
wstring wsPathTo = s2ws(sTmpPathTo);
LPCWSTR lPathTo = wsPathTo.c_str();
int deletedSymlink = -1;
if (checkIfFileExists(wsPathTo))
deletedSymlink = DeleteFileW(wsPathTo.c_str());
string deleted = "Deleted symlink: ";
deleted.append(sTmpPathTo);
deleted.append(" --> ");
deleted.append(sTmpPathFrom);
deleted.append(", result= ");
deleted.append(to_string(deletedSymlink));
WcaLog(LOGMSG_STANDARD, deleted.c_str());
i++;
}
/*
for(size_t i = 0; i < std::size(symlink_to); i++) {
wchar_t pathTo[MAX_PATH];
wcscpy(pathTo, binDir);
wcscat(pathTo, symlink_to[i].data());
wstring wsPathTo(pathTo);
if ( checkIfFileExists(wsPathTo) ) {
DeleteFileW(pathTo);
} else {
hr = HRESULT_FROM_WIN32(GetLastError());
ExitOnFailure(hr, "Could not delete symlink");
}
}
*/
ReleaseStr(installDir);
ReleaseStr(binDir);
return WcaFinalize(er);
}
\ No newline at end of file
......@@ -8,3 +8,5 @@ CheckDatabaseProperties
CheckDataDirectoryEmpty
CheckDBInUse
CheckServiceUpgrades
CreateSymlinks
DeleteSymlinks
# get the symlink lists
#INCLUDE(${CMAKE_SOURCE_DIR}/../../cmake/symlinks.cmake)
#INCLUDE(symlinks)
INCLUDE(${CMAKE_CURRENT_LIST_DIR}/../../cmake/symlinks.cmake)
MACRO(MAKE_WIX_IDENTIFIER str varname)
STRING(REPLACE "/" "." ${varname} "${str}")
STRING(REGEX REPLACE "[^a-zA-Z_0-9.]" "_" ${varname} "${${varname}}")
......
......@@ -63,6 +63,9 @@
<Property Id="BUFFERPOOLSIZE" Secure="yes"/>
<!-- Innodb page size -->
<Property Id="PAGESIZE" Secure="yes" Value="16K"/>
<!-- Symlinks -->
<Property Id="SYMLINK_TOS" Value="@MARIADB_SYMLINK_TOS@" />
<Property Id="SYMLINK_FROMS" Value="@MARIADB_SYMLINK_FROMS@" />
<CustomAction Id="LaunchUrl" BinaryKey="WixCA" DllEntry="WixShellExec" Execute="immediate" Return="check" Impersonate="yes" />
......@@ -661,6 +664,19 @@
</Feature>
<?endif?>
<!-- Custom action, create symlinks -->
<CustomAction Id="CreateSymlinks.SetProperty" Return="check" Property="CreateSymlinks" Value="[INSTALLDIR]|[SYMLINK_FROMS]|[SYMLINK_TOS]" />
<CustomAction Id="CreateSymlinks" BinaryKey="wixca.dll" DllEntry="CreateSymlinks" Execute="deferred" Impersonate="no" Return="ignore" />
<CustomAction Id="DeleteSymlinks.SetProperty" Return="check" Property="DeleteSymlinks" Value="[INSTALLDIR]|[SYMLINK_FROMS]|[SYMLINK_TOS]" />
<CustomAction Id='DeleteSymlinks' BinaryKey="wixca.dll" DllEntry="DeleteSymlinks" Execute="deferred" Impersonate="no" Return="ignore" />
<InstallExecuteSequence>
<Custom Action="CreateSymlinks.SetProperty" Before="CreateSymlinks">NOT Installed</Custom>
<Custom Action="CreateSymlinks" Before="InstallFinalize">NOT Installed</Custom>
<Custom Action="DeleteSymlinks.SetProperty" Before="DeleteSymlinks">Installed AND NOT REINSTALL</Custom>
<Custom Action="DeleteSymlinks" Before="RemoveFiles">Installed AND NOT REINSTALL</Custom>
</InstallExecuteSequence>
<!-- Custom action, call mysql_install_db -->
<SetProperty Sequence='execute' Before='CreateDatabaseCommand' Id="SKIPNETWORKING" Value="--skip-networking" >SKIPNETWORKING</SetProperty>
<SetProperty Sequence='execute' Before='CreateDatabaseCommand' Id="ALLOWREMOTEROOTACCESS" Value="--allow-remote-root-access">ALLOWREMOTEROOTACCESS</SetProperty>
......@@ -881,10 +897,10 @@
>
<![CDATA[ NOT(NSISINSTALLKEY << "MariaDB @MAJOR_VERSION@.@MINOR_VERSION@.") OR Installed]]>
</Condition>
<Condition Message=
<!-- Condition Message=
'Setting the ALLUSERS property is not allowed because [ProductName] is a per-machine application. Setup will now exit.'>
<![CDATA[ALLUSERS = "1"]]>
</Condition>
</Condition -->
<Condition Message='This application is only supported on Windows Vista, Windows Server 2008, or higher.'>
<![CDATA[Installed OR (VersionNT >= 600)]]>
</Condition>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment