Skip to content

Commit a1b1c63

Browse files
Merge pull request #75 from corbindavenport/dev
Nexus Tools 5.6
2 parents 30c2bc7 + 13ef187 commit a1b1c63

File tree

5 files changed

+42
-31
lines changed

5 files changed

+42
-31
lines changed

README.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ Nexus Tools is an installer and updater for [Android SDK Platform Tools](https:/
44

55
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`.
66

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

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

bin/main.dart

+39-26
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ String macZip = 'https://dl.google.com/android/repository/platform-tools-latest-
1010
String linuxZip = 'https://dl.google.com/android/repository/platform-tools-latest-linux.zip';
1111
String windowsZip = 'https://dl.google.com/android/repository/platform-tools-latest-windows.zip';
1212
Map envVars = io.Platform.environment;
13-
double appVersion = 5.5;
13+
double appVersion = 5.6;
1414
String baseRepo = 'corbindavenport/nexus-tools';
1515

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

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

144143
// Function for removing Platform Tools package
144+
// Nexus Tools 5.5+ (May 2023 - Present) on Windows installs files in %AppData%\NexusTools
145+
// Nexus Tools 5.0-5.4 (Sep 2021 - May 2023) on Windows installs files in $Home\NexusTools\
146+
// Nexus Tools 3.2+ (August 2016-Present) on Linux/macOS/ChromeOS installs files in ~/.nexustools
145147
Future removePlatformTools() async {
146148
print('[WARN] This will delete the Android System Tools (ADB, Fastboot, etc.) installed by Nexus Tools, as well as the Nexus Tools application.');
147149
io.stdout.write('[WARN] Continue with removal? [Y/N] ');
148150
var input = io.stdin.readLineSync();
149151
if (input?.toLowerCase() != 'y') {
150152
return;
151153
}
152-
// Delete primary directory if it exists
153-
// TODO: Add support for new directory on Windows
154-
// Nexus Tools 3.2+ (August 2016-Present) installs binaries in ~/.nexustools
154+
// Stop ADB server, if it's running it can prevent deletion (at least on Windows)
155+
try {
156+
await io.Process.run('adb', ['kill-server']);
157+
print('[ OK ] Shut down ADB server.');
158+
} catch (e) {
159+
print('[WARN] Could not kill ADB server, attempting to continue.');
160+
}
161+
// Delete registry key on Windows hosts
162+
if (io.Platform.isWindows) {
163+
await io.Process.run('reg', ['delete', r'HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall\NexusTools', '/f']);
164+
print('[ OK ] Removed registry keys.');
165+
}
166+
// Delete current installation directory if it exists
155167
var dir = nexusToolsDir();
156168
var installExists = false;
157169
installExists = await io.Directory(dir).exists();
158-
if (installExists) {
170+
if (installExists && (io.Platform.isWindows)) {
171+
// Create a temporary batch file to delete the Nexus Tools directory, because Windows executables can't delete themselves
172+
var batchFile = await io.File(envVars['TEMP'] + r'\nexustoolsdelete.bat');
173+
var batchFileContents = '''
174+
@echo off
175+
echo Deleting Nexus Tools folder at $dir, please wait.
176+
ping localhost -n 5 > nul
177+
rmdir /s /q "$dir"
178+
''';
179+
await batchFile.writeAsString(batchFileContents, mode: io.FileMode.writeOnly);
180+
io.Process.start('cmd.exe', ['/c', batchFile.path], mode: io.ProcessStartMode.detached, runInShell: true);
181+
print('[ OK ] Directory at $dir will be deleted in new window.');
182+
} else if (installExists) {
159183
// Proceed with deletion
160184
await io.Directory(dir).delete(recursive: true);
161185
print('[ OK ] Deleted directory at $dir.');
162-
}
163-
// Windows-specific functions
164-
if (io.Platform.isWindows) {
165-
var oldDir = envVars['UserProfile'] + r'\NexusTools';
166-
var oldinstallExists = await io.Directory(oldDir).exists();
167-
if (oldinstallExists) {
168-
// Proceed with deletion
169-
await io.Directory(oldDir).delete(recursive: true);
170-
print('[ OK ] Deleted directory at $oldDir.');
171-
}
172-
// Clean up registry
173-
await io.Process.run('reg', ['delete', r'HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall\NexusTools', '/f']);
174-
print('[ OK ] Removed registry keys.');
186+
} else {
187+
print('[ OK ] Nexus Tools directory not found.');
175188
}
176189
// Exit message
177190
print('[INFO] Nexus Tools can be reinstalled from here: https://github.com/$baseRepo\n');

pubspec.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,4 @@ packages:
162162
source: hosted
163163
version: "2.1.4"
164164
sdks:
165-
dart: ">=2.19.0 <3.0.0"
165+
dart: ">=3.3.1 <4.0.0"

pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version: 5.0.0
44
homepage: https://github.com/corbindavenport/nexus-tools/
55

66
environment:
7-
sdk: '>=2.12.0 <3.0.0'
7+
sdk: '>=3.3.1'
88

99
# dependencies:
1010
# path: ^1.8.0

screen.png

174 KB
Loading

0 commit comments

Comments
 (0)