fix(linux): search for info file case insensitively

On linux only exactly Info.dat was matched, and many maps use different casing.
This commit is contained in:
RedlineTriad
2023-06-28 22:53:26 +02:00
parent 90d4ebc7e3
commit 17a2bc552e
2 changed files with 34 additions and 19 deletions
+21 -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,21 @@ 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 files = await readdir(folderPath, {withFileTypes: true});
const promises = files.map(async file => {
if(file.isFile()){ return path.join(folderPath, file.name); }
return undefined;
});
return (await Promise.all(promises)).filter(file => file);
}
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 +74,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 +105,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 +119,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 infoFilePaths = files
.filter(file => (path.basename(file).toLowerCase() === "info.dat"))
if(!(await pathExist(infoFilePath))){ return null; }
if(infoFilePaths.length === 0){ return null; }
const rawInfoString = await readFile(infoFilePath, {encoding: "utf-8"});
const rawInfoString = await readFile(infoFilePaths[0], {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));
}
}
}