Skip to content

Commit

Permalink
Implemented "upgrade"-logic (user can change port/service-name... whe…
Browse files Browse the repository at this point in the history
…n upgrading and sees the current values)
  • Loading branch information
dbernhard committed Mar 29, 2019
1 parent 126a861 commit 5ffa903
Show file tree
Hide file tree
Showing 9 changed files with 250 additions and 7 deletions.
72 changes: 72 additions & 0 deletions CA_ReadConfig/CA_ReadConfig.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" InitialTargets="EnsureWixToolsetInstalled" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{C01A4B05-BE4B-460F-9DF4-D431505721DF}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CA_ReadConfig</RootNamespace>
<AssemblyName>CA_ReadConfig</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.Deployment.WindowsInstaller">
<Private>True</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="CustomAction.cs" />
<Compile Include="IniFile.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Content Include="CustomAction.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(WixCATargetsPath)" Condition=" '$(WixCATargetsPath)' != '' " />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.CA.targets" Condition=" '$(WixCATargetsPath)' == '' AND Exists('$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.CA.targets') " />
<Target Name="EnsureWixToolsetInstalled" Condition=" '$(WixCATargetsImported)' != 'true' ">
<Error Text="The WiX Toolset v3.11 (or newer) build tools must be installed to build this project. To download the WiX Toolset, see http://wixtoolset.org/releases/" />
</Target>
</Project>
32 changes: 32 additions & 0 deletions CA_ReadConfig/CustomAction.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">

<!--
Use supportedRuntime tags to explicitly specify the version(s) of the .NET Framework runtime that
the custom action should run on. If no versions are specified, the chosen version of the runtime
will be the "best" match to what Microsoft.Deployment.WindowsInstaller.dll was built against.
WARNING: leaving the version unspecified is dangerous as it introduces a risk of compatibility
problems with future versions of the .NET Framework runtime. It is highly recommended that you specify
only the version(s) of the .NET Framework runtime that you have tested against.
Note for .NET Framework v3.0 and v3.5, the runtime version is still v2.0.
In order to enable .NET Framework version 2.0 runtime activation policy, which is to load all assemblies
by using the latest supported runtime, @useLegacyV2RuntimeActivationPolicy="true".
For more information, see http://msdn.microsoft.com/en-us/library/bbx34a2h.aspx
-->

<supportedRuntime version="v4.0" />
<supportedRuntime version="v2.0.50727"/>

</startup>

<!--
Add additional configuration settings here. For more information on application config files,
see http://msdn.microsoft.com/en-us/library/kza1yk3a.aspx
-->

</configuration>
35 changes: 35 additions & 0 deletions CA_ReadConfig/CustomAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Deployment.WindowsInstaller;

namespace CA_ReadConfig
{
public class CustomActions
{
[CustomAction]
public static ActionResult ReadHost(Session session)
{
var config = GetConfig(session["CONFIG_FILE"]);

session["SERVICE_HOST"] = config.IniReadValue("default", "host");

return ActionResult.Success;
}

[CustomAction]
public static ActionResult ReadPort(Session session)
{
var config = GetConfig(session["CONFIG_FILE"]);

session["SERVICE_PORT"] = config.IniReadValue("default", "port");

return ActionResult.Success;
}

private static INIFile GetConfig(string path)
{
return new INIFile(path);
}
}
}
32 changes: 32 additions & 0 deletions CA_ReadConfig/IniFile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Text;
using System.Runtime.InteropServices;


