Merge pull request #2369 from nextcloud/enh/windows-msi

Windows: MSI support & Win32 migration tools
This commit is contained in:
Michael Schuster 2020-09-21 17:35:37 +02:00 committed by GitHub
commit b72bfb5c65
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
42 changed files with 5617 additions and 13 deletions

View file

@ -37,15 +37,23 @@ option( APPLICATION_WIZARD_USE_CUSTOM_LOGO "Use the logo from ':/client/theme/co
# #
## Windows Shell Extensions - IMPORTANT: Generate new GUIDs for custom builds with "guidgen" or "uuidgen" ## Windows Shell Extensions & MSI - IMPORTANT: Generate new GUIDs for custom builds with "guidgen" or "uuidgen"
# #
if(WIN32)
# Context Menu
set( WIN_SHELLEXT_CONTEXT_MENU_GUID "{BC6988AB-ACE2-4B81-84DC-DC34F9B24401}" )
# Context Menu # Overlays
set( WIN_SHELLEXT_CONTEXT_MENU_GUID "{BC6988AB-ACE2-4B81-84DC-DC34F9B24401}" ) set( WIN_SHELLEXT_OVERLAY_GUID_ERROR "{E0342B74-7593-4C70-9D61-22F294AAFE05}" )
set( WIN_SHELLEXT_OVERLAY_GUID_OK "{E1094E94-BE93-4EA2-9639-8475C68F3886}" )
set( WIN_SHELLEXT_OVERLAY_GUID_OK_SHARED "{E243AD85-F71B-496B-B17E-B8091CBE93D2}" )
set( WIN_SHELLEXT_OVERLAY_GUID_SYNC "{E3D6DB20-1D83-4829-B5C9-941B31C0C35A}" )
set( WIN_SHELLEXT_OVERLAY_GUID_WARNING "{E4977F33-F93A-4A0A-9D3C-83DEA0EE8483}" )
# Overlays # MSI Upgrade Code (without brackets)
set( WIN_SHELLEXT_OVERLAY_GUID_ERROR "{E0342B74-7593-4C70-9D61-22F294AAFE05}" ) set( WIN_MSI_UPGRADE_CODE "FD2FCCA9-BB8F-4485-8F70-A0621B84A7F4" )
set( WIN_SHELLEXT_OVERLAY_GUID_OK "{E1094E94-BE93-4EA2-9639-8475C68F3886}" )
set( WIN_SHELLEXT_OVERLAY_GUID_OK_SHARED "{E243AD85-F71B-496B-B17E-B8091CBE93D2}" ) # Windows build options
set( WIN_SHELLEXT_OVERLAY_GUID_SYNC "{E3D6DB20-1D83-4829-B5C9-941B31C0C35A}" ) option( BUILD_WIN_MSI "Build MSI scripts and helper DLL" OFF )
set( WIN_SHELLEXT_OVERLAY_GUID_WARNING "{E4977F33-F93A-4A0A-9D3C-83DEA0EE8483}" ) option( BUILD_WIN_TOOLS "Build Win32 migration tools" OFF )
endif()

View file

@ -1,2 +1,7 @@
# traverse into osx subdirectory to install and patch the create-pack script if(APPLE)
add_subdirectory(osx) # traverse into osx subdirectory to install and patch the create-pack script
add_subdirectory(osx)
elseif(WIN32)
# MSI package scripts, helper DLL and migration tools
add_subdirectory(win)
endif()

8
admin/win/CMakeLists.txt Normal file
View file

@ -0,0 +1,8 @@
# MSI package scripts, helper DLL and migration tools
if(BUILD_WIN_MSI)
add_subdirectory(msi)
endif()
if(BUILD_WIN_MSI OR BUILD_WIN_TOOLS)
add_subdirectory(tools)
endif()

View file

@ -0,0 +1,25 @@
if(CMAKE_SIZEOF_VOID_P MATCHES 4)
set(MSI_BUILD_ARCH x86)
else()
set(MSI_BUILD_ARCH x64)
endif()
string(SUBSTRING ${GIT_SHA1} 0 7 GIT_REVISION)
set(VERSION "${MIRALL_VERSION_MAJOR}.${MIRALL_VERSION_MINOR}.${MIRALL_VERSION_PATCH}.${MIRALL_VERSION_BUILD}")
set(MSI_INSTALLER_FILENAME "${APPLICATION_SHORTNAME}-${VERSION}-${MSI_BUILD_ARCH}.msi")
configure_file(OEM.wxi.in ${CMAKE_CURRENT_BINARY_DIR}/OEM.wxi)
configure_file(collect-transform.xsl.in ${CMAKE_CURRENT_BINARY_DIR}/collect-transform.xsl)
configure_file(make-msi.bat.in ${CMAKE_CURRENT_BINARY_DIR}/make-msi.bat)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/OEM.wxi
${CMAKE_CURRENT_BINARY_DIR}/collect-transform.xsl
${CMAKE_CURRENT_BINARY_DIR}/make-msi.bat
Platform.wxi
Nextcloud.wxs
gui/banner.bmp
gui/dialog.bmp
DESTINATION msi/)

207
admin/win/msi/Nextcloud.wxs Normal file
View file

