2
* Copyright (c) 2007, 2008 Agostino Russo
4
* Written by Agostino Russo <agostino.russo@gmail.com>
5
* Heavily inspired by exemaker from Fredrik Lundh
7
* pylauncher is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as
9
* published by the Free Software Foundation; either version 2 of
10
* the License, or (at your option) any later version.
12
* pylauncher is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21
* Pylauncher extracts a lzma archive that can be appended to this
22
* executable and containing:
24
* ./main.pyo # main script to run
26
* ./lib # python modules, ./lib is added to PYTHONPATH
27
* ./python.dll # python dll
29
* then it loads python.dll and runs main.py within that. A python
30
* script can be packed in the appropriate format using pack.py
32
* Note that the current implementation assumes that the python modules
33
* are bytecompiled and optimized (*.pyo)
40
#include "deletedir.h"
47
main(int ac, char **av)
49
//~ printf("pylauncher: starting\n");
52
char message[MAX_PATH + 1000];
53
char targetdir[MAX_PATH];
54
char exefile[MAX_PATH];
55
strcpy(targetdir, av[1]);
56
strcpy(exefile, av[2]);
58
//Run script in python script via pyrun
59
cmd = (char *)malloc((strlen(targetdir)*2 + +strlen(exefile) + 19) * sizeof(char));
60
sprintf(cmd, "\"%s\\pyrun.exe\" \"%s\" \"%s\"", targetdir, targetdir, exefile);
61
for (i = 3; i < (DWORD) ac; i++){
62
cmd = concat(cmd, " ", true);
63
cmd = concat(cmd, av[i], true);
66
ZeroMemory(&si, sizeof(si));
68
PROCESS_INFORMATION pi;
69
//~ printf("pylauncher running cmd: %s\n", cmd);
70
if(!CreateProcess(NULL, cmd, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi)){
71
strcpy(message, "Failed to run pyrun\n");
75
WaitForSingleObject(pi.hProcess, INFINITE);
80
//~ printf("pylauncher: deleting temp directory %s\n", targetdir);
81
delete_directory(targetdir);
83
//~ printf("pylauncher: Finished\n");
87
MessageBox(NULL, message, "Internal error", MB_ICONERROR | MB_OK);
88
//TBD We should delete the targetdir but might be risky
93
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
94
LPSTR lpCmdLine, int nCmdShow)
96
return main(__argc, __argv);