mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-11 13:56:16 +00:00
feat: logs
This commit is contained in:
@@ -23,6 +23,14 @@ const addGame = (
|
||||
: achievementFiles.set(objectId, [achivementFile]);
|
||||
};
|
||||
|
||||
const getObjectIdsInFolder = (path: string) => {
|
||||
if (fs.existsSync(path)) {
|
||||
return fs.readdirSync(path);
|
||||
}
|
||||
|
||||
return [];
|
||||
};
|
||||
|
||||
export const findSteamGameAchievementFiles = (objectId?: string) => {
|
||||
//TODO: change to a automatized method
|
||||
const publicDir = path.join("C:", "Users", "Public", "Documents");
|
||||
@@ -52,7 +60,9 @@ export const findSteamGameAchievementFiles = (objectId?: string) => {
|
||||
fileLocation = ["achievements.ini"];
|
||||
}
|
||||
|
||||
const objectIds = objectId ? [objectId] : fs.readdirSync(achievementPath);
|
||||
const objectIds = objectId
|
||||
? [objectId]
|
||||
: getObjectIdsInFolder(achievementPath);
|
||||
|
||||
for (const objectId of objectIds) {
|
||||
addGame(
|
||||
|
||||
@@ -6,6 +6,7 @@ import { mergeAchievements } from "./merge-achievements";
|
||||
import fs from "node:fs";
|
||||
import { findSteamGameAchievementFiles } from "./find-steam-game-achivement-files";
|
||||
import type { AchievementFile } from "@types";
|
||||
import { logger } from "../logger";
|
||||
|
||||
type GameAchievementObserver = {
|
||||
[id: number]: AbortController;
|
||||
@@ -15,17 +16,22 @@ const gameAchievementObserver: GameAchievementObserver = {};
|
||||
|
||||
const processAchievementFile = async (game: Game, file: AchievementFile) => {
|
||||
const localAchievementFile = await parseAchievementFile(file.filePath);
|
||||
console.log(localAchievementFile);
|
||||
|
||||
logger.log("Parsed achievements file", file.filePath, localAchievementFile);
|
||||
if (localAchievementFile) {
|
||||
const unlockedAchievements = checkUnlockedAchievements(
|
||||
file.type,
|
||||
localAchievementFile
|
||||
);
|
||||
console.log(unlockedAchievements);
|
||||
logger.log("Achievements from file", file.filePath, unlockedAchievements);
|
||||
|
||||
if (unlockedAchievements.length) {
|
||||
mergeAchievements(game.objectID, game.shop, unlockedAchievements, true);
|
||||
return mergeAchievements(
|
||||
game.objectID,
|
||||
game.shop,
|
||||
unlockedAchievements,
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -34,7 +40,7 @@ const startFileWatch = async (game: Game, file: AchievementFile) => {
|
||||
const signal = gameAchievementObserver[game.id]?.signal;
|
||||
|
||||
try {
|
||||
processAchievementFile(game, file);
|
||||
await processAchievementFile(game, file);
|
||||
|
||||
const watcher = watch(file.filePath, {
|
||||
signal,
|
||||
@@ -42,13 +48,13 @@ const startFileWatch = async (game: Game, file: AchievementFile) => {
|
||||
|
||||
for await (const event of watcher) {
|
||||
if (event.eventType === "change") {
|
||||
processAchievementFile(game, file);
|
||||
logger.log("Detected change in file", file.filePath);
|
||||
await processAchievementFile(game, file);
|
||||
}
|
||||
}
|
||||
} catch (err: any) {
|
||||
if (err?.name === "AbortError") return;
|
||||
console.log(`cracker: ${file.type}, steamId ${game.objectID}`);
|
||||
throw err;
|
||||
logger.error("Failed to watch file", file.filePath, err);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -59,7 +65,7 @@ export const startGameAchievementObserver = async (game: Game) => {
|
||||
const achievementFiles =
|
||||
findSteamGameAchievementFiles(game.objectID).get(game.objectID) || [];
|
||||
|
||||
console.log(
|
||||
logger.log(
|
||||
"Achievements files to observe for:",
|
||||
game.title,
|
||||
achievementFiles
|
||||
|
||||
Reference in New Issue
Block a user