Skip to content

Commit

Permalink
Merge pull request #1094 from hydralauncher/feat/refactor-achievement…
Browse files Browse the repository at this point in the history
…s-files

feat: refactor achievements file
  • Loading branch information
zamitto authored Oct 24, 2024
2 parents 430b07e + 4a3ba43 commit 7d79048
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 35 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hydralauncher",
"version": "3.0.1",
"version": "3.0.2",
"description": "Hydra",
"main": "./out/main/index.js",
"author": "Los Broxas",
Expand Down
12 changes: 10 additions & 2 deletions src/main/services/achievements/achievement-watcher-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,18 @@ export class AchievementWatcherManager {
? await this.preSearchAchievementsWindows()
: await this.preSearchAchievementsWithWine();

const totalNewGamesWithAchievements = newAchievementsCount.filter(
(achievements) => achievements
).length;
const totalNewAchievements = newAchievementsCount.reduce(
(acc, val) => acc + val,
0
);

WindowManager.notificationWindow?.webContents.send(
"on-combined-achievements-unlocked",
newAchievementsCount.filter((achievements) => achievements).length,
newAchievementsCount.reduce((acc, val) => acc + val, 0)
totalNewGamesWithAchievements,
totalNewAchievements
);

this.hasFinishedMergingWithRemote = true;
Expand Down
66 changes: 41 additions & 25 deletions src/main/services/achievements/find-achivement-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ const getPathFromCracker = (cracker: Cracker) => {
return [
{
folderPath: path.join(publicDocuments, "Steam", "CODEX"),
fileLocation: ["achievements.ini"],
fileLocation: ["<objectId>", "achievements.ini"],
},
{
folderPath: path.join(appData, "Steam", "CODEX"),
fileLocation: ["achievements.ini"],
fileLocation: ["<objectId>", "achievements.ini"],
},
];
}
Expand All @@ -92,7 +92,7 @@ const getPathFromCracker = (cracker: Cracker) => {
return [
{
folderPath: path.join(publicDocuments, "Steam", "RUNE"),
fileLocation: ["achievements.ini"],
fileLocation: ["<objectId>", "achievements.ini"],
},
];
}
Expand All @@ -101,11 +101,11 @@ const getPathFromCracker = (cracker: Cracker) => {
return [
{
folderPath: path.join(publicDocuments, "OnlineFix"),
fileLocation: ["Stats", "Achievements.ini"],
fileLocation: ["<objectId>", "Stats", "Achievements.ini"],
},
{
folderPath: path.join(publicDocuments, "OnlineFix"),
fileLocation: ["Achievements.ini"],
fileLocation: ["<objectId>", "Achievements.ini"],
},
];
}
Expand All @@ -114,11 +114,11 @@ const getPathFromCracker = (cracker: Cracker) => {
return [
{
folderPath: path.join(appData, "Goldberg SteamEmu Saves"),
fileLocation: ["achievements.json"],
fileLocation: ["<objectId>", "achievements.json"],
},
{
folderPath: path.join(appData, "GSE Saves"),
fileLocation: ["achievements.json"],
fileLocation: ["<objectId>", "achievements.json"],
},
];
}
Expand All @@ -131,19 +131,19 @@ const getPathFromCracker = (cracker: Cracker) => {
return [
{
folderPath: path.join(programData, "RLD!"),
fileLocation: ["achievements.ini"],
fileLocation: ["<objectId>", "achievements.ini"],
},
{
folderPath: path.join(programData, "Steam", "Player"),
fileLocation: ["stats", "achievements.ini"],
fileLocation: ["<objectId>", "stats", "achievements.ini"],
},
{
folderPath: path.join(programData, "Steam", "RLD!"),
fileLocation: ["stats", "achievements.ini"],
fileLocation: ["<objectId>", "stats", "achievements.ini"],
},
{
folderPath: path.join(programData, "Steam", "dodi"),
fileLocation: ["stats", "achievements.ini"],
fileLocation: ["<objectId>", "stats", "achievements.ini"],
},
];
}
Expand All @@ -152,11 +152,16 @@ const getPathFromCracker = (cracker: Cracker) => {
return [
{
folderPath: path.join(appData, "EMPRESS", "remote"),
fileLocation: ["achievements.json"],
fileLocation: ["<objectId>", "achievements.json"],
},
{
folderPath: path.join(publicDocuments, "EMPRESS", "remote"),
fileLocation: ["achievements.json"],
folderPath: path.join(publicDocuments, "EMPRESS"),
fileLocation: [
"<objectId>",
"remote",
"<objectId>",
"achievements.json",
],
},
];
}
Expand All @@ -165,15 +170,15 @@ const getPathFromCracker = (cracker: Cracker) => {
return [
{
folderPath: path.join(documents, "SKIDROW"),
fileLocation: ["SteamEmu", "UserStats", "achiev.ini"],
fileLocation: ["<objectId>", "SteamEmu", "UserStats", "achiev.ini"],
},
{
folderPath: path.join(documents, "Player"),
fileLocation: ["SteamEmu", "UserStats", "achiev.ini"],
fileLocation: ["<objectId>", "SteamEmu", "UserStats", "achiev.ini"],
},
{
folderPath: path.join(localAppData, "SKIDROW"),
fileLocation: ["SteamEmu", "UserStats", "achiev.ini"],
fileLocation: ["<objectId>", "SteamEmu", "UserStats", "achiev.ini"],
},
];
}
Expand All @@ -182,7 +187,7 @@ const getPathFromCracker = (cracker: Cracker) => {
return [
{
folderPath: path.join(appData, "CreamAPI"),
fileLocation: ["stats", "CreamAPI.Achievements.cfg"],
fileLocation: ["<objectId>", "stats", "CreamAPI.Achievements.cfg"],
},
];
}
Expand All @@ -191,7 +196,7 @@ const getPathFromCracker = (cracker: Cracker) => {
return [
{
folderPath: path.join(appData, "SmartSteamEmu"),
fileLocation: ["User", "Achievements.ini"],
fileLocation: ["<objectId>", "User", "Achievements.ini"],
},
];
}
Expand All @@ -213,11 +218,11 @@ const getPathFromCracker = (cracker: Cracker) => {
return [
{
folderPath: path.join(appData, "RLE"),
fileLocation: ["achievements.ini"],
fileLocation: ["<objectId>", "achievements.ini"],
},
{
folderPath: path.join(appData, "RLE"),
fileLocation: ["Achievements.ini"],
fileLocation: ["<objectId>", "Achievements.ini"],
},
];
}
Expand All @@ -226,7 +231,7 @@ const getPathFromCracker = (cracker: Cracker) => {
return [
{
folderPath: path.join(appData, ".1911"),
fileLocation: ["achievement"],
fileLocation: ["<objectId>", "achievement"],
},
];
}
Expand All @@ -253,8 +258,7 @@ export const findAchievementFiles = (game: Game) => {
const filePath = path.join(
game.winePrefixPath ?? "",
folderPath,
objectId,
...fileLocation
...mapFileLocationWithObjectId(fileLocation, objectId)
);

if (fs.existsSync(filePath)) {
Expand Down Expand Up @@ -303,6 +307,15 @@ export const findAchievementFileInExecutableDirectory = (
];
};

const mapFileLocationWithObjectId = (
fileLocation: string[],
objectId: string
) => {
return fileLocation.map((location) =>
location.replace("<objectId>", objectId)
);
};

export const findAllAchievementFiles = () => {
const gameAchievementFiles = new Map<string, AchievementFile[]>();

Expand All @@ -315,7 +328,10 @@ export const findAllAchievementFiles = () => {
const objectIds = fs.readdirSync(folderPath);

for (const objectId of objectIds) {
const filePath = path.join(folderPath, objectId, ...fileLocation);
const filePath = path.join(
folderPath,
...mapFileLocationWithObjectId(fileLocation, objectId)
);

if (!fs.existsSync(filePath)) continue;

Expand Down
9 changes: 7 additions & 2 deletions src/main/services/achievements/parse-achievement-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ export const parseAchievementFile = (
return processCreamAPI(parsed);
}

if (type === Cracker.empress) {
const parsed = jsonParse(filePath);
return processGoldberg(parsed);
}

if (type === Cracker.razor1911) {
return processRazor1911(filePath);
}
Expand Down Expand Up @@ -118,7 +123,7 @@ const jsonParse = (filePath: string) => {
const processRazor1911 = (filePath: string): UnlockedAchievement[] => {
try {
const fileContent = readFileSync(filePath, "utf-8");
achievementsLogger.log("processing file", filePath, fileContent);

const lines =
fileContent.charCodeAt(0) === 0xfeff
? fileContent.slice(1).split(/[\r\n]+/)
Expand All @@ -136,7 +141,7 @@ const processRazor1911 = (filePath: string): UnlockedAchievement[] => {
});
}
}
achievementsLogger.log("processing file", achievements);

return achievements;
} catch (err) {
achievementsLogger.error(`Error processing ${filePath}`, err);
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/src/hooks/use-date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ export function useDate() {
},

formatDate: (date: number | Date | string): string => {
if (isNaN(new Date(date).getDate())) return "N/A";

const locale = getDateLocale();
return format(date, locale == enUS ? "MM/dd/yyyy" : "dd/MM/yyyy");
},
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/pages/game-details/hero/hero-panel.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const panel = recipe({
position: "sticky",
overflow: "hidden",
top: "0",
zIndex: "1",
zIndex: "2",
},
variants: {
stuck: {
Expand Down
9 changes: 6 additions & 3 deletions src/renderer/src/pages/game-details/hero/hero-panel.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { format } from "date-fns";
import { useContext } from "react";
import { useTranslation } from "react-i18next";

import { useDownload } from "@renderer/hooks";
import { useDate, useDownload } from "@renderer/hooks";

import { HeroPanelActions } from "./hero-panel-actions";
import * as styles from "./hero-panel.css";
Expand All @@ -17,6 +16,8 @@ export interface HeroPanelProps {
export function HeroPanel({ isHeaderStuck }: HeroPanelProps) {
const { t } = useTranslation("game_details");

const { formatDate } = useDate();

const { game, repacks, gameColor } = useContext(gameDetailsContext);

const { lastPacket } = useDownload();
Expand All @@ -29,7 +30,9 @@ export function HeroPanel({ isHeaderStuck }: HeroPanelProps) {
const [latestRepack] = repacks;

if (latestRepack) {
const lastUpdate = format(latestRepack.uploadDate!, "dd/MM/yyyy");
const lastUpdate = latestRepack.uploadDate
? formatDate(latestRepack.uploadDate!)
: "";
const repacksCount = repacks.length;

return (
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/pages/game-details/sidebar/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export function Sidebar() {
<div
style={{
position: "absolute",
zIndex: 2,
zIndex: 1,
inset: 0,
width: "100%",
height: "100%",
Expand Down

0 comments on commit 7d79048

Please sign in to comment.