mirror of
https://github.com/Zagrios/bs-manager.git
synced 2026-07-03 14:08:25 +02:00
[chore] Use regedit-rs instead of node-regedit
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { execOnOs } from "../../helpers/env.helpers";
|
||||
import { list, createKey, putValue, deleteKey, RegSzValue } from "regedit-rs";
|
||||
import path from "path";
|
||||
import regedit from "regedit";
|
||||
|
||||
export class LivService {
|
||||
|
||||
@@ -23,8 +23,8 @@ export class LivService {
|
||||
public async isLivInstalled(): Promise<boolean> {
|
||||
return execOnOs({
|
||||
win32: async () => {
|
||||
const regRes = await regedit.promisified.list([this.livRegeditKey]).then(res => res[this.livRegeditKey]);
|
||||
return regRes?.exists;
|
||||
const regRes = await list(this.livRegeditKey).then(res => res[this.livRegeditKey]);
|
||||
return regRes.exists;
|
||||
},
|
||||
}, true);
|
||||
}
|
||||
@@ -33,25 +33,13 @@ export class LivService {
|
||||
return execOnOs({
|
||||
win32: async () => {
|
||||
const livExternalAppRegeditKey = path.join(this.livExternalAppsRegeditKey, entry.id);
|
||||
await regedit.promisified.createKey([livExternalAppRegeditKey]);
|
||||
await regedit.promisified.putValue({
|
||||
await createKey(livExternalAppRegeditKey);
|
||||
await putValue({
|
||||
[livExternalAppRegeditKey]: {
|
||||
"InstallPath": {
|
||||
value: entry.installPath,
|
||||
type: "REG_SZ"
|
||||
},
|
||||
"Executable": {
|
||||
value: entry.executable,
|
||||
type: "REG_SZ"
|
||||
},
|
||||
"Arguments": {
|
||||
value: entry.arguments,
|
||||
type: "REG_SZ"
|
||||
},
|
||||
"Name": {
|
||||
value: entry.name,
|
||||
type: "REG_SZ"
|
||||
}
|
||||
InstallPath: new RegSzValue(entry.installPath),
|
||||
Executable: new RegSzValue(entry.executable),
|
||||
Arguments: new RegSzValue(entry.arguments),
|
||||
Name: new RegSzValue(entry.name)
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -62,7 +50,7 @@ export class LivService {
|
||||
return execOnOs({
|
||||
win32: async () => {
|
||||
const shotcutsKeys = ids.map(id => path.join(this.livExternalAppsRegeditKey, id));
|
||||
return regedit.promisified.deleteKey(shotcutsKeys);
|
||||
return deleteKey(shotcutsKeys);
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -70,7 +58,7 @@ export class LivService {
|
||||
public getLivShortcuts(): Promise<LivEntry[]> {
|
||||
return execOnOs({
|
||||
win32: async () => {
|
||||
const regRes = await regedit.promisified.list([this.livExternalAppsRegeditKey]).then(res => res[this.livExternalAppsRegeditKey]);
|
||||
const regRes = await list(this.livExternalAppsRegeditKey).then(res => res[this.livExternalAppsRegeditKey]);
|
||||
|
||||
if(!regRes.exists){
|
||||
return [];
|
||||
@@ -78,7 +66,7 @@ export class LivService {
|
||||
|
||||
const promises = regRes.keys.map(async key => {
|
||||
const shortcutKey = path.join(this.livExternalAppsRegeditKey, key);
|
||||
const entries = await regedit.promisified.list([shortcutKey]).then(res => res[shortcutKey]);
|
||||
const entries = await list(shortcutKey).then(res => res[shortcutKey]);
|
||||
|
||||
if(!entries.exists){
|
||||
return undefined;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import regedit from "regedit";
|
||||
import { list } from "regedit-rs";
|
||||
import path from "path";
|
||||
import { pathExist } from "../helpers/fs.helpers";
|
||||
import log from "electron-log";
|
||||
@@ -29,26 +29,25 @@ export class OculusService {
|
||||
}
|
||||
|
||||
const oculusLibsRegKey = "HKCU\\SOFTWARE\\Oculus VR, LLC\\Oculus\\Libraries";
|
||||
const libsRegData = await list(oculusLibsRegKey).then(data => data[oculusLibsRegKey]);
|
||||
|
||||
const libsRegData = (await regedit.promisified.list([oculusLibsRegKey]))["HKCU\\SOFTWARE\\Oculus VR, LLC\\Oculus\\Libraries"];
|
||||
|
||||
if (!libsRegData.exists || !libsRegData.keys) {
|
||||
if (!libsRegData.keys?.length) {
|
||||
log.info("Registry key \"HKCU\\SOFTWARE\\Oculus VR, LLC\\Oculus\\Libraries\" not found");
|
||||
return null;
|
||||
}
|
||||
|
||||
const defaultLibraryId = libsRegData.values.DefaultLibrary.value as string;
|
||||
|
||||
const libsPath: OculusLibrary[] = (
|
||||
await Promise.all(
|
||||
libsRegData.keys.map(async key => {
|
||||
const originalPath = (await regedit.promisified.list([`${oculusLibsRegKey}\\${key}`]))[`${oculusLibsRegKey}\\${key}`];
|
||||
if (!originalPath.exists || !libsRegData.values || !originalPath.values.OriginalPath) {
|
||||
return null;
|
||||
}
|
||||
await Promise.all(libsRegData.keys.map(async key => {
|
||||
const originalPath = await list([`${oculusLibsRegKey}\\${key}`]).then(res => res[`${oculusLibsRegKey}\\${key}`]);
|
||||
|
||||
if (!originalPath.values?.OriginalPath) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return { id: key, path: originalPath.values.OriginalPath.value, isDefault: defaultLibraryId === key } as OculusLibrary
|
||||
}, [])
|
||||
)
|
||||
return { id: key, path: originalPath.values.OriginalPath.value, isDefault: defaultLibraryId === key } as OculusLibrary
|
||||
}, []))
|
||||
).filter(Boolean);
|
||||
|
||||
this.oculusLibraries = libsPath;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { UtilsService } from "./utils.service";
|
||||
import regedit from "regedit";
|
||||
import { list, RegDwordValue } from "regedit-rs"
|
||||
import path from "path";
|
||||
import { parse } from "@node-steam/vdf";
|
||||
import { readFile } from "fs/promises";
|
||||
@@ -11,15 +10,9 @@ import { taskRunning } from "../helpers/os.helpers";
|
||||
export class SteamService {
|
||||
|
||||
private static instance: SteamService;
|
||||
|
||||
private readonly utils: UtilsService = UtilsService.getInstance();
|
||||
|
||||
private steamPath: string = '';
|
||||
|
||||
private constructor(){
|
||||
const vbsDirectory = path.join(this.utils.getAssetsScriptsPath(), "node-regedit", "vbs");
|
||||
regedit.setExternalVBSLocation(vbsDirectory);
|
||||
}
|
||||
private constructor(){}
|
||||
|
||||
public static getInstance(){
|
||||
if(!SteamService.instance){ SteamService.instance = new SteamService(); }
|
||||
@@ -27,17 +20,19 @@ export class SteamService {
|
||||
}
|
||||
|
||||
public async getActiveUser(): Promise<number>{
|
||||
const res = await regedit.promisified.list(["HKCU\\Software\\Valve\\Steam\\ActiveProcess"]);
|
||||
const keys = res?.["HKCU\\Software\\Valve\\Steam\\ActiveProcess"];
|
||||
if(!keys?.exists){ throw "Key \"HKCU\\Software\\Valve\\Steam\\ActiveProcess\" not exist"; }
|
||||
return (keys.values?.ActiveUser.value || undefined) as number;
|
||||
const res = await list("HKCU\\Software\\Valve\\Steam\\ActiveProcess");
|
||||
const key = res["HKCU\\Software\\Valve\\Steam\\ActiveProcess"];
|
||||
if(!key.exists){ throw "Key \"HKCU\\Software\\Valve\\Steam\\ActiveProcess\" not exist"; }
|
||||
const registryValue = key.values.ActiveUser as RegDwordValue;
|
||||
if(!registryValue){ throw "Value \"ActiveUser\" not exist"; }
|
||||
return registryValue.value;
|
||||
}
|
||||
|
||||
public async steamRunning(): Promise<boolean>{
|
||||
const steamProcessRunning = await taskRunning("steam");
|
||||
if(process.platform === "linux") { return steamProcessRunning; }
|
||||
|
||||
return steamProcessRunning && !!(await this.getActiveUser());
|
||||
const activeUser = await this.getActiveUser().catch(err => log.error(err));
|
||||
return steamProcessRunning && !!activeUser;
|
||||
}
|
||||
|
||||
public async getSteamPath(): Promise<string>{
|
||||
@@ -48,24 +43,19 @@ export class SteamService {
|
||||
case "linux":
|
||||
this.steamPath = path.join(app.getPath('home'), '.steam', "steam");
|
||||
return this.steamPath;
|
||||
case "win32":
|
||||
// eslint-disable-next-line no-case-declarations
|
||||
const [win32Res, win64Res] = await Promise.all([
|
||||
regedit.promisified.list(['HKLM\\SOFTWARE\\Valve\\Steam']),
|
||||
regedit.promisified.list(['HKLM\\SOFTWARE\\WOW6432Node\\Valve\\Steam'])
|
||||
]);
|
||||
case "win32": {
|
||||
const res = await list(['HKLM\\SOFTWARE\\Valve\\Steam', 'HKLM\\SOFTWARE\\WOW6432Node\\Valve\\Steam']);
|
||||
const win64 = res['HKLM\\SOFTWARE\\Valve\\Steam'];
|
||||
const win32 = res['HKLM\\SOFTWARE\\WOW6432Node\\Valve\\Steam'];
|
||||
|
||||
// eslint-disable-next-line no-case-declarations
|
||||
const [win32, win64] = [win32Res["HKLM\\SOFTWARE\\Valve\\Steam"], win64Res["HKLM\\SOFTWARE\\WOW6432Node\\Valve\\Steam"]];
|
||||
|
||||
if(win64.exists && win64?.values?.InstallPath?.value){
|
||||
if (win64.exists && win64?.values?.InstallPath?.value) {
|
||||
this.steamPath = win64.values.InstallPath.value as string;
|
||||
}
|
||||
else if (win32.exists && win32?.values?.InstallPath?.value){
|
||||
this.steamPath = win32.values.InstallPath.value as string;
|
||||
} else if (win32.exists && win32?.values?.InstallPath?.value) {
|
||||
this.steamPath = win32.values.InstallPath.value as string;
|
||||
}
|
||||
|
||||
return this.steamPath;
|
||||
}
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user