mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-02-03 00:33:49 +03:00
fix: handle achievement parse error causing hydra to never search new achievements in real time
This commit is contained in:
parent
58cbf78fb9
commit
6f417d23d1
@ -236,24 +236,28 @@ export class AchievementWatcherManager {
|
|||||||
};
|
};
|
||||||
|
|
||||||
public static preSearchAchievements = async () => {
|
public static preSearchAchievements = async () => {
|
||||||
const newAchievementsCount =
|
try {
|
||||||
process.platform === "win32"
|
const newAchievementsCount =
|
||||||
? await this.preSearchAchievementsWindows()
|
process.platform === "win32"
|
||||||
: await this.preSearchAchievementsWithWine();
|
? await this.preSearchAchievementsWindows()
|
||||||
|
: await this.preSearchAchievementsWithWine();
|
||||||
|
|
||||||
const totalNewGamesWithAchievements = newAchievementsCount.filter(
|
const totalNewGamesWithAchievements = newAchievementsCount.filter(
|
||||||
(achievements) => achievements
|
(achievements) => achievements
|
||||||
).length;
|
).length;
|
||||||
const totalNewAchievements = newAchievementsCount.reduce(
|
const totalNewAchievements = newAchievementsCount.reduce(
|
||||||
(acc, val) => acc + val,
|
(acc, val) => acc + val,
|
||||||
0
|
0
|
||||||
);
|
|
||||||
|
|
||||||
if (totalNewAchievements > 0) {
|
|
||||||
publishCombinedNewAchievementNotification(
|
|
||||||
totalNewAchievements,
|
|
||||||
totalNewGamesWithAchievements
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (totalNewAchievements > 0) {
|
||||||
|
publishCombinedNewAchievementNotification(
|
||||||
|
totalNewAchievements,
|
||||||
|
totalNewGamesWithAchievements
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
achievementsLogger.error("Error on preSearchAchievements", err);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.hasFinishedMergingWithRemote = true;
|
this.hasFinishedMergingWithRemote = true;
|
||||||
|
@ -9,144 +9,134 @@ export const parseAchievementFile = (
|
|||||||
): UnlockedAchievement[] => {
|
): UnlockedAchievement[] => {
|
||||||
if (!existsSync(filePath)) return [];
|
if (!existsSync(filePath)) return [];
|
||||||
|
|
||||||
if (type == Cracker.codex) {
|
try {
|
||||||
const parsed = iniParse(filePath);
|
if (type == Cracker.codex) {
|
||||||
return processDefault(parsed);
|
const parsed = iniParse(filePath);
|
||||||
|
return processDefault(parsed);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type == Cracker.rune) {
|
||||||
|
const parsed = iniParse(filePath);
|
||||||
|
return processDefault(parsed);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type === Cracker.onlineFix) {
|
||||||
|
const parsed = iniParse(filePath);
|
||||||
|
return processOnlineFix(parsed);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type === Cracker.goldberg) {
|
||||||
|
const parsed = jsonParse(filePath);
|
||||||
|
return processGoldberg(parsed);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type == Cracker.userstats) {
|
||||||
|
const parsed = iniParse(filePath);
|
||||||
|
return processUserStats(parsed);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type == Cracker.rld) {
|
||||||
|
const parsed = iniParse(filePath);
|
||||||
|
return processRld(parsed);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type === Cracker.skidrow) {
|
||||||
|
const parsed = iniParse(filePath);
|
||||||
|
return processSkidrow(parsed);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type === Cracker._3dm) {
|
||||||
|
const parsed = iniParse(filePath);
|
||||||
|
return process3DM(parsed);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type === Cracker.flt) {
|
||||||
|
const achievements = readdirSync(filePath);
|
||||||
|
|
||||||
|
return achievements.map((achievement) => {
|
||||||
|
return {
|
||||||
|
name: achievement,
|
||||||
|
unlockTime: Date.now(),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type === Cracker.creamAPI) {
|
||||||
|
const parsed = iniParse(filePath);
|
||||||
|
return processCreamAPI(parsed);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type === Cracker.empress) {
|
||||||
|
const parsed = jsonParse(filePath);
|
||||||
|
return processGoldberg(parsed);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type === Cracker.razor1911) {
|
||||||
|
return processRazor1911(filePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
achievementsLogger.log(
|
||||||
|
`Unprocessed ${type} achievements found on ${filePath}`
|
||||||
|
);
|
||||||
|
return [];
|
||||||
|
} catch (err) {
|
||||||
|
achievementsLogger.error(`Error parsing ${type} - ${filePath}`, err);
|
||||||
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == Cracker.rune) {
|
|
||||||
const parsed = iniParse(filePath);
|
|
||||||
return processDefault(parsed);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type === Cracker.onlineFix) {
|
|
||||||
const parsed = iniParse(filePath);
|
|
||||||
return processOnlineFix(parsed);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type === Cracker.goldberg) {
|
|
||||||
const parsed = jsonParse(filePath);
|
|
||||||
return processGoldberg(parsed);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type == Cracker.userstats) {
|
|
||||||
const parsed = iniParse(filePath);
|
|
||||||
return processUserStats(parsed);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type == Cracker.rld) {
|
|
||||||
const parsed = iniParse(filePath);
|
|
||||||
return processRld(parsed);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type === Cracker.skidrow) {
|
|
||||||
const parsed = iniParse(filePath);
|
|
||||||
return processSkidrow(parsed);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type === Cracker._3dm) {
|
|
||||||
const parsed = iniParse(filePath);
|
|
||||||
return process3DM(parsed);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type === Cracker.flt) {
|
|
||||||
const achievements = readdirSync(filePath);
|
|
||||||
|
|
||||||
return achievements.map((achievement) => {
|
|
||||||
return {
|
|
||||||
name: achievement,
|
|
||||||
unlockTime: Date.now(),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type === Cracker.creamAPI) {
|
|
||||||
const parsed = iniParse(filePath);
|
|
||||||
return processCreamAPI(parsed);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type === Cracker.empress) {
|
|
||||||
const parsed = jsonParse(filePath);
|
|
||||||
return processGoldberg(parsed);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type === Cracker.razor1911) {
|
|
||||||
return processRazor1911(filePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
achievementsLogger.log(
|
|
||||||
`Unprocessed ${type} achievements found on ${filePath}`
|
|
||||||
);
|
|
||||||
return [];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const iniParse = (filePath: string) => {
|
const iniParse = (filePath: string) => {
|
||||||
try {
|
const fileContent = readFileSync(filePath, "utf-8");
|
||||||
const fileContent = readFileSync(filePath, "utf-8");
|
|
||||||
|
|
||||||
const lines =
|
const lines =
|
||||||
fileContent.charCodeAt(0) === 0xfeff
|
fileContent.charCodeAt(0) === 0xfeff
|
||||||
? fileContent.slice(1).split(/[\r\n]+/)
|
? fileContent.slice(1).split(/[\r\n]+/)
|
||||||
: fileContent.split(/[\r\n]+/);
|
: fileContent.split(/[\r\n]+/);
|
||||||
|
|
||||||
let objectName = "";
|
let objectName = "";
|
||||||
const object: Record<string, Record<string, string | number>> = {};
|
const object: Record<string, Record<string, string | number>> = {};
|
||||||
|
|
||||||
for (const line of lines) {
|
for (const line of lines) {
|
||||||
if (line.startsWith("###") || !line.length) continue;
|
if (line.startsWith("###") || !line.length) continue;
|
||||||
|
|
||||||
if (line.startsWith("[") && line.endsWith("]")) {
|
if (line.startsWith("[") && line.endsWith("]")) {
|
||||||
objectName = line.slice(1, -1);
|
objectName = line.slice(1, -1);
|
||||||
object[objectName] = {};
|
object[objectName] = {};
|
||||||
} else {
|
} else {
|
||||||
const [name, ...value] = line.split("=");
|
const [name, ...value] = line.split("=");
|
||||||
object[objectName][name.trim()] = value.join("=").trim();
|
object[objectName][name.trim()] = value.join("=").trim();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return object;
|
|
||||||
} catch (err) {
|
|
||||||
achievementsLogger.error(`Error parsing ${filePath}`, err);
|
|
||||||
return {};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return object;
|
||||||
};
|
};
|
||||||
|
|
||||||
const jsonParse = (filePath: string) => {
|
const jsonParse = (filePath: string) => {
|
||||||
try {
|
return JSON.parse(readFileSync(filePath, "utf-8"));
|
||||||
return JSON.parse(readFileSync(filePath, "utf-8"));
|
|
||||||
} catch (err) {
|
|
||||||
achievementsLogger.error(`Error parsing ${filePath}`, err);
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const processRazor1911 = (filePath: string): UnlockedAchievement[] => {
|
const processRazor1911 = (filePath: string): UnlockedAchievement[] => {
|
||||||
try {
|
const fileContent = readFileSync(filePath, "utf-8");
|
||||||
const fileContent = readFileSync(filePath, "utf-8");
|
|
||||||
|
|
||||||
const lines =
|
const lines =
|
||||||
fileContent.charCodeAt(0) === 0xfeff
|
fileContent.charCodeAt(0) === 0xfeff
|
||||||
? fileContent.slice(1).split(/[\r\n]+/)
|
? fileContent.slice(1).split(/[\r\n]+/)
|
||||||
: fileContent.split(/[\r\n]+/);
|
: fileContent.split(/[\r\n]+/);
|
||||||
|
|
||||||
const achievements: UnlockedAchievement[] = [];
|
const achievements: UnlockedAchievement[] = [];
|
||||||
for (const line of lines) {
|
for (const line of lines) {
|
||||||
if (!line.length) continue;
|
if (!line.length) continue;
|
||||||
|
|
||||||
const [name, unlocked, unlockTime] = line.split(" ");
|
const [name, unlocked, unlockTime] = line.split(" ");
|
||||||
if (unlocked === "1") {
|
if (unlocked === "1") {
|
||||||
achievements.push({
|
achievements.push({
|
||||||
name,
|
name,
|
||||||
unlockTime: Number(unlockTime) * 1000,
|
unlockTime: Number(unlockTime) * 1000,
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return achievements;
|
|
||||||
} catch (err) {
|
|
||||||
achievementsLogger.error(`Error processing ${filePath}`, err);
|
|
||||||
return [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return achievements;
|
||||||
};
|
};
|
||||||
|
|
||||||
const processOnlineFix = (unlockedAchievements: any): UnlockedAchievement[] => {
|
const processOnlineFix = (unlockedAchievements: any): UnlockedAchievement[] => {
|
||||||
|
Loading…
Reference in New Issue
Block a user