fdo#46519 workaround of MSI installer error 1935

In some circumstances installation of embedded VC++ runtime
fails with error code 1935. This usually occurs, when there are
many different versions of VC++ runtimes installed on the computer,
including beta versions. We can workaround this Microsoft bug, if we
don't install our VC++ runtime. A new property was introduced. It is
called VC_REDIST, and installation of VC++ runtime depends on its
value. (BTW the solution is general, ComponentCondition can be used
for any merge module, now we have only the VC++ runtime merge module.)
When the user experiences error code 1935, he should try to install
LibreOffice with the following command line:
msiexec /i <msi file name> VC_REDIST=0
The patch fixes another minor issue. 64-bit VC++ runtime will
not be installed on 32-bit systems any more.

Change-Id: I I6c5e066c6e60b011235e6019a8a35c9e953209bc
diff --git a/instsetoo_native/inc_openoffice/windows/msi_templates/Property.idt b/instsetoo_native/inc_openoffice/windows/msi_templates/Property.idt
index 188f344d..920251e 100644
--- a/instsetoo_native/inc_openoffice/windows/msi_templates/Property.idt
+++ b/instsetoo_native/inc_openoffice/windows/msi_templates/Property.idt
@@ -59,3 +59,4 @@ STR_MS_POWERPOINT_TEMPLATE	OOO_STR_MS_POWERPOINT_TEMPLATE
STR_MS_POWERPOINT_SHOW	OOO_STR_MS_POWERPOINT_SHOW
STR_INSTALLATION_WIZARD	OOO_STR_INSTALLATION_WIZARD
UpgradeCode	UPGRADECODETEMPLATE
VC_REDIST	1
diff --git a/scp2/source/ooo/vc_redist.scp b/scp2/source/ooo/vc_redist.scp
index a01f891..5ec433c 100644
--- a/scp2/source/ooo/vc_redist.scp
+++ b/scp2/source/ooo/vc_redist.scp
@@ -33,12 +33,14 @@ MergeModule gid_MergeModule_Microsoft_VC90_CRT_x86
    Feature = gm_Root;
    Name = "Microsoft_VC90_CRT_x86.msm";
    RootDir = "TARGETDIR";
    ComponentCondition = "VC_REDIST=1";
End

MergeModule gid_MergeModule_policy_9_0_Microsoft_VC90_CRT_x86
    Feature = gm_Root;
    Name = "policy_9_0_Microsoft_VC90_CRT_x86.msm";
    RootDir = "TARGETDIR";
    ComponentCondition = "VC_REDIST=1";
End

#if defined(BUILD_X64)
@@ -47,12 +49,14 @@ MergeModule gid_MergeModule_Microsoft_VC90_CRT_x86_x64
    Feature = gm_Root;
    Name = "Microsoft_VC90_CRT_x86_x64.msm";
    RootDir = "TARGETDIR";
    ComponentCondition = "(VC_REDIST=1) AND VersionNT64";
End

MergeModule gid_MergeModule_policy_9_0_Microsoft_VC90_CRT_x86_x64
    Feature = gm_Root;
    Name = "policy_9_0_Microsoft_VC90_CRT_x86_x64.msm";
    RootDir = "TARGETDIR";
    ComponentCondition = "(VC_REDIST=1) AND VersionNT64";
End

#endif
diff --git a/solenv/bin/modules/installer/windows/mergemodule.pm b/solenv/bin/modules/installer/windows/mergemodule.pm
index b9591c4..7faa4b5 100755
--- a/solenv/bin/modules/installer/windows/mergemodule.pm
+++ b/solenv/bin/modules/installer/windows/mergemodule.pm
@@ -302,6 +302,7 @@ sub merge_mergemodules_into_msi_database
                $onemergemodulehash{'cabinetfile'} = $workdir . $installer::globals::separator . $cabinetfile;
                $onemergemodulehash{'filenumber'} = $filecounter;
                $onemergemodulehash{'componentnames'} = \%componentnames;
                $onemergemodulehash{'componentcondition'} = $mergemodule->{'ComponentCondition'};
                $onemergemodulehash{'cabfilename'} = $cabfilename;
                $onemergemodulehash{'feature'} = $mergemodule->{'Feature'};
                $onemergemodulehash{'rootdir'} = $mergemodule->{'RootDir'};
