diff --git a/src/main/ipcs/beat-saver-ipcs.ts b/src/main/ipcs/beat-saver-ipcs.ts index 980666b1..1c9b6c9f 100644 --- a/src/main/ipcs/beat-saver-ipcs.ts +++ b/src/main/ipcs/beat-saver-ipcs.ts @@ -3,6 +3,7 @@ import { UtilsService } from "../services/utils.service"; import { IpcRequest } from "shared/models/ipc"; import { SearchParams } from "shared/models/maps/beat-saver.model"; import { BeatSaverService } from "../services/thrid-party/beat-saver/beat-saver.service"; +import log from "electron-log"; ipcMain.on("bsv-search-map", async (event, request: IpcRequest) => { const utlis = UtilsService.getInstance(); @@ -22,6 +23,7 @@ ipcMain.on("bsv-get-map-details-from-hashs", async (event, request: IpcRequest { utlis.ipcSend(request.responceChannel, {success: true, data: maps}); }).catch(e => { + log.error(e); utlis.ipcSend(request.responceChannel, {success: false, error: e}); }) }); diff --git a/src/main/services/additional-content/local-maps-manager.service.ts b/src/main/services/additional-content/local-maps-manager.service.ts index 972593c5..859b3d54 100644 --- a/src/main/services/additional-content/local-maps-manager.service.ts +++ b/src/main/services/additional-content/local-maps-manager.service.ts @@ -6,19 +6,17 @@ import { BSLocalVersionService } from "../bs-local-version.service"; import { InstallationLocationService } from "../installation-location.service"; import { UtilsService } from "../utils.service"; import crypto from "crypto"; -import { lstatSync, symlinkSync, unlinkSync, readdirSync, createWriteStream } from "fs"; +import { lstatSync, symlinkSync, unlinkSync } from "fs"; import { copy, copySync } from "fs-extra"; import StreamZip from "node-stream-zip"; import { RequestService } from "../request.service"; import sanitize from "sanitize-filename"; -import archiver from "archiver"; import { DeepLinkService } from "../deep-link.service"; import log from 'electron-log'; import { WindowManagerService } from "../window-manager.service"; import { ipcMain } from "electron"; import { IpcRequest } from 'shared/models/ipc'; import { Observable } from "rxjs"; -import { defer } from "rxjs"; import { Archive } from "../../models/archive.class"; export class LocalMapsManagerService { @@ -53,12 +51,12 @@ export class LocalMapsManagerService { this.deepLink = DeepLinkService.getInstance(); this.windows = WindowManagerService.getInstance(); - this.deepLink.addLinkOpenedListener(this.DEEP_LINKS.BeatSaver, (link) => { + this.deepLink.addLinkOpenedListener(this.DEEP_LINKS.BeatSaver, link => { log.info("DEEP-LINK RECEIVED FROM", this.DEEP_LINKS.BeatSaver, link); this.openOneClickDownloadMapWindow(new URL(link).host); }); - this.deepLink.addLinkOpenedListener(this.DEEP_LINKS.ScoreSaber, (link) => { + this.deepLink.addLinkOpenedListener(this.DEEP_LINKS.ScoreSaber, link => { log.info("DEEP-LINK RECEIVED FROM", this.DEEP_LINKS.ScoreSaber, link); this.openOneClickDownloadMapWindow(new URL(link).host, true); }); @@ -76,18 +74,16 @@ export class LocalMapsManagerService { private async computeMapHash(mapPath: string, rawInfoString: string): Promise{ const mapRawInfo = JSON.parse(rawInfoString); - let content = rawInfoString; + const shasum = crypto.createHash("sha1"); + shasum.update(rawInfoString); for(const set of mapRawInfo._difficultyBeatmapSets){ for(const diff of set._difficultyBeatmaps){ const diffFilePath = path.join(mapPath, diff._beatmapFilename); - if(!await this.utils.pathExist(diffFilePath)){ continue; } - const diffContent = (await this.utils.readFileAsync(diffFilePath)).toString(); - content += diffContent; + const diffContent = await this.utils.readFileAsync(diffFilePath).catch(() => null); + diffContent && shasum.update(diffContent); } } - - const shasum = crypto.createHash("sha1"); - shasum.update(content); + return shasum.digest("hex"); } @@ -96,7 +92,7 @@ export class LocalMapsManagerService { if(!(await this.utils.pathExist(infoFilePath))){ return null; } - const rawInfoString = await (await (this.utils.readFileAsync(infoFilePath))).toString(); + const rawInfoString = await this.utils.readFileAsync(infoFilePath); const rawInfo: RawMapInfoData = JSON.parse(rawInfoString); const coverUrl = new URL(`file:///${path.join(mapPath, rawInfo._coverImageFilename)}`).href; @@ -145,14 +141,22 @@ export class LocalMapsManagerService { progression.total = levelsPaths.length; - for(const levelPath of levelsPaths){ + const promises = levelsPaths.map(async levelPath => { const mapInfo = await this.loadMapInfoFromPath(levelPath); - if(mapInfo){ - progression.maps.push(mapInfo); - progression.loaded = progression.maps.length; - observer.next({...progression, maps: []}); + if(!mapInfo){ return null; } + progression.loaded++; + observer.next(progression); + return mapInfo; + }); + + const mapsInfo = (await Promise.allSettled(promises)).reduce((acc, mapInfo) => { + if(mapInfo.status === "fulfilled" && mapInfo.value){ + acc.push(mapInfo.value); } - } + return acc; + } ,[] as BsmLocalMap[]); + + progression.maps = mapsInfo; observer.next(progression); @@ -222,7 +226,6 @@ export class LocalMapsManagerService { observer.next(progress); } }catch(e){ - console.log(e); observer.error(e); } observer.complete(); diff --git a/src/main/services/bs-version-lib.service.ts b/src/main/services/bs-version-lib.service.ts index 1ffe437b..c6121bc1 100644 --- a/src/main/services/bs-version-lib.service.ts +++ b/src/main/services/bs-version-lib.service.ts @@ -35,7 +35,7 @@ export class BSVersionLibService{ private async getLocalVersions(): Promise{ const localVersionsPath = path.join(this.utilsService.getAssestsJsonsPath(), this.VERSIONS_FILE); - const rawVersion = (await this.utilsService.readFileAsync(localVersionsPath)).toString(); + const rawVersion = await this.utilsService.readFileAsync(localVersionsPath); return JSON.parse(rawVersion); } diff --git a/src/main/services/ipc.service.ts b/src/main/services/ipc.service.ts index 7f7665ea..e6b64796 100644 --- a/src/main/services/ipc.service.ts +++ b/src/main/services/ipc.service.ts @@ -47,7 +47,6 @@ export class IpcService { observable.subscribe(data => { this.send(channel, window, data); }, error => { - console.log("LAAAA 2", error); this.send(this.getErrorChannel(channel), window, error); }, () => { this.send(this.getCompleteChannel(channel), window); diff --git a/src/main/services/supporters.service.ts b/src/main/services/supporters.service.ts index 5bb59130..14d1c628 100644 --- a/src/main/services/supporters.service.ts +++ b/src/main/services/supporters.service.ts @@ -43,7 +43,7 @@ export class SupportersService { private async getLocalSupporters(): Promise{ const patreonsPath = path.join(this.utilsService.getAssestsJsonsPath(), this.PATREONS_FILE); - const rawPatreons = (await this.utilsService.readFileAsync(patreonsPath)).toString(); + const rawPatreons = await this.utilsService.readFileAsync(patreonsPath); return JSON.parse(rawPatreons); } diff --git a/src/main/services/thrid-party/beat-saver/beat-saver.service.ts b/src/main/services/thrid-party/beat-saver/beat-saver.service.ts index 087f2861..619293ed 100644 --- a/src/main/services/thrid-party/beat-saver/beat-saver.service.ts +++ b/src/main/services/thrid-party/beat-saver/beat-saver.service.ts @@ -32,7 +32,7 @@ export class BeatSaverService { return res; }, [] as BsvMapDetail[]); - await Promise.all(chunkHash.map(async hashs => { + await Promise.allSettled(chunkHash.map(async hashs => { const res = await this.bsaverApi.getMapsDetailsByHashs(hashs); if(res.status === 200){ diff --git a/src/main/services/utils.service.ts b/src/main/services/utils.service.ts index 5735bc4c..ed3af52d 100644 --- a/src/main/services/utils.service.ts +++ b/src/main/services/utils.service.ts @@ -9,6 +9,7 @@ import { IpcResponse } from "shared/models/ipc"; import log from "electron-log"; import { AppWindow } from "shared/models/window-manager/app-window.model"; + // TODO : REFACTOR export class UtilsService{ @@ -64,8 +65,8 @@ export class UtilsService{ } public readFileAsync(path: string){ - return new Promise((resolve, reject) => { - readFile(path, (err, data) => { + return new Promise((resolve, reject) => { + readFile(path, {encoding: "utf-8", flag: "r"}, (err, data) => { if(err){ reject(err); } else{ resolve(data); } }); @@ -73,9 +74,12 @@ export class UtilsService{ } public listDirsInDir(dirPath: string, fullPath = false): string[]{ - let files = readdirSync(dirPath, { withFileTypes:true}); - files = files.filter(f => f.isDirectory()) - return files.map(f => fullPath ? path.join(dirPath, f.name) : f.name); + let files = readdirSync(dirPath, { withFileTypes:true }); + return files.reduce((acc, f) => { + if(!f.isDirectory()){ return acc; } + acc.push(fullPath ? path.join(dirPath, f.name) : f.name); + return acc; + }, []); } public async deleteFolder(folderPath: string): Promise{ diff --git a/src/renderer/components/maps-mangement-components/filter-panel.component.tsx b/src/renderer/components/maps-mangement-components/filter-panel.component.tsx index 23bd8477..293bc4e8 100644 --- a/src/renderer/components/maps-mangement-components/filter-panel.component.tsx +++ b/src/renderer/components/maps-mangement-components/filter-panel.component.tsx @@ -51,7 +51,6 @@ export function FilterPanel({className, ref, playlist = false, filter, onChange, firstRun.current = false; return; } - console.log(filter, firstFilter); setHaveChanged(() => !equal(filter, firstFilter)); }, [filter]) diff --git a/src/renderer/components/maps-mangement-components/local-maps-list-panel.component.tsx b/src/renderer/components/maps-mangement-components/local-maps-list-panel.component.tsx index 53e659a7..23163db2 100644 --- a/src/renderer/components/maps-mangement-components/local-maps-list-panel.component.tsx +++ b/src/renderer/components/maps-mangement-components/local-maps-list-panel.component.tsx @@ -117,7 +117,6 @@ export const LocalMapsListPanel = forwardRef(({version, className, filter, searc const loadMapsObs$ = mapsManager.getMaps(version); loadMapsObs$.pipe(map(progess => { - console.log(progess); return Math.floor(((progess.loaded / progess.total) * 100)); })).subscribe(percent => loadPercent$.next(percent)); diff --git a/src/renderer/pages/version-viewer.component.tsx b/src/renderer/pages/version-viewer.component.tsx index 0d6b00ab..ab5b9a19 100644 --- a/src/renderer/pages/version-viewer.component.tsx +++ b/src/renderer/pages/version-viewer.component.tsx @@ -29,7 +29,6 @@ export function VersionViewer() { const [currentTabIndex, setCurrentTabIndex] = useState(0); const navigateToVersion = (version?: BSVersion) => { - console.log(version); if(!version){ return navigate("/available-versions"); } diff --git a/src/renderer/services/maps-manager.service.ts b/src/renderer/services/maps-manager.service.ts index b4ba9147..75f43f61 100644 --- a/src/renderer/services/maps-manager.service.ts +++ b/src/renderer/services/maps-manager.service.ts @@ -115,8 +115,6 @@ export class MapsManagerService { const progress$ = this.ipcService.sendV2("delete-maps", {args: maps}).pipe(map(progress => (progress.deleted / progress.total) * 100)); - progress$.subscribe(console.log); - showProgressBar && this.progressBar.show(progress$, true); progress$.toPromise().finally(() => this.progressBar.hide(true));