Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bd2ca700d5 | ||
|
|
654d70c17b | ||
|
|
573de4b4c2 | ||
|
|
95730a0002 | ||
|
|
c75801fc07 | ||
|
|
4e4e5919d6 | ||
|
|
70e11d4277 | ||
|
|
f6228ca729 | ||
|
|
321a03a36e | ||
|
|
2682eac500 | ||
|
|
a345dfa495 | ||
|
|
83894674dc | ||
|
|
7a7e813c7e | ||
|
|
b5ca94ae58 | ||
|
|
92d1d52ec2 | ||
|
|
2ad1b8dc97 |
+6
-2
@@ -1,3 +1,7 @@
|
||||
bin
|
||||
res
|
||||
.dub
|
||||
build
|
||||
.gradle
|
||||
.vscode
|
||||
.settings
|
||||
.classpath
|
||||
.project
|
||||
@@ -5,8 +5,8 @@ This is a re-implementation of the [15 seconds ADB Installer](https://forum.xda-
|
||||
|
||||
This installer requires an internet connection.
|
||||
|
||||
Icon is from [Google via icon-icons.com](https://icon-icons.com/icon/adb/90476)
|
||||
Icon is from [material.io](https://material.io/resources/icons/?icon=bug_report&style=baseline)
|
||||
|
||||
Windows version packaged with [Ptiso](https://pismotec.com/ptiso/)
|
||||
Windows version packaged with [7zip](https://www.7-zip.org/)
|
||||
|
||||
Linux & Mac version packaged with [UPX](https://upx.github.io/)
|
||||
Linux & Mac version packaged with [makeself](https://makeself.io/)
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
id 'application'
|
||||
id "org.beryx.runtime" version "1.8.0" //https://plugins.gradle.org/plugin/org.beryx.runtime
|
||||
}
|
||||
sourceSets.main.java.srcDirs = ['src']
|
||||
application.mainClassName = 'gui'
|
||||
repositories {
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
google()
|
||||
maven { url 'https://jitpack.io' }
|
||||
}
|
||||
dependencies {
|
||||
implementation 'info.picocli:picocli:4.2.0'
|
||||
}
|
||||
runtime {
|
||||
options = ['--strip-debug','--no-header-files','--no-man-pages']
|
||||
modules = ['java.desktop','jdk.crypto.ec']
|
||||
}
|
||||
task sfx(type: Exec,dependsOn: "runtime"){
|
||||
int complevel=1
|
||||
workingDir runtime.imageDir
|
||||
String dest="../"+application.applicationName
|
||||
if(System.getProperty("os.name").toLowerCase().startsWith("win")){
|
||||
doFirst{
|
||||
new File("build/image/setup.bat").text="@echo off\ncall bin/"+applicationName+".bat"
|
||||
}
|
||||
String stub="7zs2con.sfx"
|
||||
executable "7z"
|
||||
args "a",dest,"-mx"+complevel,"-sfx"+stub
|
||||
}else{
|
||||
executable "makeself"
|
||||
args "--complevel",complevel,".",dest+".sh",application.applicationName,"bin/adbi"
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
name "adbi"
|
||||
description "Android Debug Bridge Installer"
|
||||
authors "josephsmendoza"
|
||||
copyright "Copyright © 2019, josephsmendoza"
|
||||
license "GPL-3.0"
|
||||
targetType "executable"
|
||||
targetPath "bin/$PLATFORM/$ARCH"
|
||||
dflags "-Llib/curl.lib" platform="windows"
|
||||
configuration "application" {
|
||||
excludedSourceFiles "source/cli.d"
|
||||
dependency "tkd" version="1.1.13"
|
||||
copyFiles \
|
||||
"$TCLTK_PACKAGE_DIR/dist/$ARCH/tcl86t.dll" \
|
||||
"$TCLTK_PACKAGE_DIR/dist/$ARCH/tk86t.dll" \
|
||||
"$TCLTK_PACKAGE_DIR/dist/library" \
|
||||
"C:/windows/system32/msvcr110.dll" \
|
||||
"C:/windows/system32/vcruntime140.dll" \
|
||||
"lib/libcurl.dll" \
|
||||
platform="windows"
|
||||
}
|
||||
configuration "cli" {
|
||||
excludedSourceFiles "source/gui.d"
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
-141
@@ -1,141 +0,0 @@
|
||||
import std.path, std.process, std.algorithm.searching, std.stdio;
|
||||
|
||||
private string APPEND;
|
||||
bool userMode;
|
||||
version (Windows) string HOME = "HOMEPATH";
|
||||
version (Posix) string HOME = "HOME";
|
||||
enum LogLevel {
|
||||
SILENT,
|
||||
silent = SILENT,
|
||||
s = SILENT,
|
||||
ERROR,
|
||||
error = ERROR,
|
||||
e = ERROR,
|
||||
INFO,
|
||||
info = INFO,
|
||||
i = INFO,
|
||||
VERBOSE,
|
||||
verbose = VERBOSE,
|
||||
v = VERBOSE
|
||||
}
|
||||
|
||||
alias SILENT = LogLevel.SILENT;
|
||||
alias ERROR = LogLevel.ERROR;
|
||||
alias INFO = LogLevel.INFO;
|
||||
alias VERBOSE = LogLevel.VERBOSE;
|
||||
LogLevel logLevel = INFO;
|
||||
|
||||
void function(string message, int messageMode = INFO) log;
|
||||
|
||||
private string append() {
|
||||
if (!APPEND)
|
||||
APPEND = buildNormalizedPath("Android", "SDK", "platform-tools");
|
||||
return APPEND;
|
||||
}
|
||||
|
||||
string defaultUserDir() {
|
||||
version (Windows) string dir = "C:/" ~ environment.get(HOME) ~ "/AppData/Local";
|
||||
version (linux) string dir = "~";
|
||||
version (OSX) string dir = "~/Library";
|
||||
return buildNormalizedPath(dir.expandTilde, append);
|
||||
}
|
||||
|
||||
string defaultAllUsersDir() {
|
||||
version (Windows) string dir = "C:/Program Files";
|
||||
version (linux) string dir = "/opt";
|
||||
version (OSX) string dir = "/Library";
|
||||
return buildNormalizedPath(dir, append);
|
||||
}
|
||||
|
||||
bool isUserDir(string installDir) {
|
||||
return installDir.canFind(environment.get(HOME));
|
||||
}
|
||||
|
||||
void installTools(string installDir) {
|
||||
import std.zip, std.file, std.net.curl, std.conv;
|
||||
|
||||
version (Windows) string url = "https://dl.google.com/android/repository/platform-tools-latest-windows.zip";
|
||||
version (OSX) string url = "https://dl.google.com/android/repository/platform-tools-latest-darwin.zip";
|
||||
version (linux) string url = "https://dl.google.com/android/repository/platform-tools-latest-linux.zip";
|
||||
|
||||
log("Downloading");
|
||||
log(url, VERBOSE);
|
||||
|
||||
ubyte[] data;
|
||||
auto http = HTTP(url);
|
||||
http.onReceive = (ubyte[] response) {
|
||||
data ~= response;
|
||||
return response.length;
|
||||
};
|
||||
http.perform();
|
||||
|
||||
log("Extracting");
|
||||
log(installDir, VERBOSE);
|
||||
|
||||
auto zip = new ZipArchive(data);
|
||||
foreach (zipEntry; zip.directory) {
|
||||
auto extractPath = buildNormalizedPath(installDir, zipEntry.name[15 .. $]);
|
||||
if (zipEntry.compressedSize != 0) {
|
||||
log(zipEntry.name, VERBOSE);
|
||||
if (extractPath.exists && extractPath.isDir) {
|
||||
rmdirRecurse(extractPath);
|
||||
} else if (!extractPath.dirName.exists)
|
||||
mkdirRecurse(extractPath.dirName);
|
||||
zip.expand(zipEntry);
|
||||
extractPath.write(zipEntry.expandedData);
|
||||
version (Posix)
|
||||
setAttributes(extractPath, octal!775);
|
||||
} else {
|
||||
if (extractPath.exists) {
|
||||
if (extractPath.isFile) {
|
||||
extractPath.remove();
|
||||
extractPath.mkdir();
|
||||
}
|
||||
} else
|
||||
extractPath.mkdirRecurse();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void installPath(string installDir) {
|
||||
import std.process : environment;
|
||||
|
||||
log("Adding to PATH");
|
||||
string path = environment.get("PATH");
|
||||
if (path.canFind(installDir)) {
|
||||
log("Install folder is already in PATH");
|
||||
return;
|
||||
}
|
||||
|
||||
version (Windows) {
|
||||
import std.windows.registry : Registry, Key, REGSAM;
|
||||
|
||||
Key env;
|
||||
if (userMode) {
|
||||
env = Registry.currentUser.getKey("Environment", REGSAM.KEY_ALL_ACCESS);
|
||||
} else {
|
||||
env = Registry.localMachine.getKey("SYSTEM").getKey("CurrentControlSet").getKey("Control")
|
||||
.getKey("Session Manager").getKey("Environment", REGSAM.KEY_ALL_ACCESS);
|
||||
}
|
||||
path = env.getValue("Path").value_SZ;
|
||||
path ~= pathSeparator ~ installDir;
|
||||
env.setValue("Path", path);
|
||||
//import core.sys.windows.winuser; SendNotifyMessageW(HWND_BROADCAST,WM_SETTINGCHANGE,cast(ulong)null,cast(long)"Environment");
|
||||
} else {
|
||||
import std.file : exists,append,write;
|
||||
|
||||
string profile;
|
||||
string installProfile = "\nexport PATH=$PATH" ~ pathSeparator ~ installDir;
|
||||
if (userMode)
|
||||
profile = "~/.profile".expandTilde;
|
||||
else
|
||||
profile = "/etc/profile";
|
||||
if (profile.exists)
|
||||
append(profile, installProfile);
|
||||
else {
|
||||
write(profile, installProfile);
|
||||
}
|
||||
}
|
||||
|
||||
log("logout or reboot to finish install");
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
import adbi, std.getopt;
|
||||
|
||||
private void log(string message, int messageMode = INFO) {
|
||||
if (logLevel < messageMode)
|
||||
return;
|
||||
if (messageMode == ERROR) {
|
||||
import std.stdio : stderr;
|
||||
|
||||
stderr.writeln(message);
|
||||
} else {
|
||||
import std.stdio : writeln;
|
||||
|
||||
writeln(message);
|
||||
}
|
||||
}
|
||||
|
||||
void main(string[] args) {
|
||||
adbi.log = &cli.log;
|
||||
string installDir;
|
||||
try {
|
||||
auto xargs = getopt(args,
|
||||
"user-mode|u", "Install for current user only instead of all users.", &userMode,
|
||||
"install-dir|i", "Path to install folder.", &installDir,
|
||||
"log-level|l", "silent, error, info, or verbose", &logLevel);
|
||||
if (xargs.helpWanted) {
|
||||
defaultGetoptPrinter("Install Android Platform Tools", xargs.options);
|
||||
return;
|
||||
}
|
||||
if (!installDir) {
|
||||
if (userMode)
|
||||
installDir = defaultUserDir;
|
||||
else
|
||||
installDir = defaultAllUsersDir;
|
||||
} else if (installDir.isUserDir)
|
||||
userMode = true;
|
||||
installTools(installDir);
|
||||
installPath(installDir);
|
||||
} catch (Exception e) {
|
||||
log(cast(string) e.message, ERROR);
|
||||
}
|
||||
}
|
||||
-182
@@ -1,182 +0,0 @@
|
||||
import tkd.tkdapplication, tkd.widget.widget;
|
||||
import adbi;
|
||||
import std.concurrency, std.parallelism, std.process, std.file, std.regex,
|
||||
std.path, std.string, std.algorithm.searching, std.stdio, std.uni;
|
||||
import core.time;
|
||||
|
||||
string[] skip = ["temp"];
|
||||
|
||||
Widget packPreset(Widget w) {
|
||||
return w.pack(0, 0, GeometrySide.top, GeometryFill.both, AnchorPosition.center, true);
|
||||
}
|
||||
|
||||
bool isWriteable(DirEntry d) {
|
||||
try
|
||||
File(d.name, "a").close();
|
||||
catch (Exception e)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool isInstallable(DirEntry d) {
|
||||
if (!d.isWriteable)
|
||||
return false;
|
||||
foreach (s; skip) {
|
||||
if (d.name.toLower.canFind(s)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
class Application : TkdApplication {
|
||||
|
||||
private Label instructionLabel;
|
||||
private Label statusLabel;
|
||||
private Tid searchThread;
|
||||
|
||||
enum {
|
||||
STATUS = LogLevel.max + 1,
|
||||
INSTRUCT,
|
||||
OPTION,
|
||||
KILL
|
||||
}
|
||||
|
||||
static void search() {
|
||||
version (Windows) {
|
||||
skip ~= "recycle.bin";
|
||||
string regex = "(.*)(\\\\)(adb.exe|fastboot.exe)($)";
|
||||
string[] dirs = [
|
||||
"C:\\Program Files", "C:\\Program Files (x86)",
|
||||
"C:" ~ environment.get("HOMEPATH"), "C:\\"
|
||||
];
|
||||
} else
|
||||
string regex = "(.*)(\\/)(adb|fastboot)($)";
|
||||
version (linux) string[] dirs = ["/usr", "/opt"];
|
||||
version (OSX) string[] dirs = ["/Library", "/Applications"];
|
||||
version (Posix) {
|
||||
dirs ~= ["~".expandTilde, "/"];
|
||||
}
|
||||
adbi.log = &Application.log;
|
||||
string[] results;
|
||||
void search(DirEntry dir) {
|
||||
try {
|
||||
foreach (DirEntry d; dirEntries(dir.name, SpanMode.shallow)) {
|
||||
receiveTimeout(seconds(-1), delegate(int i) {
|
||||
if (i != KILL) {
|
||||
log("Unsupported signal received by search thread", ERROR);
|
||||
return;
|
||||
} else
|
||||
return;
|
||||
});
|
||||
if (d.isDir)
|
||||
search(d);
|
||||
else if (d.name.matchFirst(regex)) {
|
||||
string s = d.name.dirName.strip;
|
||||
if (!results.canFind(s) && d.isInstallable) {
|
||||
results ~= s;
|
||||
log(s, OPTION);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log(cast(string) e.message, ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
log("Searching for install locations");
|
||||
log(defaultAllUsersDir, OPTION);
|
||||
log(defaultUserDir, OPTION);
|
||||
log("Select install location", INSTRUCT);
|
||||
results ~= [defaultAllUsersDir, defaultUserDir, ""];
|
||||
foreach (string dir; dirs) {
|
||||
search(DirEntry(dir));
|
||||
}
|
||||
log("Search done");
|
||||
}
|
||||
|
||||
static void log(string message, int messageMode = INFO) {
|
||||
ownerTid.send(messageMode);
|
||||
ownerTid.send(message);
|
||||
}
|
||||
|
||||
int mode;
|
||||
|
||||
private void receiveInt(int i) {
|
||||
mode = i;
|
||||
}
|
||||
|
||||
static void install(string dir) {
|
||||
adbi.log = &Application.log;
|
||||
if (dir.isUserDir)
|
||||
adbi.userMode = true;
|
||||
try {
|
||||
log("Please Wait", INSTRUCT);
|
||||
adbi.installTools(dir);
|
||||
adbi.installPath(dir);
|
||||
log("You can close this window", INSTRUCT);
|
||||
} catch (immutable Exception e) {
|
||||
ownerTid.send(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void receiveString(string message) {
|
||||
switch (mode) {
|
||||
case INFO:
|
||||
case STATUS:
|
||||
statusLabel.setText(message);
|
||||
break;
|
||||
case INSTRUCT:
|
||||
instructionLabel.setText(message);
|
||||
break;
|
||||
case OPTION:
|
||||
new Button(message).setCommand(delegate(CommandArgs args) {
|
||||
spawn(&install, message);
|
||||
}).packPreset();
|
||||
break;
|
||||
case ERROR:
|
||||
import std.stdio;
|
||||
|
||||
stderr.writeln(message);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
mode = INFO;
|
||||
}
|
||||
|
||||
private void receiveException(immutable Exception e) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
private void idleCommand(CommandArgs args) {
|
||||
this.mainWindow.setIdleCommand(&idleCommand);
|
||||
receiveTimeout(seconds(-1), &receiveString, &receiveInt, &receiveException);
|
||||
}
|
||||
|
||||
private void exitCommand(CommandArgs args) {
|
||||
this.exit();
|
||||
}
|
||||
|
||||
private void directoryDialog(CommandArgs args) {
|
||||
string dir = new DirectoryDialog().show().getResult();
|
||||
if (dir.isDir)
|
||||
spawn(&install, dir);
|
||||
}
|
||||
|
||||
override protected void initInterface() {
|
||||
this.mainWindow.setMinSize(300, 0);
|
||||
instructionLabel = new Label("Please wait").pack();
|
||||
statusLabel = new Label("Loading").pack();
|
||||
new Button("Manually select folder").setCommand(&directoryDialog).packPreset();
|
||||
this.mainWindow.setIdleCommand(&idleCommand);
|
||||
this.mainWindow.setProtocolCommand(WindowProtocol.deleteWindow, &exitCommand);
|
||||
searchThread = spawn(&search);
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
adbi.log = &Application.log;
|
||||
auto app = new Application();
|
||||
app.run();
|
||||
}
|
||||
+189
@@ -0,0 +1,189 @@
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.nio.file.attribute.PosixFilePermissions;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
public class adbi {
|
||||
|
||||
private final String os;
|
||||
|
||||
public adbi() throws Exception {
|
||||
switch (System.getProperty("os.name").substring(0, 3).toLowerCase()) {
|
||||
case "win": {
|
||||
os = "windows";
|
||||
break;
|
||||
}
|
||||
case "mac": {
|
||||
os = "darwin";
|
||||
break;
|
||||
}
|
||||
case "lin": {
|
||||
os = "linux";
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
throw new Exception("unknown os");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public String getHome() {
|
||||
if (os == "windows") {
|
||||
return System.getenv("HOMEPATH");
|
||||
} else {
|
||||
return System.getenv("HOME");
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isPathPrivileged(String path) {
|
||||
return path.startsWith(getHome());
|
||||
}
|
||||
|
||||
public String getCannonicalPath(String path) {
|
||||
return Paths.get(path).toAbsolutePath().normalize().toString();
|
||||
}
|
||||
|
||||
public String getDefaultInstallPath(boolean privileged) {
|
||||
String append = "/Android/SDK/platform-tools";
|
||||
if (privileged) {
|
||||
switch (os) {
|
||||
case "windows": {
|
||||
return System.getenv("programfiles") + append;
|
||||
}
|
||||
case "darwin": {
|
||||
return "/Library" + append;
|
||||
}
|
||||
default: {
|
||||
return "/opt" + append;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
switch (os) {
|
||||
case "windows": {
|
||||
return System.getenv("localappdata") + append;
|
||||
}
|
||||
case "darwin": {
|
||||
return System.getenv("HOME") + "/Library" + append;
|
||||
}
|
||||
default: {
|
||||
return System.getenv("HOME") + append;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private InputStream getUrlStream() throws MalformedURLException, IOException {
|
||||
return new URL("https://dl.google.com/android/repository/platform-tools-latest-" + os + ".zip").openStream();
|
||||
}
|
||||
|
||||
private boolean isNeeded(String name, int mode) {
|
||||
switch (mode) {
|
||||
case (1): {
|
||||
if (name.startsWith("fastboot"))
|
||||
return true;
|
||||
}
|
||||
case (0): {
|
||||
return name.toLowerCase().startsWith("adb");
|
||||
}
|
||||
default: {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void download(String dir, int mode) throws MalformedURLException, IOException {
|
||||
ZipInputStream zInputStream = new ZipInputStream(getUrlStream());
|
||||
ZipEntry zEntry = zInputStream.getNextEntry();
|
||||
while (zEntry != null) {
|
||||
String name = zEntry.getName().substring(15);
|
||||
if (isNeeded(name, mode) && zEntry.getSize() > 0) {
|
||||
Path dest = Paths.get(dir, name);
|
||||
Files.createDirectories(dest.getParent());
|
||||
Files.write(dest, zInputStream.readAllBytes());
|
||||
if (os != "windows") {
|
||||
Files.setPosixFilePermissions(dest, PosixFilePermissions.fromString("755"));
|
||||
}
|
||||
}
|
||||
zEntry = zInputStream.getNextEntry();
|
||||
}
|
||||
}
|
||||
|
||||
public void install(String dir, boolean privileged) throws Exception {
|
||||
if (System.getenv("PATH").contains(dir)) {
|
||||
return;
|
||||
}
|
||||
if (os == "windows") {
|
||||
installWindows(dir, privileged);
|
||||
} else {
|
||||
installPosix(dir, privileged);
|
||||
}
|
||||
}
|
||||
|
||||
private void installPosix(String dir, boolean privileged) throws IOException {
|
||||
Path profile = getProfilePath(privileged);
|
||||
String path = "export PATH=$PATH:\"" + dir + "\"";
|
||||
if (Files.exists(profile) && Files.readAllLines(profile).add(path)) {
|
||||
Files.writeString(profile, "\n" + path, StandardOpenOption.APPEND);
|
||||
} else {
|
||||
Files.writeString(profile, path);
|
||||
}
|
||||
}
|
||||
|
||||
private Path getProfilePath(boolean privileged) {
|
||||
if (privileged) {
|
||||
return Paths.get("/etc/profile");
|
||||
} else {
|
||||
Path home = Paths.get(System.getenv("HOME"));
|
||||
if (os == "darwin") {
|
||||
return home.resolve(".bash_profile");
|
||||
} else {
|
||||
return home.resolve(".bashrc");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void installWindows(String dir, boolean privileged) throws Exception {
|
||||
String type = "REG_EXPAND_SZ";
|
||||
String valueName = "Path";
|
||||
String keyName = getKeyName(privileged);
|
||||
|
||||
String path = regQuery(keyName, valueName, type);
|
||||
if (path.contains(dir)) {
|
||||
return;
|
||||
}
|
||||
regAdd(keyName, valueName, type, path + ";" + dir + ";");
|
||||
}
|
||||
|
||||
private void regAdd(String keyName, String valueName, String type, String data) throws Exception {
|
||||
Process p = Runtime.getRuntime()
|
||||
.exec(new String[] { "reg", "add", keyName, "/v", valueName, "/t", type, "/d", data, "/f" });
|
||||
if (p.waitFor() != 0) {
|
||||
throw new Exception(new String(p.getErrorStream().readAllBytes()));
|
||||
}
|
||||
}
|
||||
|
||||
private String regQuery(String keyName, String valueName, String type) throws Exception {
|
||||
Process p = Runtime.getRuntime().exec(new String[] { "reg", "query", keyName, "/v", valueName });
|
||||
if (p.waitFor() != 0) {
|
||||
throw new Exception(new String(p.getErrorStream().readAllBytes()));
|
||||
}
|
||||
return new String(p.getInputStream().readAllBytes()).replace(keyName, "").replace(valueName, "")
|
||||
.replace(type, "").trim();
|
||||
}
|
||||
|
||||
private String getKeyName(boolean privileged) {
|
||||
if (privileged) {
|
||||
return "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment";
|
||||
} else {
|
||||
return "HKEY_CURRENT_USER\\Environment";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
import picocli.CommandLine;
|
||||
import picocli.CommandLine.Command;
|
||||
import picocli.CommandLine.Option;
|
||||
import picocli.CommandLine.ParseResult;
|
||||
|
||||
@Command(name = "adbi", description = "install adb", mixinStandardHelpOptions = true, version = "beta")
|
||||
public class cli implements Runnable {
|
||||
@Option(names = { "-i", "--install-dir" }, description = "directory to install to")
|
||||
String dir;
|
||||
@Option(names = { "-u", "--user-mode" }, description = "unpriveleged install, current user only")
|
||||
boolean user;
|
||||
@Option(names = { "-f", "--add-fastboot" }, description = "include fastboot")
|
||||
boolean fastboot;
|
||||
@Option(names = { "-a", "--add-all" }, description = "include everything")
|
||||
boolean all;
|
||||
@Option(names = { "-d", "--download-only" }, description = "do not try to add adb to PATH")
|
||||
boolean downloadOnly;
|
||||
|
||||
public static void main(String[] args) {
|
||||
new cli(args).run();
|
||||
}
|
||||
|
||||
public cli(String[] args) {
|
||||
CommandLine cli = new CommandLine(this);
|
||||
ParseResult argv = cli.parseArgs(args);
|
||||
if (argv.isUsageHelpRequested()) {
|
||||
cli.usage(System.err);
|
||||
System.exit(0);
|
||||
}
|
||||
if (argv.isVersionHelpRequested()) {
|
||||
cli.printVersionHelp(System.err);
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
int mode = 0;
|
||||
if (fastboot)
|
||||
mode += 1;
|
||||
if (all)
|
||||
mode += 2;
|
||||
try {
|
||||
adbi adbi = new adbi();
|
||||
if (dir == null)
|
||||
dir = adbi.getDefaultInstallPath(!user);
|
||||
else{
|
||||
if(!user && !adbi.isPathPrivileged(dir)){
|
||||
user=true;
|
||||
System.out.println("User directory specified, switching to user mode");
|
||||
}
|
||||
}
|
||||
dir = adbi.getCannonicalPath(dir);
|
||||
adbi.download(dir, mode);
|
||||
if (!downloadOnly) {
|
||||
adbi.install(dir, !user);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.exit(e.hashCode());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+137
@@ -0,0 +1,137 @@
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.LayoutManager;
|
||||
import java.io.File;
|
||||
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.UIManager;
|
||||
|
||||
public class gui extends JFrame {
|
||||
|
||||
private static final long serialVersionUID = -2628083151723078126L;
|
||||
private final adbi adbi;
|
||||
private final gui gui = this;
|
||||
private final LayoutManager manager = new GridBagLayout();
|
||||
private final GridBagConstraints constraints = new GridBagConstraints();
|
||||
private final String title = "ADBi";
|
||||
private final JComboBox<String> installPath = new JComboBox<String>();
|
||||
private final JButton startButton = new JButton("Start");
|
||||
private final JRadioButton adb = new JRadioButton("adb");
|
||||
private final JRadioButton fastboot = new JRadioButton("adb and fastboot");
|
||||
private final JRadioButton all = new JRadioButton("everything");
|
||||
private final ButtonGroup components = new ButtonGroup();
|
||||
private final JLabel componentsLabel = new JLabel("From platform-tools, install:");
|
||||
private final JButton selectFolderButton = new JButton(UIManager.getIcon("FileView.directoryIcon"));
|
||||
private final JLabel installPathLabel = new JLabel("Install to:");
|
||||
private final JCheckBox download = new JCheckBox("Download/Update only, don't install");
|
||||
private JFileChooser fileChooser = new JFileChooser();
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
new gui();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace(System.err);
|
||||
JOptionPane.showMessageDialog(null, e.getMessage(), e.getClass().getSimpleName(), JOptionPane.ERROR_MESSAGE);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
public gui() throws Exception {
|
||||
adbi = new adbi();
|
||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
setTitle(title);
|
||||
setLayout(manager);
|
||||
|
||||
constraints.gridx = GridBagConstraints.RELATIVE;
|
||||
constraints.gridy = 1;
|
||||
constraints.fill = GridBagConstraints.HORIZONTAL;
|
||||
add(installPath, constraints);
|
||||
|
||||
constraints.fill = GridBagConstraints.NONE;
|
||||
add(selectFolderButton, constraints);
|
||||
|
||||
constraints.gridx = 0;
|
||||
constraints.gridy = 0;
|
||||
constraints.fill = GridBagConstraints.HORIZONTAL;
|
||||
constraints.gridwidth = GridBagConstraints.REMAINDER;
|
||||
add(installPathLabel, constraints);
|
||||
|
||||
constraints.gridy = 2;
|
||||
add(componentsLabel, constraints);
|
||||
|
||||
constraints.gridy = GridBagConstraints.RELATIVE;
|
||||
add(adb, constraints);
|
||||
add(fastboot, constraints);
|
||||
add(all, constraints);
|
||||
add(download, constraints);
|
||||
add(startButton, constraints);
|
||||
|
||||
components.add(adb);
|
||||
components.add(fastboot);
|
||||
components.add(all);
|
||||
adb.setSelected(true);
|
||||
|
||||
installPath.addItem(adbi.getDefaultInstallPath(true));
|
||||
installPath.addItem(adbi.getDefaultInstallPath(false));
|
||||
installPath.setSelectedIndex(0);
|
||||
installPath.setEditable(true);
|
||||
|
||||
pack();
|
||||
selectFolderButton.addActionListener(l -> selectFolder());
|
||||
startButton.addActionListener(l -> start());
|
||||
setVisible(true);
|
||||
|
||||
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
||||
}
|
||||
|
||||
private void start() {
|
||||
JPanel statusPanel = new JPanel(manager);
|
||||
JLabel statusLabel = new JLabel("Setting up");
|
||||
statusPanel.add(statusLabel, constraints);
|
||||
gui.setContentPane(statusPanel);
|
||||
int x = 0;
|
||||
if (fastboot.isSelected())
|
||||
x += 1;
|
||||
if (all.isSelected())
|
||||
x += 2;
|
||||
final int mode = x;
|
||||
final String dir = adbi.getCannonicalPath((String) installPath.getSelectedItem());
|
||||
final boolean privileged = adbi.isPathPrivileged(dir);
|
||||
new Thread(() -> {
|
||||
try {
|
||||
statusLabel.setText("Downloading");
|
||||
adbi.download(dir, mode);
|
||||
if (!download.isSelected()) {
|
||||
statusLabel.setText("Installing");
|
||||
adbi.install(dir, privileged);
|
||||
}
|
||||
JOptionPane.showMessageDialog(gui, "Done", "ADBi", JOptionPane.INFORMATION_MESSAGE);
|
||||
System.exit(0);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace(System.err);
|
||||
JOptionPane.showMessageDialog(gui, e.getMessage() + "\n" + e.getClass().getSimpleName(),
|
||||
"Install Failed", JOptionPane.ERROR_MESSAGE);
|
||||
System.exit(1);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
private void selectFolder() {
|
||||
fileChooser.showOpenDialog(gui);
|
||||
try{
|
||||
installPath.setSelectedItem(fileChooser.getSelectedFile().getAbsolutePath());
|
||||
}catch(NullPointerException e){
|
||||
//non-issue
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user