@@ -404,6 +405,7 @@ sub merge_mergemodules_into_msi_database
            if ( -f "FeatureC.idt" ) { installer::systemactions::rename_one_file("FeatureC.idt", "old.FeatureC.idt.$counter"); }
            if ( -f "MsiAssembly.idt" ) { installer::systemactions::rename_one_file("MsiAssembly.idt", "old.MsiAssembly.idt.$counter"); }
            if ( -f "MsiAssem.idt" ) { installer::systemactions::rename_one_file("MsiAssem.idt", "old.MsiAssem.idt.$counter"); }
            if ( -f "Componen.idt" ) { installer::systemactions::rename_one_file("Componen.idt", "old.Componen.idt.$counter"); }

            # Extracting tables

@@ -412,6 +414,7 @@ sub merge_mergemodules_into_msi_database
            my $workingtables = "File Media Directory FeatureComponents"; # required tables
            # Optional tables can be added now
            if ( $mergemodulehash->{'hasmsiassemblies'} ) { $workingtables = $workingtables . " MsiAssembly"; }
            if ( $mergemodulehash->{'componentcondition'} ) { $workingtables = $workingtables . " Component"; }

            # Table "Feature" has to be exported, but it is not necessary to import it.
            if ( $^O =~ /cygwin/i ) {
@@ -451,8 +454,9 @@ sub merge_mergemodules_into_msi_database
            if ( -f "Directory.idt" ) { installer::systemactions::rename_one_file("Directory.idt", "Director.idt"); }
            if ( -f "FeatureComponents.idt" ) { installer::systemactions::rename_one_file("FeatureComponents.idt", "FeatureC.idt"); }
            if ( -f "MsiAssembly.idt" ) { installer::systemactions::rename_one_file("MsiAssembly.idt", "MsiAssem.idt"); }
            if ( -f "Component.idt" ) { installer::systemactions::rename_one_file("Component.idt", "Componen.idt"); }

            # Changing content of tables: File, Media, Directory, FeatureComponent, MsiAssembly
            # Changing content of tables: File, Media, Directory, FeatureComponent, MsiAssembly, Component
            installer::logger::include_timestamp_into_logfile("\nPerformance Info: Changing Media table");
            change_media_table($mergemodulehash, $workdir, $mergemodulegid, $allupdatelastsequences, $allupdatediskids);
            installer::logger::include_timestamp_into_logfile("\nPerformance Info: Changing File table");
@@ -467,6 +471,12 @@ sub merge_mergemodules_into_msi_database
                change_msiassembly_table($mergemodulehash, $workdir);
            }

            if ( $mergemodulehash->{'componentcondition'} )
            {
                installer::logger::include_timestamp_into_logfile("\nPerformance Info: Changing Component table");
                change_component_table($mergemodulehash, $workdir);
            }

            # msidb.exe does not merge InstallExecuteSequence, AdminExecuteSequence and AdvtExecuteSequence. Instead it creates
            # new tables ModuleInstallExecuteSequence, ModuleAdminExecuteSequence and ModuleAdvtExecuteSequence that need to be
            # merged into the three ExecuteSequences with the following process (also into InstallUISequence.idt).
@@ -1365,6 +1375,50 @@ sub change_featurecomponent_table
    installer::files::save_file($idtfilename, $filecontent);
}

###############################################################################
# In the components table, the conditions of merge modules should be updated
###############################################################################

sub change_component_table
{
    my ($mergemodulehash, $workdir) = @_;

    my $infoline = "Changing content of table \"Component\"\n";
    push( @installer::globals::logfileinfo, $infoline);

    my $idtfilename = "Componen.idt";
    if ( ! -f $idtfilename ) { installer::exiter::exit_program("ERROR: Could not find file \"$idtfilename\" in \"$workdir\" !", "change_component_table"); }

    my $filecontent = installer::files::read_file($idtfilename);

    for ( my $i = 0; $i <= $#{$filecontent}; $i++ )
    {
        my $component;
        foreach $component ( keys %{$mergemodulehash->{'componentnames'}} )
        {
            if ( ${$filecontent}[$i] =~ /^\s*$component/)
            {
                if ( ${$filecontent}[$i] =~ /^\s*(.+?)\t(.*?)\t(.+?)\t(.+?)\t(.*?)\t(.*?)\s*$/ )
                {
                    $infoline = "Adding condition ($5) from scp to component $1\n";
                    push( @installer::globals::logfileinfo, $infoline);
                    if ($5)
                    {
                        ${$filecontent}[$i] = "$1\t$2\t$3\t$4\t($5) AND ($mergemodulehash->{'componentcondition'})\t$6\n";
                    }
                    else
                    {
                        ${$filecontent}[$i] = "$1\t$2\t$3\t$4\t$mergemodulehash->{'componentcondition'}\t$6\n";
                    }
                }
            }
        }
    }

    # saving file
    installer::files::save_file($idtfilename, $filecontent);
}

#########################################################################
# In the directory table, the directory parent has to be changed,
# if it is not TARGETDIR.