Skip to content

Commit

Permalink
Windows: Support "just for me" Python installs (bug 1480)
Browse files Browse the repository at this point in the history
  • Loading branch information
thp committed Nov 11, 2011
1 parent fab79cf commit 619b6f3
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tools/win32-launcher/downloader.c
Expand Up @@ -19,6 +19,11 @@ DownloadFile(const char *filename, const char *url, unsigned long size)
HWND label;
MSG msg;

/**
* TODO: Check if filename exists and is size bytes long - if so,
* return size immediately without downloading the file again.
**/

#if defined(GPODDER_GUI)
dlg = CreateDialog(NULL, "PROGRESS", NULL, NULL);

Expand Down
Binary file modified tools/win32-launcher/gpo.exe
Binary file not shown.
34 changes: 34 additions & 0 deletions tools/win32-launcher/gpodder.c
Expand Up @@ -60,11 +60,37 @@
#define LOOKUP_FUNCTION(x) {x = GetProcAddress(python_dll, #x); \
if(x == NULL) {BAILOUT("Cannot find function: " #x);}}


const char *FindPythonDLL()
{
static char InstallPath[MAX_PATH];
DWORD InstallPathSize = MAX_PATH;
HKEY RegKey;
char *result = NULL;

if (RegOpenKeyEx(HKEY_CURRENT_USER,
"Software\\Python\\PythonCore\\2.7\\InstallPath",
0, KEY_READ, &RegKey) != ERROR_SUCCESS) {
return NULL;
}

if (RegQueryValueEx(RegKey, NULL, NULL, NULL,
InstallPath, &InstallPathSize) == ERROR_SUCCESS) {
strncat(InstallPath, "\\python27.dll", sizeof(InstallPath));
result = InstallPath;
}

RegCloseKey(RegKey);
return result;
}


int main(int argc, char** argv)
{
char path_env[MAX_PATH];
char current_dir[MAX_PATH];
char *endmarker = NULL;
char *dll_path = NULL;
int i;
void *MainPy;
void *GtkModule;
Expand Down Expand Up @@ -122,6 +148,14 @@ int main(int argc, char** argv)
/* Only load the Python DLL after we've set up the environment */
python_dll = LoadLibrary("python27.dll");

if (python_dll == NULL) {
/* Try to detect "just for me"-installed Python version (bug 1480) */
dll_path = FindPythonDLL();
if (dll_path != NULL) {
python_dll = LoadLibrary(dll_path);
}
}

if (python_dll == NULL) {
if (MessageBox(NULL,
PROGNAME " requires Python 2.7.\n"
Expand Down
Binary file modified tools/win32-launcher/gpodder.exe
Binary file not shown.

0 comments on commit 619b6f3

Please sign in to comment.