Wix从路径中获取价值

时间:2012-12-14 09:45:09

标签: wix

嘿我正在创建一个程序的安装程序,该程序依赖于另一个名为“visma”的程序,我想要做的只是当用户选择安装路径时。

用户还需要指定两个已安装visma的路径。 然后我想从输入读取一个txt文件或其他东西,以便我可以在程序之外读取路径并从visma复制我需要的一些文件。

enter image description here

这是我在用户界面中安装工作并完成其工作的距离

但我不知道如何创建更改图片中三个字段的默认路径所需的目录变量

MYInstalldirdlg

*

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Fragment>
    <UI>
        <Dialog Id="MYInstallDirDlg" Width="370" Height="270" Title="!(loc.InstallDirDlg_Title)">
            <Control Id="Next" Type="PushButton" X="236" Y="243" Width="56" Height="17" Default="yes" Text="!(loc.WixUINext)" />
            <Control Id="Back" Type="PushButton" X="180" Y="243" Width="56" Height="17" Text="!(loc.WixUIBack)" />
            <Control Id="Cancel" Type="PushButton" X="304" Y="243" Width="56" Height="17" Cancel="yes" Text="!(loc.WixUICancel)">
                <Publish Event="SpawnDialog" Value="CancelDlg">1</Publish>
            </Control>

            <Control Id="Description" Type="Text" X="25" Y="23" Width="280" Height="15" Transparent="yes" NoPrefix="yes" Text="Choose default or your own folder for install and specify visma folders" />
            <Control Id="Title" Type="Text" X="15" Y="6" Width="200" Height="15" Transparent="yes" NoPrefix="yes" Text="{\WixUI_Font_Title}Destination Folders" />
            <Control Id="BannerBitmap" Type="Bitmap" X="0" Y="0" Width="370" Height="44" TabSkip="no" Text="!(loc.InstallDirDlgBannerBitmap)" />
            <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="FolderLabel1" Type="Text" X="20" Y="50" Width="290" Height="12" NoPrefix="yes" Text="!(loc.InstallDirDlgFolderLabel)" />
            <Control Id="Folder1" Type="PathEdit" X="20" Y="65" Width="320" Height="18" Property="WIXUI_INSTALLDIR" Indirect="yes" />
            <Control Id="ChangeFolder1" Type="PushButton" X="20" Y="85" Width="56" Height="15" Text="!(loc.InstallDirDlgChange)" />

            <Control Id="FolderLabel2" Type="Text" X="20" Y="110" Width="290" Height="12" NoPrefix="yes" Text="Please specify where your Visma Administration installation folder is:" />
            <Control Id="Folder2" Type="PathEdit" X="20" Y="125" Hidden ="no" Width="320" Height="18" Property="WIXUI_INSTALLDIR" Indirect="yes" />
            <Control Id="ChangeFolder2" Type="Text" X="20" Y="150" Width="56" Height="18" Text="Change..." />

            <Control Id="FolderLabel3" Type="Text" X="20" Y="175" Width="290" Height="22" NoPrefix="yes" Text="Please specify where your SPCS folder is which contains (Företag) and (Gemensamma filer):" />
            <Control Id="Folder3" Type="PathEdit" X="20" Y="195" Hidden ="no" Width="320" Height="18" Property="WIXUI_INSTALLDIR" Indirect="yes" />
            <Control Id="ChangeFolder3" Type="Text" X="20" Y="215" Width="56" Height="18" Text="Change..." />
        </Dialog>
    </UI>
</Fragment>

如你所见,他们都有从我的目录中获得的相同路径 WIXUI_INSTALLDIR

WixUI_MYInstallDir

