blob: b293bfc196c4ea8597706eab2ee488f95c34688b [file] [log] [blame]
Martin v. Löwiseb68be42004-12-12 15:29:21 +00001#include "windows.h"
2#include "msiquery.h"
3
Martin v. Löwis3c24d962005-02-18 16:18:09 +00004int isWinNT;
5
Martin v. Löwiseb68be42004-12-12 15:29:21 +00006/* Print a debug message to the installer log file.
7 * To see the debug messages, install with
8 * msiexec /i pythonxy.msi /l*v python.log
9 */
Martin v. Löwis3c24d962005-02-18 16:18:09 +000010static UINT debug(MSIHANDLE hInstall, LPCSTR msg)
Martin v. Löwiseb68be42004-12-12 15:29:21 +000011{
12 MSIHANDLE hRec = MsiCreateRecord(1);
Martin v. Löwis3c24d962005-02-18 16:18:09 +000013 if (!hRec || MsiRecordSetStringA(hRec, 1, msg) != ERROR_SUCCESS) {
Martin v. Löwiseb68be42004-12-12 15:29:21 +000014 return ERROR_INSTALL_FAILURE;
15 }
16 MsiProcessMessage(hInstall, INSTALLMESSAGE_INFO, hRec);
17 MsiCloseHandle(hRec);
18 return ERROR_SUCCESS;
19}
20
21/* Check whether the TARGETDIR exists and is a directory.
22 * Set TargetExists appropriately.
23 */
24UINT __declspec(dllexport) __stdcall CheckDir(MSIHANDLE hInstall)
25{
Martin v. Löwis3c24d962005-02-18 16:18:09 +000026#define PSIZE 1024
27 WCHAR wpath[PSIZE];
28 char path[PSIZE];
Martin v. Löwiseb68be42004-12-12 15:29:21 +000029 UINT result;
Martin v. Löwis3c24d962005-02-18 16:18:09 +000030 DWORD size = PSIZE;
Martin v. Löwiseb68be42004-12-12 15:29:21 +000031 DWORD attributes;
Martin v. Löwis3c24d962005-02-18 16:18:09 +000032
33 isWinNT = (GetVersion() < 0x80000000) ? 1 : 0;
Martin v. Löwiseb68be42004-12-12 15:29:21 +000034
Martin v. Löwis3c24d962005-02-18 16:18:09 +000035 if (isWinNT)
36 result = MsiGetPropertyW(hInstall, L"TARGETDIR", wpath, &size);
37 else
38 result = MsiGetPropertyA(hInstall, "TARGETDIR", path, &size);
Martin v. Löwiseb68be42004-12-12 15:29:21 +000039 if (result != ERROR_SUCCESS)
40 return result;
Martin v. Löwis3c24d962005-02-18 16:18:09 +000041 wpath[size] = L'\0';
Martin v. Löwiseb68be42004-12-12 15:29:21 +000042 path[size] = L'\0';
43
Martin v. Löwis3c24d962005-02-18 16:18:09 +000044 if (isWinNT)
45 attributes = GetFileAttributesW(wpath);
46 else
47 attributes = GetFileAttributesA(path);
Martin v. Löwiseb68be42004-12-12 15:29:21 +000048 if (attributes == INVALID_FILE_ATTRIBUTES ||
49 !(attributes & FILE_ATTRIBUTE_DIRECTORY))
50 {
Martin v. Löwis3c24d962005-02-18 16:18:09 +000051 return MsiSetPropertyA(hInstall, "TargetExists", "0");
Martin v. Löwiseb68be42004-12-12 15:29:21 +000052 } else {
Martin v. Löwis3c24d962005-02-18 16:18:09 +000053 return MsiSetPropertyA(hInstall, "TargetExists", "1");
Martin v. Löwiseb68be42004-12-12 15:29:21 +000054 }
55}
56
57/* Update the state of the REGISTRY.tcl component according to the
58 * Extension and TclTk features. REGISTRY.tcl must be installed
59 * if both features are installed, and must be absent otherwise.
60 */
61UINT __declspec(dllexport) __stdcall UpdateEditIDLE(MSIHANDLE hInstall)
62{
63 INSTALLSTATE ext_old, ext_new, tcl_old, tcl_new, reg_new;
64 UINT result;
65
Martin v. Löwis3c24d962005-02-18 16:18:09 +000066 result = MsiGetFeatureStateA(hInstall, "Extensions", &ext_old, &ext_new);
Martin v. Löwiseb68be42004-12-12 15:29:21 +000067 if (result != ERROR_SUCCESS)
68 return result;
Martin v. Löwis3c24d962005-02-18 16:18:09 +000069 result = MsiGetFeatureStateA(hInstall, "TclTk", &tcl_old, &tcl_new);
Martin v. Löwiseb68be42004-12-12 15:29:21 +000070 if (result != ERROR_SUCCESS)
71 return result;
72
73 /* If the current state is Absent, and the user did not select
74 the feature in the UI, Installer apparently sets the "selected"
75 state to unknown. Update it to the current value, then. */
76 if (ext_new == INSTALLSTATE_UNKNOWN)
77 ext_new = ext_old;
78 if (tcl_new == INSTALLSTATE_UNKNOWN)
79 tcl_new = tcl_old;
80
81 // XXX consider current state of REGISTRY.tcl?
82 if (((tcl_new == INSTALLSTATE_LOCAL) ||
83 (tcl_new == INSTALLSTATE_SOURCE) ||
84 (tcl_new == INSTALLSTATE_DEFAULT)) &&
85 ((ext_new == INSTALLSTATE_LOCAL) ||
86 (ext_new == INSTALLSTATE_SOURCE) ||
87 (ext_new == INSTALLSTATE_DEFAULT))) {
88 reg_new = INSTALLSTATE_SOURCE;
89 } else {
90 reg_new = INSTALLSTATE_ABSENT;
91 }
Martin v. Löwis3c24d962005-02-18 16:18:09 +000092 result = MsiSetComponentStateA(hInstall, "REGISTRY.tcl", reg_new);
Martin v. Löwiseb68be42004-12-12 15:29:21 +000093 return result;
94}
95
96BOOL APIENTRY DllMain(HANDLE hModule,
97 DWORD ul_reason_for_call,
98 LPVOID lpReserved)
99{
100 return TRUE;
101}
102