diff --git a/PC/bdist_wininst/install.c b/PC/bdist_wininst/install.c --- a/PC/bdist_wininst/install.c +++ b/PC/bdist_wininst/install.c @@ -647,7 +647,6 @@ { char fullpath[_MAX_PATH]; LONG size = sizeof(fullpath); - char subkey_name[80]; char buffer[260 + 12]; HINSTANCE h; @@ -657,14 +656,11 @@ h = LoadLibrary(fname); if (h) return h; - wsprintf(subkey_name, - "SOFTWARE\\Python\\PythonCore\\%d.%d\\InstallPath", - py_major, py_minor); - if (ERROR_SUCCESS != RegQueryValue(HKEY_CURRENT_USER, subkey_name, - fullpath, &size) && - ERROR_SUCCESS != RegQueryValue(HKEY_LOCAL_MACHINE, subkey_name, - fullpath, &size)) + /* Now look in python_dir - this has come from the InstallPath in + // the registry (but only if our buffer is big enough!) */ + if (strlen(python_dir)+strlen(fname)+2 >= _MAX_PATH) return NULL; + strcpy(fullpath, python_dir); strcat(fullpath, "\\"); strcat(fullpath, fname); return LoadLibrary(fullpath); @@ -1732,6 +1728,7 @@ static BOOL OpenLogfile(char *dir) { char buffer[_MAX_PATH+1]; + char errBuffer[_MAX_PATH+100]; time_t ltime; struct tm *now; long result; @@ -1774,6 +1771,11 @@ sprintf(buffer, "%s\\%s-wininst.log", dir, meta_name); logfile = fopen(buffer, "a"); + if (logfile==NULL) { + sprintf(errBuffer, "Failed to open log file '%s'", buffer); + MessageBox(GetFocus(), errBuffer, "Can't open log file", MB_OK); + return FALSE; + } time(<ime); now = localtime(<ime); strftime(buffer, sizeof(buffer), @@ -1852,9 +1854,10 @@ strftime(buffer, sizeof(buffer), "*** Installation finished %Y/%m/%d %H:%M ***\n", localtime(<ime)); - fprintf(logfile, buffer); - if (logfile) + if (logfile) { + fprintf(logfile, buffer); fclose(logfile); + } } BOOL CALLBACK @@ -2462,9 +2465,13 @@ char *dllname; char *scriptname; static char lastscript[MAX_PATH]; + int lendllname; // includes \0 /* Format is 'Run Scripts: [pythondll]scriptname' */ -/* XXX Currently, pythondll carries no path!!! */ +/* XXX Currently, pythondll carries no path!!! The caller + works around this by setting the python_dir global to + the directory of the installation dir. +*/ dllname = strchr(line, '['); if (!dllname) return FALSE; @@ -2472,6 +2479,11 @@ scriptname = strchr(dllname, ']'); if (!scriptname) return FALSE; + /* copy the DLL name now we know where it ends. */ + lendllname = min(scriptname - dllname, _MAX_PATH-1); + strncpy(pythondll, dllname, lendllname); /* no \0 copied */ + pythondll[lendllname+1] = '\0'; + /* Terminate the scriptname */ *scriptname++ = '\0'; /* this function may be called more than one time with the same script, only run it one time */ @@ -2505,6 +2517,8 @@ int nErrors = 0; char **lines; int lines_buffer_size = 10; + char logfiledrive[_MAX_DRIVE]; + char logfiledir[_MAX_DIR]; if (argc != 3) { MessageBox(NULL, @@ -2529,6 +2543,19 @@ MB_OK); return 1; /* Error */ } + /* Assume the directory with the logfile is the Python directory, so + when we come to load the Python dll and can't find it "globally" + we try here. + */ + _splitpath(argv[2], logfiledrive, logfiledir, NULL, NULL); + strcpy(python_dir, logfiledrive); + strcat(python_dir, logfiledir); + /* trim trailing slash */ + if (python_dir[0] && + (python_dir[strlen(python_dir)-1]=='\\' || + python_dir[strlen(python_dir)-1]=='/')) { + python_dir[strlen(python_dir)-1] = '\0'; + } lines = (char **)malloc(sizeof(char *) * lines_buffer_size); if (!lines)