【发布时间】:2019-07-13 00:58:04
【问题描述】:
我正在尝试查找游戏的可执行文件;但是有些是嵌套的(例如 Ark: Survival Evolved)(A:\Steam Games\steamapps\common\ARK\ShooterGame\Binaries\Win64\ShooterGame.exe)
我花了很长时间试图找到一种方法来只找到相关的可执行文件。
This link 在我们不递归搜索时显示游戏。它会找到大多数,但不是所有的 .exe 文件
This link 显示递归搜索游戏,但也显示一堆二进制文件/redist exe。
最初我尝试排除“bin”、“binary”、“binaries”、“redist”文件夹,但后来并没有给我方舟:生存进化的例子。
我也考虑过根据大小过滤 .exe,但 Aperture Tag 的 QC_Eyes.exe 为 3055KB,而古墓丽影 II.exe 为 892KB。
这是我用来查找 Steam 安装目录的方法,并检查 libraryfolders.vdf 文件中的库位置。现在我只是写信给控制台,以便我可以看到输出是什么。
如果有人对我如何为正确的游戏找到正确的文件有任何建议,我将不胜感激。谢谢
public void SearchSteam()
{
steamGameDirs.Clear();
string steam32 = "SOFTWARE\\VALVE\\";
string steam64 = "SOFTWARE\\Wow6432Node\\Valve\\";
string steam32path;
string steam64path;
string config32path;
string config64path;
RegistryKey key32 = Registry.LocalMachine.OpenSubKey(steam32);
RegistryKey key64 = Registry.LocalMachine.OpenSubKey(steam64);
foreach(string k32subKey in key32.GetSubKeyNames())
{
using (RegistryKey subKey = key32.OpenSubKey(k32subKey))
{
steam32path = subKey.GetValue("InstallPath").ToString();
config32path = steam32path + "/steamapps/libraryfolders.vdf";
if (File.Exists(config32path))
{
string[] configLines = File.ReadAllLines(config32path);
foreach(var item in configLines)
{
Console.WriteLine("32: " + item);
}
}
}
}
foreach(string k64subKey in key64.GetSubKeyNames())
{
using (RegistryKey subKey = key64.OpenSubKey(k64subKey))
{
steam64path = subKey.GetValue("InstallPath").ToString();
config64path = steam64path + "/steamapps/libraryfolders.vdf";
string driveRegex = @"[A-Z]:\\";
if (File.Exists(config64path))
{
string[] configLines = File.ReadAllLines(config64path);
foreach (var item in configLines)
{
Console.WriteLine("64: " + item);
Match match = Regex.Match(item, driveRegex);
if(item != string.Empty && match.Success)
{
string matched = match.ToString();
string item2 = item.Substring(item.IndexOf(matched));
item2 = item2.Replace("\\\\", "\\");
steamGameDirs.Add(item2);
}
}
steamGameDirs.Add(steam64path + "\\steamapps\\common\\");
}
}
}
foreach(string item in steamGameDirs)
{
string GameTitle;
string[] Executables = new string[0];
string[] steamGames = Directory.GetDirectories(item);
foreach (var dir in steamGames)
{
string title = dir.Substring(dir.IndexOf("\\common\\"));
string[] titlex = title.Split('\\');
title = titlex[2].ToString();
GameTitle = title;
Console.WriteLine("Title: " + GameTitle);
Console.WriteLine("Directory: " + dir);
string[] executables = Directory.GetFiles(dir, "*.exe", SearchOption.AllDirectories);
int num = 0;
foreach (var ex in executables)
{
//add "ex" to Executables[] if poss
Console.WriteLine(ex);
num++;
}
}
}
}
【问题讨论】:
-
没有标准化的方法来确定哪些可执行文件是“正确”的。有时它们将整个游戏包含在二进制文件中,有时它们只是一个非常薄的包装器。通常的解决方案是拥有一个包含 exe 名称的数据库。您可以尝试从现有来源获取这些数据(我想到了显卡驱动程序的配置文件),但除此之外,您别无选择,只能维护自己的映射。
-
我不明白这怎么可能。您可以移动您的 Steam 文件夹。您可以完全将磁盘安装到其他地方。你怎么知道哪个exe是游戏?例如。我的 winspww2 副本位于 E:\WinspWW2
-
它存储在 appcache\appinfo.vdf 中:每个游戏都有一个条目和一个“可执行”属性。但是,它以二进制格式存储,您需要取消选择。那里已经有一些代码,例如the Python steamfiles module
-
谢谢@Rup,我得调查一下。 Andy,steam 文件夹存储在 library.vdf 中,因此我们可以找到游戏的存储位置,而不是游戏的 .exe 文件(Rup 提供了帮助)。 Lennart 是的,我是这么认为的,我也会看一下,很可能会退回到用户选择正确的那个。 Liam 好吧,这是一个启动游戏的文件.. 所以
标签: c# exe executable steam