Martin v. Löwis | eb68be4 | 2004-12-12 15:29:21 +0000 | [diff] [blame] | 1 | #include "windows.h" |
| 2 | #include "msiquery.h" |
| 3 | |
Martin v. Löwis | 3c24d96 | 2005-02-18 16:18:09 +0000 | [diff] [blame] | 4 | int isWinNT; |
| 5 | |
Martin v. Löwis | eb68be4 | 2004-12-12 15:29:21 +0000 | [diff] [blame] | 6 | /* 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öwis | 3c24d96 | 2005-02-18 16:18:09 +0000 | [diff] [blame] | 10 | static UINT debug(MSIHANDLE hInstall, LPCSTR msg) |
Martin v. Löwis | eb68be4 | 2004-12-12 15:29:21 +0000 | [diff] [blame] | 11 | { |
| 12 | MSIHANDLE hRec = MsiCreateRecord(1); |
Martin v. Löwis | 3c24d96 | 2005-02-18 16:18:09 +0000 | [diff] [blame] | 13 | if (!hRec || MsiRecordSetStringA(hRec, 1, msg) != ERROR_SUCCESS) { |
Martin v. Löwis | eb68be4 | 2004-12-12 15:29:21 +0000 | [diff] [blame] | 14 | 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 | */ |
| 24 | UINT __declspec(dllexport) __stdcall CheckDir(MSIHANDLE hInstall) |
| 25 | { |
Martin v. Löwis | 3c24d96 | 2005-02-18 16:18:09 +0000 | [diff] [blame] | 26 | #define PSIZE 1024 |
| 27 | WCHAR wpath[PSIZE]; |
| 28 | char path[PSIZE]; |
Martin v. Löwis | eb68be4 | 2004-12-12 15:29:21 +0000 | [diff] [blame] | 29 | UINT result; |
Martin v. Löwis | 3c24d96 | 2005-02-18 16:18:09 +0000 | [diff] [blame] | 30 | DWORD size = PSIZE; |
Martin v. Löwis | eb68be4 | 2004-12-12 15:29:21 +0000 | [diff] [blame] | 31 | DWORD attributes; |
Martin v. Löwis | 3c24d96 | 2005-02-18 16:18:09 +0000 | [diff] [blame] | 32 | |
| 33 | isWinNT = (GetVersion() < 0x80000000) ? 1 : 0; |
Martin v. Löwis | eb68be4 | 2004-12-12 15:29:21 +0000 | [diff] [blame] | 34 | |
Martin v. Löwis | 3c24d96 | 2005-02-18 16:18:09 +0000 | [diff] [blame] | 35 | if (isWinNT) |
| 36 | result = MsiGetPropertyW(hInstall, L"TARGETDIR", wpath, &size); |
| 37 | else |
| 38 | result = MsiGetPropertyA(hInstall, "TARGETDIR", path, &size); |
Martin v. Löwis | eb68be4 | 2004-12-12 15:29:21 +0000 | [diff] [blame] | 39 | if (result != ERROR_SUCCESS) |
| 40 | return result; |
Martin v. Löwis | 3c24d96 | 2005-02-18 16:18:09 +0000 | [diff] [blame] | 41 | wpath[size] = L'\0'; |
Martin v. Löwis | eb68be4 | 2004-12-12 15:29:21 +0000 | [diff] [blame] | 42 | path[size] = L'\0'; |
| 43 | |
Martin v. Löwis | 3c24d96 | 2005-02-18 16:18:09 +0000 | [diff] [blame] | 44 | if (isWinNT) |
| 45 | attributes = GetFileAttributesW(wpath); |
| 46 | else |
| 47 | attributes = GetFileAttributesA(path); |
Martin v. Löwis | eb68be4 | 2004-12-12 15:29:21 +0000 | [diff] [blame] | 48 | if (attributes == INVALID_FILE_ATTRIBUTES || |
| 49 | !(attributes & FILE_ATTRIBUTE_DIRECTORY)) |
| 50 | { |
Martin v. Löwis | 3c24d96 | 2005-02-18 16:18:09 +0000 | [diff] [blame] | 51 | return MsiSetPropertyA(hInstall, "TargetExists", "0"); |
Martin v. Löwis | eb68be4 | 2004-12-12 15:29:21 +0000 | [diff] [blame] | 52 | } else { |
Martin v. Löwis | 3c24d96 | 2005-02-18 16:18:09 +0000 | [diff] [blame] | 53 | return MsiSetPropertyA(hInstall, "TargetExists", "1"); |
Martin v. Löwis | eb68be4 | 2004-12-12 15:29:21 +0000 | [diff] [blame] | 54 | } |
| 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 | */ |
| 61 | UINT __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öwis | 3c24d96 | 2005-02-18 16:18:09 +0000 | [diff] [blame] | 66 | result = MsiGetFeatureStateA(hInstall, "Extensions", &ext_old, &ext_new); |
Martin v. Löwis | eb68be4 | 2004-12-12 15:29:21 +0000 | [diff] [blame] | 67 | if (result != ERROR_SUCCESS) |
| 68 | return result; |
Martin v. Löwis | 3c24d96 | 2005-02-18 16:18:09 +0000 | [diff] [blame] | 69 | result = MsiGetFeatureStateA(hInstall, "TclTk", &tcl_old, &tcl_new); |
Martin v. Löwis | eb68be4 | 2004-12-12 15:29:21 +0000 | [diff] [blame] | 70 | 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öwis | 3c24d96 | 2005-02-18 16:18:09 +0000 | [diff] [blame] | 92 | result = MsiSetComponentStateA(hInstall, "REGISTRY.tcl", reg_new); |
Martin v. Löwis | eb68be4 | 2004-12-12 15:29:21 +0000 | [diff] [blame] | 93 | return result; |
| 94 | } |
| 95 | |
| 96 | BOOL APIENTRY DllMain(HANDLE hModule, |
| 97 | DWORD ul_reason_for_call, |
| 98 | LPVOID lpReserved) |
| 99 | { |
| 100 | return TRUE; |
| 101 | } |
| 102 | |