WiX/MSI引用C++;
是否有方法引用wix代码中声明的文件,例如:WiX/MSI引用C++;,wix,windows-installer,custom-action,Wix,Windows Installer,Custom Action,是否有方法引用wix代码中声明的文件,例如: <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"/>
<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>
这样一来,人们就可以根据不同的内容打开和编辑该文件了
编辑与@NC1公开的方法相同的方法,但使用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;
//...
我就是这样做的。我的自定义操作是在安装文件之后安排的,因此我会获取安装它的目录并附加我想要编辑的文件(对于我来说是文本文件),不确定这是否是唯一的方法,但它对我有效
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");
其中
szLocation
将具有完整路径。希望这有助于读取同一目录的属性和目标路径可能是一种清洗,但要知道MsiGetTargetPath存在。但是:请注意,dirproperty后面会有一个反斜杠,因此strcat本身不需要有一个。(警告:使用wcstombs将丢失ACP上不存在的路径中的字符,使用strcat可能会导致缓冲区溢出。)感谢@NC1,这与我现在所做的非常相似,但我认为这可能是直接引用某个特定文件的另一种方式。尽管如此,我还是编辑了我的问题,这样你就可以用C++上的WixAPI来实现这个方法。
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");