From 9f52acf2498685c74331d85810347b85a924fe22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4ki?= Date: Wed, 13 Nov 2024 16:32:00 +0200 Subject: [PATCH] Simplify ProfileUtils.readProfileFile Users can't pick r2x files anymore, so supporting only r2z files will suffice. Also renamed the argument and a variable to be more descriptive. --- src/utils/ProfileUtils.ts | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/utils/ProfileUtils.ts b/src/utils/ProfileUtils.ts index 7700227c..03fa8455 100644 --- a/src/utils/ProfileUtils.ts +++ b/src/utils/ProfileUtils.ts @@ -201,23 +201,18 @@ export async function populateImportedProfile( } } -export async function readProfileFile(file: string): Promise { - let read: string | null | undefined; - if (file.endsWith('.r2x')) { - read = (await FsProvider.instance.readFile(file)).toString(); - } else if (file.endsWith('.r2z')) { - await ZipProvider.instance.readFile(file, "export.r2x") - .then((value) => { read = value ? value.toString() : null; }) - .catch(() => { read = null }); - } +export async function readProfileFile(zipPath: string): Promise { + const profileContent = await ZipProvider.instance.readFile(zipPath, 'export.r2x') + .then((value) => value ? value.toString() : null) + .catch(() => null); - if (!read) { + if (!profileContent) { throw new R2Error( 'Error when reading file contents', 'Reading the .r2x file contents failed. The contents might be empty or corrupted.', ); } - return read; + return profileContent; } function throwForR2Error(maybeError: unknown) {