Скопируйте выбранный файл из командной строки или пользовательского диалогового окна, чтобы выбрать файл - PullRequest
0 голосов
/ 03 мая 2018

Я борюсь с этим с помощью wix. Я хочу скопировать предоставленный пользователем файл конфигурации в папку с данными программы. Пользователь может либо

  • указать путь к файлу с параметром командной строки msiexec
  • или путем выбора файла в диалоговом окне открытия файла

Не могли бы вы дать направление, пожалуйста?

1 Ответ

0 голосов
/ 04 мая 2018

Если кому-то нужно, вот мой рабочий пример wxs. В командной строке для настройки файла конфигурации используйте: msiexec / i CONFIGFILE = "" / qn

   <?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Product Id="*" Name="SoftwareProject" Language="1033" Version="1.0.0.0" Manufacturer="SomeCompany GmbH" UpgradeCode="18109D29-BA4A-4514-9365-F18850566492">
    <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />

    <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
    <MediaTemplate EmbedCab="yes" />

    <Property Id="DISABLEADVTSHORTCUTS" Value="1" />
    <Property Id="WIXUI_INSTALLDIR" Value="INSTALLFOLDER"/>
    <UIRef Id="WixUI_InstallDir" />

    <Property Id="CONFIGFILE" />

    <WixVariable Id="WixUILicenseRtf" Value="SomeCompanyLicense.rtf" />

    <Condition Message="You need to be an administrator to install this product.">Privileged</Condition>


    <Feature Id="ProductFeature" Title="SoftwareProject" Level="1">
      <ComponentGroupRef Id="ProductComponents" />
      <ComponentGroupRef Id="ProgramDataComponents" />
      <ComponentRef Id="ApplicationShortcutDesktop" />
    </Feature>

    <UIRef Id="BrowseForFileDlg"/>

    <!--
  <InstallUISequence>
      <Show Dialog="ConfigDialog" OnExit="success" />
    </InstallUISequence>

  <InstallExecuteSequence>
      <Custom Action="CopyConfigFile" After="CAChooseFile" />
    </InstallExecuteSequence>
    -->

  </Product>

  <Fragment>
    <Binary Id='ConfigAction_CA' SourceFile="$(var.CustomActionProjectName.TargetDir)\$(var.CustomActionProjectName.TargetName).CA.dll" />
    <CustomAction Id='CAChooseFile' BinaryKey='ConfigAction_CA' DllEntry='ChooseConfigFile'  Execute="immediate"
              Return="check"
              Impersonate="no"/>

    <UI Id="BrowseForFileDlg">
      <Dialog Id="BrowseForFileDlg" Width="370" Height="270" Title="Locate configuration file" KeepModeless="yes">
        <Control Id="BannerBitmap" Type="Bitmap" X="0" Y="0" Width="370" Height="44" TabSkip="no" Text="!(loc.InstallScopeDlgBannerBitmap)" />
        <Control Id="BannerLine" Type="Line" X="0" Y="44" Width="370" Height="0" />
        <Control Id="BottomLine" Type="Line" X="0" Y="234" Width="370" Height="0" />
        <Control Id="Description" Type="Text" X="25" Y="23" Width="280" Height="20" Transparent="yes" NoPrefix="yes" Text="Enter the path to the configuration file" />
        <Control Id="Title" Type="Text" X="15" Y="6" Width="200" Height="15" Transparent="yes" NoPrefix="yes" Text="{\WixUI_Font_Title}Locate configuration" />

        <Control Id="SourceFileLabel" Type="Text" X="20" Y="60" Width="290" Height="32" NoPrefix="yes" Text="Specify the location of the configuration file"/>
        <Control Id="SourceFile" Type="Edit" X="20" Y="94" Width="260" Height="18" Property="CONFIGFILE"/>
        <Control Id="BrowseSource" Type="PushButton" X="283" Y="94" Width="18" Height="18" Text="..."/>

        <Control Id="Back" Type="PushButton" X="80" Y="243" Width="56" Height="17" Text="!(loc.WixUIBack)"/>
        <Control Id="UseDefault" Type="PushButton" X="138" Y="243" Width="106" Height="17" Text="Use default configuratoin"/>
        <Control Id="Next" Type="PushButton" X="246" Y="243" Width="56" Height="17" Default="yes" Text="!(loc.WixUINext)"/>
        <Control Id="Cancel" Type="PushButton" X="304" Y="243" Width="56" Height="17" Cancel="yes" Text="!(loc.WixUICancel)"/>
      </Dialog>
      <Publish Dialog="BrowseForFileDlg" Control="BrowseSource" Event="DoAction" Value="CAChooseFile" Order="1">1</Publish>
      <Publish Dialog="BrowseForFileDlg" Control="BrowseSource" Property="CONFIGFILE" Value="[CONFIGFILE]" Order="2">1</Publish>
      <Publish Dialog="LicenseAgreementDlg" Control="Next" Event="NewDialog" Value="BrowseForFileDlg" Order="2">LicenseAccepted="1"</Publish>
      <Publish Dialog="BrowseForFileDlg" Control="Back" Event="NewDialog" Value="LicenseAgreementDlg">1</Publish>
      <Publish Dialog="BrowseForFileDlg" Control="Next" Event="EndDialog" Value="Return">1</Publish>
      <Publish Dialog="BrowseForFileDlg" Control="Cancel" Event="SpawnDialog" Value="CancelDlg">1</Publish>
      <Publish Dialog="BrowseForFileDlg" Control="UseDefault" Property="CONFIGFILE" Order="1">1</Publish>
      <Publish Dialog="BrowseForFileDlg" Control="UseDefault" Event="EndDialog" Value="Return" Order="2">1</Publish>
    </UI>
  </Fragment>

  <Fragment>

    <Directory Id="TARGETDIR" Name="SourceDir">

      <Directory Id="ProgramFilesFolder">
        <Directory Id='SomeCompany' Name='SomeCompany'>
          <Directory Id='INSTALLFOLDER' Name='SoftwareProject'>
          </Directory>
        </Directory>
      </Directory>

      <Directory Id="CommonAppDataFolder">
        <Directory Id='SomeCompanyData' Name='SomeCompany'>
          <Directory Id='SoftwareProjectData' Name='SoftwareProject'>
            <Directory Id='CONFIGAPPDATAFOLDER' Name='Config' />
          </Directory>
        </Directory>
      </Directory>

      <Directory Id="DesktopFolder" Name="Desktop">
        <Component Id="ApplicationShortcutDesktop" Guid="{generated guid here}">
          <Shortcut Id="ApplicationDesktopShortcut" Name="Launch SoftwareProject" Description="SomeCompany SoftwareProject" Target="[INSTALLFOLDER]SoftwareProject.exe" Arguments="-debug" WorkingDirectory="INSTALLFOLDER"/>
          <RemoveFolder Id="DesktopFolder" On="uninstall"/>
          <RegistryValue Root="HKCU" Key="Software/SoftwareProject" Name="installed" Type="integer" Value="1" KeyPath="yes"/>
        </Component>
      </Directory>

    </Directory>

    <ComponentGroup Id="ProgramDataComponents" Directory="CONFIGAPPDATAFOLDER">
      <Component Id="ProgramDataDefaultConfigFile" Guid="{generated guid here}">
        <Condition>CONFIGFILE=""</Condition>
        <File Id="GCC" Name="SoftwareProjectConfig.json" Source="SoftwareProject\Config\SoftwareProjectConfig.json"/>
      </Component>
      <Component Id="ProgramDataCustomConfigFile" Guid="{generated guid here}">
        <Condition>NOT CONFIGFILE=""</Condition>
        <CopyFile Id="CopyConfigFile" SourceProperty="CONFIGFILE"
                  DestinationDirectory="CONFIGAPPDATAFOLDER" DestinationName="SoftwareProjectConfig.json" />
      </Component>
    </ComponentGroup>

  </Fragment>

</Wix>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...