blob: f60a356c10315d586d45eabbdbb7b30d668012c7 [file] [log] [blame]
Martin v. Löwiseb68be42004-12-12 15:29:21 +00001#include "windows.h"
2#include "msiquery.h"
3
4/* Print a debug message to the installer log file.
5 * To see the debug messages, install with
6 * msiexec /i pythonxy.msi /l*v python.log
7 */
Martin v. Löwis3c24d962005-02-18 16:18:09 +00008static UINT debug(MSIHANDLE hInstall, LPCSTR msg)
Martin v. Löwiseb68be42004-12-12 15:29:21 +00009{
10 MSIHANDLE hRec = MsiCreateRecord(1);
Martin v. Löwis3c24d962005-02-18 16:18:09 +000011 if (!hRec || MsiRecordSetStringA(hRec, 1, msg) != ERROR_SUCCESS) {
Martin v. Löwiseb68be42004-12-12 15:29:21 +000012 return ERROR_INSTALL_FAILURE;
13 }
14 MsiProcessMessage(hInstall, INSTALLMESSAGE_INFO, hRec);
15 MsiCloseHandle(hRec);
16 return ERROR_SUCCESS;
17}
18
19/* Check whether the TARGETDIR exists and is a directory.
20 * Set TargetExists appropriately.
21 */
22UINT __declspec(dllexport) __stdcall CheckDir(MSIHANDLE hInstall)
23{
Martin v. Löwis3c24d962005-02-18 16:18:09 +000024#define PSIZE 1024
25 WCHAR wpath[PSIZE];
26 char path[PSIZE];
Martin v. Löwiseb68be42004-12-12 15:29:21 +000027 UINT result;
Martin v. Löwis3c24d962005-02-18 16:18:09 +000028 DWORD size = PSIZE;
Martin v. Löwiseb68be42004-12-12 15:29:21 +000029 DWORD attributes;
Martin v. Löwis3c24d962005-02-18 16:18:09 +000030
Martin v. Löwiseb68be42004-12-12 15:29:21 +000031
Alexandre Vassalottia79e33e2008-05-15 22:51:26 +000032 result = MsiGetPropertyW(hInstall, L"TARGETDIR", wpath, &size);
Martin v. Löwiseb68be42004-12-12 15:29:21 +000033 if (result != ERROR_SUCCESS)
34 return result;
Martin v. Löwis3c24d962005-02-18 16:18:09 +000035 wpath[size] = L'\0';
Martin v. Löwiseb68be42004-12-12 15:29:21 +000036 path[size] = L'\0';
37
Alexandre Vassalottia79e33e2008-05-15 22:51:26 +000038 attributes = GetFileAttributesW(wpath);
Martin v. Löwiseb68be42004-12-12 15:29:21 +000039 if (attributes == INVALID_FILE_ATTRIBUTES ||
40 !(attributes & FILE_ATTRIBUTE_DIRECTORY))
41 {
Martin v. Löwis3c24d962005-02-18 16:18:09 +000042 return MsiSetPropertyA(hInstall, "TargetExists", "0");
Martin v. Löwiseb68be42004-12-12 15:29:21 +000043 } else {
Martin v. Löwis3c24d962005-02-18 16:18:09 +000044 return MsiSetPropertyA(hInstall, "TargetExists", "1");
Martin v. Löwiseb68be42004-12-12 15:29:21 +000045 }
46}
47
48/* Update the state of the REGISTRY.tcl component according to the
49 * Extension and TclTk features. REGISTRY.tcl must be installed
50 * if both features are installed, and must be absent otherwise.
51 */
52UINT __declspec(dllexport) __stdcall UpdateEditIDLE(MSIHANDLE hInstall)
53{
54 INSTALLSTATE ext_old, ext_new, tcl_old, tcl_new, reg_new;
55 UINT result;
56
Martin v. Löwis3c24d962005-02-18 16:18:09 +000057 result = MsiGetFeatureStateA(hInstall, "Extensions", &ext_old, &ext_new);
Martin v. Löwiseb68be42004-12-12 15:29:21 +000058 if (result != ERROR_SUCCESS)
59 return result;
Martin v. Löwis3c24d962005-02-18 16:18:09 +000060 result = MsiGetFeatureStateA(hInstall, "TclTk", &tcl_old, &tcl_new);
Martin v. Löwiseb68be42004-12-12 15:29:21 +000061 if (result != ERROR_SUCCESS)
62 return result;
63
64 /* If the current state is Absent, and the user did not select
65 the feature in the UI, Installer apparently sets the "selected"
66 state to unknown. Update it to the current value, then. */
67 if (ext_new == INSTALLSTATE_UNKNOWN)
68 ext_new = ext_old;
69 if (tcl_new == INSTALLSTATE_UNKNOWN)
70 tcl_new = tcl_old;
71
72 // XXX consider current state of REGISTRY.tcl?
73 if (((tcl_new == INSTALLSTATE_LOCAL) ||
74 (tcl_new == INSTALLSTATE_SOURCE) ||
75 (tcl_new == INSTALLSTATE_DEFAULT)) &&
76 ((ext_new == INSTALLSTATE_LOCAL) ||
77 (ext_new == INSTALLSTATE_SOURCE) ||
78 (ext_new == INSTALLSTATE_DEFAULT))) {
79 reg_new = INSTALLSTATE_SOURCE;
80 } else {
81 reg_new = INSTALLSTATE_ABSENT;
82 }
Martin v. Löwis3c24d962005-02-18 16:18:09 +000083 result = MsiSetComponentStateA(hInstall, "REGISTRY.tcl", reg_new);
Martin v. Löwiseb68be42004-12-12 15:29:21 +000084 return result;
85}
86
87BOOL APIENTRY DllMain(HANDLE hModule,
88 DWORD ul_reason_for_call,
89 LPVOID lpReserved)
90{
91 return TRUE;
92}
93