Electron Node.js 获取 Steam 游戏目标文件夹路径
在 Electron 中,可以使用 Node.js 的 'child_process' 模块来执行 shell 命令,从而获取 Steam 游戏目标文件夹的路径。
以下是一个示例代码:
const { exec } = require('child_process');
// Steam游戏ID
const gameId = '281990';
// 执行shell命令获取目标文件夹路径
exec(`steam://rungameid/${gameId}`, (err, stdout, stderr) => {
if (err) {
console.error(err);
return;
}
// 从stdout中提取目标文件夹路径
const regex = /'GameInstallDir' +'(.+)'/;
const match = regex.exec(stdout);
if (match) {
const gamePath = match[1];
console.log(`Steam游戏ID为${gameId}的目标文件夹路径为:${gamePath}`);
} else {
console.error(`无法获取Steam游戏ID为${gameId}的目标文件夹路径`);
}
});
注意,由于 Steam 的协议并不是一个真正的文件路径,因此需要通过执行 shell 命令来获取目标文件夹路径。在上述代码中,我们使用了正则表达式来从 shell 命令的输出中提取路径信息。
原文地址: https://www.cveoy.top/t/topic/kU0q 著作权归作者所有。请勿转载和采集!