改进 Steam LibraryPath 文件、文件夹不存在时候不再纪录错误

This commit is contained in:
Aigio Liu
2021-11-22 10:22:55 +08:00
parent 479a54a4e3
commit d0e09913df
2 changed files with 39 additions and 32 deletions
+4
View File
@@ -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** 的文件
@@ -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);