Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
Check for Steam install in the default folder, don't error when Steam…
Browse files Browse the repository at this point in the history
… is not installed
  • Loading branch information
mircearoata committed Jun 20, 2020
1 parent bb087b9 commit 88f2ec6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 22 deletions.
59 changes: 38 additions & 21 deletions src/installFinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import vdf from 'vdf';
import Registry from 'winreg';
import { exiftool } from 'exiftool-vendored';
import { SatisfactoryInstall } from './satisfactoryInstall';
import { warn, info } from './logging';
import {
warn, info, error, debug,
} from './logging';

const EpicManifestsFolder = path.join(getDataFolders()[0], 'Epic', 'EpicGamesLauncher', 'Data', 'Manifests'); // TODO: other platforms
const UEInstalledManifest = path.join(getDataFolders()[0], 'Epic', 'UnrealEngineLauncher', 'LauncherInstalled.dat'); // TODO: other platforms
Expand Down Expand Up @@ -69,6 +71,9 @@ function getInstallsEpicWindows(): InstallFindResult {
}
}
});
} else {
debug('Epic Games Launcher is not installed');
return { installs: [], invalidInstalls: [] };
}
let installedManifest: UEInstalledManifest = { InstallationList: [] };
if (fs.existsSync(UEInstalledManifest)) {
Expand Down Expand Up @@ -135,27 +140,39 @@ async function getRegValue(hive: string, key: string, valueName: string): Promis
}

async function getInstallsSteamWindows(): Promise<InstallFindResult> {
const steamPath = (await getRegValue(Registry.HKCU, '\\Software\\Valve\\Steam', 'SteamPath')).value;
const steamAppsPath = path.join(steamPath, 'steamapps');
const libraryfoldersManifest = vdf.parse(fs.readFileSync(path.join(steamAppsPath, 'libraryfolders.vdf'), 'utf8')) as SteamLibraryFoldersManifest;
const libraryfolders = Object.entries(libraryfoldersManifest.LibraryFolders).filter(([key]) => /^\d+$/.test(key)).map((entry) => entry[1]);
const installs: Array<SatisfactoryInstall> = [];
await libraryfolders.forEachAsync(async (libraryFolder) => {
const sfManifestPath = path.join(libraryFolder, 'steamapps', 'appmanifest_526870.acf');
if (fs.existsSync(sfManifestPath)) {
const manifest = vdf.parse(fs.readFileSync(sfManifestPath, 'utf8')) as SteamManifest;
const fullInstallPath = path.join(libraryFolder, 'steamapps', 'common', manifest.AppState.installdir);
const gameVersion = await getGameVersionFromExe(path.join(fullInstallPath, 'FactoryGame', 'Binaries', 'Win64', 'FactoryGame-Win64-Shipping.exe'));
installs.push(new SatisfactoryInstall(
`${manifest.AppState.name} ${manifest.AppState.UserConfig.betakey?.toLowerCase() === 'experimental' ? 'Experimental' : 'Early Access'} (Steam)`,
gameVersion,
manifest.AppState.UserConfig.betakey || 'EA',
fullInstallPath,
'steam://rungameid/526870',
));
try {
const steamPath = (await getRegValue(Registry.HKCU, '\\Software\\Valve\\Steam', 'SteamPath')).value;
const steamAppsPath = path.join(steamPath, 'steamapps');
const libraryfoldersManifest = vdf.parse(fs.readFileSync(path.join(steamAppsPath, 'libraryfolders.vdf'), 'utf8')) as SteamLibraryFoldersManifest;
const libraryfolders = Object.entries(libraryfoldersManifest.LibraryFolders).filter(([key]) => /^\d+$/.test(key)).map((entry) => entry[1]);
libraryfolders.push(steamPath);
const installs: Array<SatisfactoryInstall> = [];
await Promise.all(libraryfolders.map(async (libraryFolder) => {
const sfManifestPath = path.join(libraryFolder, 'steamapps', 'appmanifest_526870.acf');
if (fs.existsSync(sfManifestPath)) {
const manifest = vdf.parse(fs.readFileSync(sfManifestPath, 'utf8')) as SteamManifest;
const fullInstallPath = path.join(libraryFolder, 'steamapps', 'common', manifest.AppState.installdir);
const gameVersion = await getGameVersionFromExe(path.join(fullInstallPath, 'FactoryGame', 'Binaries', 'Win64', 'FactoryGame-Win64-Shipping.exe'));
installs.push(new SatisfactoryInstall(
`${manifest.AppState.name} ${manifest.AppState.UserConfig.betakey?.toLowerCase() === 'experimental' ? 'Experimental' : 'Early Access'} (Steam)`,
gameVersion,
manifest.AppState.UserConfig.betakey || 'EA',
fullInstallPath,
'steam://rungameid/526870',
));
}
}));
exiftool.end();
return { installs, invalidInstalls: [] };
} catch (e) {
if ((e as Error).message.includes('unable to find')) {
debug('Steam is not installed');
} else {
error(e);
}
});
return { installs, invalidInstalls: [] };
exiftool.end();
return { installs: [], invalidInstalls: [] };
}
}

async function getInstallsWindows(): Promise<InstallFindResult> {
Expand Down
4 changes: 3 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const path = require('path');
const fs = require('fs');
const assert = require('assert');
const semver = require('semver');
const { SatisfactoryInstall, getManifestFolderPath, UnsolvableDependencyError, DependencyManifestMismatchError, InvalidProfileError, ModNotFoundError } = require('../');
const { SatisfactoryInstall, getInstalls, getManifestFolderPath, UnsolvableDependencyError, DependencyManifestMismatchError, InvalidProfileError, ModNotFoundError } = require('../');
const { modCacheDir, forEachAsync, clearCache } = require('../lib/utils');
const { addTempMod, addTempModVersion, removeTempMod, removeTempModVersion, setUseTempMods, setTempModReference } = require('../lib/ficsitApp');
const { getProfileFolderPath } = require('../lib/satisfactoryInstall');
Expand Down Expand Up @@ -157,6 +157,8 @@ function deleteFolderRecursive(path) {
};

async function main() {
console.log(await getInstalls());

clearCache();
setUseTempMods(true);

Expand Down

0 comments on commit 88f2ec6

Please sign in to comment.