blob: a6feadfd14ec89f431b4c03fd5a669bf87386652 [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 */
8static UINT debug(MSIHANDLE hInstall, LPCWSTR msg)
9{
10 MSIHANDLE hRec = MsiCreateRecord(1);
11 if (!hRec || MsiRecordSetStringW(hRec, 1, msg) != ERROR_SUCCESS) {
12 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{
24 WCHAR path[1024];
25 UINT result;
26 DWORD size = sizeof(path)/sizeof(WCHAR);
27 DWORD attributes;
28
29 result = MsiGetPropertyW(hInstall, L"TARGETDIR", path, &size);
30 if (result != ERROR_SUCCESS)
31 return result;
32 path[size] = L'\0';
33
34 attributes = GetFileAttributesW(path);
35 if (attributes == INVALID_FILE_ATTRIBUTES ||
36 !(attributes & FILE_ATTRIBUTE_DIRECTORY))
37 {
38 return MsiSetPropertyW(hInstall, L"TargetExists", L"0");
39 } else {
40 return MsiSetPropertyW(hInstall, L"TargetExists", L"1");
41 }
42}
43
44/* Update the state of the REGISTRY.tcl component according to the
45 * Extension and TclTk features. REGISTRY.tcl must be installed
46 * if both features are installed, and must be absent otherwise.
47 */
48UINT __declspec(dllexport) __stdcall UpdateEditIDLE(MSIHANDLE hInstall)
49{
50 INSTALLSTATE ext_old, ext_new, tcl_old, tcl_new, reg_new;
51 UINT result;
52
53 result = MsiGetFeatureStateW(hInstall, L"Extensions", &ext_old, &ext_new);
54 if (result != ERROR_SUCCESS)
55 return result;
56 result = MsiGetFeatureStateW(hInstall, L"TclTk", &tcl_old, &tcl_new);
57 if (result != ERROR_SUCCESS)
58 return result;
59
60 /* If the current state is Absent, and the user did not select
61 the feature in the UI, Installer apparently sets the "selected"
62 state to unknown. Update it to the current value, then. */
63 if (ext_new == INSTALLSTATE_UNKNOWN)
64 ext_new = ext_old;
65 if (tcl_new == INSTALLSTATE_UNKNOWN)
66 tcl_new = tcl_old;
67
68 // XXX consider current state of REGISTRY.tcl?
69 if (((tcl_new == INSTALLSTATE_LOCAL) ||
70 (tcl_new == INSTALLSTATE_SOURCE) ||
71 (tcl_new == INSTALLSTATE_DEFAULT)) &&
72 ((ext_new == INSTALLSTATE_LOCAL) ||
73 (ext_new == INSTALLSTATE_SOURCE) ||
74 (ext_new == INSTALLSTATE_DEFAULT))) {
75 reg_new = INSTALLSTATE_SOURCE;
76 } else {
77 reg_new = INSTALLSTATE_ABSENT;
78 }
79 result = MsiSetComponentStateW(hInstall, L"REGISTRY.tcl", reg_new);
80 return result;
81}
82
83BOOL APIENTRY DllMain(HANDLE hModule,
84 DWORD ul_reason_for_call,
85 LPVOID lpReserved)
86{
87 return TRUE;
88}
89