@@ -10,7 +10,7 @@ String macZip = 'https://dl.google.com/android/repository/platform-tools-latest-
10
10
String linuxZip = 'https://dl.google.com/android/repository/platform-tools-latest-linux.zip' ;
11
11
String windowsZip = 'https://dl.google.com/android/repository/platform-tools-latest-windows.zip' ;
12
12
Map envVars = io.Platform .environment;
13
- double appVersion = 5.5 ;
13
+ double appVersion = 5.6 ;
14
14
String baseRepo = 'corbindavenport/nexus-tools' ;
15
15
16
16
// Function for checking for update
@@ -20,7 +20,7 @@ Future checkUpdate() async {
20
20
var data = await http.read (net);
21
21
var parsedData = json.decode (data);
22
22
// Compare versions
23
- if (double .parse (parsedData['tag_name' ]) > appVersion) {
23
+ if (double .parse (parsedData['tag_name' ]) != appVersion) {
24
24
print ('[INFO] Nexus Tools update available! https://github.com/$baseRepo /blob/main/README.md' );
25
25
} else {
26
26
print ('[INFO] You have the latest version of Nexus Tools.' );
@@ -34,9 +34,7 @@ Future checkUpdate() async {
34
34
// Credit: https://stackoverflow.com/a/25498458
35
35
String nexusToolsDir () {
36
36
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) {
40
38
home = envVars['HOME' ];
41
39
} else if (io.Platform .isWindows) {
42
40
home = envVars['AppData' ];
@@ -53,6 +51,7 @@ String nexusToolsDir() {
53
51
54
52
// Function for installing Platform Tools package
55
53
Future installPlatformTools () async {
54
+ print ('[INFO] You agree to the Terms & Conditions by installing this software: https://developer.android.com/studio/terms' );
56
55
var dir = nexusToolsDir ();
57
56
// Get the proper ZIP file
58
57
var zip = '' ;
@@ -71,8 +70,7 @@ Future installPlatformTools() async {
71
70
var archive = ZipDecoder ().decodeBytes (data);
72
71
extractArchiveToDisk (archive, dir);
73
72
} 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 ());
76
74
io.exit (1 );
77
75
}
78
76
// Move files out of platform-tools subdirectory and delete the subdirectory
@@ -128,50 +126,65 @@ Future installPlatformTools() async {
128
126
// Add entry to Windows Installed Apps List
129
127
// Documentation: https://learn.microsoft.com/en-us/windows/win32/msi/uninstall-registry-key
130
128
var uninstallString = dir + r'\nexustools.exe' ;
129
+ var iconString = r'C:\Windows\System32\cmd.exe' ;
131
130
var regEntry = 'Windows Registry Editor Version 5.00\n\n ' ;
132
131
regEntry += r'[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall\NexusTools]' ;
133
132
regEntry += '\n "DisplayName"="Nexus Tools (ADB, Fastboot, Android SDK Platform Tools)"' ;
134
133
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 "' ;
137
135
regEntry += '\n ' + r'"UninstallString"="\"' + uninstallString.replaceAll (r'\' , r'\\' ) + r'\" --remove"' ;
136
+ regEntry += '\n ' + r'"DisplayIcon"="' + iconString.replaceAll (r'\' , r'\\' ) + r'"' ;
138
137
var regFile = await io.File ('$dir /nexustools.reg' );
139
138
await regFile.writeAsString (regEntry, mode: io.FileMode .writeOnly);
140
139
await io.Process .run ('reg' , ['import' , '$dir /nexustools.reg' ]);
141
140
}
142
141
}
143
142
144
143
// 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
145
147
Future removePlatformTools () async {
146
148
print ('[WARN] This will delete the Android System Tools (ADB, Fastboot, etc.) installed by Nexus Tools, as well as the Nexus Tools application.' );
147
149
io.stdout.write ('[WARN] Continue with removal? [Y/N] ' );
148
150
var input = io.stdin.readLineSync ();
149
151
if (input? .toLowerCase () != 'y' ) {
150
152
return ;
151
153
}
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
155
167
var dir = nexusToolsDir ();
156
168
var installExists = false ;
157
169
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) {
159
183
// Proceed with deletion
160
184
await io.Directory (dir).delete (recursive: true );
161
185
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.' );
175
188
}
176
189
// Exit message
177
190
print ('[INFO] Nexus Tools can be reinstalled from here: https://github.com/$baseRepo \n ' );
0 commit comments