mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-01-24 05:54:55 +03:00
feat: searching new folders
This commit is contained in:
parent
7e2d9316f3
commit
9731035820
@ -55,7 +55,7 @@ const compareFile = async (game: Game, file: AchievementFile) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const checkAchievementFileChange = async (games: Game[]) => {
|
export const checkAchievementFileChange = async (games: Game[]) => {
|
||||||
const achievementFiles = findAllAchievementFiles();
|
const achievementFiles = await findAllAchievementFiles();
|
||||||
|
|
||||||
for (const game of games) {
|
for (const game of games) {
|
||||||
const gameAchievementFiles = achievementFiles.get(game.objectID) || [];
|
const gameAchievementFiles = achievementFiles.get(game.objectID) || [];
|
||||||
|
@ -9,54 +9,120 @@ import { Game } from "@main/entity";
|
|||||||
const publicDir = path.join("C:", "Users", "Public", "Documents");
|
const publicDir = 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 crackers = [
|
const crackers = [
|
||||||
Cracker.codex,
|
Cracker.codex,
|
||||||
Cracker.goldberg,
|
Cracker.goldberg,
|
||||||
Cracker.goldberg2,
|
|
||||||
Cracker.rune,
|
Cracker.rune,
|
||||||
Cracker.onlineFix,
|
Cracker.onlineFix,
|
||||||
Cracker.userstats,
|
Cracker.userstats,
|
||||||
Cracker.rld,
|
Cracker.rld,
|
||||||
|
Cracker.creamAPI,
|
||||||
|
Cracker.skidrow,
|
||||||
|
Cracker.smartSteamEmu,
|
||||||
|
Cracker.empress,
|
||||||
];
|
];
|
||||||
|
|
||||||
const getPathFromCracker = (cracker: Cracker) => {
|
const getPathFromCracker = async (cracker: Cracker) => {
|
||||||
let folderPath: string;
|
if (cracker === Cracker.smartSteamEmu) {
|
||||||
let fileLocation: string[];
|
return [
|
||||||
|
{
|
||||||
if (cracker === Cracker.onlineFix) {
|
folderPath: path.join(appData, "SmartSteamEmu"),
|
||||||
folderPath = path.join(publicDir, Cracker.onlineFix);
|
fileLocation: ["User", "Achievements"],
|
||||||
fileLocation = ["Stats", "Achievements.ini"];
|
},
|
||||||
} else if (cracker === Cracker.goldberg) {
|
];
|
||||||
folderPath = path.join(appData, "Goldberg SteamEmu Saves");
|
|
||||||
fileLocation = ["achievements.json"];
|
|
||||||
} else if (cracker === Cracker.goldberg2) {
|
|
||||||
folderPath = path.join(appData, "GSE Saves");
|
|
||||||
fileLocation = ["achievements.json"];
|
|
||||||
} else if (cracker === Cracker.rld) {
|
|
||||||
folderPath = path.join(programData, Cracker.rld);
|
|
||||||
fileLocation = ["achievements.ini"];
|
|
||||||
} else {
|
|
||||||
folderPath = path.join(publicDir, "Steam", cracker);
|
|
||||||
fileLocation = ["achievements.ini"];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return { folderPath, fileLocation };
|
if (cracker === Cracker.onlineFix) {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
folderPath: path.join(publicDir, Cracker.onlineFix),
|
||||||
|
fileLocation: ["Stats", "Achievements.ini"],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cracker === Cracker.goldberg) {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
folderPath: path.join(appData, "Goldberg SteamEmu Saves"),
|
||||||
|
fileLocation: ["achievements.json"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
folderPath: path.join(appData, "GSE Saves"),
|
||||||
|
fileLocation: ["achievements.json"],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cracker === Cracker.rld) {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
folderPath: path.join(programData, "RLD!"),
|
||||||
|
fileLocation: ["achievements.ini"],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cracker === Cracker.creamAPI) {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
folderPath: path.join(appData, "CreamAPI"),
|
||||||
|
fileLocation: ["achievements.ini"],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cracker === Cracker.skidrow) {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
folderPath: path.join(documents, "SKIDROW"),
|
||||||
|
fileLocation: ["SteamEmu", "UserStats", "achiev.ini"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
folderPath: path.join(documents, "Player"),
|
||||||
|
fileLocation: ["SteamEmu", "UserStats", "achiev.ini"],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cracker === Cracker.codex) {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
folderPath: path.join(publicDir, "Steam", "CODEX"),
|
||||||
|
fileLocation: ["achievements.ini"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
folderPath: path.join(appData, "Steam", "CODEX"),
|
||||||
|
fileLocation: ["achievements.ini"],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
folderPath: path.join(publicDir, "Steam", cracker),
|
||||||
|
fileLocation: ["achievements.ini"],
|
||||||
|
},
|
||||||
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
export const findAchievementFiles = (game: Game) => {
|
export const findAchievementFiles = async (game: Game) => {
|
||||||
const achievementFiles: AchievementFile[] = [];
|
const achievementFiles: AchievementFile[] = [];
|
||||||
|
|
||||||
for (const cracker of crackers) {
|
for (const cracker of crackers) {
|
||||||
const { folderPath, fileLocation } = getPathFromCracker(cracker);
|
for (const { folderPath, fileLocation } of await getPathFromCracker(
|
||||||
|
cracker
|
||||||
|
)) {
|
||||||
|
const filePath = path.join(folderPath, game.objectID, ...fileLocation);
|
||||||
|
|
||||||
const filePath = path.join(folderPath, game.objectID, ...fileLocation);
|
if (fs.existsSync(filePath)) {
|
||||||
|
achievementFiles.push({
|
||||||
if (fs.existsSync(filePath)) {
|
type: cracker,
|
||||||
achievementFiles.push({
|
filePath,
|
||||||
type: cracker,
|
});
|
||||||
filePath: path.join(folderPath, game.objectID, ...fileLocation),
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,31 +149,33 @@ export const findAchievementFileInExecutableDirectory = (
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const findAllAchievementFiles = () => {
|
export const findAllAchievementFiles = async () => {
|
||||||
const gameAchievementFiles = new Map<string, AchievementFile[]>();
|
const gameAchievementFiles = new Map<string, AchievementFile[]>();
|
||||||
|
|
||||||
for (const cracker of crackers) {
|
for (const cracker of crackers) {
|
||||||
const { folderPath, fileLocation } = getPathFromCracker(cracker);
|
for (const { folderPath, fileLocation } of await getPathFromCracker(
|
||||||
|
cracker
|
||||||
|
)) {
|
||||||
|
if (!fs.existsSync(folderPath)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (!fs.existsSync(folderPath)) {
|
const objectIds = fs.readdirSync(folderPath);
|
||||||
return gameAchievementFiles;
|
|
||||||
}
|
|
||||||
|
|
||||||
const objectIds = fs.readdirSync(folderPath);
|
for (const objectId of objectIds) {
|
||||||
|
const filePath = path.join(folderPath, objectId, ...fileLocation);
|
||||||
|
|
||||||
for (const objectId of objectIds) {
|
if (!fs.existsSync(filePath)) continue;
|
||||||
const filePath = path.join(folderPath, objectId, ...fileLocation);
|
|
||||||
|
|
||||||
if (!fs.existsSync(filePath)) continue;
|
const achivementFile = {
|
||||||
|
type: cracker,
|
||||||
|
filePath,
|
||||||
|
};
|
||||||
|
|
||||||
const achivementFile = {
|
gameAchievementFiles.get(objectId)
|
||||||
type: cracker,
|
? gameAchievementFiles.get(objectId)!.push(achivementFile)
|
||||||
filePath,
|
: gameAchievementFiles.set(objectId, [achivementFile]);
|
||||||
};
|
}
|
||||||
|
|
||||||
gameAchievementFiles.get(objectId)
|
|
||||||
? gameAchievementFiles.get(objectId)!.push(achivementFile)
|
|
||||||
: gameAchievementFiles.set(objectId, [achivementFile]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,11 +9,28 @@ export const parseAchievementFile = async (
|
|||||||
): Promise<UnlockedAchievement[]> => {
|
): Promise<UnlockedAchievement[]> => {
|
||||||
if (!existsSync(filePath)) return [];
|
if (!existsSync(filePath)) return [];
|
||||||
|
|
||||||
|
if (type === Cracker.empress) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type === Cracker.skidrow) {
|
||||||
|
const parsed = await iniParse(filePath);
|
||||||
|
return processSkidrow(parsed);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type === Cracker.smartSteamEmu) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
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 || type === Cracker.goldberg2) {
|
if (type === Cracker.goldberg) {
|
||||||
const parsed = await jsonParse(filePath);
|
const parsed = await jsonParse(filePath);
|
||||||
return processGoldberg(parsed);
|
return processGoldberg(parsed);
|
||||||
}
|
}
|
||||||
@ -88,6 +105,24 @@ const processOnlineFix = (unlockedAchievements: any): UnlockedAchievement[] => {
|
|||||||
return parsedUnlockedAchievements;
|
return parsedUnlockedAchievements;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const processSkidrow = (unlockedAchievements: any): UnlockedAchievement[] => {
|
||||||
|
const parsedUnlockedAchievements: UnlockedAchievement[] = [];
|
||||||
|
const achievements = unlockedAchievements["Achievements"];
|
||||||
|
|
||||||
|
for (const achievement of Object.keys(achievements)) {
|
||||||
|
const unlockedAchievement = achievements[achievement].split("@");
|
||||||
|
|
||||||
|
if (unlockedAchievement[0] === "1") {
|
||||||
|
parsedUnlockedAchievements.push({
|
||||||
|
name: achievement,
|
||||||
|
unlockTime: unlockedAchievement[unlockedAchievement.length - 1],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return parsedUnlockedAchievements;
|
||||||
|
};
|
||||||
|
|
||||||
const processGoldberg = (unlockedAchievements: any): UnlockedAchievement[] => {
|
const processGoldberg = (unlockedAchievements: any): UnlockedAchievement[] => {
|
||||||
const newUnlockedAchievements: UnlockedAchievement[] = [];
|
const newUnlockedAchievements: UnlockedAchievement[] = [];
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ import type { UnlockedAchievement } from "@types";
|
|||||||
import { getGameAchievementData } from "./get-game-achievement-data";
|
import { getGameAchievementData } from "./get-game-achievement-data";
|
||||||
|
|
||||||
export const updateAllLocalUnlockedAchievements = async () => {
|
export const updateAllLocalUnlockedAchievements = async () => {
|
||||||
const gameAchievementFilesMap = findAllAchievementFiles();
|
const gameAchievementFilesMap = await findAllAchievementFiles();
|
||||||
|
|
||||||
for (const objectId of gameAchievementFilesMap.keys()) {
|
for (const objectId of gameAchievementFilesMap.keys()) {
|
||||||
const gameAchievementFiles = gameAchievementFilesMap.get(objectId)!;
|
const gameAchievementFiles = gameAchievementFilesMap.get(objectId)!;
|
||||||
@ -69,7 +69,7 @@ export const updateLocalUnlockedAchivements = async (objectId: string) => {
|
|||||||
|
|
||||||
if (!game) return;
|
if (!game) return;
|
||||||
|
|
||||||
const gameAchievementFiles = findAchievementFiles(game);
|
const gameAchievementFiles = await findAchievementFiles(game);
|
||||||
|
|
||||||
console.log("Achievements files for", game.title, gameAchievementFiles);
|
console.log("Achievements files for", game.title, gameAchievementFiles);
|
||||||
|
|
||||||
|
@ -29,7 +29,10 @@ export enum Cracker {
|
|||||||
rune = "RUNE",
|
rune = "RUNE",
|
||||||
onlineFix = "OnlineFix",
|
onlineFix = "OnlineFix",
|
||||||
goldberg = "Goldberg",
|
goldberg = "Goldberg",
|
||||||
goldberg2 = "Goldberg2",
|
|
||||||
userstats = "user_stats",
|
userstats = "user_stats",
|
||||||
rld = "RLD!",
|
rld = "RLD!",
|
||||||
|
empress = "EMPRESS",
|
||||||
|
skidrow = "SKIDROW",
|
||||||
|
creamAPI = "CreamAPI",
|
||||||
|
smartSteamEmu = "SmartSteamEmu",
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user