Wix get value from paths

后端 未结 1 879

Hey im creating an installer of a program that is depending on another program called \"visma\" what i want to do is simply that when the user will choose the install path.

相关标签:
1条回答
  • 2021-01-25 16:34

    Use different properties like you mentioned:

     <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..." />
    

    If you want to save them to a text file then I would use a custom action. Heres my code on how I save data to a text file.

      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");
    

    I am assuming you are installing the text file with the product so get the directory it is in:

    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);
    }
    

    And the helper function:

    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;
    }
    

    EDIT: forgot to mention to add the custom action and schedule it after InstallFinalize

    0 讨论(0)
提交回复
热议问题