@ -0,0 +1,207 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
*
* Copyright (C) by Michael Schuster <michael.schuster@nextcloud.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
-->
<?include $(sys.CURRENTDIR)OEM.wxi?>
<?include $(sys.CURRENTDIR)Platform.wxi?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
<!--
When to change the Product GUID:
https://www.firegiant.com/wix/tutorial/upgrades-and-modularization/
https://www.firegiant.com/wix/tutorial/upgrades-and-modularization/checking-for-oldies/
We change the Product Id for every release, to let up-/downgrading always work.
But we then should never change the UpgradeCode.
-->
<Product Name="$(var.AppName)" Manufacturer="$(var.AppVendor)"
Id="*"
UpgradeCode="$(var.UpgradeCode)"
Language="1033" Codepage="$(var.codepage)" Version="$(var.VerFull)">
<Package Id="*" Keywords="Installer" Description="$(var.AppName) $(var.VerDesc)" Manufacturer="$(var.AppVendor)"
InstallerVersion="300" Platform="$(var.Platform)" Languages="1033" Compressed="yes" SummaryCodepage="$(var.codepage)" InstallScope="perMachine" />
<!--
Upgrading: Since we always want to allow up-/downgrade, we don't specify a maximum version, thus
leading the WiX linker (light.exe) to trigger the following warning:
warning LGHT1076 : ICE61: This product should remove only older versions of itself. No Maximum version was detected for the current product. (WIX_UPGRADE_DETECTED)
We suppress the warning: light.exe -sw1076
If at some point we want to change this behaviour, read the docs:
https://www.firegiant.com/wix/tutorial/upgrades-and-modularization/replacing-ourselves/
https://www.joyofsetup.com/2010/01/16/major-upgrades-now-easier-than-ever/
-->
<MajorUpgrade Schedule="afterInstallInitialize" AllowDowngrades="yes" />
<Media Id="1" Cabinet="$(var.AppShortName).cab" EmbedCab="yes" />
<!-- If already installed: Use previously chosen path (use 32-bit registry like NSIS does) -->
<Property Id="INSTALLDIR">
<RegistrySearch Id="RegistryInstallDir" Type="raw" Root="HKLM" Key="Software\$(var.AppVendor)\$(var.AppName)" Win64="no" />
</Property>
<!-- Detect legacy NSIS installation -->
<Property Id="NSIS_UNINSTALLEXE">
<DirectorySearch Id="LegacyUninstallVersion" Path="[INSTALLDIR]">
<FileSearch Name="Uninstall.exe" />
</DirectorySearch>
</Property>
<!-- Quit / restart application -->
<util:RestartResource ProcessName="$(var.AppExe)" />
<!-- Helper DLL Custom Actions -->
<SetProperty Id="ExecNsisUninstaller" Value="&quot;$(var.AppShortName)&quot; &quot;[NSIS_UNINSTALLEXE]&quot;" Before="ExecNsisUninstaller" Sequence="execute" />
<SetProperty Id="RemoveNavigationPaneEntries" Value="&quot;$(var.AppName)&quot;" Before="RemoveNavigationPaneEntries" Sequence="execute" />
<InstallExecuteSequence>
<!-- Install: Remove previous NSIS installation, if detected -->
<Custom Action="ExecNsisUninstaller" Before="ProcessComponents">NSIS_UNINSTALLEXE AND NOT Installed</Custom>
<!-- Uninstall: Remove sync folders from Explorer's Navigation Pane, only effective for the current user (home users) -->
<Custom Action="RemoveNavigationPaneEntries" After="RemoveFiles">(NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL")</Custom>
<!-- Schedule Reboot for the Shell Extensions -->
<ScheduleReboot After="InstallFinalize">NOT (DO_NOT_SCHEDULE_REBOOT=1)</ScheduleReboot>
</InstallExecuteSequence>
<!-- "Add or Remove" Programs Entries -->
<Property Id="ARPPRODUCTICON">$(var.AppIcon)</Property>
<Property Id="ARPHELPLINK">$(var.AppHelpLink)</Property>
<Property Id="ARPURLINFOABOUT">$(var.AppInfoLink)</Property>
<!-- https://www.firegiant.com/wix/tutorial/com-expression-syntax-miscellanea/add-or-remove-programs-entries/ -->
<!--
<Property Id="ARPNOMODIFY">1</Property>
<Property Id="ARPNOREPAIR">1</Property>
-->
<!-- App icon -->
<Icon Id="$(var.AppIcon)" SourceFile="$(var.HarvestAppDir)\$(var.AppIcon)" />
<!-- Custom bitmaps -->
<WixVariable Id="WixUIBannerBmp" Value="$(var.UIBannerBmp)" />
<WixVariable Id="WixUIDialogBmp" Value="$(var.UIDialogBmp)" />
<!-- Custom icons -->
<!-- https://wixtoolset.org/documentation/manual/v3/wixui/wixui_customizations.html -->
<!--
<WixVariable Id="WixUIExclamationIco" Value="ui\Exclam.ico" />
<WixVariable Id="WixUIInfoIco" Value="ui\Info.ico" />
<WixVariable Id="WixUINewIco" Value="ui\New.ico" />
<WixVariable Id="WixUIUpIco" Value="ui\Up.ico" />
-->
<!-- Custom license -->
<!--
<WixVariable Id="WixUILicenseRtf" Value="$(var.AppLicenseRtf)" />
-->
<UI>
<UIRef Id="WixUI_FeatureTree" />
<UIRef Id="WixUI_ErrorProgressText" />
<!-- Skip the license page -->
<Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="CustomizeDlg" Order="3">1</Publish>
<!-- Skip the page on the way back too -->
<Publish Dialog="CustomizeDlg" Control="Back" Event="NewDialog" Value="WelcomeDlg" Order="3">1</Publish>
<!-- https://wixtoolset.org/documentation/manual/v3/howtos/ui_and_localization/run_program_after_install.html -->
<Publish Dialog="ExitDialog"
Control="Finish"
Event="DoAction"
Value="LaunchApplication">WIXUI_EXITDIALOGOPTIONALCHECKBOX = 1 and NOT Installed</Publish>
<ProgressText Action="ExecNsisUninstaller">Removing previous installation</ProgressText>
<ProgressText Action="KillProcess">Trying to terminate application process of previous installation</ProgressText>
<ProgressText Action="RemoveNavigationPaneEntries">Removing sync folders from Explorer's Navigation Pane</ProgressText>
</UI>
<!-- "Launch" checkbox -->
<Property Id="WixShellExecTarget" Value="[#MainExecutable]" />
<CustomAction Id="LaunchApplication" BinaryKey="WixCA" DllEntry="WixShellExec" Impersonate="yes" />
<Property Id="WIXUI_EXITDIALOGOPTIONALCHECKBOXTEXT" Value="Launch $(var.AppName)" />
<SetProperty Id="WIXUI_EXITDIALOGOPTIONALCHECKBOX" Value="1" Before="CostInitialize">NOT (LAUNCH=0)</SetProperty>
<!-- Components -->
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="$(var.PlatformProgramFilesFolder)" Name="PFiles">
<Directory Id="INSTALLDIR" Name="$(var.AppName)">
<!-- Shell Extensions -->
<Directory Id="ShellExtDir" Name="shellext" />
</Directory>
</Directory>
<Directory Id="ProgramMenuFolder" Name="Programs">
<!-- Start Menu Shortcut -->
<Component Id="StartMenuIcon" Guid="*" Win64="$(var.PlatformWin64)">
<Shortcut Id="StartMenu" Name="$(var.AppName)" Target="[INSTALLDIR]$(var.AppExe)" WorkingDirectory="INSTALLDIR" Icon="$(var.AppIcon)" IconIndex="0" Advertise="no" />
<RegistryValue Root="HKCU" Key="Software\$(var.AppVendor)\$(var.AppName)" Name="installedStartMenuShortcut" Type="integer" Value="1" KeyPath="yes"/>
</Component>
</Directory>
<Directory Id="DesktopFolder" Name="Desktop">
<!-- Desktop Shortcut -->
<Component Id="DesktopIcon" Guid="*" Win64="$(var.PlatformWin64)">
<Shortcut Id="Desktop" Name="$(var.AppName)" Target="[INSTALLDIR]$(var.AppExe)" WorkingDirectory="INSTALLDIR" Icon="$(var.AppIcon)" IconIndex="0" Advertise="no" />
<RegistryValue Root="HKCU" Key="Software\$(var.AppVendor)\$(var.AppName)" Name="installedDesktopShortcut" Type="integer" Value="1" KeyPath="yes"/>
</Component>
</Directory>
</Directory>
<DirectoryRef Id="TARGETDIR">
<Component Id="RegistryEntries" Guid="*" Win64="no">
<!-- Version numbers used to detect existing installation (use 32-bit registry like NSIS does) -->
<RegistryKey Root="HKLM" Key="Software\$(var.AppVendor)\$(var.AppName)" ForceCreateOnInstall="yes" ForceDeleteOnUninstall="yes">
<RegistryValue Type="string" Value="[INSTALLDIR]" />
<RegistryValue Type="integer" Name="VersionMajor" Value="$(var.VerMajor)" />
<RegistryValue Type="integer" Name="VersionMinor" Value="$(var.VerMinor)" />
<RegistryValue Type="integer" Name="VersionRevision" Value="$(var.VerRevision)" />
<RegistryValue Type="integer" Name="VersionBuild" Value="$(var.VerBuild)" />
<!-- Save MSI ProductCode to allow being uninstalled by custom tools -->
<RegistryValue Type="string" Name="InstallerProductCode" Value="[ProductCode]" />
</RegistryKey>
</Component>
</DirectoryRef>
<!-- Features -->
<Feature Id="Client" Title="$(var.AppName) $(var.PlatformBitness)" Display="collapse" Absent="disallow" ConfigurableDirectory="INSTALLDIR"
Description="$(var.AppName) $(var.VerDesc)">
<ComponentGroupRef Id="ClientFiles" />
<ComponentRef Id="RegistryEntries" />
<Feature Id="ShellExtensions" Title="Integration for Windows Explorer"
Description="This feature requires a reboot." >
<ComponentGroupRef Id="ShellExtensions" />
<Condition Level="0">(NO_SHELL_EXTENSIONS=1)</Condition>
</Feature>
<Feature Id="StartMenuShortcut" Title="Start Menu Shortcut">
<ComponentRef Id="StartMenuIcon" />
<Condition Level="0">(NO_START_MENU_SHORTCUTS=1)</Condition>
</Feature>
<Feature Id="DesktopShortcut" Title="Desktop Shortcut">
<ComponentRef Id="DesktopIcon" />
<Condition Level="0">(NO_DESKTOP_SHORTCUT=1)</Condition>
</Feature>
</Feature>
</Product>
</Wix>

54
admin/win/msi/OEM.wxi.in Normal file
View file

@ -0,0 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
*
* Copyright (C) by Michael Schuster <michael.schuster@nextcloud.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
-->
<Include>
<!-- Changing the Vendor breaks registry (also NSIS) product detection -->
<?define AppVendor = "@APPLICATION_VENDOR@" ?>
<!-- App Defines -->
<?define AppName = "@APPLICATION_NAME@" ?>
<?define AppShortName = "@APPLICATION_EXECUTABLE@" ?>
<?define AppIcon = "@APPLICATION_ICON_NAME@.ico" ?>
<?define AppExe = "@APPLICATION_EXECUTABLE@.exe" ?>
<?define AppHelpLink = "https://@APPLICATION_DOMAIN@/" ?>
<?define AppInfoLink = "$(var.AppHelpLink)" ?>
<!-- Custom license: To use it, also remove the "Skip the license page" stuff in the <UI> section
and uncomment <WixVariable Id="WixUILicenseRtf"...
<?define AppLicenseRtf = "path\License.rtf" ?>
-->
<!-- App Version -->
<?define VerMajor = "@MIRALL_VERSION_MAJOR@" ?>
<?define VerMinor = "@MIRALL_VERSION_MINOR@" ?>
<?define VerRevision = "@MIRALL_VERSION_PATCH@" ?>
<?define VerBuild = "@MIRALL_VERSION_BUILD@" ?>
<?define VerStd = "$(var.VerMajor).$(var.VerMinor).$(var.VerRevision)" ?>
<?define VerFull = "$(var.VerStd).$(var.VerBuild)" ?>
<?define VerDesc = "@MIRALL_VERSION_STRING@ (Git revision @GIT_REVISION@)" ?>
<!-- MSI upgrade support -->
<?define UpgradeCode = "@WIN_MSI_UPGRADE_CODE@" ?>
<!-- UI resources -->
<?define UIBannerBmp = "banner.bmp" ?>
<?define UIDialogBmp = "dialog.bmp" ?>
</Include>

View file

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
*
* Copyright (C) by Michael Schuster <michael.schuster@nextcloud.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
-->
<Include>
<!--
MSI packages are built either for x86 or x64, we use defines to maintain a single WiX script.
Some hints:
https://www.joyofsetup.com/2010/05/14/working-hard-or-hardly-working/
https://stackoverflow.com/questions/18628790/build-wix-3-6-project-targeting-x64
https://www.howtobuildsoftware.com/index.php/how-do/1oQ/wix-detect-if-32-or-64-bit-windows-and-define-var
-->
<?if $(var.Platform) = x64 ?>
<?define PlatformBitness = "(64-bit)" ?>
<?define PlatformWin64 = "yes" ?>
<?define PlatformProgramFilesFolder = "ProgramFiles64Folder" ?>
<?else ?>
<?define PlatformBitness = "(32-bit)" ?>
<?define PlatformWin64 = "no" ?>
<?define PlatformProgramFilesFolder = "ProgramFilesFolder" ?>
<?endif ?>
</Include>

View file

@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wix="http://schemas.microsoft.com/wix/2006/wi">
<xsl:output method="xml" indent="yes" />
<!-- Copy all attributes and elements to the output. -->
<xsl:template match="@*|*">
<xsl:copy>
<xsl:apply-templates select="@*" />
<xsl:apply-templates select="*" />
</xsl:copy>
</xsl:template>
<!-- Identify MainExecutable -->
<xsl:key name="exe-search" match="wix:File[contains(@Source, '@APPLICATION_EXECUTABLE@.exe')]" use="@Id" />
<xsl:template match="wix:File[key('exe-search', @Id)]">
<xsl:copy>
<xsl:apply-templates select="@*" />
<xsl:attribute name="Id">
<xsl:text>MainExecutable</xsl:text>
</xsl:attribute>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<!-- Exclude Shell Extensions -->
<xsl:key name="shellext-search" match="wix:Component[contains(wix:File/@Source, 'shellext')]" use="@Id" />
<xsl:template match="wix:Component[key('shellext-search', @Id)]" />
<xsl:template match="wix:ComponentRef[key('shellext-search', @Id)]" />
<xsl:key name="shellext-search" match="wix:Directory[contains(@Name, 'shellext')]" use="@Id" />
<xsl:template match="wix:Directory[key('shellext-search', @Id)]" />
<!-- Exclude VC Redist -->
<xsl:key name="vc-redist-32-search" match="wix:Component[contains(wix:File/@Source, 'vc_redist.x86.exe')]" use="@Id" />
<xsl:template match="wix:Component[key('vc-redist-32-search', @Id)]" />
<xsl:template match="wix:ComponentRef[key('vc-redist-32-search', @Id)]" />
<xsl:key name="vc-redist-64-search" match="wix:Component[contains(wix:File/@Source, 'vc_redist.x64.exe')]" use="@Id" />
<xsl:template match="wix:Component[key('vc-redist-64-search', @Id)]" />
<xsl:template match="wix:ComponentRef[key('vc-redist-64-search', @Id)]" />
</xsl:stylesheet>

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

View file

@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
version="1.1"
id="Layer_1"
x="0px"
y="0px"
viewBox="0 0 462.18754 54.374996"
enable-background="new 0 0 196.6 72"
xml:space="preserve"
inkscape:version="1.0 (4035a4f, 2020-05-01)"
sodipodi:docname="banner.svg"
width="493"
height="58"
inkscape:export-filename="/Users/misch/nextcloud/_icon/_msi/banner.png"
inkscape:export-xdpi="96"
inkscape:export-ydpi="96"><metadata
id="metadata20"><rdf:RDF><cc:Work
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title /></cc:Work></rdf:RDF></metadata><defs
id="defs18"><clipPath
clipPathUnits="userSpaceOnUse"
id="clipPath8812"><circle
id="circle8814"
cx="95.669289"
cy="95.669296"
r="79.724197"
style="fill:#00080d;fill-opacity:1;stroke-width:1" /></clipPath></defs><sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="1"
inkscape:pageshadow="2"
inkscape:window-width="1440"
inkscape:window-height="812"
id="namedview16"
showgrid="false"
inkscape:zoom="1.3964178"
inkscape:cx="264.97589"
inkscape:cy="100.72146"
inkscape:current-layer="Layer_1"
fit-margin-top="10"
fit-margin-left="10"
fit-margin-right="10"
fit-margin-bottom="10"
inkscape:window-x="0"
inkscape:window-y="23"
inkscape:window-maximized="1"
units="px"
inkscape:snap-bbox="true"
inkscape:bbox-paths="true"
inkscape:bbox-nodes="true"
inkscape:snap-bbox-edge-midpoints="true"
inkscape:snap-bbox-midpoints="true"
inkscape:snap-page="true"
inkscape:document-rotation="0" /><path
inkscape:connector-curvature="0"
id="path1052"
d="m 411.83858,10.876373 c -7.55537,0 -13.95917,5.122046 -15.94393,12.061838 -1.72495,-3.680971 -5.463,-6.259801 -9.76856,-6.259801 -5.92119,0 -10.78856,4.867369 -10.78856,10.78855 0,5.921172 4.86737,10.790763 10.78856,10.790763 4.30556,0 8.04361,-2.580407 9.76856,-6.262024 1.98476,6.94032 8.38856,12.064068 15.94393,12.064068 7.49951,0 13.87065,-5.046471 15.90617,-11.908511 1.75682,3.598038 5.4486,6.106467 9.69302,6.106467 5.92118,0 10.79076,-4.869591 10.79076,-10.790763 0,-5.921181 -4.86958,-10.78855 -10.79076,-10.78855 -4.24442,0 -7.9362,2.506858 -9.69302,6.10425 -2.03552,-6.861503 -8.40666,-11.906287 -15.90617,-11.906287 z m 0,6.333131 c 5.70346,0 10.25968,4.554019 10.25968,10.257456 0,5.703427 -4.55622,10.259672 -10.25968,10.259672 -5.70341,0 -10.25743,-4.556245 -10.25743,-10.259672 0,-5.703437 4.55402,-10.257454 10.25743,-10.257456 z m -25.71249,5.802039 c 2.4988,0 4.45763,1.9566 4.45763,4.455417 0,2.498807 -1.95883,4.457631 -4.45763,4.457631 -2.49882,0 -4.45544,-1.958824 -4.45544,-4.457631 0,-2.498817 1.95662,-4.455417 4.45544,-4.455417 z m 51.31168,0 c 2.49883,0 4.45764,1.9566 4.45764,4.455417 0,2.498807 -1.95883,4.457631 -4.45764,4.457631 -2.49879,0 -4.45541,-1.958824 -4.45541,-4.457631 0,-2.498817 1.95662,-4.455417 4.45541,-4.455417 z"
style="color:#000000;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:medium;line-height:normal;font-family:sans-serif;text-indent:0;text-align:start;text-decoration:none;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;writing-mode:lr-tb;direction:ltr;baseline-shift:baseline;text-anchor:start;white-space:normal;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#0082c9;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:3.56218;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:10;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
inkscape:export-filename="Nextcloud Hub logo variants.png"
inkscape:export-xdpi="300"
inkscape:export-ydpi="300" /></svg>

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 454 KiB

View file

@ -0,0 +1,26 @@
@echo off
set HarvestAppDir=%~1
set BuildArch=@MSI_BUILD_ARCH@
if "%HarvestAppDir%" == "" (
echo "Missing parameter: Please specify file collection source path (HarvestAppDir)."
exit 1
)
if "%WIX%" == "" (
echo "WiX Toolset path not set (environment variable 'WIX'). Please install the WiX Toolset."
exit 1
)
Rem Generate collect.wxs
"%WIX%\bin\heat.exe" dir "%HarvestAppDir%" -dr INSTALLDIR -sreg -srd -sfrag -ag -cg ClientFiles -var var.HarvestAppDir -platform='%BuildArch%' -t collect-transform.xsl -out collect.wxs
if %ERRORLEVEL% neq 0 exit %ERRORLEVEL%
Rem Compile en-US (https://www.firegiant.com/wix/tutorial/transforms/morphing-installers/)
"%WIX%\bin\candle.exe" -dcodepage=1252 -dPlatform=%BuildArch% -arch %BuildArch% -dHarvestAppDir="%HarvestAppDir%" -ext WixUtilExtension NCMsiHelper.wxs WinShellExt.wxs collect.wxs Nextcloud.wxs
if %ERRORLEVEL% neq 0 exit %ERRORLEVEL%
Rem Link MSI package
"%WIX%\bin\light.exe" -sw1076 -ext WixUIExtension -ext WixUtilExtension -cultures:en-us NCMsiHelper.wixobj WinShellExt.wixobj collect.wixobj Nextcloud.wixobj -out "@MSI_INSTALLER_FILENAME@"
exit %ERRORLEVEL%

View file

@ -0,0 +1,63 @@
cmake_minimum_required(VERSION 3.2)
set(CMAKE_CXX_STANDARD 17)
if(CMAKE_SIZEOF_VOID_P MATCHES 4)
set(BITNESS 32)
else()
set(BITNESS 64)
endif()
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
NCToolsShared
)
add_definitions(-DUNICODE)
add_definitions(-D_UNICODE)
add_definitions(-DNDEBUG)
add_definitions(-D_WINDOWS)
# Get APIs from from Vista onwards.
add_definitions(-D_WIN32_WINNT=0x0601)
add_definitions(-DWINVER=0x0601)
# Use automatic overload for suitable CRT safe-functions
# See https://docs.microsoft.com/de-de/cpp/c-runtime-library/security-features-in-the-crt?view=vs-2019
add_definitions(-D_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES=1)
# Also: Disable compiler warnings because we don't use Windows CRT safe-functions explicitly and don't intend to
# as this is a pure cross-platform source the only alternative would be a ton of ifdefs with calls to the _s version
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
# Optimize for size
set(COMPILER_FLAGS "/GL /O1 /sdl /Zc:inline /Oi /EHsc /nologo")
set(LINKER_FLAGS "/LTCG /OPT:REF /SUBSYSTEM:WINDOWS /NOLOGO")
# Enable DEP, ASLR and CFG
set(LINKER_FLAGS "${LINKER_FLAGS} /nxcompat /dynamicbase /guard:cf")
# x86 only: Enable SafeSEH
if(CMAKE_SIZEOF_VOID_P MATCHES 4)
set(LINKER_FLAGS "${LINKER_FLAGS} /safeseh")
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMPILER_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMPILER_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LINKER_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${LINKER_FLAGS}")
# Use static runtime for all subdirectories
foreach(buildType "" "_DEBUG" "_MINSIZEREL" "_RELEASE" "_RELWITHDEBINFO")
string(REPLACE "/MD" "/MT" "CMAKE_CXX_FLAGS${buildType}" "${CMAKE_CXX_FLAGS${buildType}}")
endforeach()
add_subdirectory(NCToolsShared)
if(BUILD_WIN_MSI)
add_subdirectory(NCMsiHelper)
endif()
if(BUILD_WIN_TOOLS)
add_subdirectory(NCNavRemove)
endif()

View file

@ -0,0 +1,41 @@
# Find WiX Toolset
if(NOT DEFINED ENV{WIX})
# Example: WIX=C:\Program Files (x86)\WiX Toolset v3.11\
message(FATAL_ERROR "WiX Toolset path not set (environment variable 'WIX'). Please install the WiX Toolset.")
else()
set(WIX_SDK_PATH $ENV{WIX}/SDK/VS2017)
message(STATUS "WiX Toolset SDK path: ${WIX_SDK_PATH}")
endif()
include_directories(${WIX_SDK_PATH}/inc)
if(CMAKE_SIZEOF_VOID_P MATCHES 4)
link_directories(${WIX_SDK_PATH}/lib/x86)
else()
link_directories(${WIX_SDK_PATH}/lib/x64)
endif()
add_definitions(-D_NCMSIHELPER_EXPORTS)
add_definitions(-D_USRDLL)
add_definitions(-D_WINDLL)
set(TARGET_NAME NCMsiHelper${BITNESS})
add_library(${TARGET_NAME} MODULE
CustomAction.cpp
CustomAction.def
LogResult.cpp
NCMsiHelper.cpp
)
target_link_libraries(${TARGET_NAME}
NCToolsShared
)
install(TARGETS ${TARGET_NAME}
DESTINATION msi/
)
install(FILES
NCMsiHelper.wxs
DESTINATION msi/
)

View file

@ -0,0 +1,118 @@
/*
* Copyright (C) by Michael Schuster <michael.schuster@nextcloud.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* Parts of this file are based on:
* https://www.codeproject.com/articles/570751/devmsi-an-example-cplusplus-msi-wix-deferred-custo
*
* Licensed under the The Code Project Open License (CPOL):
* https://www.codeproject.com/info/cpol10.aspx
*
*/
#include "NCMsiHelper.h"
/**
* Sets up logging for MSIs and then calls the appropriate custom action with argc/argv parameters.
*
* MSI deferred custom action dlls have to handle parameters (properties) a little differently,
* since the deferred action may not have an active session when it begins. Since the easiest
* way to pass parameter(s) is to put them all into a CustomActionData property and then retrieve it,
* the easiest thing to do on this ( C/C++ ) end is to pull the parameter and then split it into
* a list of parameter(s) that we need.
*
* For this implementation, it made sense to treat the single string provided in CustomActionData
* as if it were a command line, and then parse it out just as if it were a command line. Obviously,
* the "program name" isn't going to be the first argument unless the MSI writer is pedantic, but
* otherwise it seems to be a good way to do it.
*
* Since all entry points need to do this same work, it was easiest to have a single function that
* would do the setup, pull the CustomActionData parameter, split it into an argc/argv style of
* argument list, and then pass that argument list into a function that actually does something
* interesting.
*
* @param hInstall The hInstall parameter provided by MSI/WiX.
* @param func The function to be called with argc/argv parameters.
* @param actionName The text description of the function. It will be put in the log.
* @return Returns ERROR_SUCCESS or ERROR_INSTALL_FAILURE.
*/
UINT CustomActionArgcArgv(MSIHANDLE hInstall, CUSTOM_ACTION_ARGC_ARGV func, LPCSTR actionName)
{
LPWSTR pszCustomActionData = nullptr, *argv = nullptr;
HRESULT hr = WcaInitialize(hInstall, actionName);
ExitOnFailure(hr, "Failed to initialize");
WcaLog(LOGMSG_STANDARD, "Initialized.");
// Retrieve our custom action property. This is one of
// only three properties we can request on a Deferred
// Custom Action. So, we assume the caller puts all
// parameters in this one property.
hr = WcaGetProperty(L"CustomActionData", &pszCustomActionData);
ExitOnFailure(hr, "Failed to get Custom Action Data.");
WcaLog(LOGMSG_STANDARD, "Custom Action Data = '%ls'.", pszCustomActionData);
// Convert the string retrieved into a standard argc/arg layout
// (ignoring the fact that the first parameter is whatever was
// passed, not necessarily the application name/path).
int argc = 0;
argv = CommandLineToArgvW(pszCustomActionData, &argc);
if (argv) {
hr = HRESULT_FROM_WIN32(GetLastError());
ExitOnFailure(hr, "Failed to convert Custom Action Data to argc/argv.");
}
hr = (func)(argc, argv);
ExitOnFailure(hr, "Custom action failed");
LExit:
// Resource freeing here!
ReleaseStr(pszCustomActionData);
if (argv)
LocalFree(argv);
return WcaFinalize(SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE);
}
UINT __stdcall ExecNsisUninstaller(MSIHANDLE hInstall)
{
return CustomActionArgcArgv(hInstall, DoExecNsisUninstaller, "ExecNsisUninstaller");
}
UINT __stdcall RemoveNavigationPaneEntries(MSIHANDLE hInstall)
{
return CustomActionArgcArgv(hInstall, DoRemoveNavigationPaneEntries, "RemoveNavigationPaneEntries");
}
/**
* DllMain - Initialize and cleanup WiX custom action utils.
*/
extern "C" BOOL WINAPI DllMain(
__in HINSTANCE hInst,
__in ULONG ulReason,
__in LPVOID
)
{
switch(ulReason)
{
case DLL_PROCESS_ATTACH:
WcaGlobalInitialize(hInst);
break;
case DLL_PROCESS_DETACH:
WcaGlobalFinalize();
break;
}
return TRUE;
}

View file

@ -0,0 +1,3 @@
EXPORTS
ExecNsisUninstaller
RemoveNavigationPaneEntries

View file

@ -0,0 +1,134 @@
/*
* Copyright (C) by Michael Schuster <michael.schuster@nextcloud.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* Parts of this file are based on:
* https://www.codeproject.com/articles/570751/devmsi-an-example-cplusplus-msi-wix-deferred-custo
*
* Licensed under the The Code Project Open License (CPOL):
* https://www.codeproject.com/info/cpol10.aspx
*
*/
#include "NCMsiHelper.h"
//
// This code modified from MSDN article 256348
// "How to obtain error message descriptions using the FormatMessage API"
// Currently found at http://support.microsoft.com/kb/256348/en-us
#define ERRMSGBUFFERSIZE 256
/**
* Use FormatMessage() to look an error code and log the error text.
*
* @param dwErrorMsgId The error code to be investigated.
*/
void LogError(DWORD dwErrorMsgId)
{
HLOCAL pBuffer = nullptr; // Buffer to hold the textual error description.
DWORD ret = 0; // Temp space to hold a return value.
HINSTANCE hInst = nullptr; // Instance handle for DLL.
bool doLookup = true;
DWORD dwMessageId = dwErrorMsgId;
LPCSTR pMessage = "Error %d";
DWORD flags = FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS;
if (HRESULT_FACILITY(dwErrorMsgId) == FACILITY_MSMQ) {
hInst = LoadLibrary(TEXT("MQUTIL.DLL"));
flags |= FORMAT_MESSAGE_FROM_HMODULE;
doLookup = (nullptr != hInst);
} else if (dwErrorMsgId >= NERR_BASE && dwErrorMsgId <= MAX_NERR) {
hInst = LoadLibrary(TEXT("NETMSG.DLL"));
flags |= FORMAT_MESSAGE_FROM_HMODULE;
doLookup = (nullptr != hInst);
} else if (HRESULT_FACILITY(dwErrorMsgId) == FACILITY_WIN32) {
// A "GetLastError" error, drop the HRESULT_FACILITY
dwMessageId &= 0x0000FFFF;
flags |= FORMAT_MESSAGE_FROM_SYSTEM;
}
if (doLookup) {
ret = FormatMessageA(
flags,
hInst, // Handle to the DLL.
dwMessageId, // Message identifier.
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language.
reinterpret_cast<LPSTR>(&pBuffer), // Buffer that will hold the text string.
ERRMSGBUFFERSIZE, // Allocate at least this many chars for pBuffer.
nullptr // No insert values.
);
}
if (0 < ret && nullptr != pBuffer) {
pMessage = static_cast<LPSTR>(pBuffer);
}
// Display the string.
if (WcaIsInitialized()) {
WcaLogError(dwErrorMsgId, pMessage, dwMessageId);
} else {
// Log to stdout/stderr
fprintf_s(stderr, pMessage, dwMessageId);
if ('\n' != pMessage[strlen(pMessage) - 1]) {
fprintf_s(stderr, "\n");
}
}
// Free the buffer.
LocalFree(pBuffer);
}
void LogResult(
__in HRESULT hr,
__in_z __format_string PCSTR fmt, ...
)
{
// This code taken from MSDN vsprintf example found currently at
// http://msdn.microsoft.com/en-us/library/28d5ce15(v=vs.71).aspx
// ...and then modified... because it doesn't seem to work!
va_list args;
va_start(args, fmt);
#pragma warning(push)
#pragma warning(disable : 4996)
const auto len = _vsnprintf(nullptr, 0, fmt, args) + 1;
#pragma warning(pop)
auto buffer = static_cast<char*>(malloc(len * sizeof(char)));
#ifdef _DEBUG
::ZeroMemory(buffer, len);
#endif // _DEBUG
_vsnprintf_s(buffer, len, len - 1, fmt, args);
// (MSDN code complete)
// Now that the buffer holds the formatted string, send it to
// the appropriate output.
if (WcaIsInitialized()) {
if (FAILED(hr)) {
WcaLogError(hr, buffer);
LogError(hr);
} else {
WcaLog(LOGMSG_STANDARD, buffer);
}
} else { // Log to stdout/stderr
if (FAILED(hr)) {
fprintf_s(stderr, "%s\n", buffer);
LogError(hr);
} else {
fprintf_s(stdout, "%s\n", buffer);
}
}
free(buffer);
}

View file

@ -0,0 +1,48 @@
/*
* Copyright (C) by Michael Schuster <michael.schuster@nextcloud.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* Parts of this file are based on:
* https://www.codeproject.com/articles/570751/devmsi-an-example-cplusplus-msi-wix-deferred-custo
*
* Licensed under the The Code Project Open License (CPOL):
* https://www.codeproject.com/info/cpol10.aspx
*
*/
/**
* Function prototype for LogResult()
*/
#pragma once
/**
* Log a message.
*
* If the DLL is being used in a WiX MSI environment, LogResult() will
* route any log messages to the MSI log file via WcaLog() or WcaLogError().
*
* If the DLL is NOT being used in a WiX MSI environment, LogResult() will
* route any log messages to stdout or stderr.
*
* If the result is an error code, LogResult will attempt to gather a
* text version of the error code and place it in the log. For example,
* if the error code means ERROR_FILE_NOT_FOUND, it will look up the appropriate
* message ( via FormatMessage() ) and add "The system cannot find the file specified."
* to the log.
*
* @param hr The HRESULT to be interrogated for success or failure.
* @param fmt The string format for a user-specified error message.
*/
void LogResult(
__in HRESULT hr,
__in_z __format_string PCSTR fmt, ...
);

View file

@ -0,0 +1,84 @@
/*
* Copyright (C) by Michael Schuster <michael.schuster@nextcloud.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include "NCMsiHelper.h"
#include "utility.h"
#include "LogResult.h"
using namespace NCTools;
HRESULT NCMSIHELPER_API DoExecNsisUninstaller(int argc, LPWSTR *argv)
{
if (argc != 2) {
return HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);
}
const auto appShortName = std::wstring(argv[0]);
const auto uninstallExePath = std::wstring(argv[1]);
if (appShortName.empty()
|| uninstallExePath.empty()) {
return HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);
}
auto appInstallDir = uninstallExePath;
const auto posLastSlash = appInstallDir.find_last_of(PathSeparator);
if (posLastSlash != std::wstring::npos) {
appInstallDir.erase(posLastSlash);
} else {
return HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);
}
// Run uninstaller
const std::wstring cmd = L'\"' + uninstallExePath + L"\" /S _?=" + appInstallDir;
LogResult(S_OK, "Running '%ls'.", cmd.data());
Utility::execCmd(cmd);
LogResult(S_OK, "Waiting for NSIS uninstaller.");
// Can't wait for the process because Uninstall.exe (opposed to Setup.exe) immediately returns, so we'll sleep a bit.
Utility::waitForNsisUninstaller(appShortName);
LogResult(S_OK, "Removing the NSIS uninstaller.");
// Sleep a bit and clean up the NSIS mess
Sleep(1500);
DeleteFile(uninstallExePath.data());
RemoveDirectory(appInstallDir.data());
LogResult(S_OK, "Finished.");
return S_OK;
}
HRESULT NCMSIHELPER_API DoRemoveNavigationPaneEntries(int argc, LPWSTR *argv)
{
if (argc != 1) {
return HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);
}
const auto appName = std::wstring(argv[0]);
if (appName.empty()) {
return HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);
}
LogResult(S_OK, "Removing '%ls' sync folders from Explorer's Navigation Pane for the current user.", appName.data());
Utility::removeNavigationPaneEntries(appName);
LogResult(S_OK, "Finished.");
return S_OK;
}

View file

@ -0,0 +1,99 @@
/*
* Copyright (C) by Michael Schuster <michael.schuster@nextcloud.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* Parts of this file are based on:
* https://www.codeproject.com/articles/570751/devmsi-an-example-cplusplus-msi-wix-deferred-custo
*
* Licensed under the The Code Project Open License (CPOL):
* https://www.codeproject.com/info/cpol10.aspx
*
*/
/**
* Function prototypes for external "C" interfaces into the DLL.
*
* This project builds a "hybrid" DLL that will work either from
* a MSI Custom Action environment or from an external C program.
* The former routes through "C" interface functions defined in
* CustomAction.def. The latter uses the interfaces defined here.
*
* This header is suitable for inclusion by a project wanting to
* call these methods. Note that _NCMSIHELPER_EXPORTS should not be
* defined for the accessing application source code.
*/
#pragma once
#include <windows.h>
#ifdef _NCMSIHELPER_EXPORTS
# pragma comment (lib, "newdev")
# pragma comment (lib, "setupapi")
# pragma comment (lib, "msi")
# pragma comment (lib, "dutil")
# pragma comment (lib, "wcautil")
# pragma comment (lib, "Version")
# include <cstdlib>
# include <string>
# include <tchar.h>
# include <msiquery.h>
# include <lmerr.h>
// WiX Header Files:
# include <wcautil.h>
# include <strutil.h>
# define NCMSIHELPER_API __declspec(dllexport)
#else
# define NCMSIHELPER_API __declspec(dllimport)
#endif
/**
* Runs the NSIS uninstaller and waits for its completion.
*
* argc MUST be 2.
*
* argv[0] is APPLICATION_EXECUTABLE, e.g. "nextcloud"
* argv[1] is the full path to "Uninstall.exe"
*
* @param argc The count of valid arguments in argv.
* @param argv An array of string arguments for the function.
* @return Returns an HRESULT indicating success or failure.
*/
HRESULT NCMSIHELPER_API DoExecNsisUninstaller(int argc, LPWSTR *argv);
/**
* Removes the Explorer's Navigation Pane entries.
*
* argc MUST be 1.
*
* argv[0] is APPLICATION_NAME, e.g. "Nextcloud"
*
* @param argc The count of valid arguments in argv.
* @param argv An array of string arguments for the function.
* @return Returns an HRESULT indicating success or failure.
*/
HRESULT NCMSIHELPER_API DoRemoveNavigationPaneEntries(int argc, LPWSTR *argv);
/**
* Standardized function prototype for NCMsiHelper.
*
* Functions in NCMsiHelper can be called through the MSI Custom
* Action DLL or through an external C program. Both
* methods expect to wrap things into this function prototype.
*
* As a result, all functions defined in this header should
* conform to this function prototype.
*/
using CUSTOM_ACTION_ARGC_ARGV = NCMSIHELPER_API HRESULT(*)(int argc, LPWSTR *argv);

View file

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
*
* Copyright (C) by Michael Schuster <michael.schuster@nextcloud.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
-->
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Fragment>
<?if $(var.Platform) = x64 ?>
<?define bitness = "64" ?>
<?else ?>
<?define bitness = "32" ?>
<?endif ?>
<Binary Id="NCMsiHelper" SourceFile="NCMsiHelper$(var.bitness).dll" />
<CustomAction Id="ExecNsisUninstaller"
Return="ignore"
BinaryKey="NCMsiHelper"
DllEntry="ExecNsisUninstaller"
Execute="deferred"
Impersonate="no" />
<CustomAction Id="RemoveNavigationPaneEntries"
Return="ignore"
BinaryKey="NCMsiHelper"
DllEntry="RemoveNavigationPaneEntries"
Execute="deferred"
Impersonate="yes" />
</Fragment>
</Wix>

View file

@ -0,0 +1,14 @@
project(NCNavRemove)
set(MUTEX_NAME "NCNavRemove")
configure_file(NavRemoveConstants.h.in ${CMAKE_CURRENT_BINARY_DIR}/NavRemoveConstants.h)
configure_file(NavRemove.ini.in ${CMAKE_CURRENT_BINARY_DIR}/NavRemove.ini)
configure_file(version.rc.in ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
add_subdirectory(dll)
add_subdirectory(exe)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/NavRemove.ini
DESTINATION tools/NCNavRemove/
)

View file

@ -0,0 +1,77 @@
/*
* Copyright (C) by Michael Schuster <michael.schuster@nextcloud.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include <windows.h>
#include "3rdparty/SimpleIni.h"
#include "NavRemoveConstants.h"
#include "ConfigIni.h"
ConfigIni::ConfigIni()
{
}
bool ConfigIni::load()
{
const DWORD bufferLen = GetCurrentDirectory(0, nullptr);
TCHAR *pszBuffer = nullptr;
if (bufferLen == 0) {
return false;
}
pszBuffer = new TCHAR[bufferLen];
if (!pszBuffer) {
return false;
}
std::wstring filename;
if (GetCurrentDirectory(bufferLen, pszBuffer) != 0) {
filename = pszBuffer;
}
delete[] pszBuffer;
if (filename.empty()) {
return false;
}
filename.append(L"\\");
filename.append(INI_NAME);
CSimpleIni ini;
const wchar_t iniSection[] = CFG_KEY;
const wchar_t iniKey[] = CFG_VAR_APPNAME;
const auto rc = ini.LoadFile(filename.data());
if (rc != SI_OK) {
return false;
}
const auto pv = ini.GetValue(iniSection, iniKey);
bool success = false;
if (pv) {
_appName = pv;
success = !_appName.empty();
}
ini.Reset();
return success;
}
std::wstring ConfigIni::getAppName() const
{
return _appName;
}

View file

@ -0,0 +1,30 @@
/*
* Copyright (C) by Michael Schuster <michael.schuster@nextcloud.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#pragma once
#include <string>
class ConfigIni
{
public:
ConfigIni();
bool load();
std::wstring getAppName() const;
private:
std::wstring _appName;
};

View file

@ -0,0 +1,2 @@
[NavRemove]
ApplicationName=@APPLICATION_NAME@

View file

@ -0,0 +1,9 @@
#pragma once
#define MUTEX_NAME L"@MUTEX_NAME@"
#define TOOL_NAME L"NCNavRemove (@BITNESS@-bit)"
#define TOOL_DESCRIPTION L"Removes all Explorer Navigation Pane entries for a given ApplicationName."
#define INI_NAME L"NavRemove.ini"
#define CFG_KEY L"NavRemove"
#define CFG_VAR_APPNAME L"ApplicationName"

View file

@ -0,0 +1,25 @@
add_definitions(-D_NAVREMOVE_EXPORTS)
add_definitions(-D_USRDLL)
add_definitions(-D_WINDLL)
include_directories(
${CMAKE_CURRENT_BINARY_DIR}/../
)
set(TARGET_NAME libNavRemove${BITNESS})
add_library(${TARGET_NAME} MODULE
dllmain.cpp
NavRemove.cpp
exports.def
../ConfigIni.cpp
${CMAKE_CURRENT_BINARY_DIR}/../version.rc
)
target_link_libraries(${TARGET_NAME}
NCToolsShared
)
install(TARGETS ${TARGET_NAME}
DESTINATION tools/NCNavRemove/dll/
)

View file

@ -0,0 +1,40 @@
/*
* Copyright (C) by Michael Schuster <michael.schuster@nextcloud.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include <windows.h>
#include "utility.h"
#include "NavRemove.h"
#include "../ConfigIni.h"
using namespace NCTools;
extern bool g_alreadyRunning;
HRESULT NAVREMOVE_API RemoveNavigationPaneEntries()
{
if (g_alreadyRunning) {
return S_OK;
}
// Config
ConfigIni ini;
if (!ini.load()) {
return HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);
}
Utility::removeNavigationPaneEntries(ini.getAppName());
return S_OK;
}

View file

@ -0,0 +1,32 @@
/*
* Copyright (C) by Michael Schuster <michael.schuster@nextcloud.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#pragma once
#include <windows.h>
// The following ifdef block is the standard way of creating macros which make exporting
// from a DLL simpler. All files within this DLL are compiled with the _NAVREMOVE_EXPORTS
// symbol defined on the command line. This symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see
// NAVREMOVE_API functions as being imported from a DLL, whereas this DLL sees symbols
// defined with this macro as being exported.
#ifdef _NAVREMOVE_EXPORTS
#define NAVREMOVE_API __declspec(dllexport)
#else
#define NAVREMOVE_API __declspec(dllimport)
#endif
NAVREMOVE_API HRESULT RemoveNavigationPaneEntries();

View file

@ -0,0 +1,42 @@
/*
* Copyright (C) by Michael Schuster <michael.schuster@nextcloud.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include <windows.h>
#include "SimpleNamedMutex.h"
#include "NavRemoveConstants.h"
SimpleNamedMutex g_mutex(std::wstring(MUTEX_NAME));
bool g_alreadyRunning = false;
extern "C" BOOL WINAPI DllMain(
__in HINSTANCE hInst,
__in ULONG ulReason,
__in LPVOID
)
{
switch(ulReason)
{
case DLL_PROCESS_ATTACH:
// Mutex
g_alreadyRunning = !g_mutex.lock();
break;
case DLL_PROCESS_DETACH:
// Release mutex
g_mutex.unlock();
break;
}
return TRUE;
}

View file

@ -0,0 +1,2 @@
EXPORTS
RemoveNavigationPaneEntries

View file

@ -0,0 +1,19 @@
set(TARGET_NAME NavRemove${BITNESS})
include_directories(
${CMAKE_CURRENT_BINARY_DIR}/../
)
add_executable(${TARGET_NAME} WIN32
main.cpp
../ConfigIni.cpp
${CMAKE_CURRENT_BINARY_DIR}/../version.rc
)
target_link_libraries(${TARGET_NAME}
NCToolsShared
)
install(TARGETS ${TARGET_NAME}
DESTINATION tools/NCNavRemove/exe/
)

View file

@ -0,0 +1,53 @@
/*
* Copyright (C) by Michael Schuster <michael.schuster@nextcloud.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include <windows.h>
#include "utility.h"
#include "SimpleNamedMutex.h"
#include "NavRemoveConstants.h"
#include "../ConfigIni.h"
using namespace NCTools;
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPWSTR lpCmdLine,
_In_ int nCmdShow)
{
UNREFERENCED_PARAMETER(hInstance);
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
UNREFERENCED_PARAMETER(nCmdShow);
// Mutex
SimpleNamedMutex mutex(std::wstring(MUTEX_NAME));
if (!mutex.lock()) {
return 0;
}
// Config
ConfigIni ini;
if (!ini.load()) {
return 1;
}
Utility::removeNavigationPaneEntries(ini.getAppName());
// Release mutex
mutex.unlock();
return 0;
}

View file

@ -0,0 +1,40 @@
#include "winresrc.h"
#include "NavRemoveConstants.h"
#define VER_FILEVERSION @MIRALL_VERSION_MAJOR@,@MIRALL_VERSION_MINOR@,@MIRALL_VERSION_PATCH@,@MIRALL_VERSION_BUILD@
#define VER_FILEVERSION_STR "@MIRALL_VERSION_MAJOR@.@MIRALL_VERSION_MINOR@.@MIRALL_VERSION_PATCH@.@MIRALL_VERSION_BUILD@\0"
#define VER_PRODUCTVERSION @MIRALL_VERSION_MAJOR@,@MIRALL_VERSION_MINOR@,@MIRALL_VERSION_PATCH@,@MIRALL_VERSION_BUILD@
#define VER_PRODUCTVERSION_STR "@MIRALL_VERSION_MAJOR@.@MIRALL_VERSION_MINOR@.@MIRALL_VERSION_PATCH@.@MIRALL_VERSION_BUILD@\0"
#define VER_PRODUCTNAME_STR TOOL_NAME
#define VER_COMPANYNAME_STR "@APPLICATION_VENDOR@"
#define VER_COPYRIGHT_STR "(c) @MIRALL_VERSION_YEAR@"
#define VER_PRODUCTDESC_STR TOOL_DESCRIPTION
VS_VERSION_INFO VERSIONINFO
FILEVERSION VER_FILEVERSION
PRODUCTVERSION VER_PRODUCTVERSION
FILEOS VOS__WINDOWS32
FILETYPE VFT_APP
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "080904b0"
BEGIN
VALUE "CompanyName", VER_COMPANYNAME_STR
VALUE "LegalCopyright", VER_COPYRIGHT_STR
VALUE "FileVersion", VER_FILEVERSION_STR
VALUE "Comment", VER_PRODUCTNAME_STR
VALUE "FileDescription", VER_PRODUCTDESC_STR
VALUE "ProductName", VER_PRODUCTNAME_STR
VALUE "ProductVersion", VER_PRODUCTVERSION_STR
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x809, 1200
END
END

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,4 @@
add_library(NCToolsShared STATIC
utility_win.cpp
SimpleNamedMutex.cpp
)

View file

@ -0,0 +1,48 @@
/*
* Copyright (C) by Michael Schuster <michael.schuster@nextcloud.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include "SimpleNamedMutex.h"
SimpleNamedMutex::SimpleNamedMutex(const std::wstring &name)
{
_name = name;
}
bool SimpleNamedMutex::lock()
{
if (_name.empty() || _hMutex) {
return false;
}
// Mutex
_hMutex = CreateMutex(nullptr, TRUE, _name.data());
if (GetLastError() == ERROR_ALREADY_EXISTS) {
CloseHandle(_hMutex);
_hMutex = nullptr;
return false;
}
return true;
}
void SimpleNamedMutex::unlock()
{
// Release mutex
if (_hMutex) {
ReleaseMutex(_hMutex);
CloseHandle(_hMutex);
_hMutex = nullptr;
}
}

View file

@ -0,0 +1,31 @@
/*
* Copyright (C) by Michael Schuster <michael.schuster@nextcloud.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#pragma once
#include <windows.h>
#include <string>
class SimpleNamedMutex
{
public:
SimpleNamedMutex(const std::wstring &name);
bool lock();
void unlock();
private:
std::wstring _name;
HANDLE _hMutex = nullptr;
};

View file

@ -0,0 +1,58 @@
/*
* Copyright (C) by Klaas Freitag <freitag@owncloud.com>
* Copyright (C) by Daniel Molkentin <danimo@owncloud.com>
* Copyright (C) by Michael Schuster <michael.schuster@nextcloud.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#pragma once
#include <windows.h>
#include <string>
#include <vector>
#include <variant>
#include <functional>
namespace NCTools {
typedef std::variant<int, std::wstring, std::vector<unsigned char>> registryVariant;
static const std::wstring PathSeparator = L"\\";
namespace Utility {
// Ported from libsync
registryVariant registryGetKeyValue(HKEY hRootKey, const std::wstring& subKey, const std::wstring& valueName);
bool registrySetKeyValue(HKEY hRootKey, const std::wstring &subKey, const std::wstring &valueName, DWORD type, const registryVariant &value);
bool registryDeleteKeyTree(HKEY hRootKey, const std::wstring &subKey);
bool registryDeleteKeyValue(HKEY hRootKey, const std::wstring &subKey, const std::wstring &valueName);
bool registryWalkSubKeys(HKEY hRootKey, const std::wstring &subKey, const std::function<void(HKEY, const std::wstring&)> &callback);
// Ported from gui, modified to optionally rename matching files
typedef std::function<void(const std::wstring&, std::wstring&)> copy_dir_recursive_callback;
bool copy_dir_recursive(std::wstring from_dir, std::wstring to_dir, copy_dir_recursive_callback* callbackFileNameMatchReplace = nullptr);
// Created for native Win32
DWORD execCmd(std::wstring cmd, bool wait = true);
bool killProcess(const std::wstring &exePath);
bool isValidDirectory(const std::wstring &path);
std::wstring getAppRegistryString(const std::wstring &appVendor, const std::wstring &appName, const std::wstring &valueName);
std::wstring getAppPath(const std::wstring &appVendor, const std::wstring &appName);
std::wstring getConfigPath(const std::wstring &appName);
void waitForNsisUninstaller(const std::wstring& appShortName);
void removeNavigationPaneEntries(const std::wstring &appName);
}
} // namespace NCTools

View file

@ -0,0 +1,477 @@
/*
* Copyright (C) by Daniel Molkentin <danimo@owncloud.com>
* Copyright (C) by Michael Schuster <michael.schuster@nextcloud.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "utility.h"
#include <cassert>
#include <algorithm>
#include <Shlobj.h>
#include <psapi.h>
#define ASSERT assert
#define Q_ASSERT assert
namespace NCTools {
// Ported from libsync
registryVariant Utility::registryGetKeyValue(HKEY hRootKey, const std::wstring &subKey, const std::wstring &valueName)
{
registryVariant value;
HKEY hKey;
REGSAM sam = KEY_READ | KEY_WOW64_64KEY;
LONG result = RegOpenKeyEx(hRootKey, reinterpret_cast<LPCWSTR>(subKey.data()), 0, sam, &hKey);
ASSERT(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND);
if (result != ERROR_SUCCESS)
return value;
DWORD type = 0, sizeInBytes = 0;
result = RegQueryValueEx(hKey, reinterpret_cast<LPCWSTR>(valueName.data()), 0, &type, nullptr, &sizeInBytes);
ASSERT(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND);
if (result == ERROR_SUCCESS) {
switch (type) {
case REG_DWORD:
DWORD dword;
Q_ASSERT(sizeInBytes == sizeof(dword));
if (RegQueryValueEx(hKey, reinterpret_cast<LPCWSTR>(valueName.data()), 0, &type, reinterpret_cast<LPBYTE>(&dword), &sizeInBytes) == ERROR_SUCCESS) {
value = int(dword);
}
break;
case REG_EXPAND_SZ:
case REG_SZ: {
std::wstring string;
string.resize(sizeInBytes / sizeof(wchar_t));
result = RegQueryValueEx(hKey, reinterpret_cast<LPCWSTR>(valueName.data()), 0, &type, reinterpret_cast<LPBYTE>(string.data()), &sizeInBytes);
if (result == ERROR_SUCCESS) {
int newCharSize = sizeInBytes / sizeof(wchar_t);
// From the doc:
// If the data has the REG_SZ, REG_MULTI_SZ or REG_EXPAND_SZ type, the string may not have been stored with
// the proper terminating null characters. Therefore, even if the function returns ERROR_SUCCESS,
// the application should ensure that the string is properly terminated before using it; otherwise, it may overwrite a buffer.
if (string.at(newCharSize - 1) == wchar_t('\0'))
string.resize(newCharSize - 1);
value = string;
}
break;
}
case REG_BINARY: {
std::vector<unsigned char> buffer;
buffer.resize(sizeInBytes);
result = RegQueryValueEx(hKey, reinterpret_cast<LPCWSTR>(valueName.data()), 0, &type, reinterpret_cast<LPBYTE>(buffer.data()), &sizeInBytes);
if (result == ERROR_SUCCESS) {
value = buffer.at(12);
}
break;
}
default:
break;// Q_UNREACHABLE();
}
}
ASSERT(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND);
RegCloseKey(hKey);
return value;
}
bool Utility::registrySetKeyValue(HKEY hRootKey, const std::wstring &subKey, const std::wstring &valueName, DWORD type, const registryVariant &value)
{
HKEY hKey;
// KEY_WOW64_64KEY is necessary because CLSIDs are "Redirected and reflected only for CLSIDs that do not specify InprocServer32 or InprocHandler32."
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa384253%28v=vs.85%29.aspx#redirected__shared__and_reflected_keys_under_wow64
// This shouldn't be an issue in our case since we use shell32.dll as InprocServer32, so we could write those registry keys for both 32 and 64bit.
// FIXME: Not doing so at the moment means that explorer will show the cloud provider, but 32bit processes' open dialogs (like the ownCloud client itself) won't show it.
REGSAM sam = KEY_WRITE | KEY_WOW64_64KEY;
LONG result = RegCreateKeyEx(hRootKey, reinterpret_cast<LPCWSTR>(subKey.data()), 0, nullptr, 0, sam, nullptr, &hKey, nullptr);
ASSERT(result == ERROR_SUCCESS);
if (result != ERROR_SUCCESS)
return false;
result = -1;
switch (type) {
case REG_DWORD: {
try {
DWORD dword = std::get<int>(value);
result = RegSetValueEx(hKey, reinterpret_cast<LPCWSTR>(valueName.data()), 0, type, reinterpret_cast<const BYTE *>(&dword), sizeof(dword));
}
catch (const std::bad_variant_access&) {}
break;
}
case REG_EXPAND_SZ:
case REG_SZ: {
try {
std::wstring string = std::get<std::wstring>(value);
result = RegSetValueEx(hKey, reinterpret_cast<LPCWSTR>(valueName.data()), 0, type, reinterpret_cast<const BYTE *>(string.data()), static_cast<DWORD>((string.size() + 1) * sizeof(wchar_t)));
}
catch (const std::bad_variant_access&) {}
break;
}
default:
break;// Q_UNREACHABLE();
}
ASSERT(result == ERROR_SUCCESS);
RegCloseKey(hKey);
return result == ERROR_SUCCESS;
}
bool Utility::registryDeleteKeyTree(HKEY hRootKey, const std::wstring &subKey)
{
HKEY hKey;
REGSAM sam = DELETE | KEY_ENUMERATE_SUB_KEYS | KEY_QUERY_VALUE | KEY_SET_VALUE | KEY_WOW64_64KEY;
LONG result = RegOpenKeyEx(hRootKey, reinterpret_cast<LPCWSTR>(subKey.data()), 0, sam, &hKey);
ASSERT(result == ERROR_SUCCESS);
if (result != ERROR_SUCCESS)
return false;
result = RegDeleteTree(hKey, nullptr);
RegCloseKey(hKey);
ASSERT(result == ERROR_SUCCESS);
result |= RegDeleteKeyEx(hRootKey, reinterpret_cast<LPCWSTR>(subKey.data()), sam, 0);
ASSERT(result == ERROR_SUCCESS);
return result == ERROR_SUCCESS;
}
bool Utility::registryDeleteKeyValue(HKEY hRootKey, const std::wstring &subKey, const std::wstring &valueName)
{
HKEY hKey;
REGSAM sam = KEY_WRITE | KEY_WOW64_64KEY;
LONG result = RegOpenKeyEx(hRootKey, reinterpret_cast<LPCWSTR>(subKey.data()), 0, sam, &hKey);
ASSERT(result == ERROR_SUCCESS);
if (result != ERROR_SUCCESS)
return false;
result = RegDeleteValue(hKey, reinterpret_cast<LPCWSTR>(valueName.data()));
ASSERT(result == ERROR_SUCCESS);
RegCloseKey(hKey);
return result == ERROR_SUCCESS;
}
bool Utility::registryWalkSubKeys(HKEY hRootKey, const std::wstring &subKey, const std::function<void(HKEY, const std::wstring&)> &callback)
{
HKEY hKey;
REGSAM sam = KEY_READ | KEY_WOW64_64KEY;
LONG result = RegOpenKeyEx(hRootKey, reinterpret_cast<LPCWSTR>(subKey.data()), 0, sam, &hKey);
ASSERT(result == ERROR_SUCCESS);
if (result != ERROR_SUCCESS)
return false;
DWORD maxSubKeyNameSize;
// Get the largest keyname size once instead of relying each call on ERROR_MORE_DATA.
result = RegQueryInfoKey(hKey, nullptr, nullptr, nullptr, nullptr, &maxSubKeyNameSize, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
ASSERT(result == ERROR_SUCCESS);
if (result != ERROR_SUCCESS) {
RegCloseKey(hKey);
return false;
}
std::wstring subKeyName;
subKeyName.reserve(maxSubKeyNameSize + 1);
DWORD retCode = ERROR_SUCCESS;
for (DWORD i = 0; retCode == ERROR_SUCCESS; ++i) {
Q_ASSERT(unsigned(subKeyName.capacity()) > maxSubKeyNameSize);
// Make the previously reserved capacity official again.
subKeyName.resize(subKeyName.capacity());
DWORD subKeyNameSize = static_cast<DWORD>(subKeyName.size());
retCode = RegEnumKeyEx(hKey, i, reinterpret_cast<LPWSTR>(subKeyName.data()), &subKeyNameSize, nullptr, nullptr, nullptr, nullptr);
ASSERT(result == ERROR_SUCCESS || retCode == ERROR_NO_MORE_ITEMS);
if (retCode == ERROR_SUCCESS) {
// subKeyNameSize excludes the trailing \0
subKeyName.resize(subKeyNameSize);
// Pass only the sub keyname, not the full path.
callback(hKey, subKeyName);
}
}
RegCloseKey(hKey);
return retCode != ERROR_NO_MORE_ITEMS;
}
// Created for Win32
DWORD Utility::execCmd(std::wstring cmd, bool wait)
{
// https://docs.microsoft.com/en-us/windows/win32/procthread/creating-processes
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
// Start the child process.
if (!CreateProcess(nullptr, // No module name (use command line)
cmd.data(), // Command line
nullptr, // Process handle not inheritable
nullptr, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
nullptr, // Use parent's environment block
nullptr, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi) // Pointer to PROCESS_INFORMATION structure
)
{
return ERROR_INVALID_FUNCTION;
}
DWORD exitCode = 0;
if (wait) {
// Wait until child process exits.
WaitForSingleObject(pi.hProcess, INFINITE);
GetExitCodeProcess(pi.hProcess, &exitCode);
}
// Close process and thread handles.
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return exitCode;
}
bool Utility::killProcess(const std::wstring &exePath)
{
// https://docs.microsoft.com/en-us/windows/win32/psapi/enumerating-all-processes
// Get the list of process identifiers.
DWORD aProcesses[1024], cbNeeded, cProcesses, i;
if (!EnumProcesses(aProcesses, sizeof(aProcesses), &cbNeeded)) {
return false;
}
// Calculate how many process identifiers were returned.
cProcesses = cbNeeded / sizeof(DWORD);
std::wstring tmpMatch = exePath;
std::transform(tmpMatch.begin(), tmpMatch.end(), tmpMatch.begin(), std::tolower);
for (i = 0; i < cProcesses; i++) {
if (aProcesses[i] != 0) {
// Get a handle to the process.
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_TERMINATE, FALSE, aProcesses[i]);
// Get the process name.
if (hProcess) {
TCHAR szProcessName[MAX_PATH] = {0};
DWORD cbSize = sizeof(szProcessName) / sizeof(TCHAR);
if (QueryFullProcessImageName(hProcess, 0, szProcessName, &cbSize) == TRUE && cbSize > 0) {
std::wstring procName = szProcessName;
std::transform(procName.begin(), procName.end(), procName.begin(), std::tolower);
if (procName == tmpMatch) {
if (TerminateProcess(hProcess, 0) == TRUE) {
WaitForSingleObject(hProcess, INFINITE);
CloseHandle(hProcess);
return true;
}
}
}
CloseHandle(hProcess);
}
}
}
return false;
}
bool Utility::isValidDirectory(const std::wstring &path)
{
auto attrib = GetFileAttributes(path.data());
if (attrib == INVALID_FILE_ATTRIBUTES || GetLastError() == ERROR_FILE_NOT_FOUND) {
return false;
}
return (attrib & FILE_ATTRIBUTE_DIRECTORY);
}
std::wstring Utility::getAppRegistryString(const std::wstring &appVendor, const std::wstring &appName, const std::wstring &valueName)
{
std::wstring appKey = std::wstring(LR"(SOFTWARE\)") + appVendor + L'\\' + appName;
std::wstring appKeyWow64 = std::wstring(LR"(SOFTWARE\WOW6432Node\)") + appVendor + L'\\' + appName;
std::vector<std::wstring> appKeys = { appKey, appKeyWow64 };
for (auto &key : appKeys) {
try {
return std::get<std::wstring>(Utility::registryGetKeyValue(HKEY_LOCAL_MACHINE,
key,
valueName));
}
catch (const std::bad_variant_access&) {}
}
return {};
}
std::wstring Utility::getAppPath(const std::wstring &appVendor, const std::wstring &appName)
{
return getAppRegistryString(appVendor, appName, L""); // intentionally left empty to get the key's "(default)" value
}
std::wstring Utility::getConfigPath(const std::wstring &appName)
{
// On Windows, use AppDataLocation, that's where the roaming data is and where we should store the config file
PWSTR pszPath = nullptr;
if (!SUCCEEDED(SHGetKnownFolderPath(FOLDERID_RoamingAppData, 0, nullptr, &pszPath)) || !pszPath) {
return {};
}
std::wstring path = pszPath + PathSeparator + appName + PathSeparator;
CoTaskMemFree(pszPath);
auto newLocation = path;
return newLocation;
}
void Utility::waitForNsisUninstaller(const std::wstring &appShortName)
{
// Can't WaitForSingleObject because NSIS Uninstall.exe copies itself to a TEMP directory and creates a new process,
// so we do sort of a hack and wait for its mutex (see nextcloud.nsi).
HANDLE hMutex;
DWORD lastError = ERROR_SUCCESS;
std::wstring name = appShortName + std::wstring(L"Uninstaller");
// Give the process enough time to start, to wait for the NSIS mutex.
Sleep(1500);
do {
hMutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, name.data());
lastError = GetLastError();
if (hMutex) {
CloseHandle(hMutex);
}
// This is sort of a hack because WaitForSingleObject immediately returns for the NSIS mutex.
Sleep(500);
} while (lastError != ERROR_FILE_NOT_FOUND);
}
void Utility::removeNavigationPaneEntries(const std::wstring &appName)
{
if (appName.empty()) {
return;
}
// Start by looking at every registered namespace extension for the sidebar, and look for an "ApplicationName" value
// that matches ours when we saved.
std::vector<std::wstring> entriesToRemove;
Utility::registryWalkSubKeys(
HKEY_CURRENT_USER,
LR"(Software\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace)",
[&entriesToRemove, &appName](HKEY key, const std::wstring &subKey) {
try {
auto curAppName = std::get<std::wstring>(Utility::registryGetKeyValue(key, subKey, L"ApplicationName"));
if (curAppName == appName) {
entriesToRemove.push_back(subKey);
}
}
catch (const std::bad_variant_access&) {}
});
for (auto &clsid : entriesToRemove) {
std::wstring clsidStr = clsid;
std::wstring clsidPath = std::wstring(LR"(Software\Classes\CLSID\)") + clsidStr;
std::wstring clsidPathWow64 = std::wstring(LR"(Software\Classes\Wow6432Node\CLSID\)") + clsidStr;
std::wstring namespacePath = std::wstring(LR"(Software\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\)") + clsidStr;
Utility::registryDeleteKeyTree(HKEY_CURRENT_USER, clsidPath);
Utility::registryDeleteKeyTree(HKEY_CURRENT_USER, clsidPathWow64);
Utility::registryDeleteKeyTree(HKEY_CURRENT_USER, namespacePath);
Utility::registryDeleteKeyValue(HKEY_CURRENT_USER, LR"(Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel)", clsidStr);
}
}
// Ported from gui, modified to optionally rename matching files
bool Utility::copy_dir_recursive(std::wstring from_dir, std::wstring to_dir, copy_dir_recursive_callback *callbackFileNameMatchReplace)
{
WIN32_FIND_DATA fileData;
if (from_dir.empty() || to_dir.empty()) {
return false;
}
if (from_dir.back() != PathSeparator.front())
from_dir.append(PathSeparator);
if (to_dir.back() != PathSeparator.front())
to_dir.append(PathSeparator);
std::wstring startDir = from_dir;
startDir.append(L"*.*");
auto hFind = FindFirstFile(startDir.data(), &fileData);
if (hFind == INVALID_HANDLE_VALUE) {
return false;
}
bool success = true;
do {
if (fileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
if (std::wstring(fileData.cFileName) == L"." || std::wstring(fileData.cFileName) == L"..") {
continue;
}
std::wstring from = from_dir + fileData.cFileName;
std::wstring to = to_dir + fileData.cFileName;
if (CreateDirectoryEx(from.data(), to.data(), nullptr) == FALSE) {
success = false;
break;
}
if (copy_dir_recursive(from, to, callbackFileNameMatchReplace) == false) {
success = false;
break;
}
} else {
std::wstring newFilename = fileData.cFileName;
if (callbackFileNameMatchReplace) {
(*callbackFileNameMatchReplace)(std::wstring(fileData.cFileName), newFilename);
}
std::wstring from = from_dir + fileData.cFileName;
std::wstring to = to_dir + newFilename;
if (CopyFile(from.data(), to.data(), TRUE) == FALSE) {
success = false;
break;
}
}
} while (FindNextFile(hFind, &fileData));
FindClose(hFind);
return success;
}
} // namespace NCTools

View file

@ -7,9 +7,16 @@ include_directories(
${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}
) )
configure_file(WinShellExtConstants.h.in ${CMAKE_CURRENT_BINARY_DIR}/WinShellExtConstants.h) configure_file(WinShellExtConstants.h.in ${CMAKE_CURRENT_BINARY_DIR}/WinShellExtConstants.h)
configure_file(WinShellExt.wxs.in ${CMAKE_CURRENT_BINARY_DIR}/WinShellExt.wxs)
add_subdirectory(NCContextMenu) add_subdirectory(NCContextMenu)
add_subdirectory(NCOverlays) add_subdirectory(NCOverlays)
add_subdirectory(NCUtil) add_subdirectory(NCUtil)
if(BUILD_WIN_MSI)
configure_file(WinShellExt.wxs.in ${CMAKE_CURRENT_BINARY_DIR}/WinShellExt.wxs)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/WinShellExt.wxs
DESTINATION msi/
)
endif()

View file

@ -14,7 +14,7 @@
* for more details. * for more details.
* *
--> -->
<?include $(var.ProjectPath)Platform.wxi?> <?include $(sys.CURRENTDIR)Platform.wxi?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"> <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Fragment> <Fragment>