Reputation: 3133
Is there a way to refer to a file declared on wix code, for instance:
<DirectoryRef Id="MAIN_INSTALLLOCATION">
<Component Id="CMP_config_system" Guid="a430710e-a95b-48d7-acbe-3bf4e6b2c8fc">
<File Id="FILE_config_system" KeyPath="yes" Source="config_system.ini"/>
</Component>
</DirectoryRef>
In a custom action coded in C++, for instance (see question marks)
UINT __stdcall entryPoint(MSIHANDLE hInstall)
{
//...
LPWSTR filePath = NULL;
hr = WcaGetProperty(???, &filePath);
//...
}
So this way one could open and edit that file base on different things?
EDIT same method as exposed by @NC1 but with WiX API
// ...
const std::wstring APPDATA_DIR = L"AppDataDir";
const std::wstring CONFIG_SYSTEM = L"config_system.ini";
LPWSTR path = NULL;
hr = WcaGetProperty(APPDATA_DIR.c_str(), &path);
ExitOnFailure(hr, "Failed to get Path");
config_system_path = std::wstring(path) + CONFIG_SYSTEM;
//...
Upvotes: 0
Views: 649
Reputation: 3797
This is the way I do it. My custom action is scheduled after install files so I get the directory in which it was installed to and append the file I would like to edit(for me text files), not sure if this is the only way but it works for me.
HRESULT hr = S_OK;
UINT er = ERROR_SUCCESS;
char szLocation[MAX_PATH];
LPWSTR szInstallLocation = NULL;
CString lpszString;
hr = WcaInitialize(hInstall, "NAMEOFCUSTOMACTION");
ExitOnFailure(hr, "Failed to initialize");
WcaLog(LOGMSG_STANDARD, "Initialized.");
hr = WcaGetProperty(L"MAIN_INSTALLLOCATION",&szInstallLocation);
ExitOnFailure(hr, "failed to get install location");
wcstombs(szLocation, szInstallLocation, 260);
strcat(szLocation, "\config_system.ini");
Where szLocation
will then have the full path. Hope this helps
Upvotes: 1