14 Commits
0.7 ... 1
Author SHA1 Message Date
Joseph mendozaandGitHub 550e52cf1e Update README.md 2019-08-31 22:24:46 -07:00
Joseph Mendoza 0077844000 mac version working 2019-08-31 21:57:09 -07:00
josephsmendoza c086ad5552 fixed typo 2019-08-15 00:33:59 -07:00
josephsmendoza 0c298432f2 Update adbi.cmd 2019-08-15 00:31:38 -07:00
Joseph mendozaandGitHub 981fea7af8 Create build.sh 2019-08-14 23:17:39 -07:00
Joseph mendozaandGitHub edd7717a08 Update README.md 2019-08-14 23:16:04 -07:00
Joseph mendozaandGitHub 5fc505d789 Merge pull request #2 from josephsmendoza/dlang
Dlang conversion
2019-08-14 15:51:57 -07:00
josephsmendoza fa59eed572 D command line basics done 2019-08-14 15:50:24 -07:00
Josef Mendoza d9e3ca1f50 d conversion start 2019-08-12 01:57:38 -07:00
Josef Mendoza 51c1c71475 d conversion start 2019-08-12 01:57:14 -07:00
Joseph mendozaandGitHub 0e8df6cf77 Update and rename sfx.txt to build.cmd 2019-08-10 12:43:38 -07:00
Joseph mendozaandGitHub b23ded7286 Update README.md 2019-08-10 12:40:16 -07:00
f238391707 Update build.gradle 2019-07-29 03:54:46 -07:00
Joseph mendozaandGitHub 64e8e294c4 Update build.gradle 2019-07-29 03:45:53 -07:00
16 changed files with 174 additions and 461 deletions
+3 -1
View File
@@ -7,4 +7,6 @@ This installer requires an internet connection.
Icon is from [Google via icon-icons.com](https://icon-icons.com/icon/adb/90476)
Packaged with [7z SFX Builder](https://sourceforge.net/projects/s-zipsfxbuilder)
Windows version packaged with [Ptiso](https://pismotec.com/ptiso/)
Linux & Mac version packaged with [UPX](https://upx.github.io/)
+130
View File
@@ -0,0 +1,130 @@
/+ dub.sdl:
targetPath "bin/$PLATFORM/$ARCH"
+/
import std.path;
import std.stdio : writeln;
import std.algorithm.searching : canFind;
import std.process : environment;
bool sys,user,silent,verbose;
string installDir;
int installTools(){
import std.zip,std.conv,std.file,std.net.curl,std.conv : octal;
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";
ubyte[] data;
auto http=HTTP(url);
http.onReceive=(ubyte[] response){
data~=response;
return response.length;
};
http.perform();
"Download complete".writeln();
auto zip=new ZipArchive(data);
foreach (x;zip.directory){
auto path=buildNormalizedPath(installDir,x.name[15 .. $]);
if(x.compressedSize!=0){
if(!path.dirName.exists) path.dirName.mkdirRecurse();
if(path.exists) path.remove();
zip.expand(x);
write(path, x.expandedData);
setAttributes(path,octal!775);
} else {
try if(path.isFile) {
path.remove;
path.mkdirRecurse;
} catch (Exception e) path.mkdirRecurse;
}
}
"Extraction complete".writeln();
return 0;
}
int installPath(){
string path=environment.get("PATH");
if(path.canFind(installDir)){
"Install folder is already in PATH".writeln;
return 0;
}
version(Windows){
import std.windows.registry;
Key env;
if(user){
env=Registry.currentUser.getKey("Environment",REGSAM.KEY_ALL_ACCESS);
}
if(sys){
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 : append;
if(user) append("~/.profile".expandTilde,"\nexport PATH=$PATH"~pathSeparator~installDir);
if(sys) append("/etc/profile","\nexport PATH=$PATH"~pathSeparator~installDir);
}
"Install folder was added to PATH".writeln();
"logout/login or reboot to coplete install".writeln();
return 0;
}
int install(){
if(user) "Installing for current user".writeln();
if(sys) "Installing for all users".writeln();
("Installing to " ~ installDir).writeln();
return installTools() + installPath();
}
int main(string[] args){
import std.getopt : getopt,defaultGetoptPrinter;
auto xargs=getopt(args,
"all-users|a","Install for all users.",&sys,
"user|u","Install for current user.",&user,
//"silent|s","Silent standard output.",&silent,
//"verbose|v","Verbose standard output.",&verbose,
"install-dir|i","Install to specified directory",&installDir
);
if(installDir){
installDir=installDir.buildNormalizedPath.absolutePath;
if(!sys && !user){
string allHome="~".expandTilde.dirName;
if(!allHome.isRooted && installDir.canFind(allHome)) user=true;
else sys=true;
}
return install();
}
if(user || sys){
auto append=buildNormalizedPath("Android","SDK","platform-tools");
if(user){
version(Windows)installDir=buildNormalizedPath(environment.get("LocalAppData"),append);
version(linux)installDir=buildNormalizedPath("~".expandTilde,append);
version(OSX)installDir=buildNormalizedPath("~/Library".expandTilde,append);
return install();
}
if(sys){
version(Windows)installDir=buildNormalizedPath(environment.get("ProgramFiles"),append);
version(linux)installDir=buildNormalizedPath("/opt",append);
version(OSX)installDir=buildNormalizedPath("/Library",append);
return install();
}
}
defaultGetoptPrinter("Download platform-tools and add to PATH.",xargs.options);
return 0;
}
+3
View File
@@ -0,0 +1,3 @@
@echo off
%~dp0\adbi.exe %*
pause
+2
View File
@@ -0,0 +1,2 @@
dub build --single adbi.d
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 adbi.cmd -x icon adb.ico ADB-Installer.exe bin/windows/x86_64
-34
View File
@@ -1,34 +0,0 @@
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']
}
+3
View File
@@ -0,0 +1,3 @@
#!/bin/sh
dub build --single adbi.d
upx --best bin/linux/x86_64/adbi
+3
View File
@@ -0,0 +1,3 @@
/+ dub.sdl
sourceFiles "adbi.d"
+/
+30
View File
@@ -0,0 +1,30 @@
/+ dub.sdl:
dependency "tkd" version="1.1.13"
targetPath "bin/$PLATFORM/$ARCH"
copyFiles \
"$TCLTK_PACKAGE_DIR/dist/$ARCH/tcl86t.dll" \
"$TCLTK_PACKAGE_DIR/dist/$ARCH/tk86t.dll" \
"$TCLTK_PACKAGE_DIR/dist/library" \
platform="windows"
+/
import tkd.tkdapplication;
class GUI : TkdApplication
{
override protected void initInterface()
{
auto frame = new Frame().pack(5);
new Label(frame, "Select an install location").pack(0);
auto searchLabel=new Label(frame,"Searching for pre-existing files...").pack(0);
new Button(frame, "System").pack(0);
new Button(frame, "User").pack(0);
new Button(frame, "Mixed").pack(0);
}
}
void main(string[] args)
{
auto gui = new GUI();
gui.run();
}
-11
View File
@@ -1,11 +0,0 @@
;!@Install@!UTF-8!
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\image.7z
7zSFXBuilder_SFXIcon=C:\Users\Josef\Documents\ADB-Installer\-adb_90476.ico
7zSFXBuilder_UseDefMod=7zsd_All
7zSFXBuilder_UPXCommands=--best --all-methods
@@ -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";
}
}
}