|
27 | 27 | #include <windows.h> |
28 | 28 | #include <shlobj.h> |
29 | 29 |
|
| 30 | +#include <stdio.h> |
30 | 31 | #include <stdlib.h> |
31 | 32 | #include <shellapi.h> |
32 | 33 | #include <string.h> |
| 34 | +#include <sys/stat.h> |
| 35 | +#include <stdbool.h> |
33 | 36 |
|
34 | 37 | #include "gpodder.h" |
35 | 38 | #include "downloader.h" |
@@ -81,6 +84,45 @@ const char *FindPythonDLL(HKEY rootKey) |
81 | 84 | return result; |
82 | 85 | } |
83 | 86 |
|
| 87 | +bool contains_system_dll(const char *path, const char *filename) |
| 88 | +{ |
| 89 | + bool result = false; |
| 90 | + struct stat st; |
| 91 | + |
| 92 | + char *fn = malloc(strlen(path) + 1 + strlen(filename) + 1); |
| 93 | + sprintf(fn, "%s\\%s", path, filename); |
| 94 | + if (stat(fn, &st) == 0) { |
| 95 | + result = true; |
| 96 | + } |
| 97 | + free(fn); |
| 98 | + |
| 99 | + return result; |
| 100 | +} |
| 101 | + |
| 102 | +char *clean_path_variable(const char *path) |
| 103 | +{ |
| 104 | + char *old_path = strdup(path); |
| 105 | + int length = strlen(path) + 1; |
| 106 | + char *new_path = (char *)malloc(length); |
| 107 | + memset(new_path, 0, length); |
| 108 | + |
| 109 | + char *tok = strtok(old_path, ";"); |
| 110 | + while (tok != NULL) { |
| 111 | + // Only add the path component if it doesn't contain msvcr90.dll |
| 112 | + if (!contains_system_dll(tok, "msvcr90.dll")) { |
| 113 | + if (strlen(new_path) > 0) { |
| 114 | + strcat(new_path, ";"); |
| 115 | + } |
| 116 | + |
| 117 | + strcat(new_path, tok); |
| 118 | + } |
| 119 | + |
| 120 | + tok = strtok(NULL, ";"); |
| 121 | + } |
| 122 | + |
| 123 | + free(old_path); |
| 124 | + return new_path; |
| 125 | +} |
84 | 126 |
|
85 | 127 | int main(int argc, char** argv) |
86 | 128 | { |
@@ -140,6 +182,14 @@ int main(int argc, char** argv) |
140 | 182 | } |
141 | 183 | } |
142 | 184 |
|
| 185 | + /** |
| 186 | + * Workaround for error R6034 (need to do this before Python DLL |
| 187 | + * is loaded, otherwise the runtime error will still show up) |
| 188 | + **/ |
| 189 | + char *new_path = clean_path_variable(getenv("PATH")); |
| 190 | + SetEnvironmentVariable("PATH", new_path); |
| 191 | + free(new_path); |
| 192 | + |
143 | 193 | /* Only load the Python DLL after we've set up the environment */ |
144 | 194 | python_dll = LoadLibrary("python27.dll"); |
145 | 195 |
|
|
0 commit comments