-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from josephsmendoza/java
Java conversion
- Loading branch information
Showing
11 changed files
with
457 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'] | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
57 changes: 57 additions & 0 deletions
57
src/josephsmendoza/android/sdk/platformTools/installer/AVFixInstall.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
53
src/josephsmendoza/android/sdk/platformTools/installer/Common.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
src/josephsmendoza/android/sdk/platformTools/installer/FileInstall.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
61 changes: 61 additions & 0 deletions
61
src/josephsmendoza/android/sdk/platformTools/installer/FileSearch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
Oops, something went wrong.