namespace CA_ReadConfig
{
public class INIFile
{
public string path { get; private set; }

[DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);

public INIFile(string INIPath)
{
path = INIPath;
}
public void IniWriteValue(string Section, string Key, string Value)
{
WritePrivateProfileString(Section, Key, Value, path);
}

public string IniReadValue(string Section, string Key)
{
StringBuilder temp = new StringBuilder(255);
int i = GetPrivateProfileString(Section, Key, "", temp, 255, path);
return temp.ToString();
}
}
}
35 changes: 35 additions & 0 deletions CA_ReadConfig/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("CA_ReadConfig")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyCompany("Meusburger Georg GmbH")]
[assembly: AssemblyProduct("CA_ReadConfig")]
[assembly: AssemblyCopyright("Copyright © Meusburger Georg GmbH 2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("c01a4b05-be4b-460f-9df4-d431505721df")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
13 changes: 13 additions & 0 deletions TikaServiceInstaller.sln
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
VisualStudioVersion = 15.0.28010.2050
MinimumVisualStudioVersion = 10.0.40219.1
Project("{930C7802-8A8C-48F9-8165-68863BCCD9DD}") = "TikaServiceInstaller", "TikaServiceInstaller\TikaServiceInstaller.wixproj", "{63B23924-060F-4D4A-9B88-9457EA87662F}"
ProjectSection(ProjectDependencies) = postProject
{C01A4B05-BE4B-460F-9DF4-D431505721DF} = {C01A4B05-BE4B-460F-9DF4-D431505721DF}
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2E4721ED-B1F4-44E8-95C7-8CBB056BD8FC}"
ProjectSection(SolutionItems) = preProject
Expand All @@ -13,6 +16,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
README.md = README.md
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CA_ReadConfig", "CA_ReadConfig\CA_ReadConfig.csproj", "{C01A4B05-BE4B-460F-9DF4-D431505721DF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Expand All @@ -29,6 +34,14 @@ Global
{63B23924-060F-4D4A-9B88-9457EA87662F}.Release|x64.Build.0 = Release|x64
{63B23924-060F-4D4A-9B88-9457EA87662F}.Release|x86.ActiveCfg = Release|x86
{63B23924-060F-4D4A-9B88-9457EA87662F}.Release|x86.Build.0 = Release|x86
{C01A4B05-BE4B-460F-9DF4-D431505721DF}.Debug|x64.ActiveCfg = Debug|x64
{C01A4B05-BE4B-460F-9DF4-D431505721DF}.Debug|x64.Build.0 = Debug|x64
{C01A4B05-BE4B-460F-9DF4-D431505721DF}.Debug|x86.ActiveCfg = Debug|x86
{C01A4B05-BE4B-460F-9DF4-D431505721DF}.Debug|x86.Build.0 = Debug|x86
{C01A4B05-BE4B-460F-9DF4-D431505721DF}.Release|x64.ActiveCfg = Release|x64
{C01A4B05-BE4B-460F-9DF4-D431505721DF}.Release|x64.Build.0 = Release|x64
{C01A4B05-BE4B-460F-9DF4-D431505721DF}.Release|x86.ActiveCfg = Release|x86
{C01A4B05-BE4B-460F-9DF4-D431505721DF}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
3 changes: 3 additions & 0 deletions TikaServiceInstaller/Binaries.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@

<!-- dll to make input validation -->
<Binary Id="CA_InputValidation" SourceFile="$(var.SolutionDir)/packages/CA_InputValidation.1.0.2/lib/net45/CA_InputValidation.CA.dll" />

<!-- CA_ReadConfig to read the host and port for upgrades (with IniFileSearch it's difficult to read the value from a dynamic path -->
<Binary Id="CA_ReadConfig" SourceFile="$(var.SolutionDir)/CA_ReadConfig/bin/$(var.Configuration)/CA_ReadConfig.CA.dll" />
</Fragment>
</Wix>
33 changes: 27 additions & 6 deletions TikaServiceInstaller/PreviousProperties.wxs
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">

<!-- This file reads all properties from a previous installation (used for an upgrade) -->

<!-- Properties loaded:
Registry:
* INSTALLFOLDER
* PREVIOUS_SERVICE_NAME (used to uninstall the service)
* PREVIOUS_PRUNSRV_NAME (used to uninstall and stop the service; in the correct bitness)
* PREVIOUS_LOG_PATH (for an upgrade)
* PREVIOUS_STARTUP_TYPE
* PREVIOUS_LOGLEVEL
Ini-File-Values:
Ini-File-Values: they are loaded in CA_ReadConfig; and will get displayed in the UI
* SERVICE_HOST
* SERVICE_PORT
-->

<?include PreProcessorVariables.wxi ?>
<Fragment>

<Fragment>
<!-- fake component to have a reference inside this file (PreviousProperties.wxs) -->
<Component Id="PreviousProperties" Directory="INSTALLFOLDER" Guid="{3D5809C4-D825-4343-BFC8-54B62288B6D4}">
<CreateFolder />
</Component>

<!-- the previous installed service name-->
<Property Id='PREVIOUS_SERVICE_NAME'>
<RegistrySearch Id='SearchPreviousServiceName'
Expand Down Expand Up @@ -121,9 +124,27 @@
Type='raw' />
</Property>
<SetProperty Action='SetInstallFolder' After='AppSearch' Id='INSTALLFOLDER' Value='[PREVIOUS_INSTALLFOLDER]'>PREVIOUS_INSTALLFOLDER</SetProperty>

<!-- path to ini file; used in the CA_ReadConfig -->
<Property Id='CONFIG_FILE'>
<DirectorySearch Id='SearchInstallFolder' Path='[PREVIOUS_INSTALLFOLDER]'>
<DirectorySearch Id='SearchConfigFolder' Path='config' >
<FileSearch Id='SearchConfigFile' Name='service.config' />
</DirectorySearch>
</DirectorySearch>
</Property>

<CustomAction Id="ReadHost" DllEntry="ReadHost" BinaryKey="CA_ReadConfig" />
<CustomAction Id="ReadPort" DllEntry="ReadPort" BinaryKey="CA_ReadConfig" />

<InstallUISequence>
<Custom Action='ReplacePREVIOUS_LOG_PATH' After='AppSearch'>1</Custom>

<!-- read only if CONFIG_FILE exists (when upgrading) -->
<!-- TODO: when choosing the InstallFolder -> test if config file exits -->
<Custom Action='ReadHost' After='AppSearch'>CONFIG_FILE</Custom>
<Custom Action='ReadPort' After='AppSearch'>CONFIG_FILE</Custom>
<!-- only read host/port in UI-Sequence, because only here it could be changed -->
</InstallUISequence>

<InstallExecuteSequence>
Expand Down
2 changes: 1 addition & 1 deletion TikaServiceInstaller/Product.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
<!-- only write into .ini file when first installing; because if the user changes them after the first installment, we cannot override that file anymore
BUT this is solved using neverOverwriteConfigs.xslt; here we only write these values
-->
<Condition>NOT WIX_UPGRADE_DETECTED</Condition>
<!-- This got removed to change the port/host when upgrading: <Condition>NOT WIX_UPGRADE_DETECTED</Condition>-->
<IniFile Id="WritePort" Action="addLine" Directory="dirF5D9BDF13CBC346EDDFD6D0959FFB838" Section="default" Name="service.config" Key="port" Value="[SERVICE_PORT]" />
<IniFile Id="WriteHost" Action="addLine" Directory="dirF5D9BDF13CBC346EDDFD6D0959FFB838" Section="default" Name="service.config" Key="host" Value="[SERVICE_HOST]" />
</Component>
Expand Down

0 comments on commit 5ffa903

Please sign in to comment.