Skip to content

Commit

Permalink
Merge pull request #1 from josephsmendoza/java
Browse files Browse the repository at this point in the history
Java conversion
  • Loading branch information
sugoidogo authored Jul 20, 2019
2 parents c5fa538 + 5513cab commit dd4ba9f
Show file tree
Hide file tree
Showing 11 changed files with 457 additions and 88 deletions.
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ This is a re-implementation of the [15 seconds ADB Installer](https://forum.xda-

This installer requires an internet connection.

The main component is [the PowerShell script](https://github.com/josephsmendoza/ADB-Installer/blob/master/install.ps1) which downloads [the latest android platform tools for windows](https://dl.google.com/android/repository/platform-tools-latest-windows.zip) and installs them to either `C:\android-platform-tools`, an auto-detected previous install location, or a path you can specify via `-installPath`.

For convenience, this is wrapped in an `.exe` file which runs the script with `ExecutionPolicy` set to `Bypass`. This file is fully automated.

Icon is from [Google via icon-icons.com](https://icon-icons.com/icon/adb/90476)

Built with [7z SFX Builder](https://sourceforge.net/projects/s-zipsfxbuilder)
Packaged with [7z SFX Builder](https://sourceforge.net/projects/s-zipsfxbuilder)
34 changes: 34 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
plugins {
id 'java-library'
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 {
compile 'net.java.dev.jna:jna:5.3.1'
compile 'net.java.dev.jna:jna-platform:5.3.1'
}

jar {
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
}

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']
}
79 changes: 0 additions & 79 deletions install.ps1

This file was deleted.

11 changes: 7 additions & 4 deletions sfx.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
;!@Install@!UTF-8!
RunProgram="powershell -executionpolicy bypass -file %%T\install.ps1"
GUIMode="1"
MiscFlags="4"
OverwriteMode="2"
RunProgram="%%T/bin/ADB-Installer.bat"
;Config file generated by 7z SFX Builder v2.1. (http://sourceforge.net/projects/s-zipsfxbuilder/)
;!@InstallEnd@!
7zSFXBuilder_7zArchive=C:\Users\Josef\Documents\ADB-Installer\install.7z
7zSFXBuilder_SFXIcon=C:\Users\Josef\Documents\ADB-Installer\adb.ico
7zSFXBuilder_UseDefMod=7zsd_All_x64
7zSFXBuilder_7zArchive=C:\Users\Josef\Documents\ADB-Installer\image.7z
7zSFXBuilder_SFXIcon=C:\Users\Josef\Documents\ADB-Installer\-adb_90476.ico
7zSFXBuilder_UseDefMod=7zsd_All
7zSFXBuilder_UPXCommands=--best --all-methods
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
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);
}
}

}
53 changes: 53 additions & 0 deletions src/josephsmendoza/android/sdk/platformTools/installer/Common.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
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));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
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;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
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;
}

}
Loading

0 comments on commit dd4ba9f

Please sign in to comment.