~usb-creator-hackers/usb-creator/trunk

« back to all changes in this revision

Viewing changes to tools/pylauncher/pylauncher.c

  • Committer: Brian Murray
  • Date: 2021-04-02 15:52:52 UTC
  • Revision ID: brian@canonical.com-20210402155252-tk5d4a6lczeld0e0
Tags: 0.3.9
releasing package usb-creator version 0.3.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (c) 2007, 2008 Agostino Russo
3
 
 *
4
 
 *  Written by Agostino Russo <agostino.russo@gmail.com>
5
 
 *  Heavily inspired by exemaker from Fredrik Lundh
6
 
 *
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.
11
 
 *
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.
16
 
 *
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/>.
19
 
 *
20
 
 * DESCRIPTION:
21
 
 * Pylauncher extracts a lzma archive that can be appended to this
22
 
 * executable and containing:
23
 
 *
24
 
 * ./main.pyo           # main script to run
25
 
 * ./data                  # data
26
 
 * ./lib                     # python modules, ./lib is added to PYTHONPATH
27
 
 * ./python.dll         # python dll
28
 
 *
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
31
 
 *
32
 
 * Note that the current implementation assumes that the python modules
33
 
 * are bytecompiled and  optimized (*.pyo)
34
 
 *
35
 
 */
36
 
 
37
 
#include <stdio.h>
38
 
#include <stdlib.h>
39
 
#include "windows.h"
40
 
#include "deletedir.h"
41
 
#include "str.h"
42
 
 
43
 
#define true 1
44
 
#define false 0
45
 
 
46
 
int __cdecl
47
 
main(int ac, char **av)
48
 
{
49
 
    //~ printf("pylauncher: starting\n");
50
 
    DWORD i;
51
 
    char *cmd;
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]);
57
 
 
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);
64
 
    }
65
 
    STARTUPINFO si;
66
 
    ZeroMemory(&si, sizeof(si));
67
 
    si.cb = 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");
72
 
        free(cmd);
73
 
        goto error;
74
 
    } else {
75
 
        WaitForSingleObject(pi.hProcess, INFINITE);
76
 
    }
77
 
    free(cmd);
78
 
 
79
 
    //Delete directory
80
 
    //~ printf("pylauncher: deleting temp directory %s\n", targetdir);
81
 
    delete_directory(targetdir);
82
 
 
83
 
    //~ printf("pylauncher: Finished\n");
84
 
    return 0;
85
 
 
86
 
error:
87
 
    MessageBox(NULL, message, "Internal error", MB_ICONERROR | MB_OK);
88
 
    //TBD We should delete the targetdir but might be risky
89
 
    return 1;
90
 
}
91
 
 
92
 
int WINAPI
93
 
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
94
 
        LPSTR lpCmdLine, int nCmdShow)
95
 
{
96
 
    return main(__argc, __argv);
97
 
}