feat: enhance filename handling for patched ROMs with computed ROM extension and custom filename support

This commit is contained in:
zurdi
2025-12-22 19:11:50 +00:00
parent c27b0020d9
commit cf91a1923d
2 changed files with 19 additions and 7 deletions

View File

@@ -121,10 +121,15 @@ self.addEventListener("message", async (e) => {
const romBaseName = romFileName.replace(/\.[^.]+$/, "");
const romExtension = romFileName.match(/\.[^.]+$/)?.[0] || "";
const defaultFileName = `${romBaseName} (patched-${patchNameWithoutExt})${romExtension}`;
const finalFileName =
customFileName && customFileName.trim()
? customFileName
: defaultFileName;
// If custom filename provided, strip any extension and add ROM extension
let finalFileName;
if (customFileName && customFileName.trim()) {
const customBase = customFileName.trim().replace(/\.[^.]+$/, "");
finalFileName = `${customBase}${romExtension}`;
} else {
finalFileName = defaultFileName;
}
// Send back the result
self.postMessage(

View File

@@ -2,7 +2,7 @@
import { useDropZone } from "@vueuse/core";
import type { Emitter } from "mitt";
import { storeToRefs } from "pinia";
import { inject, ref, onMounted, watch } from "vue";
import { inject, ref, onMounted, watch, computed } from "vue";
import { useI18n } from "vue-i18n";
import MissingFromFSIcon from "@/components/common/MissingFromFSIcon.vue";
import PlatformIcon from "@/components/common/Platform/PlatformIcon.vue";
@@ -79,13 +79,19 @@ const { isOverDropZone: isOverPatchDropZone } = useDropZone(patchDropZoneRef, {
preventDefaultForUnhandled: true,
});
// Computed property for ROM extension
const romExtension = computed(() => {
if (!romFile.value) return "";
const match = romFile.value.name.match(/\.[^.]+$/);
return match ? match[0] : "";
});
// Update filename placeholder when files change
watch([romFile, patchFile], ([rom, patch]) => {
if (rom && patch) {
const romBaseName = rom.name.replace(/\.[^.]+$/, "");
const romExtension = rom.name.match(/\.[^.]+$/)?.[0] || "";
const patchNameWithoutExt = patch.name.replace(/\.[^.]+$/, "");
filenamePlaceholder.value = `${romBaseName} (patched-${patchNameWithoutExt})${romExtension}`;
filenamePlaceholder.value = `${romBaseName} (patched-${patchNameWithoutExt})`;
} else {
filenamePlaceholder.value = "";
}
@@ -761,6 +767,7 @@ onMounted(async () => {
<v-text-field
v-model="customFileName"
:placeholder="filenamePlaceholder"
:suffix="romExtension"
label="Output filename (optional)"
variant="outlined"
density="compact"