@@ -228,95 +228,7 @@ def addPackage(zf, name, path, orig, distInfo=False):
228228 if file .endswith (".dll" ):
229229 shutil .copy (os .path .join (datafolder , file ), "." )
230230
231- print ("WRITE pyunity-editor.c" , flush = True )
232- with open ("pyunity-editor.c" , "w+" ) as f :
233- f .write (textwrap .dedent ("""
234- #define PY_SSIZE_T_CLEAN
235- #define Py_LIMITED_API 0x03060000
236- #include <Python.h>
237-
238- #ifdef NOCONSOLE
239- #include <windows.h>
240- #define CHECK_ERROR(n) if (PyErr_Occurred() != NULL) { showError(); exit(1); }
241-
242- void showError() {
243- printf("Error encountered\n ");
244- PyObject *type, *value, *traceback;
245- PyErr_Fetch(&type, &value, &traceback);
246- PyErr_Print();
247-
248- PyObject *tracebackModule = PyImport_ImportModule("traceback");
249- PyObject *formatFunc = PyObject_GetAttrString(tracebackModule, "format_exception");
250- Py_DecRef(tracebackModule);
251-
252- PyErr_NormalizeException(&type, &value, &traceback);
253- PyException_SetTraceback(value, traceback);
254-
255- PyObject *lines = PyObject_CallFunctionObjArgs(formatFunc, value, NULL);
256- PyObject *sep = PyUnicode_FromString("");
257- PyObject *joined = PyUnicode_Join(sep, lines);
258- Py_DecRef(sep);
259- Py_DecRef(lines);
260-
261- wchar_t *msg = PyUnicode_AsWideCharString(joined, NULL);
262- MessageBoxW(NULL, msg, L"Error loading PyUnity Editor", 0x10L);
263- PyMem_Free(msg);
264-
265- PyErr_Restore(type, value, traceback);
266- }
267- #else
268- #define CHECK_ERROR() if (PyErr_Occurred() != NULL) { PyErr_Print(); exit(1); }
269- #endif
270-
271- int main(int argc, char **argv) {
272- wchar_t *path = Py_DecodeLocale("Lib\\ python.zip;Lib;Lib\\ win32;Lib\\ win32\\ lib", NULL);
273- Py_SetPath(path);
274- wchar_t **program = (wchar_t**)PyMem_Malloc(sizeof(wchar_t**) * argc);
275- for (int i = 0; i < argc; i++) {
276- program[i] = Py_DecodeLocale(argv[i], NULL);
277- }
278- if (program[0] == NULL) {
279- fprintf(stderr, "Fatal error: cannot decode argv[0]\n ");
280- exit(1);
281- }
282- Py_SetProgramName(program[0]);
283- Py_Initialize();
284- PySys_SetArgvEx(argc, program, 0);
285- CHECK_ERROR();
286-
287- PyObject *editor = PyImport_ImportModule("pyunity_editor.cli");
288- CHECK_ERROR();
289-
290- #ifdef NOCONSOLE
291- PyObject *func = PyObject_GetAttrString(editor, "gui");
292- #else
293- PyObject *func = PyObject_GetAttrString(editor, "run");
294- #endif
295- CHECK_ERROR();
296-
297- PyObject *res = PyObject_CallFunction(func, NULL);
298- CHECK_ERROR();
299-
300- if (Py_FinalizeEx() < 0) {
301- exit(1);
302- }
303- for (int i = 0; i < argc; i++) {
304- PyMem_Free((void*)program[i]);
305- }
306- PyMem_Free((void*)program);
307- PyMem_Free((void*)path);
308- printf("Safely freed memory\n ");
309- return 0;
310- }
311-
312- #ifdef NOCONSOLE
313- int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
314- char* pCmdLine, int nShowCmd) {
315- return main(__argc, __argv);
316- }
317- #endif
318- """ ))
319-
231+ shutil .copy (orig + "\\ standalone\\ pyunity-editor.c" , ".." )
320232 shutil .copy (orig + "\\ standalone\\ icons.ico" , ".." )
321233 shutil .copy (orig + "\\ standalone\\ icons.rc" , ".." )
322234 shutil .copy (orig + "\\ standalone\\ version.rc" , ".." )
@@ -334,7 +246,7 @@ def addPackage(zf, name, path, orig, distInfo=False):
334246 print ("COMPILE pyunity-editor.exe" , flush = True )
335247 subprocess .call ([
336248 "cl.exe" , "/nologo" , "/O2" , "/Wall" ,
337- "/Tcpyunity -editor.c" , "/Fo..\\ pyunity-editor.obj" ,
249+ "/Tc.. \\ pyunity -editor.c" , "/Fo..\\ pyunity-editor.obj" ,
338250 f"/I{ sys .base_prefix } \\ include" , "/DNOCONSOLE" ,
339251 "/link" , "..\\ icons.res" , "..\\ version.res" , "/subsystem:windows" ,
340252 f"/libpath:{ sys .base_prefix } \\ libs" ,
@@ -355,10 +267,9 @@ def addPackage(zf, name, path, orig, distInfo=False):
355267 print ("COMPILE pyunity-editor.exe" , flush = True )
356268 subprocess .call ([
357269 "gcc.exe" , "-O2" , "-Wall" , "-mwindows" , "-DNOCONSOLE" ,
358- "-o" , "pyunity-editor.exe" , "pyunity-editor.c" , "..\\ icons.o" , "..\\ version.o" ,
270+ "-o" , "pyunity-editor.exe" , ".. \\ pyunity-editor.c" , "..\\ icons.o" , "..\\ version.o" ,
359271 "-L." , f"-l{ zipname } " , f"-I{ sys .base_prefix } \\ include" ,
360272 ], stdout = sys .stdout , stderr = sys .stderr )
361- os .remove ("pyunity-editor.c" )
362273
363274 print (f"ZIP pyunity-editor.zip" , flush = True )
364275 os .chdir (tmp )
0 commit comments