diff options
author | Rasmus Johansson <razze@iki.fi> | 2019-06-17 10:43:01 +0300 |
---|---|---|
committer | Rasmus Johansson <razze@iki.fi> | 2019-08-12 11:34:06 +0300 |
commit | 54d37a6765285138cd66cbdc6753d2606a95fb9c (patch) | |
tree | 24961ced3d7dc3986c9cb2280267d0595ed979b0 | |
parent | 13f36fffeaecf316435fc497b0f3ae2a5d58d749 (diff) | |
download | mariadb-git-54d37a6765285138cd66cbdc6753d2606a95fb9c.tar.gz |
MDEV-19781 Create MariaDB named commands on Windows
-rw-r--r-- | win/packaging/CMakeLists.txt | 2 | ||||
-rw-r--r-- | win/packaging/PostInstall.bat | 4 | ||||
-rw-r--r-- | win/packaging/ca/CMakeLists.txt | 4 | ||||
-rw-r--r-- | win/packaging/ca/CustomAction.cpp | 114 | ||||
-rw-r--r-- | win/packaging/ca/CustomAction.def | 1 | ||||
-rw-r--r-- | win/packaging/create_msi.cmake | 6 | ||||
-rw-r--r-- | win/packaging/mysql_server.wxs.in | 21 |
7 files changed, 147 insertions, 5 deletions
diff --git a/win/packaging/CMakeLists.txt b/win/packaging/CMakeLists.txt index 9e06638a991..52840214702 100644 --- a/win/packaging/CMakeLists.txt +++ b/win/packaging/CMakeLists.txt @@ -125,6 +125,8 @@ ELSE() ENDIF() SET(CPACK_WIX_CONFIG ${CMAKE_CURRENT_SOURCE_DIR}/CPackWixConfig.cmake) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/PostInstall.bat ${CMAKE_CURRENT_BINARY_DIR}/PostInstall.bat COPYONLY) + IF(NOT TARGET mysql_upgrade_wizard) SET(EXTRA_WIX_PREPROCESSOR_FLAGS "-dHaveUpgradeWizard=0") ENDIF() diff --git a/win/packaging/PostInstall.bat b/win/packaging/PostInstall.bat new file mode 100644 index 00000000000..58eff50dd1d --- /dev/null +++ b/win/packaging/PostInstall.bat @@ -0,0 +1,4 @@ +@ECHO OFF +for /l %%x in (1, 1, 100) do echo %%x +dir +PAUSE
\ No newline at end of file diff --git a/win/packaging/ca/CMakeLists.txt b/win/packaging/ca/CMakeLists.txt index 24a75e356c9..31c3c553de3 100644 --- a/win/packaging/ca/CMakeLists.txt +++ b/win/packaging/ca/CMakeLists.txt @@ -22,4 +22,8 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/sql) FORCE_STATIC_CRT() ADD_VERSION_INFO(wixca SHARED WIXCA_SOURCES) ADD_LIBRARY(wixca SHARED EXCLUDE_FROM_ALL ${WIXCA_SOURCES} ${CMAKE_SOURCE_DIR}/sql/winservice.c) +SET_TARGET_PROPERTIES(wixca PROPERTIES + CXX_STANDARD 17 + CXX_EXTENSIONS OFF + CXX_STANDARD_REQUIRED ON) TARGET_LINK_LIBRARIES(wixca ${WIX_WCAUTIL_LIBRARY} ${WIX_DUTIL_LIBRARY} msi version) diff --git a/win/packaging/ca/CustomAction.cpp b/win/packaging/ca/CustomAction.cpp index bc3fcfea94f..83cd40be35e 100644 --- a/win/packaging/ca/CustomAction.cpp +++ b/win/packaging/ca/CustomAction.cpp @@ -32,6 +32,15 @@ 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 <filesystem> +#include <fstream> +#include <map> +#include <Shlwapi.h> +#include "CustomAction.h" +using namespace std; +using namespace std::filesystem; #define ONE_MB 1048576 UINT ExecRemoveDataDirectory(wchar_t *dir) @@ -452,6 +461,7 @@ extern "C" UINT CheckDBInUse(MSIHANDLE hInstall) wchar_t *servicename= NULL; wchar_t *datadir= NULL; wchar_t *bindir=NULL; + wofstream myfile; SC_HANDLE scm = NULL; ULONG bufsize = sizeof(buf); @@ -467,6 +477,13 @@ extern "C" UINT CheckDBInUse(MSIHANDLE hInstall) WcaGetProperty(L"SERVICENAME", &servicename); WcaGetProperty(L"DATADIR", &datadir); WcaGetFormattedString(L"[INSTALLDIR]bin\\", &bindir); + + myfile.open("c:\\users\\rasmu\\debug2.txt"); + myfile << L"Read bindir\n"; + myfile << bindir; + myfile << L"\nEnd reading bindir\n"; + myfile.close(); + WcaLog(LOGMSG_STANDARD,"SERVICENAME=%S, DATADIR=%S, bindir=%S", servicename, datadir, bindir); @@ -1003,3 +1020,100 @@ extern "C" BOOL WINAPI DllMain( return TRUE; } + +/* Symlinks */ +extern "C" UINT __stdcall CreateSymlinks(MSIHANDLE hInstall) +{ + wchar_t *bindir= NULL; + HRESULT hr= S_OK; + UINT er= ERROR_SUCCESS; + TCHAR *szValueBuf= NULL; + DWORD cchValueBuf= 0; + UINT uiStat= NULL; + string debug; + string symlinkName; + string appendedPath1, appendedPath2; + path target, symlink; + ofstream myfile; + char installDir[MAX_PATH]; + DWORD size= MAX_VERSION_PROPERTY_SIZE; + + hr = WcaInitialize(hInstall, __FUNCTION__); + + myfile.open("c:\\users\\rasmu\\debug.txt"); + myfile << "Start\n"; + myfile.close(); + + ExitOnFailure(hr, "Failed to initialize"); + + myfile.open("c:\\users\\rasmu\\debug.txt", ios_base::app); + myfile << "Initialize successful\n"; + myfile.close(); + + //ExitOnFailure(hr, "Failed to read INSTALLDIR property."); + + // hr= WcaGetFormattedString(L"[INSTALLDIR]bin\\", &bindir); + //uiStat= MsiGetPropertyW(hInstall, L"INSTALLDIR", bindir, &cchValueBuf); + MsiGetProperty(hInstall, TEXT("INSTALLDIR"), bindir, &size); + + myfile.open("c:\\users\\rasmu\\debug.txt", ios_base::app); + myfile << "Read bindir\n"; + myfile << bindir; + myfile << "\nEnd reading bindir\n"; + myfile.close(); + + uiStat= + MsiGetProperty(hInstall, TEXT("INSTALLDIR"), LPWSTR(L""), &cchValueBuf); + // cchValueBuf now contains the size of the property's string, without null + // termination + if (ERROR_MORE_DATA == uiStat) + { + ++cchValueBuf; // add 1 for null termination + szValueBuf= new TCHAR[cchValueBuf]; + if (szValueBuf) + { + uiStat= MsiGetProperty(hInstall, TEXT("MyProperty"), szValueBuf, + &cchValueBuf); + } + } + + // string symlink_from[]= {"mysql", "mysqlaccess", "mysqladmin"}; + // string symlink_to[]= {"mariadb", "mariadb-access", "mariadb-admin"}; + + // cout << symlink_from[0]; + + // printf("%s\n", symlink_from[0].c_str()); + target = L"C:/Users/rasmu/target.txt"; + + symlinkName= "symlink.txt"; + appendedPath2= installDir + symlinkName; + + myfile.open("c:\\users\\rasmu\\debug.txt", ios_base::app); + myfile << bindir; + myfile << "2:" + symlinkName; + myfile << "\nEnd\n"; + myfile.close(); + + try + { + create_symlink(target, appendedPath2); + } + catch (const filesystem_error &e) + { + myfile.open("c:\\users\\rasmu\\debug.txt", ios_base::app); + myfile << e.what(); + myfile.close(); + } + +LExit: + myfile.open("c:\\users\\rasmu\\debug.txt", ios_base::app); + myfile << "LExit\n"; + myfile << hr; + myfile.close(); + + ReleaseStr(bindir); + + er= SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE; + + return WcaFinalize(er); +}
\ No newline at end of file diff --git a/win/packaging/ca/CustomAction.def b/win/packaging/ca/CustomAction.def index 0be77a97a08..42a9de21964 100644 --- a/win/packaging/ca/CustomAction.def +++ b/win/packaging/ca/CustomAction.def @@ -8,3 +8,4 @@ CheckDatabaseProperties CheckDataDirectoryEmpty CheckDBInUse CheckServiceUpgrades +CreateSymlinks
\ No newline at end of file diff --git a/win/packaging/create_msi.cmake b/win/packaging/create_msi.cmake index ad935803a1e..a1e23593427 100644 --- a/win/packaging/create_msi.cmake +++ b/win/packaging/create_msi.cmake @@ -275,6 +275,7 @@ FUNCTION(TRAVERSE_FILES dir topdir file file_comp dir_root) ENDIF() ENDFOREACH() FILE(APPEND ${file} "</DirectoryRef>\n") + IF(NONEXEFILES) GENERATE_GUID(guid) SET(ComponentId "C._files_${COMP_NAME}.${DirectoryRefId}") @@ -345,7 +346,6 @@ FILE(APPEND directories.wxs "</DirectoryRef>\n") FILE(READ directories.wxs CPACK_WIX_DIRECTORIES) FILE(REMOVE directories.wxs) - FOREACH(src ${CPACK_WIX_INCLUDE}) SET(CPACK_WIX_INCLUDES "${CPACK_WIX_INCLUDES} @@ -353,9 +353,11 @@ SET(CPACK_WIX_INCLUDES ) ENDFOREACH() - CONFIGURE_FILE(${SRCDIR}/mysql_server.wxs.in ${CMAKE_CURRENT_BINARY_DIR}/mysql_server.wxs) +SET(POST_INSTALL_SCRIPT_PATH "${CMAKE_CURRENT_BINARY_DIR}/PostInstall.bat") +CONFIGURE_FILE(${SRCDIR}/PostInstall.bat + ${POST_INSTALL_SCRIPT_PATH}) CONFIGURE_FILE(${SRCDIR}/extra.wxs.in ${CMAKE_CURRENT_BINARY_DIR}/extra.wxs) diff --git a/win/packaging/mysql_server.wxs.in b/win/packaging/mysql_server.wxs.in index 80dcc365e56..38ec20b0c2e 100644 --- a/win/packaging/mysql_server.wxs.in +++ b/win/packaging/mysql_server.wxs.in @@ -42,8 +42,14 @@ <Condition Message="A more recent version of [ProductName] is already installed. Setup will now exit."> NOT NEWERVERSIONDETECTED OR Installed </Condition> + + <CustomAction Id="symlinks" ExeCommand="cmd /c "PostInstall.bat"" Directory="INSTALLDIR" Execute="deferred" Impersonate="no" Return="check"/> + <CustomAction Id="CreateSymlinks" BinaryKey="wixca.dll" DllEntry="CreateSymlinks" Execute="commit" /> + <InstallExecuteSequence> <RemoveExistingProducts After="InstallFinalize"/> + <Custom Action="symlinks" After="CreateSymlinks" >NOT Installed</Custom> + <Custom Action="CreateSymlinks" After="InstallFiles">Not Installed</Custom> </InstallExecuteSequence> @@ -69,21 +75,30 @@ </Directory> </Directory> </Directory> - + <!-- CPACK_WIX_FEATURES --> @CPACK_WIX_FEATURES@ - + <!-- CPACK_WIX_DIRECTORIES --> @CPACK_WIX_DIRECTORIES@ <!--CPACK_WIX_COMPONENTS--> @CPACK_WIX_COMPONENTS@ - + <!--CPACK_WIX_COMPONENTS_GROUPS --> @CPACK_WIX_COMPONENT_GROUPS@ <!--CPACK_WIX_INCLUDES --> @CPACK_WIX_INCLUDES@ + + <DirectoryRef Id="INSTALLDIR"> + <Component Id='PostInstall.bat' Guid='*' Win64='yes' > + <File Id='PostInstall.bat' KeyPath='yes' Source='PostInstall.bat'/> + </Component> + </DirectoryRef> + <Feature Id="PostInstall" Title="MariaDB symlinks" Level="1" AllowAdvertise="no"> + <ComponentRef Id="PostInstall.bat" /> + </Feature> </Product> </Wix> |