Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bd2ca700d5 | ||
|
|
654d70c17b | ||
|
|
573de4b4c2 | ||
|
|
95730a0002 | ||
|
|
c75801fc07 | ||
|
|
4e4e5919d6 | ||
|
|
70e11d4277 | ||
|
|
f6228ca729 | ||
|
|
321a03a36e | ||
|
|
2682eac500 | ||
|
|
a345dfa495 | ||
|
|
83894674dc | ||
|
|
7a7e813c7e | ||
|
|
b5ca94ae58 | ||
|
|
92d1d52ec2 | ||
|
|
2ad1b8dc97 | ||
|
|
8c29691361 | ||
|
|
c392631339 | ||
|
|
c5de32f6dd | ||
|
|
2df8f900d6 | ||
|
|
73abfb8fa8 | ||
|
|
a62f1e998f | ||
|
|
7821de4bb4 | ||
|
|
97a89f4382 | ||
|
|
7aab701aa1 | ||
|
|
b8686d4a04 | ||
|
|
2be4c47213 | ||
|
|
d5582d17e3 | ||
|
|
ba1ba3937d | ||
|
|
fef18f8b68 | ||
|
|
d137448a7b | ||
|
|
4ce50aa635 | ||
|
|
ed5f4d7813 | ||
|
|
433330f743 | ||
|
|
e7f00bdff7 | ||
|
|
550e52cf1e | ||
|
|
0077844000 | ||
|
|
c086ad5552 | ||
|
|
0c298432f2 | ||
|
|
981fea7af8 | ||
|
|
edd7717a08 | ||
|
|
5fc505d789 | ||
|
|
fa59eed572 | ||
|
|
d9e3ca1f50 | ||
|
|
51c1c71475 |
@@ -0,0 +1,7 @@
|
||||
bin
|
||||
build
|
||||
.gradle
|
||||
.vscode
|
||||
.settings
|
||||
.classpath
|
||||
.project
|
||||
@@ -1,10 +1,12 @@
|
||||
# ADB-Installer
|
||||
# Android Debug Bridge Installer
|
||||
Download from [Releases](https://github.com/josephsmendoza/ADB-Installer/releases)
|
||||
|
||||
This is a re-implementation of the [15 seconds ADB Installer](https://forum.xda-developers.com/showthread.php?t=2588979)
|
||||
|
||||
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)
|
||||
|
||||
Packaged with [Ptiso](https://pismotec.com/ptiso/)
|
||||
Windows version packaged with [7zip](https://www.7-zip.org/)
|
||||
|
||||
Linux & Mac version packaged with [makeself](https://makeself.io/)
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
gradle runtime
|
||||
ptiso create -z lzma -c crc32 -x stub ptse_cmd.stub -x runas admin -x mount_system_visible 0 -x process_visible 1 -x run_relative 1 -x use_stderr 1 -x run_exe bin/ADB-Installer.bat -x icon adb.ico ADB-Installer.exe build\image
|
||||
+36
-27
@@ -1,27 +1,36 @@
|
||||
plugins {
|
||||
id 'org.beryx.runtime' version "1.2.1" //https://plugins.gradle.org/plugin/org.beryx.runtime
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
main.java.srcDirs = [ 'src' ]
|
||||
}
|
||||
|
||||
repositories {
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
maven { url 'https://jitpack.io' }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'net.java.dev.jna:jna:5.3.1'
|
||||
implementation 'net.java.dev.jna:jna-platform:5.3.1'
|
||||
}
|
||||
|
||||
application {
|
||||
mainClassName = 'josephsmendoza.android.sdk.platformTools.installer.Common'
|
||||
}
|
||||
|
||||
runtime {
|
||||
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
|
||||
modules = ['java.desktop','java.logging','java.datatransfer','jdk.crypto.ec']
|
||||
}
|
||||
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"
|
||||
}
|
||||
}
|
||||
+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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
package josephsmendoza.android.sdk.platformTools.installer;
|
||||
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.datatransfer.StringSelection;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JLabel;
|
||||
|
||||
public class AVFixInstall implements Runnable {
|
||||
|
||||
private String installPath;
|
||||
private String command;
|
||||
private String running;
|
||||
private String excludePath;
|
||||
private String excludeProcess;
|
||||
|
||||
public AVFixInstall(String path) {
|
||||
installPath=path;
|
||||
command="sc query WinDefend";
|
||||
running="RUNNING";
|
||||
excludePath="powershell Add-MpPreference -ExclusionPath";
|
||||
excludeProcess="powershell Add-MpPreference -ExclusionProcess";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Runtime cmd=Runtime.getRuntime();
|
||||
String av=new String(cmd.exec(command).getInputStream().readAllBytes());
|
||||
if(av.contains(running)) {
|
||||
cmd.exec(excludePath+installPath);
|
||||
cmd.exec(excludeProcess+Common.adb);
|
||||
cmd.exec(excludeProcess+Common.fastboot);
|
||||
} else {
|
||||
JDialog frame=new JDialog();
|
||||
frame.setLayout(new BoxLayout(frame.getContentPane(),BoxLayout.Y_AXIS));
|
||||
frame.setIconImage(new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB_PRE));
|
||||
frame.add(new JLabel("Windows Defender is not running!"));
|
||||
frame.add(new JLabel("Make exceptions in your antivirus for:"));
|
||||
frame.add(new JLabel("adb.exe"));
|
||||
frame.add(new JLabel("fastboot.exe"));
|
||||
frame.add(new JLabel(installPath));
|
||||
frame.add(new JLabel("The install path has been copied to your clipboard"));
|
||||
frame.setModal(true);
|
||||
frame.pack();
|
||||
frame.setLocationRelativeTo(null);
|
||||
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(installPath), null);
|
||||
frame.setVisible(true);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
package josephsmendoza.android.sdk.platformTools.installer;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
public class Common {
|
||||
|
||||
private static ExecutorService executorService;
|
||||
public static final Set<String> installPaths = Collections.synchronizedSet(new HashSet<String>());
|
||||
public static volatile boolean FileSearchComplete=false;
|
||||
public static volatile boolean PathSearchComplete=false;
|
||||
public static volatile boolean FileInstallComplete=false;
|
||||
public static volatile boolean PathInstallComplete=false;
|
||||
public static volatile boolean SettingsInstallComplete=false;
|
||||
public static final String OS = System.getProperty("os.name").toUpperCase().substring(0, 3);
|
||||
public static final String adb=" adb";
|
||||
public static final String fastboot=" fastboot";
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
GUI gui = new GUI();
|
||||
initInstallPaths();
|
||||
executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
|
||||
executorService.execute(gui);
|
||||
executorService.execute(new FileSearch());
|
||||
executorService.execute(new PathSearch());
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void initInstallPaths() {
|
||||
final String append = Paths.get("Android", "SDK", "platform-tools").toString();
|
||||
switch (OS) {
|
||||
case "WIN":
|
||||
installPaths.add(Paths.get(System.getenv("LocalAppData"), append).toString());
|
||||
installPaths.add(Paths.get(System.getenv("ProgramFiles"), append).toString());
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void install(String path) {
|
||||
executorService.execute(new FileInstall(path));
|
||||
executorService.execute(new PathInstall(path));
|
||||
executorService.execute(new AVFixInstall(path));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
package josephsmendoza.android.sdk.platformTools.installer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.net.URL;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
public class FileInstall implements Runnable {
|
||||
|
||||
private String installPath;
|
||||
|
||||
public FileInstall(String path) {
|
||||
installPath=path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
ZipInputStream ziStream=new ZipInputStream(new URL(getURL()).openStream());
|
||||
ZipEntry zEntry;
|
||||
while((zEntry=ziStream.getNextEntry())!=null) {
|
||||
File f=new File(installPath+zEntry.getName().replaceAll("platform-tools", ""));
|
||||
int size=(int) zEntry.getSize();
|
||||
if(size==0) {
|
||||
f.mkdirs();
|
||||
continue;
|
||||
}
|
||||
if(!f.exists()) {
|
||||
f.createNewFile();
|
||||
}
|
||||
FileOutputStream foStream=new FileOutputStream(f);
|
||||
foStream.write(ziStream.readNBytes(size));
|
||||
foStream.flush();
|
||||
foStream.close();
|
||||
}
|
||||
|
||||
Common.FileInstallComplete=true;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private String getURL() {
|
||||
switch(Common.OS) {
|
||||
case "WIN":
|
||||
return "https://dl.google.com/android/repository/platform-tools-latest-windows.zip";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
package josephsmendoza.android.sdk.platformTools.installer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.FileVisitResult;
|
||||
import java.nio.file.FileVisitor;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
|
||||
public class FileSearch implements FileVisitor<Path>, Runnable {
|
||||
|
||||
private String matchRegex = ".*adb.exe|.*fastboot.exe";
|
||||
private String skipRegex = ".*Recycle\\.Bin|.*Temp.*";
|
||||
private Path startPath = getRoot();
|
||||
|
||||
private Path getRoot() {
|
||||
if (Common.OS == "WIN") {
|
||||
return Paths.get("C:\\");
|
||||
}
|
||||
return Paths.get("/");
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
|
||||
if (dir.toAbsolutePath().toString().matches(skipRegex)) {
|
||||
return FileVisitResult.SKIP_SUBTREE;
|
||||
} else {
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||
Path absolutePath = file.toAbsolutePath();
|
||||
if (absolutePath.toString().matches(matchRegex) && file.toFile().canExecute())
|
||||
Common.installPaths.add((absolutePath.getParent().toString()));
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Files.walkFileTree(startPath, this);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
Common.FileSearchComplete = true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
package josephsmendoza.android.sdk.platformTools.installer;
|
||||
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.UnsupportedLookAndFeelException;
|
||||
|
||||
|
||||
public class GUI implements Runnable {
|
||||
|
||||
JFrame frame;
|
||||
JPanel statusPanel;
|
||||
JLabel searchingLabel;
|
||||
JPanel selectionPanel;
|
||||
|
||||
public GUI() throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException {
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
|
||||
frame=new JFrame("ADB Installer");
|
||||
frame.setLayout(new BoxLayout(frame.getContentPane(),BoxLayout.Y_AXIS));
|
||||
frame.setIconImage(new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB_PRE));
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
|
||||
statusPanel=new JPanel();
|
||||
statusPanel.setLayout(new GridLayout(0,1));
|
||||
frame.add(statusPanel);
|
||||
|
||||
JLabel selectLabel=new JLabel("Select an install location");
|
||||
selectLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
statusPanel.add(selectLabel);
|
||||
|
||||
searchingLabel=new JLabel("Searching for pre-existing files...");
|
||||
searchingLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
statusPanel.add(searchingLabel);
|
||||
|
||||
selectionPanel=new JPanel();
|
||||
selectionPanel.setLayout(new GridLayout(0,1));
|
||||
frame.add(selectionPanel);
|
||||
|
||||
frame.setLocationRelativeTo(null);
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
int lastSize=0;
|
||||
while (!Common.FileSearchComplete) {
|
||||
if(lastSize<Common.installPaths.size()) {
|
||||
update();
|
||||
lastSize=Common.installPaths.size();
|
||||
}
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
statusPanel.remove(searchingLabel);
|
||||
frame.pack();
|
||||
while(!Common.FileInstallComplete || !Common.PathInstallComplete) {
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
JLabel done=new JLabel("Done");
|
||||
done.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
frame.setContentPane(done);
|
||||
frame.pack();
|
||||
}
|
||||
|
||||
private void update() {
|
||||
selectionPanel.removeAll();
|
||||
for(String path:Common.installPaths) {
|
||||
JButton selectionButton=new JButton(path);
|
||||
selectionButton.setHorizontalAlignment(SwingConstants.LEFT);
|
||||
selectionButton.addActionListener(l -> install(path));
|
||||
selectionPanel.add(selectionButton);
|
||||
}
|
||||
frame.pack();
|
||||
}
|
||||
|
||||
private void install(String path) {
|
||||
JLabel installing=new JLabel("Installing...");
|
||||
installing.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
frame.setContentPane(installing);
|
||||
frame.pack();
|
||||
Common.install(path);
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
package josephsmendoza.android.sdk.platformTools.installer;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import com.sun.jna.platform.win32.Advapi32Util;
|
||||
import com.sun.jna.platform.win32.WinReg;
|
||||
|
||||
public class PathInstall implements Runnable {
|
||||
|
||||
private String dir;
|
||||
private String sysKey;
|
||||
private String userKey;
|
||||
private String value;
|
||||
//private Advapi32Util winReg;
|
||||
|
||||
public PathInstall(String installPath) {
|
||||
dir = installPath;
|
||||
sysKey = "System\\CurrentControlSet\\Control\\Session Manager\\Environment";
|
||||
userKey = "Environment";
|
||||
value = "PATH";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (dir.contains(System.getProperty("user.home"))) {
|
||||
install(userKey);
|
||||
} else {
|
||||
install(sysKey);
|
||||
}
|
||||
}
|
||||
|
||||
private void install(String key){
|
||||
try {
|
||||
final String PATH = Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, sysKey, value);
|
||||
if (!PATH.contains(dir)) {
|
||||
Advapi32Util.registrySetStringValue(WinReg.HKEY_LOCAL_MACHINE, key, value,
|
||||
PATH + File.pathSeparatorChar + dir);
|
||||
}
|
||||
Common.PathInstallComplete = true;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
package josephsmendoza.android.sdk.platformTools.installer;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class PathSearch implements Runnable{
|
||||
|
||||
public PathSearch() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
File adb=new File(new String(Runtime.getRuntime().exec(adbGetCommand()).getInputStream().readAllBytes()));
|
||||
if(adb.canExecute()) {
|
||||
Common.installPaths.add(adb.getParentFile().getAbsolutePath());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// Not found
|
||||
}
|
||||
try {
|
||||
File fastboot=new File(new String(Runtime.getRuntime().exec(fastbootGetCommand()).getInputStream().readAllBytes()));
|
||||
if(fastboot.canExecute()) {
|
||||
Common.installPaths.add(fastboot.getParentFile().getAbsolutePath());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// Not found
|
||||
}
|
||||
}
|
||||
|
||||
private String fastbootGetCommand() {
|
||||
return getCommand()+Common.fastboot;
|
||||
}
|
||||
|
||||
private String adbGetCommand() {
|
||||
return getCommand()+Common.adb;
|
||||
}
|
||||
|
||||
private String getCommand() {
|
||||
if(Common.OS=="WIN") {
|
||||
return "where";
|
||||
} else {
|
||||
return "which";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user