summaryrefslogtreecommitdiffstats
path: root/sdklauncher
diff options
context:
space:
mode:
authorRaphael Moll <ralf@android.com>2010-04-28 14:23:50 -0700
committerRaphael Moll <ralf@android.com>2010-04-28 14:23:50 -0700
commit886a4f368cf3e793403b1b637e8f54f7a3ffb8e4 (patch)
tree1aa27cc579b500b96f170de0608510fc1522a23e /sdklauncher
parent2f3041c9707ca3a196083318d299ba71ab9d5cce (diff)
downloadreplicant_sdk-886a4f368cf3e793403b1b637e8f54f7a3ffb8e4.zip
replicant_sdk-886a4f368cf3e793403b1b637e8f54f7a3ffb8e4.tar.gz
replicant_sdk-886a4f368cf3e793403b1b637e8f54f7a3ffb8e4.tar.bz2
SDK Setup fixes.
- SDK Setup: cd to the SDK dir, to cope with the case where the setup is executed from a shortcut with a different base directory. - SDK Manager: properly detect "update sdk" and "update avds" commands. Change-Id: I1f0d32fffd71d3fa0856e753a80505f3dcd076d1
Diffstat (limited to 'sdklauncher')
-rw-r--r--sdklauncher/sdklauncher.c83
1 files changed, 61 insertions, 22 deletions
diff --git a/sdklauncher/sdklauncher.c b/sdklauncher/sdklauncher.c
index 23b785d..e1d97a1 100644
--- a/sdklauncher/sdklauncher.c
+++ b/sdklauncher/sdklauncher.c
@@ -29,9 +29,24 @@
#ifdef _WIN32
#include <stdio.h>
+#include <stdarg.h>
+#include <string.h>
#include <windows.h>
+int _enable_dprintf = 0;
+
+void dprintf(char *msg, ...) {
+ va_list ap;
+ va_start(ap, msg);
+
+ if (_enable_dprintf) {
+ vfprintf(stderr, msg, ap);
+ }
+
+ va_end(ap);
+}
+
void display_error(LPSTR description) {
DWORD err = GetLastError();
LPSTR s, s2;
@@ -170,8 +185,8 @@ int sdk_launcher() {
int result = 0;
STARTUPINFO startup;
PROCESS_INFORMATION pinfo;
- CHAR program_path[MAX_PATH];
- int ret;
+ CHAR program_dir[MAX_PATH];
+ int ret, pos;
CHAR temp_filename[MAX_PATH];
HANDLE temp_handle;
@@ -189,29 +204,50 @@ int sdk_launcher() {
startup.hStdOutput = temp_handle;
startup.hStdError = temp_handle;
- /* get path of current program */
- GetModuleFileName(NULL, program_path, sizeof(program_path));
-
- ret = CreateProcess(
- NULL, /* program path */
- "tools\\android.bat update sdk", /* command-line */
- NULL, /* process handle is not inheritable */
- NULL, /* thread handle is not inheritable */
- TRUE, /* yes, inherit some handles */
- CREATE_NO_WINDOW, /* we don't want a console */
- NULL, /* use parent's environment block */
- NULL, /* use parent's starting directory */
- &startup, /* startup info, i.e. std handles */
- &pinfo);
-
- if (!ret) {
- display_error("Failed to execute tools\\android.bat:");
+ /* get path of current program, to switch dirs here when executing the command. */
+ ret = GetModuleFileName(NULL, program_dir, sizeof(program_dir));
+ if (ret == 0) {
+ display_error("Failed to get program's filename:");
result = 1;
} else {
- WaitForSingleObject(pinfo.hProcess, INFINITE);
- CloseHandle(pinfo.hProcess);
- CloseHandle(pinfo.hThread);
+ /* Remove the last segment to keep only the directory. */
+ pos = ret - 1;
+ while (pos > 0 && program_dir[pos] != '\\') {
+ --pos;
+ }
+ program_dir[pos] = 0;
+ }
+
+ if (!result) {
+ dprintf("Program dir: %s\n", program_dir);
+
+ ret = CreateProcess(
+ NULL, /* program path */
+ "tools\\android.bat update sdk", /* command-line */
+ NULL, /* process handle is not inheritable */
+ NULL, /* thread handle is not inheritable */
+ TRUE, /* yes, inherit some handles */
+ CREATE_NO_WINDOW, /* we don't want a console */
+ NULL, /* use parent's environment block */
+ program_dir, /* use parent's starting directory */
+ &startup, /* startup info, i.e. std handles */
+ &pinfo);
+
+ dprintf("CreateProcess returned %d\n", ret);
+
+ if (!ret) {
+ display_error("Failed to execute tools\\android.bat:");
+ result = 1;
+ } else {
+ dprintf("Wait for process to finish.\n");
+
+ WaitForSingleObject(pinfo.hProcess, INFINITE);
+ CloseHandle(pinfo.hProcess);
+ CloseHandle(pinfo.hThread);
+ }
}
+
+ dprintf("Cleanup.\n");
if (!CloseHandle(temp_handle)) {
display_error("CloseHandle temp file failed");
@@ -229,6 +265,9 @@ int sdk_launcher() {
}
int main(int argc, char **argv) {
+ _enable_dprintf = argc > 1 && strcmp(argv[1], "-v") == 0;
+ dprintf("Verbose debug mode.\n");
+
return sdk_launcher();
}