Skip to content

Commit

Permalink
Merge pull request #2 from josephsmendoza/dlang
Browse files Browse the repository at this point in the history
Dlang conversion
  • Loading branch information
sugoidogo authored Aug 14, 2019
2 parents 0e8df6c + fa59eed commit 5fc505d
Show file tree
Hide file tree
Showing 13 changed files with 162 additions and 444 deletions.
123 changes: 123 additions & 0 deletions adbi.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/+ dub.sdl:
dependency "vibe-d" version="~>0.8.5"
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.file,vibe.stream.operations,vibe.inet.urltransfer,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";

download(url, (scope data){
auto zip=new ZipArchive(data.readAll());
"Download complete".writeln();
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;
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;
}
4 changes: 4 additions & 0 deletions bin/windows/x86_64/adbi.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@echo off
cd %~dp0
adbi.exe %*
pause
4 changes: 2 additions & 2 deletions build.cmd
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
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
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
27 changes: 0 additions & 27 deletions build.gradle

This file was deleted.

3 changes: 3 additions & 0 deletions cli.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/+ dub.sdl
sourceFiles "adbi.d"
+/
30 changes: 30 additions & 0 deletions gui.d
Original file line number Diff line number Diff line change
@@ -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();
}

This file was deleted.

53 changes: 0 additions & 53 deletions src/josephsmendoza/android/sdk/platformTools/installer/Common.java

This file was deleted.

This file was deleted.

Loading

0 comments on commit 5fc505d

Please sign in to comment.