sdklauncher.c revision e13151727c63786342cddc3ea355425582bd4e7a
1/*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/*
18 * The "SDK Launcher" is for Windows only.
19 * This simple .exe will sit at the root of the Windows SDK
20 * and currently simply executes tools\android.bat.
21 * Eventually it should simply replace the batch file.
22 *
23 * TODO:
24 * - detect that java is installed; error dialog if not, explaning where to get it.
25 * - create temp dir, always copy *.jar there, exec android.jar
26 * - get jars to copy from some file
27 * - use a version number to copy jars only if needed (tools.revision?)
28 */
29
30#ifdef _WIN32
31
32#include <stdio.h>
33#include <windows.h>
34
35int sdk_launcher() {
36    STARTUPINFO           startup;
37    PROCESS_INFORMATION   pinfo;
38    char                  program_path[MAX_PATH];
39    int                   ret;
40
41    ZeroMemory(&startup, sizeof(startup));
42    startup.cb = sizeof(startup);
43
44    ZeroMemory(&pinfo, sizeof(pinfo));
45
46    /* get path of current program */
47    GetModuleFileName(NULL, program_path, sizeof(program_path));
48
49    ret = CreateProcess(
50            NULL,                                  /* program path */
51            "tools\\android.bat update sdk",         /* command-line */
52            NULL,                  /* process handle is not inheritable */
53            NULL,                   /* thread handle is not inheritable */
54            TRUE,                          /* yes, inherit some handles */
55            CREATE_NO_WINDOW,                /* we don't want a console */
56            NULL,                     /* use parent's environment block */
57            NULL,                    /* use parent's starting directory */
58            &startup,                 /* startup info, i.e. std handles */
59            &pinfo);
60
61    if (!ret) {
62        DWORD err = GetLastError();
63        fprintf(stderr, "CreateProcess failure, error %ld\n", err);
64
65        LPSTR s;
66        if (FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | /* dwFlags */
67                          FORMAT_MESSAGE_FROM_SYSTEM,
68                          NULL,                             /* lpSource */
69                          err,                              /* dwMessageId */
70                          0,                                /* dwLanguageId */
71                          (LPSTR)&s,                        /* lpBuffer */
72                          0,                                /* nSize */
73                          NULL) != 0) {                     /* va_list args */
74            fprintf(stderr, "%s", s);
75            LocalFree(s);
76        }
77
78        return -1;
79    }
80
81    return 0;
82}
83
84int main(int argc, char **argv) {
85    return sdk_launcher();
86}
87
88#endif /* _WIN32 */
89