Skip to content

Loading modules.json with the wrong encoding #218

Description

After installing Unity Editor 2019.4.15f1 with Unity Hub 2.4.2 on Japanese Windows 10 Pro 2004, Get-UnitySetupInstance complains with the following error:

PS C:\Program Files\Unity\Hub\Editor\2019.4.15f1> Get-UnitySetupInstance警告: ':' または '}' ではなく無効なオブジェクトが渡されました。 (7767): [{"id":"visualstudio","name":"Microsoft Visual Studio Community 2019","description":"Downloads and installs.... (snipped)

It orignates from this line:

$modules= (Get-Content"$path\modules.json"-Raw) |ConvertFrom-Json

Get-Content -Raw loads modules.json with the wrong encoding which causes subsequent ConvertFrom-Json to fail:

PS C:\Program Files\Unity\Hub\Editor\2019.4.15f1> Get-Content .\modules.json -Raw | ConvertFrom-JsonConvertFrom-Json : ':' または '}' ではなく無効なオブジェクトが渡されました。 (7767): [{"id":"visualstudio","name":"Microsoft Visual Studio Community 2019","description":"Downloads and installs.... (snipped)

modules.json is actually in UTF-8 without BOM. Get-Content -Encoding UTF8 would workaround this case, but I'm not confident whether it's a correct fix:

PS C:\Program Files\Unity\Hub\Editor\2019.4.15f1> Get-Content .\modules.json -Encoding UTF8 | ConvertFrom-Jsonid : visualstudioname : Microsoft Visual Studio Community 2019description : Downloads and installs Microsoft Visual Studio Community 2019. By installing this you accept the license terms for Visual Studio.downloadUrl : https://go.microsoft.com/fwlink/?linkid=2086755category : Dev toolsinstalledSize : 1331200000downloadSize : 1363148800visible : Trueselected : Falsecmd : --productId "Microsoft.VisualStudio.Product.Community" --add "Microsoft.VisualStudio.Workload.ManagedGame" --add "Microsoft.VisualStudio.Workload.NativeDesktop" --add "Microsoft.VisualStudio.Component.VC.Tools.x86.x64" --add "Microsoft.VisualStudio.Comp onent.Windows10SDK.16299.Desktop" --campaign "Unity3d_Unity" --passive --norestart --waiteulaUrl1 : https://go.microsoft.com/fwlink/?linkid=2092534eulaLabel1 : Visual Studio 2019 Community License TermseulaMessage : Please review and accept the license terms before downloading and installing Microsoft Visual Studio....(snipped)...id : language-janame : 日本語description : 日本語downloadUrl : https://new-translate.unity3d.jp/v1/live/54/2019.4/jacategory : Language packs (Preview)visible : Trueselected : Falsedestination : {UNITY_PATH}/Editor/Data/LocalizationinstalledSize : 1739231downloadSize : 1739231...(snipped)

It would be better to have a fall back path on modules.json parsing failures by adding a try-catch block.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions