chore: add file downloading for ezpplauncher files, add ui replacement

This commit is contained in:
2025-07-04 14:56:47 +02:00
parent 41608afae2
commit 7e524debb9
11 changed files with 583 additions and 78 deletions

View File

@@ -1,7 +1,7 @@
import { exists, mkdir, readTextFile, writeFile } from '@tauri-apps/plugin-fs';
import * as path from '@tauri-apps/api/path';
import { invoke } from '@tauri-apps/api/core';
import { Crypto } from './crypto';
import { getHWID } from './osuUtil';
export class Config {
private fileName: string;
@@ -16,7 +16,7 @@ export class Config {
}
async init(): Promise<boolean> {
const hwid: string = (await invoke('get_hwid')) ?? 'recorderinsandybridge';
const hwid = (await getHWID()) ?? 'recorderinsandybridge';
this.crypto = new Crypto(hwid);

View File

@@ -1,4 +1,23 @@
import { invoke } from '@tauri-apps/api/core';
import type { UpdateFile, UpdateStatus } from './types';
import { listen } from '@tauri-apps/api/event';
const updateUrl = 'https://ez-pp.farm/ezpplauncher';
export const getHWID = async () => {
const hwid = await invoke('get_hwid');
return typeof hwid === 'string' ? hwid : undefined;
};
export const isValidOsuFolder = async (folder: string): Promise<boolean> => {
const result = await invoke('valid_osu_folder', { folder });
return typeof result === 'boolean' ? result : false;
};
export const autoDetectOsuInstallFolder = async () => {
const result = await invoke('find_osu_installation');
return typeof result === 'string' ? result : undefined;
};
export const setUserConfigValues = async (
osuFolderPath: string,
@@ -22,3 +41,71 @@ export const getReleaseStream = async (folder: string) => {
const result = await invoke('get_osu_release_stream', { folder });
return typeof result === 'string' ? result : undefined;
};
export const getVersion = async (folder: string) => {
const result = await invoke('get_osu_version', { folder });
return typeof result === 'string' ? result : undefined;
};
export const getBeatmapSetsCount = async (folder: string) => {
const result = await invoke('get_beatmapsets_count', {
folder,
});
return typeof result === 'number' ? result : 0;
};
export const getSkinsCount = async (folder: string) => {
const result = await invoke('get_skins_count', {
folder,
});
return typeof result === 'number' ? result : 0;
};
export const getSkin = async (folder: string) => {
const result = await invoke('get_osu_skin', {
folder,
});
return typeof result === 'string' ? result : 'Default';
};
export const runUpdater = async (folder: string) => await invoke('run_osu_updater', { folder });
export const runOsu = async (folder: string) => await invoke('run_osu', { folder });
export const getEZPPLauncherUpdateFiles = async (folder: string) => {
const result = await invoke('get_ezpp_launcher_update_files', { folder, updateUrl });
if (typeof result === 'object') {
const [filesToDownload, updateFiles] = result as [UpdateFile[], UpdateFile[]];
return {
filesToDownload,
updateFiles,
};
}
return undefined;
};
export const downloadEZPPLauncherUpdateFiles = async (
folder: string,
updateFiles: UpdateFile[],
allFiles: UpdateFile[],
progressCallback: (file: UpdateStatus) => void
) => {
const downloadStatusListen = await listen('download-progress', (event) =>
progressCallback(event.payload as UpdateStatus)
);
try {
await invoke('download_ezpp_launcher_update_files', { folder, updateFiles, allFiles });
} finally {
downloadStatusListen();
}
};
export const replaceUIFiles = async (folder: string, revert: boolean) => {
await invoke('replace_ui_files', { folder, revert });
};
export const isOsuRunning = async () => {
const result = await invoke('is_osu_running');
return typeof result === 'boolean' ? result : false;
};

View File

@@ -119,3 +119,18 @@ export type StreamsResult = {
user_count: number;
}[];
};
export type UpdateFile = {
folder: string;
md5: string;
name: string;
size: number;
url: string;
};
export type UpdateStatus = {
fileName: string;
downloaded: number;
size: number;
progress: number;
};

View File

@@ -81,3 +81,15 @@ export const compareBuildNumbers = (current: string, target: string): number =>
return -1;
}
};
export const formatBytes = (bytes: number, decimals = 2) => {
if (!bytes) return '0 B';
const k = 1024;
const dm = decimals < 0 ? 0 : decimals;
const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))}${sizes[i]}`;
};