Merge branch 'feature/game-achievements' into chore/test-preview

This commit is contained in:
Zamitto 2024-10-04 13:27:03 -03:00
commit e4ca3d38ec
3 changed files with 68 additions and 35 deletions

View File

@ -4,12 +4,14 @@ import { app } from "electron";
import type { AchievementFile } from "@types"; import type { AchievementFile } from "@types";
import { Cracker } from "@shared"; import { Cracker } from "@shared";
import { Game } from "@main/entity"; import { Game } from "@main/entity";
import { achievementsLogger } from "../logger";
//TODO: change to a automatized method //TODO: change to a automatized method
const publicDir = path.join("C:", "Users", "Public", "Documents"); const publicDocuments = path.join("C:", "Users", "Public", "Documents");
const programData = path.join("C:", "ProgramData"); const programData = path.join("C:", "ProgramData");
const appData = app.getPath("appData"); const appData = app.getPath("appData");
const documents = app.getPath("documents"); const documents = app.getPath("documents");
const localAppData = path.join(appData, "..", "Local");
const crackers = [ const crackers = [
Cracker.codex, Cracker.codex,
@ -25,11 +27,24 @@ const crackers = [
]; ];
const getPathFromCracker = async (cracker: Cracker) => { const getPathFromCracker = async (cracker: Cracker) => {
if (cracker === Cracker.smartSteamEmu) { if (cracker === Cracker.codex) {
return [ return [
{ {
folderPath: path.join(appData, "SmartSteamEmu"), folderPath: path.join(publicDocuments, "Steam", "CODEX"),
fileLocation: ["User", "Achievements"], fileLocation: ["achievements.ini"],
},
{
folderPath: path.join(appData, "Steam", "CODEX"),
fileLocation: ["achievements.ini"],
},
];
}
if (cracker === Cracker.rune) {
return [
{
folderPath: path.join(publicDocuments, "Steam", "RUNE"),
fileLocation: ["achievements.ini"],
}, },
]; ];
} }
@ -37,7 +52,7 @@ const getPathFromCracker = async (cracker: Cracker) => {
if (cracker === Cracker.onlineFix) { if (cracker === Cracker.onlineFix) {
return [ return [
{ {
folderPath: path.join(publicDir, Cracker.onlineFix), folderPath: path.join(publicDocuments, Cracker.onlineFix),
fileLocation: ["Stats", "Achievements.ini"], fileLocation: ["Stats", "Achievements.ini"],
}, },
]; ];
@ -56,20 +71,32 @@ const getPathFromCracker = async (cracker: Cracker) => {
]; ];
} }
if (cracker === Cracker.userstats) {
return [];
}
if (cracker === Cracker.rld) { if (cracker === Cracker.rld) {
return [ return [
{ {
folderPath: path.join(programData, "RLD!"), folderPath: path.join(programData, "RLD!"),
fileLocation: ["achievements.ini"], fileLocation: ["achievements.ini"],
}, },
{
folderPath: path.join(programData, "Steam", "Player"),
fileLocation: ["achievements.ini"],
},
]; ];
} }
if (cracker === Cracker.creamAPI) { if (cracker === Cracker.empress) {
return [ return [
{ {
folderPath: path.join(appData, "CreamAPI"), folderPath: path.join(appData, "EMPRESS", "remote"),
fileLocation: ["achievements.ini"], fileLocation: ["achievements.json"],
},
{
folderPath: path.join(publicDocuments, "EMPRESS", "remote"),
fileLocation: ["achievements.json"],
}, },
]; ];
} }
@ -84,28 +111,33 @@ const getPathFromCracker = async (cracker: Cracker) => {
folderPath: path.join(documents, "Player"), folderPath: path.join(documents, "Player"),
fileLocation: ["SteamEmu", "UserStats", "achiev.ini"], fileLocation: ["SteamEmu", "UserStats", "achiev.ini"],
}, },
];
}
if (cracker === Cracker.codex) {
return [
{ {
folderPath: path.join(publicDir, "Steam", "CODEX"), folderPath: path.join(localAppData, "SKIDROW"),
fileLocation: ["achievements.ini"], fileLocation: ["SteamEmu", "UserStats", "achiev.ini"],
},
{
folderPath: path.join(appData, "Steam", "CODEX"),
fileLocation: ["achievements.ini"],
}, },
]; ];
} }
if (cracker === Cracker.creamAPI) {
return [ return [
{ {
folderPath: path.join(publicDir, "Steam", cracker), folderPath: path.join(appData, "CreamAPI"),
fileLocation: ["achievements.ini"], fileLocation: ["stats", "CreamAPI.Achievements.cfg"],
}, },
]; ];
}
if (cracker === Cracker.smartSteamEmu) {
return [
{
folderPath: path.join(appData, "SmartSteamEmu"),
fileLocation: ["User", "Achievements"],
},
];
}
achievementsLogger.error(`Cracker ${cracker} not implemented`);
throw new Error(`Cracker ${cracker} not implemented`);
}; };
export const findAchievementFiles = async (game: Game) => { export const findAchievementFiles = async (game: Game) => {

View File

@ -2,6 +2,7 @@ import { Cracker } from "@shared";
import { UnlockedAchievement } from "@types"; import { UnlockedAchievement } from "@types";
import { existsSync, createReadStream, readFileSync } from "node:fs"; import { existsSync, createReadStream, readFileSync } from "node:fs";
import readline from "node:readline"; import readline from "node:readline";
import { achievementsLogger } from "../logger";
export const parseAchievementFile = async ( export const parseAchievementFile = async (
filePath: string, filePath: string,
@ -9,27 +10,21 @@ export const parseAchievementFile = async (
): Promise<UnlockedAchievement[]> => { ): Promise<UnlockedAchievement[]> => {
if (!existsSync(filePath)) return []; if (!existsSync(filePath)) return [];
if (type === Cracker.empress) { if (type == Cracker.codex) {
return [];
}
if (type === Cracker.skidrow) {
const parsed = await iniParse(filePath); const parsed = await iniParse(filePath);
return processSkidrow(parsed); return processDefault(parsed);
} }
if (type === Cracker.smartSteamEmu) { if (type == Cracker.rune) {
return []; const parsed = await iniParse(filePath);
} return processDefault(parsed);
if (type === Cracker.creamAPI) {
return [];
} }
if (type === Cracker.onlineFix) { if (type === Cracker.onlineFix) {
const parsed = await iniParse(filePath); const parsed = await iniParse(filePath);
return processOnlineFix(parsed); return processOnlineFix(parsed);
} }
if (type === Cracker.goldberg) { if (type === Cracker.goldberg) {
const parsed = await jsonParse(filePath); const parsed = await jsonParse(filePath);
return processGoldberg(parsed); return processGoldberg(parsed);
@ -45,8 +40,13 @@ export const parseAchievementFile = async (
return processRld(parsed); return processRld(parsed);
} }
if (type === Cracker.skidrow) {
const parsed = await iniParse(filePath); const parsed = await iniParse(filePath);
return processDefault(parsed); return processSkidrow(parsed);
}
achievementsLogger.log(`${type} achievements found on ${filePath}`);
return [];
}; };
const iniParse = async (filePath: string) => { const iniParse = async (filePath: string) => {

View File

@ -29,3 +29,4 @@ log.initialize();
export const pythonInstanceLogger = log.scope("python-instance"); export const pythonInstanceLogger = log.scope("python-instance");
export const logger = log.scope("main"); export const logger = log.scope("main");
export const achievementsLogger = log.scope("achievements");