aboutsummaryrefslogtreecommitdiffstats
path: root/sdkmanager
diff options
context:
space:
mode:
authorRaphael <raphael@google.com>2012-01-24 15:06:56 -0800
committerRaphael <raphael@google.com>2012-01-25 10:16:18 -0800
commitd2d6999d779fffe976c55db04bf523907a8743ed (patch)
tree5a5ea7db3cac33e6f8403992ad47b1111c71c3f4 /sdkmanager
parent22fd3c107616214d2a6baecb64fe1354686cb470 (diff)
downloadsdk-d2d6999d779fffe976c55db04bf523907a8743ed.zip
sdk-d2d6999d779fffe976c55db04bf523907a8743ed.tar.gz
sdk-d2d6999d779fffe976c55db04bf523907a8743ed.tar.bz2
Windows: "find_java" exe and lib for android.bat
This adds a "find_java.exe" that will be packages in SDK/tools/lib. It will be used by android.bat and the other launchers to locate the best version of java to use for our tools (currently we have a find_java.bat that uses DOS commands to achieve something similar but more limited). In addition this creates a static "findjavalib" that is used by the NSIS installer to locate java and get its version (to complain in case we only find a Java 1.4 or lesser). The goal is for the installer to use the same logic as the tools will use to locate the java binary. Change-Id: Ic2efb388135087bab9687c3332882047fd041b1c
Diffstat (limited to 'sdkmanager')
-rw-r--r--sdkmanager/win_android/.gitignore1
-rw-r--r--sdkmanager/win_android/Android.mk70
-rw-r--r--sdkmanager/win_android/NOTICE190
-rwxr-xr-xsdkmanager/win_android/find_java.cpp321
-rwxr-xr-xsdkmanager/win_android/find_java.h29
-rw-r--r--sdkmanager/win_android/images/android_icon.icobin300318 -> 0 bytes
-rw-r--r--sdkmanager/win_android/images/android_icon.rc2
-rwxr-xr-xsdkmanager/win_android/utils.cpp193
-rwxr-xr-xsdkmanager/win_android/utils.h336
-rw-r--r--sdkmanager/win_android/win_android.cpp373
-rwxr-xr-xsdkmanager/win_android/win_android.exe.manifest33
11 files changed, 0 insertions, 1548 deletions
diff --git a/sdkmanager/win_android/.gitignore b/sdkmanager/win_android/.gitignore
deleted file mode 100644
index 589b106..0000000
--- a/sdkmanager/win_android/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-images/win_android_icon.o
diff --git a/sdkmanager/win_android/Android.mk b/sdkmanager/win_android/Android.mk
deleted file mode 100644
index 2f111a0..0000000
--- a/sdkmanager/win_android/Android.mk
+++ /dev/null
@@ -1,70 +0,0 @@
-# Copyright 2011 The Android Open Source Project
-#
-# Android.mk for sdkmanager/win_android
-
-
-LOCAL_PATH := $(call my-dir)
-
-# find_java static library for host
-# ========================================================
-
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := libfindjava
-LOCAL_SRC_FILES := find_java.cpp utils.cpp
-
-LOCAL_CFLAGS += -Wall -Wno-unused-parameter
-LOCAL_CFLAGS += -D_XOPEN_SOURCE -D_GNU_SOURCE -DSH_HISTORY -DUSE_MINGW
-
-include $(BUILD_HOST_STATIC_LIBRARY)
-
-
-# "win_android.exe", a host replacement for "android.bat". For the Windows SDK only.
-# ========================================================
-
-include $(CLEAR_VARS)
-
-ifeq ($(HOST_OS),windows)
-
-LOCAL_SRC_FILES := \
- win_android.cpp
-
-LOCAL_MODULE := win_android
-LOCAL_STATIC_LIBRARIES := libfindjava
-
-LOCAL_CFLAGS += -Wall -Wno-unused-parameter
-LOCAL_CFLAGS += -D_XOPEN_SOURCE -D_GNU_SOURCE -DSH_HISTORY -DUSE_MINGW
-
-LOCAL_MODULE_TAGS := optional
-
-# Locate windres executable
-WINDRES := windres
-ifneq ($(USE_MINGW),)
- # When building the Windows resources under Linux, use the MinGW one
- WINDRES := i586-mingw32msvc-windres
-endif
-
-# Link the Windows icon file as well into the executable, based on the technique
-# used in external/qemu/Makefile.android. The variables need to have different
-# names to not interfere with the ones from qemu/Makefile.android.
-#
-INTERMEDIATE := $(call intermediates-dir-for,EXECUTABLES,$(LOCAL_MODULE),true)
-WIN_ANDROID_ICON_OBJ := win_android_icon.o
-WIN_ANDROID_ICON_PATH := $(LOCAL_PATH)/images
-$(WIN_ANDROID_ICON_PATH)/$(WIN_ANDROID_ICON_OBJ): $(WIN_ANDROID_ICON_PATH)/android_icon.rc
- $(WINDRES) $< -I $(WIN_ANDROID_ICON_PATH) -o $@
-
-# seems to be the only way to add an object file that was not generated from
-# a C/C++/Java source file to our build system. and very unfortunately,
-# $(TOPDIR)/$(LOCALPATH) will always be prepended to this value, which forces
-# us to put the object file in the source directory...
-#
-LOCAL_PREBUILT_OBJ_FILES += images/$(WIN_ANDROID_ICON_OBJ)
-
-include $(BUILD_HOST_EXECUTABLE)
-
-$(call dist-for-goals,droid,$(LOCAL_BUILT_MODULE))
-
-endif
-
-
diff --git a/sdkmanager/win_android/NOTICE b/sdkmanager/win_android/NOTICE
deleted file mode 100644
index 7317ae2..0000000
--- a/sdkmanager/win_android/NOTICE
+++ /dev/null
@@ -1,190 +0,0 @@
-
- Copyright (c) 2005-2011, The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
-
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
- END OF TERMS AND CONDITIONS
-
diff --git a/sdkmanager/win_android/find_java.cpp b/sdkmanager/win_android/find_java.cpp
deleted file mode 100755
index eea09ef..0000000
--- a/sdkmanager/win_android/find_java.cpp
+++ /dev/null
@@ -1,321 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifdef _WIN32
-
-#include "find_java.h"
-#include <shlobj.h>
-
-extern bool gDebug;
-
-// Check whether we can find $PATH/java.exe
-static bool checkPath(CPath *inOutPath) {
- inOutPath->addPath("java.exe");
-
- bool result = false;
- PVOID oldWow64Value = disableWow64FsRedirection();
- if (inOutPath->fileExists()) {
- // Make sure we can actually run "java -version".
- CString cmd;
- cmd.setf("\"%s\" -version", inOutPath->cstr());
- int code = execWait(cmd.cstr());
- result = (code == 0);
- }
-
- revertWow64FsRedirection(oldWow64Value);
- return result;
-}
-
-// Check whether we can find $PATH/bin/java.exe
-static bool checkBinPath(CPath *inOutPath) {
- inOutPath->addPath("bin");
- return checkPath(inOutPath);
-}
-
-// Search java.exe in the environment
-bool findJavaInEnvPath(CPath *outJavaPath) {
- SetLastError(0);
-
- const char* envPath = getenv("JAVA_HOME");
- if (envPath != NULL) {
- CPath p(envPath);
- if (checkBinPath(&p)) {
- if (gDebug) msgBox("Java found via JAVA_HOME: %s", p.cstr());
- *outJavaPath = p;
- return true;
- }
- }
-
- envPath = getenv("PATH");
- if (!envPath) return false;
-
- CArray<CString> *paths = CString(envPath).split(';');
- for(int i = 0; i < paths->size(); i++) {
- CPath p((*paths)[i].cstr());
- if (checkPath(&p)) {
- if (gDebug) msgBox("Java found via env PATH: %s", p.cstr());
- *outJavaPath = p;
- delete paths;
- return true;
- }
- }
-
- delete paths;
- return false;
-}
-
-// --------------
-
-bool getRegValue(const char *keyPath, const char *keyName, REGSAM access, CString *outValue) {
- HKEY key;
- LSTATUS status = RegOpenKeyExA(
- HKEY_LOCAL_MACHINE, // hKey
- keyPath, // lpSubKey
- 0, // ulOptions
- KEY_READ | access, // samDesired,
- &key); // phkResult
- if (status == ERROR_SUCCESS) {
-
- LSTATUS ret = ERROR_MORE_DATA;
- DWORD size = 4096; // MAX_PATH is 260, so 4 KB should be good enough
- char* buffer = (char*) malloc(size);
-
- while (ret == ERROR_MORE_DATA && size < (1<<16) /*64 KB*/) {
- ret = RegQueryValueExA(
- key, // hKey
- keyName, // lpValueName
- NULL, // lpReserved
- NULL, // lpType
- (LPBYTE) buffer, // lpData
- &size); // lpcbData
-
- if (ret == ERROR_MORE_DATA) {
- size *= 2;
- buffer = (char*) realloc(buffer, size);
- } else {
- buffer[size] = 0;
- }
- }
-
- if (ret != ERROR_MORE_DATA) outValue->set(buffer);
-
- free(buffer);
- RegCloseKey(key);
-
- return (ret != ERROR_MORE_DATA);
- }
-
- return false;
-}
-
-bool exploreJavaRegistry(const char *entry, REGSAM access, CPath *outJavaPath) {
-
- // Let's visit HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment [CurrentVersion]
- CPath subKey("SOFTWARE\\JavaSoft\\");
- subKey.addPath(entry);
-
- CString currVersion;
- if (getRegValue(subKey.cstr(), "CurrentVersion", access, &currVersion)) {
- // CurrentVersion should be something like "1.7".
- // We want to read HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\1.7 [JavaHome]
- subKey.addPath(currVersion);
- CPath javaHome;
- if (getRegValue(subKey.cstr(), "JavaHome", access, &javaHome)) {
- if (checkBinPath(&javaHome)) {
- *outJavaPath = javaHome;
- return true;
- }
- }
- }
-
- return false;
-}
-
-bool findJavaInRegistry(CPath *outJavaPath) {
- // We'll do the registry test 3 times: first using the default mode,
- // then forcing the use of the 32-bit registry then forcing the use of
- // 64-bit registry. On Windows 2k, the 2 latter will fail since the
- // flags are not supported. On a 32-bit OS the 64-bit is obviously
- // useless and the 2 first test should be equivalent so we just
- // need the first case.
-
- // Check the JRE first, then the JDK.
- if (exploreJavaRegistry("Java Runtime Environment", 0, outJavaPath) ||
- exploreJavaRegistry("Java Development Kit", 0, outJavaPath)) {
- return true;
- }
-
- // Check the real sysinfo state (not the one hidden by WOW64) for x86
- SYSTEM_INFO sysInfo;
- GetNativeSystemInfo(&sysInfo);
-
- if (sysInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) {
- if (exploreJavaRegistry("Java Runtime Environment", KEY_WOW64_32KEY, outJavaPath) ||
- exploreJavaRegistry("Java Development Kit", KEY_WOW64_32KEY, outJavaPath)) {
- return true;
- }
-
- if (exploreJavaRegistry("Java Runtime Environment", KEY_WOW64_64KEY, outJavaPath) ||
- exploreJavaRegistry("Java Development Kit", KEY_WOW64_64KEY, outJavaPath)) {
- return true;
- }
- }
-
- return false;
-}
-
-// --------------
-
-static bool checkProgramFiles(CPath *outJavaPath) {
-
- char programFilesPath[MAX_PATH + 1];
- HRESULT result = SHGetFolderPathA(
- NULL, // hwndOwner
- CSIDL_PROGRAM_FILES, // nFolder
- NULL, // hToken
- SHGFP_TYPE_CURRENT, // dwFlags
- programFilesPath); // pszPath
- if (FAILED(result)) return false;
-
- CPath path(programFilesPath);
- path.addPath("Java");
-
- // Do we have a C:\\Program Files\\Java directory?
- if (!path.dirExists()) return false;
-
- CPath glob(path);
- glob.addPath("j*");
-
- bool found = false;
- WIN32_FIND_DATAA findData;
- HANDLE findH = FindFirstFileA(glob.cstr(), &findData);
- if (findH == INVALID_HANDLE_VALUE) return false;
- do {
- if ((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0) {
- CPath temp(path);
- temp.addPath(findData.cFileName);
- // Check C:\\Program Files[x86]\\Java\\{jdk,jre}*\\bin\\java.exe
- if (checkBinPath(&temp)) {
- found = true;
- *outJavaPath = temp;
- }
- }
- } while (!found && FindNextFileA(findH, &findData) != 0);
- FindClose(findH);
-
- return found;
-}
-
-bool findJavaInProgramFiles(CPath *outJavaPath) {
- // Check the C:\\Program Files (x86) directory
- // With WOW64 fs redirection in place by default, we should get the x86
- // version on a 64-bit OS since this app is a 32-bit itself.
- if (checkProgramFiles(outJavaPath)) return true;
-
- // Check the real sysinfo state (not the one hidden by WOW64) for x86
- SYSTEM_INFO sysInfo;
- GetNativeSystemInfo(&sysInfo);
-
- if (sysInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) {
- // On a 64-bit OS, try again by disabling the fs redirection so
- // that we can try the real C:\\Program Files directory.
- PVOID oldWow64Value = disableWow64FsRedirection();
- bool found = checkProgramFiles(outJavaPath);
- revertWow64FsRedirection(oldWow64Value);
- return found;
- }
-
- return false;
-}
-
-// --------------
-
-static bool getJavaVersion(CPath &javaPath, CString *version) {
- bool result = false;
-
- // Run "java -version".
- // TODO: capture output to string.
- CString cmd;
- cmd.setf("\"%s\" -version", javaPath.cstr());
-
- SECURITY_ATTRIBUTES saAttr;
- STARTUPINFO startup;
- PROCESS_INFORMATION pinfo;
-
- // Want to inherit pipe handle
- ZeroMemory(&saAttr, sizeof(saAttr));
- saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
- saAttr.bInheritHandle = TRUE;
- saAttr.lpSecurityDescriptor = NULL;
-
- // Create pipe for stdout
- HANDLE stdoutPipeRd, stdoutPipeWt;
- if (!CreatePipe(
- &stdoutPipeRd, // hReadPipe,
- &stdoutPipeWt, // hWritePipe,
- &saAttr, // lpPipeAttributes,
- 0)) { // nSize (0=default buffer size)
- displayLastError("CreatePipe failed: ");
- return false;
- }
-
-
- ZeroMemory(&pinfo, sizeof(pinfo));
-
- ZeroMemory(&startup, sizeof(startup));
- startup.cb = sizeof(startup);
- startup.dwFlags = STARTF_USESHOWWINDOW;
- startup.wShowWindow = SW_HIDE|SW_MINIMIZE;
-
- int ret = CreateProcessA(
- NULL, /* program path */
- (LPSTR) cmd, /* 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) {
- WaitForSingleObject(pinfo.hProcess, INFINITE);
-
- DWORD exitCode;
- if (GetExitCodeProcess(pinfo.hProcess, &exitCode)) {
- // this should not return STILL_ACTIVE (259)
- result = exitCode == 0;
- }
- CloseHandle(pinfo.hProcess);
- CloseHandle(pinfo.hThread);
- }
- CloseHandle(stdoutPipeRd);
- CloseHandle(stdoutPipeWt);
-
- if (result) {
- // TODO
- // Parse output of "java -version".
- // It should be something like:
- // java version "1.6.0_29"
- // (including the quotes.)
- }
-
- return result;
-}
-
-
-#endif /* _WIN32 */
diff --git a/sdkmanager/win_android/find_java.h b/sdkmanager/win_android/find_java.h
deleted file mode 100755
index 41e5720..0000000
--- a/sdkmanager/win_android/find_java.h
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _H_FIND_JAVA
-#define _H_FIND_JAVA
-
-#ifdef _WIN32
-
-#include "utils.h"
-
-bool findJavaInEnvPath(CPath *outJavaPath);
-bool findJavaInRegistry(CPath *outJavaPath);
-bool findJavaInProgramFiles(CPath *outJavaPath);
-
-#endif /* _WIN32 */
-#endif /* _H_FIND_JAVA */
diff --git a/sdkmanager/win_android/images/android_icon.ico b/sdkmanager/win_android/images/android_icon.ico
deleted file mode 100644
index bd25179..0000000
--- a/sdkmanager/win_android/images/android_icon.ico
+++ /dev/null
Binary files differ
diff --git a/sdkmanager/win_android/images/android_icon.rc b/sdkmanager/win_android/images/android_icon.rc
deleted file mode 100644
index 42298a9..0000000
--- a/sdkmanager/win_android/images/android_icon.rc
+++ /dev/null
@@ -1,2 +0,0 @@
-1 ICON "../images/android_icon.ico"
-1 RT_MANIFEST "../win_android.exe.manifest"
diff --git a/sdkmanager/win_android/utils.cpp b/sdkmanager/win_android/utils.cpp
deleted file mode 100755
index bef1aa7..0000000
--- a/sdkmanager/win_android/utils.cpp
+++ /dev/null
@@ -1,193 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifdef _WIN32
-
-#include "utils.h"
-
-#define _CRT_SECURE_NO_WARNINGS 1
-
-bool gDebug = false;
-
-// Displays a message in an ok+info dialog box.
-void msgBox(const char* text, ...) {
- CString formatted;
- va_list ap;
- va_start(ap, text);
- formatted.setv(text, ap);
- va_end(ap);
-
- MessageBoxA(NULL, formatted.cstr(), "Android SDK Manager", MB_OK | MB_ICONINFORMATION);
-}
-
-// Displays GetLastError prefixed with a description in an error dialog box
-void displayLastError(const char *description, ...) {
- CString formatted;
- va_list ap;
- va_start(ap, description);
- formatted.setv(description, ap);
- va_end(ap);
-
- CString error;
- error.setLastWin32Error();
- formatted.add("\r\n");
- formatted.add(error.cstr());
- MessageBox(NULL, formatted.cstr(), "Android SDK Manager - Error", MB_OK | MB_ICONERROR);
-}
-
-// Executes the command line. Does not wait for the program to finish.
-// The return code is from CreateProcess (0 means failure), not the running app.
-int execNoWait(const char *app, const char *params, const char *workDir) {
- STARTUPINFO startup;
- PROCESS_INFORMATION pinfo;
-
- ZeroMemory(&pinfo, sizeof(pinfo));
-
- ZeroMemory(&startup, sizeof(startup));
- startup.cb = sizeof(startup);
- startup.dwFlags = STARTF_USESHOWWINDOW;
- startup.wShowWindow = SW_SHOWDEFAULT;
-
- int ret = CreateProcessA(
- (LPSTR) app, /* program path */
- (LPSTR) params, /* command-line */
- NULL, /* process handle is not inheritable */
- NULL, /* thread handle is not inheritable */
- TRUE, /* yes, inherit some handles */
- 0, /* create flags */
- NULL, /* use parent's environment block */
- workDir, /* use parent's starting directory */
- &startup, /* startup info, i.e. std handles */
- &pinfo);
-
- if (ret) {
- CloseHandle(pinfo.hProcess);
- CloseHandle(pinfo.hThread);
- }
-
- return ret;
-}
-
-// Executes command, waits for completion and returns exit code.
-// As indicated in MSDN for CreateProcess, callers should double-quote the program name
-// e.g. cmd="\"c:\program files\myapp.exe\" arg1 arg2";
-int execWait(const char *cmd) {
- STARTUPINFO startup;
- PROCESS_INFORMATION pinfo;
-
- ZeroMemory(&pinfo, sizeof(pinfo));
-
- ZeroMemory(&startup, sizeof(startup));
- startup.cb = sizeof(startup);
- startup.dwFlags = STARTF_USESHOWWINDOW;
- startup.wShowWindow = SW_HIDE|SW_MINIMIZE;
-
- int ret = CreateProcessA(
- NULL, /* program path */
- (LPSTR) cmd, /* 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);
-
- int result = -1;
- if (ret) {
- WaitForSingleObject(pinfo.hProcess, INFINITE);
-
- DWORD exitCode;
- if (GetExitCodeProcess(pinfo.hProcess, &exitCode)) {
- // this should not return STILL_ACTIVE (259)
- result = exitCode;
- }
- CloseHandle(pinfo.hProcess);
- CloseHandle(pinfo.hThread);
- }
-
- return result;
-}
-
-bool getModuleDir(CPath *outDir) {
- CHAR programDir[MAX_PATH];
- int ret = GetModuleFileName(NULL, programDir, sizeof(programDir));
- if (ret != 0) {
- // Remove the last segment to keep only the directory.
- int pos = ret - 1;
- while (pos > 0 && programDir[pos] != '\\') {
- --pos;
- }
- outDir->set(programDir, pos);
- return true;
- }
- return false;
-}
-
-// Disables the FS redirection done by WOW64.
-// Because this runs as a 32-bit app, Windows automagically remaps some
-// folder under the hood (e.g. "Programs Files(x86)" is mapped as "Program Files").
-// This prevents the app from correctly searching for java.exe in these folders.
-// The registry is also remapped. This method disables this redirection.
-// Caller should restore the redirection later by using revertWow64FsRedirection().
-PVOID disableWow64FsRedirection() {
-
- // The call we want to make is the following:
- // PVOID oldWow64Value;
- // Wow64DisableWow64FsRedirection(&oldWow64Value);
- // However that method may not exist (e.g. on XP non-64 systems) so
- // we must not call it directly.
-
- PVOID oldWow64Value = 0;
-
- HMODULE hmod = LoadLibrary("kernel32.dll");
- if (hmod != NULL) {
- FARPROC proc = GetProcAddress(hmod, "Wow64DisableWow64FsRedirection");
- if (proc != NULL) {
- typedef BOOL (WINAPI *disableWow64FuncType)(PVOID *);
- disableWow64FuncType funcPtr = (disableWow64FuncType)proc;
- funcPtr(&oldWow64Value);
- }
-
- FreeLibrary(hmod);
- }
-
- return oldWow64Value;
-}
-
-// Reverts the redirection disabled in disableWow64FsRedirection.
-void revertWow64FsRedirection(PVOID oldWow64Value) {
-
- // The call we want to make is the following:
- // Wow64RevertWow64FsRedirection(oldWow64Value);
- // However that method may not exist (e.g. on XP non-64 systems) so
- // we must not call it directly.
-
- HMODULE hmod = LoadLibrary("kernel32.dll");
- if (hmod != NULL) {
- FARPROC proc = GetProcAddress(hmod, "Wow64RevertWow64FsRedirection");
- if (proc != NULL) {
- typedef BOOL (WINAPI *revertWow64FuncType)(PVOID);
- revertWow64FuncType funcPtr = (revertWow64FuncType)proc;
- funcPtr(oldWow64Value);
- }
-
- FreeLibrary(hmod);
- }
-}
-
-#endif /* _WIN32 */
diff --git a/sdkmanager/win_android/utils.h b/sdkmanager/win_android/utils.h
deleted file mode 100755
index 4530380..0000000
--- a/sdkmanager/win_android/utils.h
+++ /dev/null
@@ -1,336 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _H_UTILS
-#define _H_UTILS
-
-#ifdef _WIN32
-
-#define _CRT_SECURE_NO_WARNINGS 1
-
-#include <direct.h>
-#include <stdio.h>
-#include <stdarg.h>
-#include <string.h>
-#include <windows.h>
-
-// VS vs MINGW specific includes
-#ifdef USE_VS_CRT
- #include <crtdbg.h> // for _ASSERT
-#else
- #define _ASSERT(x) // undef
-#endif
-
-extern bool gDebug;
-
-// An array that knows its own size. Not dynamically resizable.
-template <class T> class CArray {
- T* mPtr;
- int mSize;
-public:
- explicit CArray(int size) {
- mSize = size;
- mPtr = new T[size];
- }
-
- ~CArray() {
- if (mPtr != NULL) {
- delete[] mPtr;
- mPtr = NULL;
- }
- mSize = 0;
- }
-
- T& operator[](int i) {
- _ASSERT(i >= 0 && i < mSize);
- return mPtr[i];
- }
-
- int size() const {
- return mSize;
- }
-};
-
-// A simple string class wrapper.
-class CString {
-protected:
- char *mStr;
-public:
- CString() { mStr = NULL; }
- CString(const CString &str) { mStr = NULL; set(str.mStr); }
- explicit CString(const char *str) { mStr = NULL; set(str); }
- CString(const char *start, int length) { mStr = NULL; set(start, length); }
-
- CString& operator=(const CString &str) {
- return set(str.cstr());
- }
-
- CString& set(const char *str) {
- if (str != mStr) {
- _free();
- if (str != NULL) {
- mStr = _strdup(str);
- }
- }
- return *this;
- }
-
- CString& set(const char *start, int length) {
- _free();
- if (start != NULL) {
- mStr = (char *)malloc(length + 1);
- strncpy(mStr, start, length);
- mStr[length] = 0;
- }
- return *this;
- }
-
- CString& setv(const char *str, va_list ap) {
- _free();
- // _vscprintf(str, ap) is only available with the MSVCRT, not MinGW.
- // Instead we'll iterate till we have enough space to generate the string.
- int len = strlen(str) + 1024;
- mStr = (char *)malloc(len);
- strcpy(mStr, str); // provide a default in case vsnprintf totally fails
- for (int guard = 0; guard < 10; guard++) {
- int ret = vsnprintf(mStr, len, str, ap);
- if (ret == -1) {
- // Some implementations don't give the proper size needed
- // so double the space and try again.
- len *= 2;
- } else if (ret >= len) {
- len = ret + 1;
- } else {
- // There was enough space to write.
- break;
- }
- mStr = (char *)realloc((void *)mStr, len);
- strcpy(mStr, str); // provide a default in case vsnprintf totally fails
- }
- return *this;
- }
-
- CString& setf(const char *str, ...) {
- _free();
- va_list ap;
- va_start(ap, str);
- setv(str, ap);
- va_end(ap);
- return *this;
- }
-
- virtual ~CString() { _free(); }
-
- // Returns the C string owned by this CString. It will be
- // invalid as soon as this CString is deleted or out of scope.
- const char * cstr() const {
- return mStr;
- }
-
- bool isEmpty() const {
- return mStr == NULL || *mStr == 0;
- }
-
- int length() const {
- return mStr == NULL ? 0 : strlen(mStr);
- }
-
- CString& add(const char *s) {
- if (mStr == NULL) {
- set(s);
- } else {
- mStr = (char *)realloc((void *)mStr, strlen(mStr) + strlen(s) + 1);
- strcat(mStr, s);
- }
- return *this;
- }
-
- CArray<CString> * split(char sep) const {
- if (mStr == NULL) {
- return new CArray<CString>(0);
- }
- const char *last = NULL;
- int n = 0;
- for (const char *s = mStr; *s; s++) {
- if (*s == sep && s != mStr && (last == NULL || s > last+1)) {
- n++;
- last = s;
- }
- }
-
- CArray<CString> *result = new CArray<CString>(n);
- last = NULL;
- n = 0;
- for (const char *s = mStr; *s; s++) {
- if (*s == sep) {
- if (s != mStr && (last == NULL || s > last+1)) {
- const char *start = last ? last : mStr;
- (*result)[n++].set(start, s-start);
- }
- last = s+1;
- }
- }
-
- return result;
- }
-
- // Sets the string to the message matching Win32 GetLastError.
- CString& setLastWin32Error() {
- DWORD err = GetLastError();
- LPSTR errStr;
- if (FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | /* dwFlags */
- FORMAT_MESSAGE_FROM_SYSTEM,
- NULL, /* lpSource */
- err, /* dwMessageId */
- 0, /* dwLanguageId */
- (LPSTR)&errStr, /* lpBuffer */
- 0, /* nSize */
- NULL) != 0) { /* va_list args */
- setf("[%d] %s", err, errStr);
- LocalFree(errStr);
- }
- return *this;
- }
-
-private:
- void _free() {
- if (mStr != NULL) {
- free((void *)mStr);
- mStr = NULL;
- }
- }
-
-};
-
-// A simple path class wrapper.
-class CPath : public CString {
-public:
- CPath() : CString() { }
- CPath(const CString &str) : CString(str) { }
- CPath(const CPath &str) : CString(str) { }
- explicit CPath(const char *str) : CString(str) { }
- CPath(const char *start, int length) : CString(start, length) { }
-
- CPath& operator=(const CPath &str) {
- set(str.cstr());
- return *this;
- }
-
- // Appends a path segment, adding a \ as necessary.
- CPath& addPath(const CString &s) {
- return addPath(s.cstr());
- }
-
- // Appends a path segment, adding a \ as necessary.
- CPath& addPath(const char *s) {
- _ASSERT(s != NULL);
- if (s != NULL && s[0] != 0) {
- int n = length();
- if (n > 0 && s[0] != '\\' && mStr[n-1] != '\\') add("\\");
- add(s);
- }
- return *this;
- }
-
- // Returns true if file exist and is not a directory.
- // There's no garantee we have rights to access it.
- bool fileExists() const {
- if (mStr == NULL) return false;
- DWORD attribs = GetFileAttributesA(mStr);
- return attribs != INVALID_FILE_ATTRIBUTES &&
- !(attribs & FILE_ATTRIBUTE_DIRECTORY);
- }
-
- // Returns true if file exist and is a directory.
- // There's no garantee we have rights to access it.
- bool dirExists() const {
- if (mStr == NULL) return false;
- DWORD attribs = GetFileAttributesA(mStr);
- return attribs != INVALID_FILE_ATTRIBUTES &&
- (attribs & FILE_ATTRIBUTE_DIRECTORY) != 0;
- }
-
- // Returns a copy of the directory portion of the path, if any
- CPath dirName() const {
- CPath result;
- if (mStr != NULL) {
- char *pos = strrchr(mStr, '\\');
- if (pos != NULL) {
- result.set(mStr, pos - mStr);
- }
- }
- return result;
- }
-
- // Returns a pointer to the baseName part of the path.
- // It becomes invalid if the path changes.
- const char * baseName() const {
- if (mStr != NULL) {
- char *pos = strrchr(mStr, '\\');
- if (pos != NULL) {
- return pos + 1;
- }
- }
- return NULL;
- }
-
- // If the path ends with the given searchName, replace in-place by the new name
- void replaceName(const char *searchName, const char* newName) {
- if (mStr == NULL) return;
- int n = length();
- int sn = strlen(searchName);
- if (n < sn) return;
- // if mStr ends with searchName
- if (strcmp(mStr + n - sn, searchName) == 0) {
- int sn2 = strlen(newName);
- if (sn2 > sn) {
- mStr = (char *)realloc((void *)mStr, n + sn2 - sn + 1);
- }
- strcpy(mStr + n - sn, newName);
- mStr[n + sn2 - sn] = 0;
- }
- }
-};
-
-// Displays a message in an ok+info dialog box.
-void msgBox(const char* text, ...);
-
-// Displays GetLastError prefixed with a description in an error dialog box
-void displayLastError(const char *description, ...);
-
-// Executes the command line. Does not wait for the program to finish.
-// The return code is from CreateProcess (0 means failure), not the running app.
-int execNoWait(const char *app, const char *params, const char *workDir);
-
-// Executes command, waits for completion and returns exit code.
-// As indicated in MSDN for CreateProcess, callers should double-quote the program name
-// e.g. cmd="\"c:\program files\myapp.exe\" arg1 arg2";
-int execWait(const char *cmd);
-
-bool getModuleDir(CPath *outDir);
-
-// Disables the FS redirection done by WOW64.
-// Because this runs as a 32-bit app, Windows automagically remaps some
-// folder under the hood (e.g. "Programs Files(x86)" is mapped as "Program Files").
-// This prevents the app from correctly searching for java.exe in these folders.
-// The registry is also remapped.
-PVOID disableWow64FsRedirection();
-
-// Reverts the redirection disabled in disableWow64FsRedirection.
-void revertWow64FsRedirection(PVOID oldWow64Value);
-
-#endif /* _WIN32 */
-#endif /* _H_UTILS */
diff --git a/sdkmanager/win_android/win_android.cpp b/sdkmanager/win_android/win_android.cpp
deleted file mode 100644
index 3a768ec..0000000
--- a/sdkmanager/win_android/win_android.cpp
+++ /dev/null
@@ -1,373 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * "win_android.exe", for Windows only. Replaces the previous android.bat.
- * In the final SDK, this is what becomes tools\android.exe and it runs
- * the UI for the SDK Manager or the AVD Manager.
- *
- * Implementation details:
- * - We don't have access to ATL or MFC.
- * - We don't want to pull in things like STL.
- * - No Unicode/MBCS support for now.
- */
-
-#ifdef _WIN32
-
-#include "utils.h"
-#include "find_java.h"
-#include <io.h>
-#include <fcntl.h>
-
-// A NULL-terminated list of directory to create in the temp folder.
-static const char * sMkDirList[] = {
- "lib",
- "lib\\x86",
- "lib\\x86_64",
- NULL,
-};
-
-// A NULL-terminated list of file patterns to copy in the temp folder.
-// The folders must be listed in sMkDirList
-static const char * sFilesToCopy[] = {
- "lib\\x86\\swt.jar",
- "lib\\x86_64\\swt.jar",
- "lib\\androidprefs.jar",
- "lib\\org.eclipse.*",
- "lib\\sdk*",
- "lib\\common.jar",
- "lib\\commons-compress*",
- "lib\\swtmenubar.jar",
- "lib\\commons-logging*",
- "lib\\commons-codec*",
- "lib\\httpclient*",
- "lib\\httpcore*",
- "lib\\httpmime*",
- NULL,
-};
-
-
-// Creates a directory named dirLeafName in the TEMP directory.
-// Returns the path in outDir on success.
-static bool mkTempDir(const char *dirLeafName, CPath *outDir) {
- SetLastError(0);
- char tempPath[MAX_PATH + 1] = "";
- DWORD len = GetTempPathA(MAX_PATH, tempPath);
- if (len > 0 && len <= MAX_PATH) {
- _ASSERT(tempPath[len-1] == '\\');
- _ASSERT(len + strlen(dirLeafName) < MAX_PATH);
- if (len + strlen(dirLeafName) >= MAX_PATH) {
- displayLastError("TEMP path too long to create a temporary directory: %s", tempPath);
- return false;
- }
- strcat(tempPath, dirLeafName);
- outDir->set(tempPath);
-
- if (outDir->dirExists() ||
- CreateDirectoryA(tempPath, NULL /*lpSecurityAttributes*/) != 0) {
- return true;
- }
- }
- displayLastError("Failed to create a temporary directory: %s", tempPath);
- return false;
-}
-
-// Creates all the directories from sMkDirList in the specified base tmpDir.
-static bool mkDirs(const char *tmpDir, const char * dirList[]) {
- SetLastError(0);
- for (const char **dir = dirList; *dir != NULL; dir++) {
- CPath path(tmpDir);
- path.addPath(*dir);
- if (!path.dirExists()) {
- if (!CreateDirectoryA(path.cstr(), NULL /*lpSecurityAttributes*/)) {
- displayLastError("Failed to create directory: %s", path.cstr());
- return false;
- }
- }
- }
- return true;
-}
-
-static bool copyFiles(const char *toolsDir, const char *tmpDir, const char *globList[]) {
- SetLastError(0);
- WIN32_FIND_DATAA srcFindData;
- WIN32_FIND_DATAA destFindData;
- for (const char **glob = globList; *glob != NULL; glob++) {
- CPath globDir = CPath(*glob).dirName();
-
- CPath fullGlob(toolsDir);
- fullGlob.addPath(*glob);
-
- HANDLE srcH = FindFirstFileA(fullGlob.cstr(), &srcFindData);
- if (srcH == INVALID_HANDLE_VALUE) {
- displayLastError("Failed to list files: %s", *glob);
- return false;
- }
- do {
- // Skip directories
- if ((srcFindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0) {
- continue;
- }
- CPath srcPath(toolsDir);
- srcPath.addPath(globDir).addPath(srcFindData.cFileName);
-
- CPath destPath(tmpDir);
- destPath.addPath(globDir).addPath(srcFindData.cFileName);
-
- // Skip copy if files are likely to not have changed.
- HANDLE destH = FindFirstFileA(destPath.cstr(), &destFindData);
- if (destH != INVALID_HANDLE_VALUE) {
- // Size must be same for us to skip it.
- if (srcFindData.nFileSizeHigh == destFindData.nFileSizeHigh &&
- srcFindData.nFileSizeLow == destFindData.nFileSizeLow) {
- // Creation & access times can differ. However if the dest write time
- // is >= than the source write time, it should be the same file.
- LARGE_INTEGER srcWriteTime;
- LARGE_INTEGER dstWriteTime;
- srcWriteTime.HighPart = srcFindData.ftLastWriteTime.dwHighDateTime;
- srcWriteTime.LowPart = srcFindData.ftLastWriteTime.dwLowDateTime;
- dstWriteTime.HighPart = destFindData.ftLastWriteTime.dwHighDateTime;
- dstWriteTime.LowPart = destFindData.ftLastWriteTime.dwLowDateTime;
- if (dstWriteTime.QuadPart >= srcWriteTime.QuadPart) {
- FindClose(destH);
- continue;
- }
- }
-
- FindClose(destH);
-
- // CopyFile copies some attributes. It's common for tools to be unzipped
- // as read-only so we need to remove any r-o attribute on existing
- // files if we want a recopy to succeed.
- if ((destFindData.dwFileAttributes & FILE_ATTRIBUTE_READONLY) != 0) {
- SetFileAttributes(destPath.cstr(),
- destFindData.dwFileAttributes ^ FILE_ATTRIBUTE_READONLY);
- }
- }
-
- if (!CopyFileA(srcPath.cstr(), destPath.cstr(), false /*bFailIfExists*/)) {
- FindClose(srcH);
- displayLastError("Failed to copy file: %s", destPath.cstr());
- return false;
- }
- } while (FindNextFileA(srcH, &srcFindData) != 0);
- FindClose(srcH);
- }
- return true;
-}
-
-static bool execSdkManager(const char *javaPath,
- const char *toolsDir,
- const char *tmpDir,
- const char *lpCmdLine) {
- SetLastError(0);
-
- // Which java binary to call.
- // The default is to use java.exe to automatically dump stdout in
- // the parent console.
- CPath javaExecPath(javaPath);
- bool redirectStdout = true;
-
- // Attach to the parent console, if there's one.
- if (AttachConsole(-1) == 0) {
- // This can fail with ERROR_ACCESS_DENIED if the process is already
- // attached to the parent console. That means there's a console so
- // we want to keep invoking java.exe to get stdout into it.
- //
- // This also fails if there is no parent console, in which
- // it means this was invoked not from a shell. It's a good
- // signal we don't want a new console to show up so we'll
- // switch to javaw.exe instead, if available.
-
- if (GetLastError() != ERROR_ACCESS_DENIED) {
- SetLastError(0);
-
- javaExecPath.replaceName("java.exe", "javaw.exe");
- // Only accept it if we can actually find the exec
- PVOID oldWow64Value = disableWow64FsRedirection();
- if (!javaExecPath.fileExists()) {
- javaExecPath.set(javaPath);
- redirectStdout = false;
- }
- revertWow64FsRedirection(&oldWow64Value);
- }
- }
- if (redirectStdout && GetStdHandle(STD_OUTPUT_HANDLE) != NULL) {
- // If we have an output, redirect to it.
- freopen("CONOUT$", "w", stdout);
- freopen("CONOUT$", "w", stderr);
- }
-
- // Check whether the underlying system is x86 or x86_64.
- // We use GetSystemInfo which will see the one masqueraded by Wow64.
- // (to get the real info, we would use GetNativeSystemInfo instead.)
- SYSTEM_INFO sysInfo;
- GetSystemInfo(&sysInfo);
-
- CString arch("x86");
- if (sysInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) {
- arch.set("x86_64");
- } else if (sysInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL) {
- // Skip this. We'll just assume x86 and let it fail later.
- // Keep this line for debugging purposes:
- // displayLastError("Unknown Processor Architecture: %d", sysInfo.wProcessorArchitecture);
- }
-
- // Now build the command line.
- // Note that we pass the absolute javaExecPath both to CreateProcess (via execNoWait)
- // and we set it as argv[0] in the command line just for the show.
- // Important: for the classpath to be able to contain "lib\\sdkmanager.jar", etc.,
- // we need to set the toolsDir as the *temp* directory in execNoWait.
- // It's important to not use toolsDir otherwise it would lock that diretory.
-
- CString cmdLine;
- cmdLine.setf("\"%s\" " // javaExecPath basename
- "-Dcom.android.sdkmanager.toolsdir=\"%s\" " // toolsDir
- "-Dcom.android.sdkmanager.workdir=\"%s\" " // workDir==toolsdir
- "-classpath \"lib\\sdkmanager.jar;lib\\swtmenubar.jar;lib\\%s\\swt.jar\" " // arch
- "com.android.sdkmanager.Main "
- "%s", // extra parameters
- javaExecPath.baseName(), toolsDir, tmpDir, arch.cstr(), lpCmdLine);
-
- // Tip: to connect the Java debugging to a running process, add this to the Java command line:
- // "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000"
-
- if (gDebug) msgBox("Executing: %s", cmdLine.cstr());
-
- if (!execNoWait(javaExecPath.cstr(), cmdLine.cstr(), tmpDir)) {
- displayLastError("Failed to run %s", cmdLine.cstr());
- return false;
- }
-
- return true;
-}
-
-// Attaches to a parent console or create one and then redirect stdout
-// and stderr to this console. Returns false if it failed to attach
-// or create the console.
-static bool sendStdoutToConsole() {
- // See http://stackoverflow.com/questions/4028353 for some background.
-
- HANDLE hConOut = GetStdHandle(STD_OUTPUT_HANDLE);
- if (hConOut != NULL) {
- // Std output is set. Might or might not be a console though.
- // Try to attach to the parent console and use its ConOut.
- if (AttachConsole(ATTACH_PARENT_PROCESS) != 0) {
- goto redirect;
- }
- }
-
- // There is no current console output.
- // Create one and attach ConOut to stdout.
- if (AllocConsole() == 0) {
- displayLastError("AllocConsole failed: ");
- return false;
- }
-
-redirect:
- // Redirect both stdout and stderr.
- HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
- int fdOut = _open_osfhandle((intptr_t) hOut, _O_TEXT);
- if (fdOut != -1) {
- FILE *fpOut = _fdopen(fdOut, "w");
- *stdout = *fpOut;
- } else {
- // Workaround for Cygwin when not redirecting to a pipe
- freopen("CONOUT$", "w", stdout);
- }
-
- HANDLE hErr = GetStdHandle(STD_ERROR_HANDLE);
- int fdErr = _open_osfhandle((intptr_t) hErr, _O_TEXT);
- if (fdErr != -1) {
- FILE *fpErr = _fdopen(fdErr, "w");
- *stderr = *fpErr;
- } else {
- // Workaround for Cygwin when not redirecting to a pipe
- // Note: there's is no such 'CONERR$'. See MSDN for GetStdHandle().
- freopen("CONOUT$", "w", stderr);
- }
- return true;
-}
-
-static void testFindJava() {
- sendStdoutToConsole();
-
- CPath javaPath("<not found>");
- bool ok = findJavaInEnvPath(&javaPath);
- printf("findJavaInEnvPath: [%s] %s\n", ok ? "OK" : "FAIL", javaPath.cstr());
-
- javaPath.set("<not found>");
- ok = findJavaInRegistry(&javaPath);
- printf("findJavaInRegistry [%s] %s\n", ok ? "OK" : "FAIL", javaPath.cstr());
-
- javaPath.set("<not found>");
- ok = findJavaInProgramFiles(&javaPath);
- printf("findJavaInProgramFiles [%s] %s\n", ok ? "OK" : "FAIL", javaPath.cstr());
-}
-
-int APIENTRY WinMain(HINSTANCE hInstance,
- HINSTANCE hPrevInstance,
- LPTSTR lpCmdLine,
- int nCmdShow) {
-
- gDebug = (getenv("ANDROID_SDKMAN_DEBUG") != NULL);
-
- if (strcmp(lpCmdLine, "/test") == 0) {
- testFindJava();
- return 0;
- }
-
- CPath javaPath;
- if (!findJavaInEnvPath(&javaPath) &&
- !findJavaInRegistry(&javaPath) &&
- !findJavaInProgramFiles(&javaPath)) {
- msgBox("Failed to find Java on your system. Please reinstall it.");
- return 2;
- }
- _ASSERT(!javaPath.isEmpty());
-
- // For debugging it's convenient to override the tools directory location
- CPath toolsDir(getenv("ANDROID_SDKMAN_TOOLS_DIR"));
- if (toolsDir.isEmpty()) {
- if (!getModuleDir(&toolsDir)) {
- displayLastError("Failed to get program's filename: ");
- return 1;
- }
- }
- _ASSERT(!toolsDir.isEmpty());
-
- CPath tmpDir;
- if (!mkTempDir("temp-android-tool", &tmpDir)) {
- return 1;
- }
- _ASSERT(!tmpDir.isEmpty());
-
- if (!mkDirs(tmpDir.cstr(), sMkDirList)) {
- return 1;
- }
-
- if (!copyFiles(toolsDir.cstr(), tmpDir.cstr(), sFilesToCopy)) {
- return 1;
- }
-
- if (!execSdkManager(javaPath.cstr(), toolsDir.cstr(), tmpDir.cstr(), lpCmdLine)) {
- displayLastError("Failed to start SDK Manager: ");
- return 1;
- }
-
- return 0;
-}
-#endif /* _WIN32 */
diff --git a/sdkmanager/win_android/win_android.exe.manifest b/sdkmanager/win_android/win_android.exe.manifest
deleted file mode 100755
index fd6c264..0000000
--- a/sdkmanager/win_android/win_android.exe.manifest
+++ /dev/null
@@ -1,33 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-
-<!--
- For details on the Assembly Manifest, please look here:
- http://msdn.microsoft.com/en-us/library/aa374191(VS.85).aspx
--->
-
-<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
-
- <application>
- <!--The ID below indicates application support for Windows Vista -->
- <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />
- <!--The ID below indicates application support for Windows 7 -->
- <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />
- </application>
-
- <assemblyIdentity version="1.0.0.0"
- processorArchitecture="x86"
- name="Android.SDK.AndroidTool"
- type="win32"
- />
-
- <description>Wrapper to start the command-line "android" tool or the Android SDK Manager user interface.</description>
-
- <!-- Identify the application security requirements. -->
- <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
- <security>
- <requestedPrivileges>
- <requestedExecutionLevel level="asInvoker" uiAccess="false" />
- </requestedPrivileges>
- </security>
- </trustInfo>
-</assembly>