From d0e09913df344ee61d2f67cbf2d3ffe318e02fbd Mon Sep 17 00:00:00 2001 From: Aigio Liu Date: Mon, 22 Nov 2021 10:22:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=20Steam=20LibraryPath=20?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E3=80=81=E6=96=87=E4=BB=B6=E5=A4=B9=E4=B8=8D?= =?UTF-8?q?=E5=AD=98=E5=9C=A8=E6=97=B6=E5=80=99=E4=B8=8D=E5=86=8D=E7=BA=AA?= =?UTF-8?q?=E5=BD=95=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- release-template.md | 4 ++ .../Implementation/SteamServiceImpl.cs | 67 ++++++++++--------- 2 files changed, 39 insertions(+), 32 deletions(-) diff --git a/release-template.md b/release-template.md index 637dd85e5..d43426441 100644 --- a/release-template.md +++ b/release-template.md @@ -83,7 +83,11 @@ - 如果你已安装了 [ASP.NET Core Runtime 6.0.0](https://dotnet.microsoft.com/download/dotnet/6.0) 则下载文件名中带有 **fde** 的文件,可减少磁盘占用空间 - [在 Windows 上安装 .NET](https://docs.microsoft.com/en-us/dotnet/core/install/windows) - 在 Windows 上不需要 Hosting Bundle 和 IIS support + - [下载安装程序并手动安装(aspnetcore-runtime-6.0.0-win-x64.exe)](https://dotnet.microsoft.com/download/dotnet/thank-you/runtime-aspnetcore-6.0.0-windows-x64-installer) + - [使用 PowerShell 自动化安装](https://docs.microsoft.com/en-us/dotnet/core/install/windows?tabs=net60#install-with-powershell-automation) - [在 Linux 上安装 .NET](https://docs.microsoft.com/en-us/dotnet/core/install/linux) + - 推荐 [通过 Snap 安装 .NET Runtime](https://docs.microsoft.com/zh-cn/dotnet/core/install/linux-snap) + - ```sudo snap install dotnet-runtime-60 --classic``` - Mobile - Android - 如果你使用 ARM64 芯片的设备(较为**普遍**)则下载文件名中带有 **android_arm64_v8a** 的文件 diff --git a/src/ST.Client/Services/Implementation/SteamServiceImpl.cs b/src/ST.Client/Services/Implementation/SteamServiceImpl.cs index 8c3501243..e920b4525 100644 --- a/src/ST.Client/Services/Implementation/SteamServiceImpl.cs +++ b/src/ST.Client/Services/Implementation/SteamServiceImpl.cs @@ -544,39 +544,41 @@ namespace System.Application.Services.Implementation { string libraryFoldersPath = Path.Combine(SteamDirPath, "SteamApps", "libraryfolders.vdf"); - - dynamic v = VdfHelper.Read(libraryFoldersPath); - - for (int i = 1; ; i++) + if (File.Exists(libraryFoldersPath)) { - try + dynamic v = VdfHelper.Read(libraryFoldersPath); + + for (int i = 1; ; i++) { - dynamic pathNode = v.Value[i.ToString()]; - - if (pathNode == null) break; - - if (pathNode.path != null) + try { - // New format - // Valve introduced a new format for the "libraryfolders.vdf" file - // In the new format, the node "1" not only contains a single value (the path), - // but multiple values: path, label, mounted, contentid + dynamic pathNode = v.Value[i.ToString()]; - // If a library folder is removed in the Steam settings, the path persists, but its 'mounted' value is set to 0 (disabled) - // We consider only the value '1' as that the path is actually enabled. - if (pathNode.mounted != null && pathNode.mounted.ToString() != "1") - continue; - pathNode = pathNode.path; + if (pathNode == null) break; + + if (pathNode.path != null) + { + // New format + // Valve introduced a new format for the "libraryfolders.vdf" file + // In the new format, the node "1" not only contains a single value (the path), + // but multiple values: path, label, mounted, contentid + + // If a library folder is removed in the Steam settings, the path persists, but its 'mounted' value is set to 0 (disabled) + // We consider only the value '1' as that the path is actually enabled. + if (pathNode.mounted != null && pathNode.mounted.ToString() != "1") + continue; + pathNode = pathNode.path; + } + + string path = Path.Combine(pathNode.ToString(), "SteamApps"); + + if (Directory.Exists(path)) + paths.Add(path); + } + catch (Exception e) + { + Log.Error(TAG, e, "GetLibraryPaths for catch"); } - - string path = Path.Combine(pathNode.ToString(), "SteamApps"); - - if (Directory.Exists(path)) - paths.Add(path); - } - catch (Exception e) - { - Log.Error(TAG, e, "GetLibraryPaths for catch"); } } @@ -679,19 +681,20 @@ namespace System.Application.Services.Implementation var libraryPaths = GetLibraryPaths(); if (!libraryPaths.Any_Nullable()) { - Toast.Show("No game library found." + Environment.NewLine + "This might appear if Steam has been installed on this machine but was uninstalled."); + Toast.Show($"No game library found.{Environment.NewLine}This might appear if Steam has been installed on this machine but was uninstalled."); } foreach (string path in libraryPaths!) { - DirectoryInfo di = new DirectoryInfo(path); + var di = new DirectoryInfo(path); + if (!di.Exists) continue; - foreach (FileInfo fileInfo in di.EnumerateFiles("*.acf")) + foreach (var fileInfo in di.EnumerateFiles("*.acf")) { // Skip if file is empty if (fileInfo.Length == 0) continue; - SteamApp? ai = FileToAppInfo(fileInfo.FullName); + var ai = FileToAppInfo(fileInfo.FullName); if (ai == null) continue; appInfos.Add(ai);