*

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Fragment>
    <UI Id="WixUI_MYInstallDir">
        <TextStyle Id="WixUI_Font_Normal" FaceName="Tahoma" Size="8" />
        <TextStyle Id="WixUI_Font_Bigger" FaceName="Tahoma" Size="12" />
        <TextStyle Id="WixUI_Font_Title" FaceName="Tahoma" Size="9" Bold="yes" />

        <Property Id="DefaultUIFont" Value="WixUI_Font_Normal" />
        <Property Id="WixUI_Mode" Value="InstallDir" />

        <DialogRef Id="BrowseDlg" />
        <DialogRef Id="DiskCostDlg" />
        <DialogRef Id="ErrorDlg" />
        <DialogRef Id="FatalError" />
        <DialogRef Id="FilesInUse" />
        <DialogRef Id="MsiRMFilesInUse" />
        <DialogRef Id="PrepareDlg" />
        <DialogRef Id="ProgressDlg" />
        <DialogRef Id="ResumeDlg" />
        <DialogRef Id="UserExit" />

        <Publish Dialog="BrowseDlg" Control="OK" Event="DoAction" Value="WixUIValidatePath" Order="3">1</Publish>
        <Publish Dialog="BrowseDlg" Control="OK" Event="SpawnDialog" Value="InvalidDirDlg" Order="4"><![CDATA[WIXUI_INSTALLDIR_VALID<>"1"]]></Publish>

        <Publish Dialog="ExitDialog" Control="Finish" Event="EndDialog" Value="Return" Order="999">1</Publish>

        <Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="LicenseAgreementDlg">NOT Installed</Publish>
        <Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="VerifyReadyDlg">Installed AND PATCH</Publish>

        <Publish Dialog="LicenseAgreementDlg" Control="Back" Event="NewDialog" Value="WelcomeDlg">1</Publish>
        <Publish Dialog="LicenseAgreementDlg" Control="Next" Event="NewDialog" Value="MYInstallDirDlg">LicenseAccepted = "1"</Publish>

        <Publish Dialog="MYInstallDirDlg" Control="Back" Event="NewDialog" Value="LicenseAgreementDlg">1</Publish>
        <Publish Dialog="MYInstallDirDlg" Control="Next" Event="SetTargetPath" Value="[WIXUI_INSTALLDIR]" Order="1">1</Publish>
        <Publish Dialog="MYInstallDirDlg" Control="Next" Event="DoAction" Value="WixUIValidatePath" Order="2">NOT WIXUI_DONTVALIDATEPATH</Publish>
        <Publish Dialog="MYInstallDirDlg" Control="Next" Event="SpawnDialog" Value="InvalidDirDlg" Order="3"><![CDATA[NOT WIXUI_DONTVALIDATEPATH AND WIXUI_INSTALLDIR_VALID<>"1"]]></Publish>
        <Publish Dialog="MYInstallDirDlg" Control="Next" Event="NewDialog" Value="VerifyReadyDlg" Order="4">WIXUI_DONTVALIDATEPATH OR WIXUI_INSTALLDIR_VALID="1"</Publish>
        <Publish Dialog="MYInstallDirDlg" Control="ChangeFolder1" Property="_BrowseProperty" Value="[WIXUI_INSTALLDIR]" Order="1">1</Publish>
        <Publish Dialog="MYInstallDirDlg" Control="ChangeFolder1" Event="SpawnDialog" Value="BrowseDlg" Order="2">1</Publish>

        <Publish Dialog="VerifyReadyDlg" Control="Back" Event="NewDialog" Value="MYInstallDirDlg" Order="1">NOT Installed</Publish>
        <Publish Dialog="VerifyReadyDlg" Control="Back" Event="NewDialog" Value="MaintenanceTypeDlg" Order="2">Installed AND NOT PATCH</Publish>
        <Publish Dialog="VerifyReadyDlg" Control="Back" Event="NewDialog" Value="WelcomeDlg" Order="2">Installed AND PATCH</Publish>

        <Publish Dialog="MaintenanceWelcomeDlg" Control="Next" Event="NewDialog" Value="MaintenanceTypeDlg">1</Publish>

        <Publish Dialog="MaintenanceTypeDlg" Control="RepairButton" Event="NewDialog" Value="VerifyReadyDlg">1</Publish>
        <Publish Dialog="MaintenanceTypeDlg" Control="RemoveButton" Event="NewDialog" Value="VerifyReadyDlg">1</Publish>
        <Publish Dialog="MaintenanceTypeDlg" Control="Back" Event="NewDialog" Value="MaintenanceWelcomeDlg">1</Publish>

        <Property Id="ARPNOMODIFY" Value="1" />
    </UI>

    <UIRef Id="WixUI_MYCommon" />
</Fragment>

这里我只进行了必要的更改才能使其工作:更改为WixUI_MYInstallDir等名称匹配

产品

*

<!-- Directory 1 (install folder) -->
<Directory Id="TARGETDIR" Name="SourceDir">
  <Directory Id="ProgramFilesFolder">
    <Directory Id="INSTALLDIR" Name="ITC_Venato" >
    </Directory>
          //componet stuff and files to install
   </Directory>
</Directory>

<Feature
  Id="Venato_Windows_Service_0.904"
  Title="Venato Windows Service"
  Level="1">
  <ComponentRef Id="Venatoexe" />
</Feature>

<!-- Include a user interface-->
<Property Id="WIXUI_INSTALLDIR">INSTALLDIR</Property>
<UIRef Id="WixUI_MYInstallDir" />
<UIRef Id="WixUI_ErrorProgressText" />

仅包含相关部分,但我订购了wix和产品标签,但我想我必须为我想要的新文件夹路径创建一个新的Property Id。

但是我如何制作它以便程序只读取路径并将它们发送到我可以读取的变量或文本文件中。我不希望程序像安装路径一样创建新文件夹。 theese应该由用户选择,然后阅读。

谢谢你的回答!

*

*

*

*

错误

enter image description here

1 个答案:

答案 0 :(得分:1)

使用您提到的不同属性:

 <Property Id="WIXUI_INSTALLDIR">INSTALLDIR</Property>
 <Property Id="VISMA_ADMIN" Secure="yes"></Property>
 <Property Id="SPCS_FOLDER">INSTALLDIR</Property>

 <Control Id="FolderLabel2" Type="Text" X="20" Y="110" Width="290" Height="12" NoPrefix="yes" Text="Please specify where your Visma Administration installation folder is:" />
 <Control Id="Folder2" Type="PathEdit" X="20" Y="125" Hidden ="no" Width="320" Height="18" Property="VISMA_ADMIN" Indirect="yes" />
 <Control Id="ChangeFolder2" Type="Text" X="20" Y="150" Width="56" Height="18" Text="Change..." />

 <Control Id="FolderLabel3" Type="Text" X="20" Y="175" Width="290" Height="22" NoPrefix="yes" Text="Please specify where your SPCS folder is which contains (Företag) and (Gemensamma filer):" />
 <Control Id="Folder3" Type="PathEdit" X="20" Y="195" Hidden ="no" Width="320" Height="18" Property="SPCS_FOLDER" Indirect="yes" />
 <Control Id="ChangeFolder3" Type="Text" X="20" Y="215" Width="56" Height="18" Text="Change..." />

如果要将它们保存到文本文件中,我会使用自定义操作。以下是关于如何将数据保存到文本文件的代码。

  extern "C" UINT __stdcall GetLoggersInfo(MSIHANDLE hInstall)
 {
HRESULT hr = S_OK;
UINT er = ERROR_SUCCESS;
char szLocation[MAX_PATH];
LPWSTR szValueBuf = NULL, szInstallDir = NULL, szVismaAdmin = NULL;

hr = WcaInitialize(hInstall, "GetLoggersInfo");
ExitOnFailure(hr, "Failed to initialize");

WcaLog(LOGMSG_STANDARD, "Initialized.");

hr = WcaGetProperty(L"VISMA_ADMIN",&szVismaAdmin);
ExitOnFailure(hr, "failed to get folder");

hr = WcaGetProperty(L"SPCS_FOLDER",&szValueBuf);
ExitOnFailure(hr, "failed to get folder");

我假设您正在使用该产品安装文本文件,因此请获取它所在的目录:

hr = WcaGetProperty(L"INSTALLDIR",&szInstallDir);
ExitOnFailure(hr, "failed to get install location");

wcstombs(szLocation, szValueBuf, 260);
strcat(szLocation, "\\NameOfTextFile.txt");


CString lpszString = CString("Visma Admin:") + szVismaAdmin + "\r\n";

hr = AppendInfo(szLocation,lpszString);
ExitOnFailure(hr, "failed to append the NameOfTextFile.txt file with the 

LExit:
ReleaseStr(szValueBuf);
er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
return WcaFinalize(er);
}

辅助函数:

HRESULT AppendInfo(__in LPCSTR lpszFile, __in LPCSTR lpszEntry )
{
HRESULT hr = S_OK;
HANDLE  hFile;
DWORD   dwWritten;
CHAR    szError[MAX_PATH*2];
CHAR    szTitle[MAX_PATH];

try
{
    if ((hFile = CreateFile(lpszFile,
        GENERIC_READ|GENERIC_WRITE,
        FILE_SHARE_READ | FILE_SHARE_WRITE,
        NULL,
        OPEN_EXISTING,
        FILE_ATTRIBUTE_NORMAL,
        NULL)) == INVALID_HANDLE_VALUE) 
    {
        // Error: Couldn't Open File. Handle error

    } 

    // No Entry Exists.
    SetFilePointer(hFile, 0, NULL, FILE_END);

    if ( !WriteFile(hFile,lpszEntry,lstrlen(lpszEntry),&dwWritten,NULL) )
    {
        CloseHandle(hFile); 
        //HandleError
    }

    CloseHandle(hFile); 
}
catch(int e)
{
    // A failure caused an exception!
    //Handle Error
}

return hr;
}

编辑:忘记提及添加自定义操作并在InstallFinalize

之后安排它