Wix get value from paths

后端 未结 1 885

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:

     INSTALLDIR
     
     INSTALLDIR
    
     
     

    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)
提交回复
热议问题