Skip to content

Commit

Permalink
Merge pull request #75 from corbindavenport/dev
Browse files Browse the repository at this point in the history
Nexus Tools 5.6
  • Loading branch information
corbindavenport authored Mar 10, 2024
2 parents 30c2bc7 + 13ef187 commit a1b1c63
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 31 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ Nexus Tools is an installer and updater for [Android SDK Platform Tools](https:/

Nexus Tools downloads the latest Platform tools package directly from Google's servers, so you're always getting the latest version. The tools are installed to `~/.nexustools` (`%AppData%\NexusTools` on Windows), and adds the directory to your system's path. On Windows, Nexus Tools can optionally install [Koush's Universal ADB Driver](https://github.com/koush/UniversalAdbDriver). The SDK Platform Tools can be updated by running `nexustools -i`, or you can uninstall everything by running `nexustools -r`.

<center>
<img src="https://i.imgur.com/Erypq9t.png" />
</center>
![Screenshot of Nexus Tools on macOS and Windows 11](screen.png)

## How to use on Linux, macOS, and Chrome OS

Expand Down
65 changes: 39 additions & 26 deletions bin/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ String macZip = 'https://dl.google.com/android/repository/platform-tools-latest-
String linuxZip = 'https://dl.google.com/android/repository/platform-tools-latest-linux.zip';
String windowsZip = 'https://dl.google.com/android/repository/platform-tools-latest-windows.zip';
Map envVars = io.Platform.environment;
double appVersion = 5.5;
double appVersion = 5.6;
String baseRepo = 'corbindavenport/nexus-tools';

// Function for checking for update
Expand All @@ -20,7 +20,7 @@ Future checkUpdate() async {
var data = await http.read(net);
var parsedData = json.decode(data);
// Compare versions
if (double.parse(parsedData['tag_name']) > appVersion) {
if (double.parse(parsedData['tag_name']) != appVersion) {
print('[INFO] Nexus Tools update available! https://github.com/$baseRepo/blob/main/README.md');
} else {
print('[INFO] You have the latest version of Nexus Tools.');
Expand All @@ -34,9 +34,7 @@ Future checkUpdate() async {
// Credit: https://stackoverflow.com/a/25498458
String nexusToolsDir() {
var home = '';
if (io.Platform.isMacOS) {
home = envVars['HOME'];
} else if (io.Platform.isLinux) {
if (io.Platform.isMacOS || io.Platform.isLinux) {
home = envVars['HOME'];
} else if (io.Platform.isWindows) {
home = envVars['AppData'];
Expand All @@ -53,6 +51,7 @@ String nexusToolsDir() {

// Function for installing Platform Tools package
Future installPlatformTools() async {
print('[INFO] You agree to the Terms & Conditions by installing this software: https://developer.android.com/studio/terms');
var dir = nexusToolsDir();
// Get the proper ZIP file
var zip = '';
Expand All @@ -71,8 +70,7 @@ Future installPlatformTools() async {
var archive = ZipDecoder().decodeBytes(data);
extractArchiveToDisk(archive, dir);
} catch (e) {
var error = e.toString();
print('[EROR] There was an error downloading Platform Tools: $error');
print('[EROR] There was an error downloading Platform Tools: ' + e.toString());
io.exit(1);
}
// Move files out of platform-tools subdirectory and delete the subdirectory
Expand Down Expand Up @@ -128,50 +126,65 @@ Future installPlatformTools() async {
// Add entry to Windows Installed Apps List
// Documentation: https://learn.microsoft.com/en-us/windows/win32/msi/uninstall-registry-key
var uninstallString = dir + r'\nexustools.exe';
var iconString = r'C:\Windows\System32\cmd.exe';
var regEntry = 'Windows Registry Editor Version 5.00\n\n';
regEntry += r'[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall\NexusTools]';
regEntry += '\n"DisplayName"="Nexus Tools (ADB, Fastboot, Android SDK Platform Tools)"';
regEntry += '\n"Publisher"="Corbin Davenport"';
regEntry += '\n"URLInfoAbout"="https://github.com/$baseRepo"';
regEntry += '\n"NoModify"=dword:00000001';
regEntry += '\n"HelpLink"="https://github.com/$baseRepo"';
regEntry += '\n' + r'"UninstallString"="\"' + uninstallString.replaceAll(r'\', r'\\') + r'\" --remove"';
regEntry += '\n' + r'"DisplayIcon"="' + iconString.replaceAll(r'\', r'\\') + r'"';
var regFile = await io.File('$dir/nexustools.reg');
await regFile.writeAsString(regEntry, mode: io.FileMode.writeOnly);
await io.Process.run('reg', ['import', '$dir/nexustools.reg']);
}
}

// Function for removing Platform Tools package
// Nexus Tools 5.5+ (May 2023 - Present) on Windows installs files in %AppData%\NexusTools
// Nexus Tools 5.0-5.4 (Sep 2021 - May 2023) on Windows installs files in $Home\NexusTools\
// Nexus Tools 3.2+ (August 2016-Present) on Linux/macOS/ChromeOS installs files in ~/.nexustools
Future removePlatformTools() async {
print('[WARN] This will delete the Android System Tools (ADB, Fastboot, etc.) installed by Nexus Tools, as well as the Nexus Tools application.');
io.stdout.write('[WARN] Continue with removal? [Y/N] ');
var input = io.stdin.readLineSync();
if (input?.toLowerCase() != 'y') {
return;
}
// Delete primary directory if it exists
// TODO: Add support for new directory on Windows
// Nexus Tools 3.2+ (August 2016-Present) installs binaries in ~/.nexustools
// Stop ADB server, if it's running it can prevent deletion (at least on Windows)
try {
await io.Process.run('adb', ['kill-server']);
print('[ OK ] Shut down ADB server.');
} catch (e) {
print('[WARN] Could not kill ADB server, attempting to continue.');
}
// Delete registry key on Windows hosts
if (io.Platform.isWindows) {
await io.Process.run('reg', ['delete', r'HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall\NexusTools', '/f']);
print('[ OK ] Removed registry keys.');
}
// Delete current installation directory if it exists
var dir = nexusToolsDir();
var installExists = false;
installExists = await io.Directory(dir).exists();
if (installExists) {
if (installExists && (io.Platform.isWindows)) {
// Create a temporary batch file to delete the Nexus Tools directory, because Windows executables can't delete themselves
var batchFile = await io.File(envVars['TEMP'] + r'\nexustoolsdelete.bat');
var batchFileContents = '''
@echo off
echo Deleting Nexus Tools folder at $dir, please wait.
ping localhost -n 5 > nul
rmdir /s /q "$dir"
''';
await batchFile.writeAsString(batchFileContents, mode: io.FileMode.writeOnly);
io.Process.start('cmd.exe', ['/c', batchFile.path], mode: io.ProcessStartMode.detached, runInShell: true);
print('[ OK ] Directory at $dir will be deleted in new window.');
} else if (installExists) {
// Proceed with deletion
await io.Directory(dir).delete(recursive: true);
print('[ OK ] Deleted directory at $dir.');
}
// Windows-specific functions
if (io.Platform.isWindows) {
var oldDir = envVars['UserProfile'] + r'\NexusTools';
var oldinstallExists = await io.Directory(oldDir).exists();
if (oldinstallExists) {
// Proceed with deletion
await io.Directory(oldDir).delete(recursive: true);
print('[ OK ] Deleted directory at $oldDir.');
}
// Clean up registry
await io.Process.run('reg', ['delete', r'HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall\NexusTools', '/f']);
print('[ OK ] Removed registry keys.');
} else {
print('[ OK ] Nexus Tools directory not found.');
}
// Exit message
print('[INFO] Nexus Tools can be reinstalled from here: https://github.com/$baseRepo\n');
Expand Down
2 changes: 1 addition & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,4 @@ packages:
source: hosted
version: "2.1.4"
sdks:
dart: ">=2.19.0 <3.0.0"
dart: ">=3.3.1 <4.0.0"
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version: 5.0.0
homepage: https://github.com/corbindavenport/nexus-tools/

environment:
sdk: '>=2.12.0 <3.0.0'
sdk: '>=3.3.1'

# dependencies:
# path: ^1.8.0
Expand Down
Binary file added screen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a1b1c63

Please sign in to comment.