ZenitH-AT / nvidia-update

Checks for a new version of the NVIDIA driver, downloads and installs it.
MIT License
56 stars 8 forks source link

Latest update breaks the script #5

Closed tavern2782 closed 1 year ago

tavern2782 commented 1 year ago

Current error: Unable to retrieve GPU data. Please try running this script again.

This was working fine before the latest update. I take it this wasn't tested?

tavern2782 commented 1 year ago

Found one of the problems: $gpuType = if (-not $Notebook -and ($Desktop -or -not $Notebook)) { "desktop" } else { "notebook" }

This logic sucks. $Notebook is set via arguments, which makes it True.

-not $Notebook thus becomes False.

$Desktop is false at global variable level and isn't changed elsewhere.

-not $Notebook, as we already discussed, is False.

So you're basically saying False and False which always defaults to notebook.

The next issue I'm running into is that: ConvertFrom-Json : A parameter cannot be found that matches parameter name 'AsHashTable'. At line:1 char:74 + ... stMethod -Uri $gpuDataFileUrl | ConvertFrom-Json -AsHashTable).$gpuTy ... + ~~~~

I think someone wrote this for one specific version of POSH and didn't test it out on the default version in Windows. Command seems to be implemented in POSH 7.x

ZenitH-AT commented 1 year ago

The logic you're showing actually uses $isNotebook near the -or, not $Notebook a second time. It does suck but works in all cases.


Fixed by https://github.com/ZenitH-AT/nvidia-update/commit/7c9decf5ad5faf1d78e4842febb2b6198d527e31. See below for my initial response.


The script works on PowerShell 6+. Tested on both my GTX 750 Ti and RTX 2060.

The issue is with this code:

(Invoke-RestMethod -Uri $gpuDataFileUrl | ConvertFrom-Json -AsHashTable).$gpuType

ConvertFrom-Json -AsHashTable was added to fix https://github.com/ZenitH-AT/nvidia-update/issues/4, which happened because the GPU data file currently temporarily has 2 keys for each SUPER variant GPU with different casing ("SUPER" and "Super") for compatibility with some other scripts/programs.

I confirmed that running the following doesn't work on PowerShell 5.x:

(Invoke-RestMethod -Uri "https://raw.githubusercontent.com/ZenitH-AT/nvidia-data/main/gpu-data.json" | ConvertFrom-Json -AsHashTable)."desktop"

Since nvidia-update already replaces "Super" with "SUPER" anyway, I've changed the code to the following and will release an a new version shortly:

((Invoke-RestMethod -Uri $gpuDataFileUrl).Replace("Super", "SUPER_") | ConvertFrom-Json).$gpuType

Once the duplicate SUPER variant GPUs in GPU data file are removed, the next release after this should be able to remove the .Replace().