Merge pull request #264 from RedlineTriad/fix-info-loading

fix(linux): search for info file case insensitively
This commit is contained in:
MathieuG-P
2023-06-29 22:15:14 +02:00
committed by GitHub
2 changed files with 31 additions and 19 deletions
+18 -8
View File
@@ -12,7 +12,7 @@ export async function pathExist(path: string): Promise<boolean> {
}catch(e){
return false;
}
}
export async function ensureFolderExist(path: string): Promise<void> {
@@ -52,8 +52,18 @@ export async function getFoldersInFolder(folderPath: string, opts?: {ignoreSymli
return (await Promise.all(promises)).filter(folder => folder);
}
export function moveFolderContent(src: string, dest: string): Observable<Progression>{
const progress: Progression = { current: 0, total: 0 };
export async function getFilesInFolder(folderPath: string): Promise<string[]> {
if(!(await pathExist(folderPath))){ return []; }
const dirEntries = await readdir(folderPath, {withFileTypes: true})
return dirEntries
.filter(entry => entry.isFile())
.map(file => path.join(folderPath, file.name));
}
export function moveFolderContent(src: string, dest: string): Observable<Progression>{
const progress: Progression = { current: 0, total: 0 };
return new Observable<Progression>(subscriber => {
subscriber.next(progress);
(async () => {
@@ -61,7 +71,7 @@ export function moveFolderContent(src: string, dest: string): Observable<Progres
const srcExist = await pathExist(src);
if(!srcExist){ return subscriber.complete(); }
ensureFolderExist(dest);
const files = await readdir(src, {encoding: "utf-8"});
@@ -92,9 +102,9 @@ export function isSubdirectory(parent: string, child: string): boolean {
if (parentNormalized === childNormalized) { return false; }
const relativePath = path.relative(parentNormalized, childNormalized);
if (path.parse(parentNormalized).root !== path.parse(childNormalized).root) { return false; }
return relativePath && !relativePath.startsWith('..') && !path.isAbsolute(relativePath);
}
@@ -106,11 +116,11 @@ export async function copyDirectoryWithJunctions(src: string, dest: string, opti
await ensureDir(dest);
const items = await readdir(src, { withFileTypes: true });
for (const item of items) {
const sourcePath = path.join(src, item.name);
const destinationPath = path.join(dest, item.name);
if (item.isDirectory()) {
await copyDirectoryWithJunctions(sourcePath, destinationPath, options);
} else if (item.isFile()) {
@@ -18,7 +18,7 @@ import { ipcMain } from "electron";
import { IpcRequest } from 'shared/models/ipc';
import { Observable, lastValueFrom } from "rxjs";
import { Archive } from "../../models/archive.class";
import { deleteFolder, ensureFolderExist, getFoldersInFolder, pathExist } from "../../helpers/fs.helpers";
import { deleteFolder, ensureFolderExist, getFilesInFolder, getFoldersInFolder, pathExist } from "../../helpers/fs.helpers";
import { readFile } from "fs/promises";
import { FolderLinkerService } from "../folder-linker.service";
import { allSettled } from "../../../shared/helpers/promise.helpers";
@@ -90,23 +90,25 @@ export class LocalMapsManagerService {
diffContent && shasum.update(diffContent);
}
}
return shasum.digest("hex");
}
private async loadMapInfoFromPath(mapPath: string): Promise<BsmLocalMap>{
const infoFilePath = path.join(mapPath, "Info.dat");
const files = await getFilesInFolder(mapPath);
const infoFile = files
.find(file => (path.basename(file).toLowerCase() === "info.dat"))
if(!(await pathExist(infoFilePath))){ return null; }
if(infoFile === null){ return null; }
const rawInfoString = await readFile(infoFilePath, {encoding: "utf-8"});
const rawInfoString = await readFile(infoFile, {encoding: "utf-8"});
const rawInfo: RawMapInfoData = JSON.parse(rawInfoString);
const coverUrl = new URL(`file:///${path.join(mapPath, rawInfo._coverImageFilename)}`).href;
const songUrl = new URL(`file:///${path.join(mapPath, rawInfo._songFilename)}`).href;
const hash = await this.computeMapHash(mapPath, rawInfoString);
return {rawInfo, coverUrl, songUrl, hash, path: mapPath};
}
@@ -127,7 +129,7 @@ export class LocalMapsManagerService {
ipcMain.once("one-click-map-info", async (event, req: IpcRequest<void>) => {
this.utils.ipcSend(req.responceChannel, {success: true, data: {id: mapId, isHash}});
});
this.windows.openWindow("oneclick-download-map.html");
}
@@ -189,7 +191,7 @@ export class LocalMapsManagerService {
}
public deleteMaps(maps: BsmLocalMap[]): Observable<DeleteMapsProgress>{
const mapsFolders = maps.map(map => map.path);
const mapsHashsToDelete = maps.map(map => map.hash);
@@ -244,7 +246,7 @@ export class LocalMapsManagerService {
public async exportMaps(version: BSVersion, maps: BsmLocalMap[], outPath: string){
const archive = new Archive(outPath);
if(!maps || maps.length === 0){
const mapsFolder = await this.getMapsFolderPath(version);
archive.addDirectory(mapsFolder, false);
@@ -290,4 +292,4 @@ export class LocalMapsManagerService {
return Array.from(Object.values(this.DEEP_LINKS)).every(link => this.deepLink.isDeepLinkRegistred(link));
}
}
}