mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-26 12:21:03 +00:00
first commit
This commit is contained in:
98
src/main/helpers/formatters.test.ts
Normal file
98
src/main/helpers/formatters.test.ts
Normal file
@@ -0,0 +1,98 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { describe, test } from "node:test";
|
||||
import {
|
||||
dodiFormatter,
|
||||
empressFormatter,
|
||||
fitGirlFormatter,
|
||||
kaosKrewFormatter,
|
||||
} from "./formatters";
|
||||
|
||||
describe("testing formatters", () => {
|
||||
describe("testing fitgirl formatter", () => {
|
||||
const fitGirlGames = [
|
||||
"REVEIL (v1.0.3f4 + 0.5 DLC, MULTi14) [FitGirl Repack]",
|
||||
"Dune: Spice Wars - The Ixian Edition (v2.0.0.31558 + DLC, MULTi9) [FitGirl Repack]",
|
||||
"HUMANKIND: Premium Edition (v1.0.22.3819 + 17 DLCs/Bonus Content, MULTi12) [FitGirl Repack, Selective Download - from 7.3 GB]",
|
||||
"Call to Arms: Gates of Hell - Ostfront: WW2 Bundle (v1.034 Hotfix 3 + 3 DLCs, MULTi9) [FitGirl Repack, Selective Download - from 21.8 GB]",
|
||||
"SUPER BOMBERMAN R 2 (v1.2.0, MULTi12) [FitGirl Repack]",
|
||||
"God of Rock (v3110, MULTi11) [FitGirl Repack]",
|
||||
];
|
||||
|
||||
test("should format games correctly", () => {
|
||||
assert.equal(fitGirlGames.map(fitGirlFormatter), [
|
||||
"REVEIL",
|
||||
"Dune: Spice Wars - The Ixian Edition",
|
||||
"HUMANKIND: Premium Edition",
|
||||
"Call to Arms: Gates of Hell - Ostfront: WW2 Bundle",
|
||||
"SUPER BOMBERMAN R 2",
|
||||
"God of Rock",
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("testing kaoskrew formatter", () => {
|
||||
const kaosKrewGames = [
|
||||
"Song.Of.Horror.Complete.Edition.v1.25.MULTi4.REPACK-KaOs",
|
||||
"Remoteness.REPACK-KaOs",
|
||||
"Persona.5.Royal.v1.0.0.MULTi5.NSW.For.PC.REPACK-KaOs",
|
||||
"The.Wreck.MULTi5.REPACK-KaOs",
|
||||
"Nemezis.Mysterious.Journey.III.v1.04.Deluxe.Edition.REPACK-KaOs",
|
||||
"The.World.Of.Others.v1.05.REPACK-KaOs",
|
||||
];
|
||||
|
||||
test("should format games correctly", () => {
|
||||
assert.equal(kaosKrewGames.map(kaosKrewFormatter), [
|
||||
"Song Of Horror Complete Edition",
|
||||
"Remoteness",
|
||||
"Persona 5 Royal NSW For PC",
|
||||
"The Wreck",
|
||||
"Nemezis Mysterious Journey III Deluxe Edition",
|
||||
"The World Of Others",
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("testing empress formatter", () => {
|
||||
const empressGames = [
|
||||
"Resident.Evil.4-EMPRESS",
|
||||
"Marvels.Guardians.of.the.Galaxy.Crackfix-EMPRESS",
|
||||
"Life.is.Strange.2.Complete.Edition-EMPRESS",
|
||||
"Forza.Horizon.4.PROPER-EMPRESS",
|
||||
"Just.Cause.4.Complete.Edition.READNFO-EMPRESS",
|
||||
"Immortals.Fenyx.Rising.Crackfix.V2-EMPRESS",
|
||||
];
|
||||
|
||||
test("should format games correctly", () => {
|
||||
assert.equal(empressGames.map(empressFormatter), [
|
||||
"Resident Evil 4",
|
||||
"Marvels Guardians of the Galaxy",
|
||||
"Life is Strange 2 Complete Edition",
|
||||
"Forza Horizon 4 PROPER",
|
||||
"Just Cause 4 Complete Edition",
|
||||
"Immortals Fenyx Rising",
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("testing kodi formatter", () => {
|
||||
const dodiGames = [
|
||||
"Tomb Raider I-III Remastered Starring Lara Croft (MULTi20) (From 2.5 GB) [DODI Repack]",
|
||||
"Trail Out: Complete Edition (v2.9st + All DLCs + MULTi11) [DODI Repack]",
|
||||
"Call to Arms - Gates of Hell: Ostfront (v1.034.0 + All DLCs + MULTi9) (From 22.4 GB) [DODI Repack]",
|
||||
"Metal Gear Solid 2: Sons of Liberty - HD Master Collection Edition (Digital book + MULTi6) [DODI Repack]",
|
||||
"DREDGE: Digital Deluxe Edition (v1.2.0.1922 + All DLCs + Bonus Content + MULTi11) (From 413 MB) [DODI Repack]",
|
||||
"Outliver: Tribulation [DODI Repack]",
|
||||
];
|
||||
|
||||
test("should format games correctly", () => {
|
||||
assert.equal(dodiGames.map(dodiFormatter), [
|
||||
"Tomb Raider I-III Remastered Starring Lara Croft",
|
||||
"Trail Out: Complete Edition",
|
||||
"Call to Arms - Gates of Hell: Ostfront",
|
||||
"Metal Gear Solid 2: Sons of Liberty - HD Master Collection Edition",
|
||||
"DREDGE: Digital Deluxe Edition",
|
||||
"Outliver: Tribulation",
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
54
src/main/helpers/formatters.ts
Normal file
54
src/main/helpers/formatters.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
/* String formatting */
|
||||
|
||||
export const removeReleaseYearFromName = (name: string) =>
|
||||
name.replace(/\([0-9]{4}\)/g, "");
|
||||
|
||||
export const removeSymbolsFromName = (name: string) =>
|
||||
name.replace(/[^A-Za-z 0-9]/g, "");
|
||||
|
||||
export const removeSpecialEditionFromName = (name: string) =>
|
||||
name.replace(
|
||||
/(The |Digital )?(GOTY|Deluxe|Standard|Ultimate|Definitive|Enhanced|Collector's|Premium|Digital|Limited|Game of the Year|Reloaded|[0-9]{4}) Edition/g,
|
||||
""
|
||||
);
|
||||
|
||||
export const removeDuplicateSpaces = (name: string) =>
|
||||
name.replace(/\s{2,}/g, " ");
|
||||
|
||||
export const removeTrash = (title: string) =>
|
||||
title.replace(/\(.*\)|\[.*]/g, "").replace(/:/g, "");
|
||||
|
||||
/* Formatters per repacker */
|
||||
|
||||
export const fitGirlFormatter = (title: string) =>
|
||||
title.replace(/\(.*\)/g, "").trim();
|
||||
|
||||
export const kaosKrewFormatter = (title: string) =>
|
||||
title
|
||||
.replace(/(v\.?[0-9])+([0-9]|\.)+/, "")
|
||||
.replace(
|
||||
/(\.Build\.[0-9]*)?(\.MULTi[0-9]{1,2})?(\.REPACK-KaOs|\.UPDATE-KaOs)?/g,
|
||||
""
|
||||
)
|
||||
.replace(/\./g, " ")
|
||||
.trim();
|
||||
|
||||
export const empressFormatter = (title: string) =>
|
||||
title
|
||||
.replace(/-EMPRESS/, "")
|
||||
.replace(/\./g, " ")
|
||||
.trim();
|
||||
|
||||
export const dodiFormatter = (title: string) =>
|
||||
title.replace(/\(.*?\)/g, "").trim();
|
||||
|
||||
export const xatabFormatter = (title: string) =>
|
||||
title
|
||||
.replace(/RePack от xatab|RePack от Decepticon|R.G. GOGFAN/, "")
|
||||
.replace(/[\u0400-\u04FF]/g, "")
|
||||
.replace(/(v\.?([0-9]| )+)+([0-9]|\.|-|_|\/|[a-zA-Z]| )+/, "");
|
||||
|
||||
export const tinyRepacksFormatter = (title: string) => title;
|
||||
|
||||
export const gogFormatter = (title: string) =>
|
||||
title.replace(/(v\.[0-9]+|v[0-9]+\.|v[0-9]{4})+.+/, "");
|
||||
83
src/main/helpers/index.ts
Normal file
83
src/main/helpers/index.ts
Normal file
@@ -0,0 +1,83 @@
|
||||
import {
|
||||
removeReleaseYearFromName,
|
||||
removeSymbolsFromName,
|
||||
removeSpecialEditionFromName,
|
||||
empressFormatter,
|
||||
kaosKrewFormatter,
|
||||
fitGirlFormatter,
|
||||
removeDuplicateSpaces,
|
||||
dodiFormatter,
|
||||
removeTrash,
|
||||
xatabFormatter,
|
||||
tinyRepacksFormatter,
|
||||
gogFormatter,
|
||||
} from "./formatters";
|
||||
import { months, repackers } from "../constants";
|
||||
|
||||
export const pipe =
|
||||
<T>(...fns: ((arg: T) => any)[]) =>
|
||||
(arg: T) =>
|
||||
fns.reduce((prev, fn) => fn(prev), arg);
|
||||
|
||||
export const formatName = pipe<string>(
|
||||
removeTrash,
|
||||
removeReleaseYearFromName,
|
||||
removeSymbolsFromName,
|
||||
removeSpecialEditionFromName,
|
||||
removeDuplicateSpaces,
|
||||
(str) => str.trim()
|
||||
);
|
||||
|
||||
export const repackerFormatter: Record<
|
||||
(typeof repackers)[number],
|
||||
(title: string) => string
|
||||
> = {
|
||||
DODI: dodiFormatter,
|
||||
"0xEMPRESS": empressFormatter,
|
||||
KaOsKrew: kaosKrewFormatter,
|
||||
FitGirl: fitGirlFormatter,
|
||||
Xatab: xatabFormatter,
|
||||
CPG: (title: string) => title,
|
||||
TinyRepacks: tinyRepacksFormatter,
|
||||
GOG: gogFormatter,
|
||||
};
|
||||
|
||||
export const formatUploadDate = (str: string) => {
|
||||
const date = new Date();
|
||||
|
||||
const [month, day, year] = str.split(" ");
|
||||
|
||||
date.setMonth(months.indexOf(month.replace(".", "")));
|
||||
date.setDate(Number(day.substring(0, 2)));
|
||||
date.setFullYear(Number("20" + year.replace("'", "")));
|
||||
date.setHours(0, 0, 0, 0);
|
||||
|
||||
return date;
|
||||
};
|
||||
|
||||
export const getSteamAppAsset = (
|
||||
category: "library" | "hero" | "logo" | "icon",
|
||||
objectID: string,
|
||||
clientIcon?: string
|
||||
) => {
|
||||
if (category === "library")
|
||||
return `https://steamcdn-a.akamaihd.net/steam/apps/${objectID}/header.jpg`;
|
||||
|
||||
if (category === "hero")
|
||||
return `https://steamcdn-a.akamaihd.net/steam/apps/${objectID}/library_hero.jpg`;
|
||||
|
||||
if (category === "logo")
|
||||
return `https://cdn.cloudflare.steamstatic.com/steam/apps/${objectID}/logo.png`;
|
||||
|
||||
return `https://cdn.cloudflare.steamstatic.com/steamcommunity/public/images/apps/${objectID}/${clientIcon}.ico`;
|
||||
};
|
||||
|
||||
export const getImageBase64 = async (url: string) =>
|
||||
fetch(url, { method: "GET" }).then((response) =>
|
||||
response.arrayBuffer().then((buffer) => {
|
||||
return `data:image/jpeg;base64,${Buffer.from(buffer).toString("base64")}`;
|
||||
})
|
||||
);
|
||||
|
||||
export * from "./formatters";
|
||||
export * from "./ps";
|
||||
12
src/main/helpers/ps.ts
Normal file
12
src/main/helpers/ps.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import psList from "ps-list";
|
||||
import { tasklist } from "tasklist";
|
||||
|
||||
export const getProcesses = async () => {
|
||||
if (process.platform === "win32") {
|
||||
return tasklist().then((tasks) =>
|
||||
tasks.map((task) => ({ ...task, name: task.imageName }))
|
||||
);
|
||||
}
|
||||
|
||||
return psList();
|
||||
};
|
||||
Reference in New Issue
Block a user