From b37d90bc585d1d7e4d83d252b15023d3897cdef7 Mon Sep 17 00:00:00 2001 From: Corbin Davenport Date: Mon, 24 Jun 2024 14:51:08 -0700 Subject: [PATCH 01/16] Update dart and dependencies --- bin/main.dart | 2 +- pubspec.lock | 86 +++++++++++++++++++++++++-------------------------- pubspec.yaml | 4 +-- 3 files changed, 46 insertions(+), 46 deletions(-) diff --git a/bin/main.dart b/bin/main.dart index 541c2b3..9ab011a 100644 --- a/bin/main.dart +++ b/bin/main.dart @@ -68,7 +68,7 @@ Future installPlatformTools() async { try { var data = await http.readBytes(net); var archive = ZipDecoder().decodeBytes(data); - extractArchiveToDisk(archive, dir); + await extractArchiveToDisk(archive, dir); } catch (e) { print('[EROR] There was an error downloading Platform Tools: ' + e.toString()); io.exit(1); diff --git a/pubspec.lock b/pubspec.lock index 9a9d5cc..6c47ed9 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -5,10 +5,10 @@ packages: dependency: "direct dev" description: name: archive - sha256: "0c8368c9b3f0abbc193b9d6133649a614204b528982bebc7026372d61677ce3a" + sha256: cb6a278ef2dbb298455e1a713bda08524a175630ec643a242c399c932a0a1f7d url: "https://pub.dev" source: hosted - version: "3.3.7" + version: "3.6.1" async: dependency: transitive description: @@ -21,10 +21,10 @@ packages: dependency: transitive description: name: collection - sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c" + sha256: a1ace0a119f20aabc852d165077c036cd864315bd99b7eaa10a60100341941bf url: "https://pub.dev" source: hosted - version: "1.17.1" + version: "1.19.0" console: dependency: "direct dev" description: @@ -33,22 +33,14 @@ packages: url: "https://pub.dev" source: hosted version: "4.1.0" - convert: - dependency: transitive - description: - name: convert - sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592" - url: "https://pub.dev" - source: hosted - version: "3.1.1" crypto: dependency: transitive description: name: crypto - sha256: aa274aa7774f8964e4f4f38cc994db7b6158dd36e9187aaceaddc994b35c6c67 + sha256: ff625774173754681d66daaf4a448684fb04b78f902da9cb3d308c19cc5e8bab url: "https://pub.dev" source: hosted - version: "3.0.2" + version: "3.0.3" dart_ipify: dependency: "direct dev" description: @@ -57,22 +49,30 @@ packages: url: "https://pub.dev" source: hosted version: "1.1.1" + fixnum: + dependency: transitive + description: + name: fixnum + sha256: "25517a4deb0c03aa0f32fd12db525856438902d9c16536311e76cdc57b31d7d1" + url: "https://pub.dev" + source: hosted + version: "1.1.0" http: dependency: "direct dev" description: name: http - sha256: "6aa2946395183537c8b880962d935877325d6a09a2867c3970c05c0fed6ac482" + sha256: "761a297c042deedc1ffbb156d6e2af13886bb305c2a343a4d972504cd67dd938" url: "https://pub.dev" source: hosted - version: "0.13.5" + version: "1.2.1" http_parser: dependency: transitive description: name: http_parser - sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b" + sha256: "40f592dd352890c3b60fec1b68e786cefb9603e05ff303dbc4dda49b304ecdf4" url: "https://pub.dev" source: hosted - version: "4.0.2" + version: "4.1.0" io: dependency: "direct dev" description: @@ -81,38 +81,22 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.4" - js: - dependency: transitive - description: - name: js - sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 - url: "https://pub.dev" - source: hosted - version: "0.6.7" meta: dependency: transitive description: name: meta - sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3" + sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7 url: "https://pub.dev" source: hosted - version: "1.9.1" + version: "1.15.0" path: dependency: transitive description: name: path - sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" url: "https://pub.dev" source: hosted - version: "1.8.3" - pointycastle: - dependency: transitive - description: - name: pointycastle - sha256: "7c1e5f0d23c9016c5bbd8b1473d0d3fb3fc851b876046039509e18e0c7485f2c" - url: "https://pub.dev" - source: hosted - version: "3.7.3" + version: "1.9.0" source_span: dependency: transitive description: @@ -121,6 +105,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.10.0" + sprintf: + dependency: transitive + description: + name: sprintf + sha256: "1fc9ffe69d4df602376b52949af107d8f5703b77cda567c4d7d86a0693120f23" + url: "https://pub.dev" + source: hosted + version: "7.0.0" string_scanner: dependency: transitive description: @@ -141,18 +133,18 @@ packages: dependency: transitive description: name: typed_data - sha256: "26f87ade979c47a150c9eaab93ccd2bebe70a27dc0b4b29517f2904f04eb11a5" + sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c url: "https://pub.dev" source: hosted - version: "1.3.1" + version: "1.3.2" uuid: dependency: "direct dev" description: name: uuid - sha256: "648e103079f7c64a36dc7d39369cabb358d377078a051d6ae2ad3aa539519313" + sha256: "814e9e88f21a176ae1359149021870e87f7cddaf633ab678a5d2b0bff7fd1ba8" url: "https://pub.dev" source: hosted - version: "3.0.7" + version: "4.4.0" vector_math: dependency: transitive description: @@ -161,5 +153,13 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.4" + web: + dependency: transitive + description: + name: web + sha256: "97da13628db363c635202ad97068d47c5b8aa555808e7a9411963c533b449b27" + url: "https://pub.dev" + source: hosted + version: "0.5.1" sdks: - dart: ">=3.3.1 <4.0.0" + dart: ">=3.4.2 <4.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index df2eef3..b5a0648 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,7 +4,7 @@ version: 5.0.0 homepage: https://github.com/corbindavenport/nexus-tools/ environment: - sdk: '>=3.3.1' + sdk: '>=3.4.2' # dependencies: # path: ^1.8.0 @@ -13,6 +13,6 @@ dev_dependencies: http: io: uuid: - archive: ^3.2.2 + archive: ^3.6.1 console: dart_ipify: ^1.1.1 \ No newline at end of file From ae4178741db93fb3ed5174a77804c7be63ccbb06 Mon Sep 17 00:00:00 2001 From: Corbin Davenport Date: Mon, 24 Jun 2024 15:12:11 -0700 Subject: [PATCH 02/16] Update github action actions, split macOS targets --- .github/workflows/compile.yaml | 43 ++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/.github/workflows/compile.yaml b/.github/workflows/compile.yaml index 91efb38..27567cc 100644 --- a/.github/workflows/compile.yaml +++ b/.github/workflows/compile.yaml @@ -3,11 +3,11 @@ on: workflow_dispatch: jobs: - compile_linux: + build_linux_x86: runs-on: ubuntu-latest steps: # Checks-out repository under $GITHUB_WORKSPACE - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 # Install dependencies - name: Install Dart SDK run: | @@ -24,40 +24,57 @@ jobs: dart compile exe "./bin/main.dart" -o "./nexustools" # Upload binary - name: Upload Dart executable - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: - name: nexustools-linux-x64 + name: nexustools-linux-x86 path: nexustools - compile_windows: + build_windows_x86: runs-on: windows-latest steps: - name: Install Dart SDK run: | choco install dart-sdk - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Compile Dart executable run: | C:\tools\dart-sdk\bin\dart pub get C:\tools\dart-sdk\bin\dart compile exe "bin\main.dart" -o "nexustools.exe" - name: Upload Dart executable - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: - name: nexustools-windows-x64 + name: nexustools-windows-x86 path: nexustools.exe - compile_macos: + build_macos_x86: + runs-on: macos-latest-large + steps: + - name: Install Dart SDK + run: | + brew tap dart-lang/dart + brew install dart + - uses: actions/checkout@v4 + - name: Compile Dart executable + run: | + dart pub get + dart compile exe "./bin/main.dart" -o "./nexustools" + - name: Upload Dart executable + uses: actions/upload-artifact@v4 + with: + name: nexustools-macos-x86 + path: nexustools + build_macos_arm: runs-on: macos-latest steps: - name: Install Dart SDK run: | brew tap dart-lang/dart brew install dart - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Compile Dart executable run: | dart pub get dart compile exe "./bin/main.dart" -o "./nexustools" - name: Upload Dart executable - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: - name: nexustools-macos-x64 - path: nexustools \ No newline at end of file + name: nexustools-macos-arm64 + path: nexustools From 7410b8f19e07145bbb7d1e82905a46f35471f9a7 Mon Sep 17 00:00:00 2001 From: Corbin Davenport Date: Mon, 24 Jun 2024 15:15:35 -0700 Subject: [PATCH 03/16] Fix macOS x86 github action --- .github/workflows/compile.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/compile.yaml b/.github/workflows/compile.yaml index 27567cc..092f220 100644 --- a/.github/workflows/compile.yaml +++ b/.github/workflows/compile.yaml @@ -45,7 +45,7 @@ jobs: name: nexustools-windows-x86 path: nexustools.exe build_macos_x86: - runs-on: macos-latest-large + runs-on: macos-12 steps: - name: Install Dart SDK run: | From a3d915ccb2d2f5ca02f2c6f71546f0abaa6d25a7 Mon Sep 17 00:00:00 2001 From: Corbin Davenport Date: Mon, 24 Jun 2024 17:39:24 -0700 Subject: [PATCH 04/16] Add universal binary macOS build --- .github/workflows/compile.yaml | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/.github/workflows/compile.yaml b/.github/workflows/compile.yaml index 092f220..7939594 100644 --- a/.github/workflows/compile.yaml +++ b/.github/workflows/compile.yaml @@ -3,7 +3,7 @@ on: workflow_dispatch: jobs: - build_linux_x86: + build_linux_x64: runs-on: ubuntu-latest steps: # Checks-out repository under $GITHUB_WORKSPACE @@ -26,9 +26,9 @@ jobs: - name: Upload Dart executable uses: actions/upload-artifact@v4 with: - name: nexustools-linux-x86 + name: nexustools-linux-x64 path: nexustools - build_windows_x86: + build_windows_x64: runs-on: windows-latest steps: - name: Install Dart SDK @@ -42,9 +42,9 @@ jobs: - name: Upload Dart executable uses: actions/upload-artifact@v4 with: - name: nexustools-windows-x86 + name: nexustools-windows-x64 path: nexustools.exe - build_macos_x86: + build_macos_x64: runs-on: macos-12 steps: - name: Install Dart SDK @@ -59,8 +59,8 @@ jobs: - name: Upload Dart executable uses: actions/upload-artifact@v4 with: - name: nexustools-macos-x86 - path: nexustools + name: nexustools-macos-x64 + path: nexustools-x64 build_macos_arm: runs-on: macos-latest steps: @@ -77,4 +77,24 @@ jobs: uses: actions/upload-artifact@v4 with: name: nexustools-macos-arm64 + path: nexustools-arm + build_macos_universal: + runs-on: macos-latest + needs: [build_macos_arm, build_macos_x64] + steps: + - name: Download x64 executable + uses: actions/download-artifact@v4 + with: + name: nexustools-macos-x64 + - name: Download ARM executable + uses: actions/download-artifact@v4 + with: + name: nexustools-macos-arm64 + - name: Create universal binary + run: | + lipo -create nexustools-macos-x64 nexustools-macos-arm64 -output nexustools + - name: Upload universal binary + uses: actions/upload-artifact@v4 + with: + name: nexustools-macos-universal path: nexustools From 0c90bb073ccce4ecbb86fe0b2218389839026fe3 Mon Sep 17 00:00:00 2001 From: Corbin Davenport Date: Mon, 24 Jun 2024 17:44:27 -0700 Subject: [PATCH 05/16] Update github action --- .github/workflows/compile.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/compile.yaml b/.github/workflows/compile.yaml index 7939594..aa57c36 100644 --- a/.github/workflows/compile.yaml +++ b/.github/workflows/compile.yaml @@ -92,7 +92,7 @@ jobs: name: nexustools-macos-arm64 - name: Create universal binary run: | - lipo -create nexustools-macos-x64 nexustools-macos-arm64 -output nexustools + lipo -create nexustools-x64 nexustools-arm -output nexustools - name: Upload universal binary uses: actions/upload-artifact@v4 with: From 46f0996e6da95cfde7072e946d922b3735be8cbc Mon Sep 17 00:00:00 2001 From: Corbin Davenport Date: Mon, 24 Jun 2024 22:33:14 -0700 Subject: [PATCH 06/16] Clean up github action --- .github/workflows/compile.yaml | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/.github/workflows/compile.yaml b/.github/workflows/compile.yaml index aa57c36..f1d833a 100644 --- a/.github/workflows/compile.yaml +++ b/.github/workflows/compile.yaml @@ -60,7 +60,7 @@ jobs: uses: actions/upload-artifact@v4 with: name: nexustools-macos-x64 - path: nexustools-x64 + path: nexustools build_macos_arm: runs-on: macos-latest steps: @@ -77,22 +77,20 @@ jobs: uses: actions/upload-artifact@v4 with: name: nexustools-macos-arm64 - path: nexustools-arm + path: nexustools build_macos_universal: runs-on: macos-latest needs: [build_macos_arm, build_macos_x64] steps: - - name: Download x64 executable - uses: actions/download-artifact@v4 - with: - name: nexustools-macos-x64 - - name: Download ARM executable + - name: Download x64 and ARM executables uses: actions/download-artifact@v4 with: - name: nexustools-macos-arm64 + path: nexustools-macos + pattern: nexustools-macos-* + merge-multiple: true - name: Create universal binary run: | - lipo -create nexustools-x64 nexustools-arm -output nexustools + lipo -create nexustools-macos-x64/nexustools nexustools-macos-arm64/nexustools -output nexustools - name: Upload universal binary uses: actions/upload-artifact@v4 with: From 7ca2675f597ffa250a946dcb136a510089381321 Mon Sep 17 00:00:00 2001 From: Corbin Davenport Date: Mon, 24 Jun 2024 22:43:26 -0700 Subject: [PATCH 07/16] Improve debugging on github action --- .github/workflows/compile.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/compile.yaml b/.github/workflows/compile.yaml index f1d833a..6362046 100644 --- a/.github/workflows/compile.yaml +++ b/.github/workflows/compile.yaml @@ -90,6 +90,7 @@ jobs: merge-multiple: true - name: Create universal binary run: | + ls -R lipo -create nexustools-macos-x64/nexustools nexustools-macos-arm64/nexustools -output nexustools - name: Upload universal binary uses: actions/upload-artifact@v4 From 80649b7eacb8e65a485d3092a3bf55341911f657 Mon Sep 17 00:00:00 2001 From: Corbin Davenport Date: Wed, 26 Jun 2024 15:39:39 -0700 Subject: [PATCH 08/16] Fix universal binary compile --- .github/workflows/compile.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/compile.yaml b/.github/workflows/compile.yaml index 6362046..4a4da26 100644 --- a/.github/workflows/compile.yaml +++ b/.github/workflows/compile.yaml @@ -87,7 +87,6 @@ jobs: with: path: nexustools-macos pattern: nexustools-macos-* - merge-multiple: true - name: Create universal binary run: | ls -R From cf8f2ca5285b0dcae96ee65d1b1ee88551c50231 Mon Sep 17 00:00:00 2001 From: Corbin Davenport Date: Wed, 26 Jun 2024 15:44:35 -0700 Subject: [PATCH 09/16] Fix paths on macOS compile github action --- .github/workflows/compile.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/compile.yaml b/.github/workflows/compile.yaml index 4a4da26..6b13e5f 100644 --- a/.github/workflows/compile.yaml +++ b/.github/workflows/compile.yaml @@ -90,7 +90,7 @@ jobs: - name: Create universal binary run: | ls -R - lipo -create nexustools-macos-x64/nexustools nexustools-macos-arm64/nexustools -output nexustools + lipo -create ./nexustools-macos/nexustools-macos-arm64/nexustools ./nexustools-macos/nexustools-macos-x64/nexustools -output ./nexustools - name: Upload universal binary uses: actions/upload-artifact@v4 with: From a7c1eed4225b165beea1cc18d39791fbdd485c43 Mon Sep 17 00:00:00 2001 From: Corbin Davenport Date: Wed, 26 Jun 2024 16:35:02 -0700 Subject: [PATCH 10/16] Add arm64 macOS to install script, remove universal builds --- .github/workflows/compile.yaml | 20 +------------------- install.sh | 9 ++++----- 2 files changed, 5 insertions(+), 24 deletions(-) diff --git a/.github/workflows/compile.yaml b/.github/workflows/compile.yaml index 6b13e5f..246eeff 100644 --- a/.github/workflows/compile.yaml +++ b/.github/workflows/compile.yaml @@ -77,22 +77,4 @@ jobs: uses: actions/upload-artifact@v4 with: name: nexustools-macos-arm64 - path: nexustools - build_macos_universal: - runs-on: macos-latest - needs: [build_macos_arm, build_macos_x64] - steps: - - name: Download x64 and ARM executables - uses: actions/download-artifact@v4 - with: - path: nexustools-macos - pattern: nexustools-macos-* - - name: Create universal binary - run: | - ls -R - lipo -create ./nexustools-macos/nexustools-macos-arm64/nexustools ./nexustools-macos/nexustools-macos-x64/nexustools -output ./nexustools - - name: Upload universal binary - uses: actions/upload-artifact@v4 - with: - name: nexustools-macos-universal - path: nexustools + path: nexustools \ No newline at end of file diff --git a/install.sh b/install.sh index 5a4b3bb..67f152c 100755 --- a/install.sh +++ b/install.sh @@ -33,11 +33,10 @@ fi mkdir -p $DIR # Start Dart executable -if [ "$OS" = "Darwin" ]; then # macOS - # Install Rosetta x86 emulation layer if needed - if [ "$ARCH" = "arm64" ]; then - echo "[WARN] Rosetta 2 compatibility layer is required. If installation fails, run Nexus Tools again after running this command: /usr/sbin/softwareupdate --install-rosetta" - fi +if [ "$OS" = "Darwin" ] && [ "$ARCH" = "arm64" ]; then # Apple Silicon Mac + DOWNLOAD="$BASEURL/releases/latest/download/nexustools-macos-arm64.zip" + _run_executable +elif [ "$OS" = "Darwin" ] && [ "$ARCH" = "x86_64" ]; then # Intel Mac DOWNLOAD="$BASEURL/releases/latest/download/nexustools-macos-x64.zip" _run_executable elif [ "$OS" = "Linux" ] && [ "$ARCH" = "x86_64" ]; then # Generic Linux From 3c667d3c09c42c0d02c36d35dcda869fa8b76d26 Mon Sep 17 00:00:00 2001 From: Corbin Davenport Date: Fri, 28 Jun 2024 17:40:44 -0400 Subject: [PATCH 11/16] Remove Rosetta CPU check --- bin/main.dart | 12 ++++++------ lib/sys.dart | 16 +--------------- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/bin/main.dart b/bin/main.dart index 9ab011a..bc6a35e 100644 --- a/bin/main.dart +++ b/bin/main.dart @@ -207,7 +207,7 @@ Future installWindowsDrivers(String dir) async { } // Function for Plausible Analytics reporting -void connectAnalytics() async { +void connectAnalytics(String cpuArch) async { var uuid = Uuid(); var id = uuid.v4(); // Get exact operating system @@ -221,12 +221,11 @@ void connectAnalytics() async { } else { realOS = io.Platform.operatingSystem; } - var cpu = await sys.getCPUArchitecture(); // Set data var net = Uri.parse('https://plausible.io/api/event'); final ipv4 = await Ipify.ipv4(); var netHeaders = {'user-agent': 'Nexus Tools', 'X-Forwarded-For': ipv4, 'Content-Type': 'application/json', 'User-Agent': 'Mozilla/5.0 ($realOS) AppleWebKit/500 (KHTML, like Gecko) Chrome/$appVersion $id'}; - var netBody = '{"name":"pageview","url":"app://localhost/$realOS/$cpu","domain":"nexustools.corbin.io"}'; + var netBody = '{"name":"pageview","url":"app://localhost/$realOS/$cpuArch","domain":"nexustools.corbin.io"}'; // Send request try { await http.post(net, headers: netHeaders, body: netBody); @@ -236,7 +235,7 @@ void connectAnalytics() async { } // Pre-installation steps -Future checkInstall() async { +Future checkInstall(String cpuArch) async { // Check if directory already exists var dir = nexusToolsDir(); var installExists = false; @@ -290,6 +289,7 @@ Example: nexustools -i (this installs Platform Tools) } void main(List arguments) async { + var cpuArch = await sys.getCPUArchitecture(); if (arguments.contains('-i') || arguments.contains('--install')) { print('[INFO] Nexus Tools $appVersion'); // Check version unless Nexus Tools is running from web (curl) installer @@ -301,10 +301,10 @@ void main(List arguments) async { if (arguments.contains('--no-analytics')) { print('[ OK ] Plausible Analytics are disabled.'); } else { - connectAnalytics(); + connectAnalytics(cpuArch); } // Start installation - await checkInstall(); + await checkInstall(cpuArch); await installPlatformTools(); // Post-install var appName = ''; diff --git a/lib/sys.dart b/lib/sys.dart index 7daf3d6..8a26f10 100644 --- a/lib/sys.dart +++ b/lib/sys.dart @@ -25,25 +25,11 @@ void checkIfInstalled(String dir, String command, String commandName) async { } } -// Function get current CPU architecture +// Function to get the current CPU architecture, even when running in an emulated Future getCPUArchitecture() async { if (io.Platform.isWindows) { var cpu = envVars['PROCESSOR_ARCHITECTURE']; return cpu; - } else if (io.Platform.isMacOS) { - // Get architecture reported by the system - var info = await io.Process.run('uname', ['-m']); - var cpu = info.stdout.toString().replaceAll('\n', ''); - if (cpu == 'x86_64') { - // Check if running under Rosetta 2 - var rosetta = await io.Process.run('sysctl', ['-in', 'sysctl.proc_translated']); - var rosettaStr = rosetta.stdout.toString().replaceAll('\n', ''); - // This command will run '1' if we're running under Rosetta 2 - if (rosettaStr == '1') { - cpu = 'arm64'; - } - } - return cpu; } else { var info = await io.Process.run('uname', ['-m']); var cpu = info.stdout.toString().replaceAll('\n', ''); From 55ddf81aba58e38037c794636e0aae7b2834ba4c Mon Sep 17 00:00:00 2001 From: Corbin Davenport Date: Fri, 28 Jun 2024 18:58:13 -0400 Subject: [PATCH 12/16] Prevent ADB driver installation on ARM Windows --- bin/main.dart | 20 ++++++++++++-------- lib/sys.dart | 10 +++++++++- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/bin/main.dart b/bin/main.dart index bc6a35e..08fb8b8 100644 --- a/bin/main.dart +++ b/bin/main.dart @@ -50,7 +50,7 @@ String nexusToolsDir() { } // Function for installing Platform Tools package -Future installPlatformTools() async { +Future installPlatformTools(cpuArch) 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 @@ -102,8 +102,9 @@ Future installPlatformTools() async { } // Windows-specific functions if (io.Platform.isWindows) { - // Check if Universal Adb Driver package is already installed - var info = await io.Process.run('wmic', ['product', 'get', 'Name']); + // Install Universal Adb Driver package on x86_64 Windows + if (cpuArch == 'AMD64') { + var info = await io.Process.run('wmic', ['product', 'get', 'Name']); var parsedInfo = info.stdout.toString(); if (parsedInfo.contains('Universal Adb Driver')) { print('[ OK ] Universal ADB Drivers already installed.'); @@ -116,6 +117,9 @@ Future installPlatformTools() async { await installWindowsDrivers(dir); } } + } else { + print('[WARN] Universal ADB Driver package cannot be installed on $cpuArch, some devices might not work.'); + } // Check if old Nexus Tools directory needs to be deleted var oldFolder = envVars['UserProfile'] + r'\NexusTools'; var oldFolderExists = await io.Directory(oldFolder).exists(); @@ -269,9 +273,9 @@ Future checkInstall(String cpuArch) async { } } -void printHelp() { +void printHelp(cpuArch) { var helpDoc = ''' -Nexus Tools $appVersion +Nexus Tools $appVersion on $cpuArch Downloader/management app for Android SDK Platform Tools Usage: nexustools [OPTIONS] @@ -291,7 +295,7 @@ Example: nexustools -i (this installs Platform Tools) void main(List arguments) async { var cpuArch = await sys.getCPUArchitecture(); if (arguments.contains('-i') || arguments.contains('--install')) { - print('[INFO] Nexus Tools $appVersion'); + print('[INFO] Nexus Tools $appVersion on $cpuArch'); // Check version unless Nexus Tools is running from web (curl) installer // The web installer adds the -w parameter if (!arguments.contains('-w')) { @@ -305,7 +309,7 @@ void main(List arguments) async { } // Start installation await checkInstall(cpuArch); - await installPlatformTools(); + await installPlatformTools(cpuArch); // Post-install var appName = ''; if (io.Platform.isWindows) { @@ -322,7 +326,7 @@ void main(List arguments) async { // Start removal await removePlatformTools(); } else if (arguments.contains('-h') || arguments.contains('--help')) { - printHelp(); + printHelp(cpuArch); } else if (arguments.contains('-c') || arguments.contains('--check')) { await checkUpdate(); } else { diff --git a/lib/sys.dart b/lib/sys.dart index 8a26f10..bea3514 100644 --- a/lib/sys.dart +++ b/lib/sys.dart @@ -25,12 +25,20 @@ void checkIfInstalled(String dir, String command, String commandName) async { } } -// Function to get the current CPU architecture, even when running in an emulated +// Function to get the current CPU architecture Future getCPUArchitecture() async { if (io.Platform.isWindows) { + // Possible values: AMD64, ARM64 var cpu = envVars['PROCESSOR_ARCHITECTURE']; + // Check if being emulated in ARM and return true architecture + var isEmulated = await io.Directory('C:\Program Files (Arm)').exists(); + if (isEmulated) { + cpu = 'ARM64'; + } return cpu; } else { + // Possible values: x86_64, arm64 + // This doesn't check for Rosetta emulation on macOS var info = await io.Process.run('uname', ['-m']); var cpu = info.stdout.toString().replaceAll('\n', ''); return cpu; From b50b42c975116830e3dc4a892659709ac0b0cbb8 Mon Sep 17 00:00:00 2001 From: Corbin Davenport Date: Fri, 28 Jun 2024 19:31:51 -0400 Subject: [PATCH 13/16] Replace wmic command for ADB drivers check (#77) --- bin/main.dart | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/bin/main.dart b/bin/main.dart index 08fb8b8..9a7af38 100644 --- a/bin/main.dart +++ b/bin/main.dart @@ -104,19 +104,19 @@ Future installPlatformTools(cpuArch) async { if (io.Platform.isWindows) { // Install Universal Adb Driver package on x86_64 Windows if (cpuArch == 'AMD64') { - var info = await io.Process.run('wmic', ['product', 'get', 'Name']); - var parsedInfo = info.stdout.toString(); - if (parsedInfo.contains('Universal Adb Driver')) { - print('[ OK ] Universal ADB Drivers already installed.'); - } else { - // Prompt to install drivers - print('[WARN] Drivers may be required for ADB if they are not already installed.'); - io.stdout.write('[WARN] Install drivers from adb.clockworkmod.com? [Y/N] '); - var input = io.stdin.readLineSync(); - if (input?.toLowerCase() == 'y') { - await installWindowsDrivers(dir); + var info = await io.Process.run('PowerShell', ['-Command', 'Get-WmiObject -Class Win32_Product | Select-Object -Property Name']); + var parsedInfo = info.stdout.toString(); + if (parsedInfo.contains('Universal Adb Driver')) { + print('[ OK ] Universal ADB Drivers already installed.'); + } else { + // Prompt to install drivers + print('[WARN] Drivers may be required for ADB if they are not already installed.'); + io.stdout.write('[WARN] Install drivers from adb.clockworkmod.com? [Y/N] '); + var input = io.stdin.readLineSync(); + if (input?.toLowerCase() == 'y') { + await installWindowsDrivers(dir); + } } - } } else { print('[WARN] Universal ADB Driver package cannot be installed on $cpuArch, some devices might not work.'); } From 08cb3ecb1683a8acfc47af35dceb81a8b1a15c82 Mon Sep 17 00:00:00 2001 From: Corbin Davenport Date: Fri, 28 Jun 2024 19:40:20 -0400 Subject: [PATCH 14/16] Update version number --- bin/main.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/main.dart b/bin/main.dart index 9a7af38..7f1158e 100644 --- a/bin/main.dart +++ b/bin/main.dart @@ -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.6; +double appVersion = 5.7; String baseRepo = 'corbindavenport/nexus-tools'; // Function for checking for update From d78ebf2b0ee019681a3139f96179136729e188e4 Mon Sep 17 00:00:00 2001 From: Corbin Davenport Date: Fri, 28 Jun 2024 20:28:23 -0400 Subject: [PATCH 15/16] Update arm64 Windows detection method --- lib/sys.dart | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/sys.dart b/lib/sys.dart index bea3514..92977ef 100644 --- a/lib/sys.dart +++ b/lib/sys.dart @@ -31,9 +31,13 @@ Future getCPUArchitecture() async { // Possible values: AMD64, ARM64 var cpu = envVars['PROCESSOR_ARCHITECTURE']; // Check if being emulated in ARM and return true architecture - var isEmulated = await io.Directory('C:\Program Files (Arm)').exists(); - if (isEmulated) { - cpu = 'ARM64'; + try { + var buildArch = await io.Process.run('reg', ['query', r'HKEY_LOCAL_MACHINE\SYSTEM\Software\Microsoft\BuildLayers\DesktopEditions', '/v', 'BuildArch']); + if (buildArch.stdout.toString().contains('arm64')) { + cpu = 'ARM64'; + } + } catch (e) { + // Fail silently } return cpu; } else { From ff6a441bcf2c9832161e28845387b701acae7e75 Mon Sep 17 00:00:00 2001 From: Corbin Davenport Date: Fri, 28 Jun 2024 20:30:43 -0400 Subject: [PATCH 16/16] Update CPU detection --- lib/sys.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sys.dart b/lib/sys.dart index 92977ef..6b11281 100644 --- a/lib/sys.dart +++ b/lib/sys.dart @@ -33,7 +33,7 @@ Future getCPUArchitecture() async { // Check if being emulated in ARM and return true architecture try { var buildArch = await io.Process.run('reg', ['query', r'HKEY_LOCAL_MACHINE\SYSTEM\Software\Microsoft\BuildLayers\DesktopEditions', '/v', 'BuildArch']); - if (buildArch.stdout.toString().contains('arm64')) { + if (buildArch.stdout.toString().toLowerCase().contains('arm64')) { cpu = 'ARM64'; } } catch (e) {