Add support for .ovl file extension and refactor it slightly

This commit is contained in:
Alula 2025-11-24 01:58:07 +01:00
parent a2a5a2995a
commit 74b699cc3c
No known key found for this signature in database
GPG Key ID: 3E00485503A1D8BA
3 changed files with 20 additions and 10 deletions

View File

@ -1,5 +1,6 @@
import { FileDown } from "lucide-react"; import { FileDown } from "lucide-react";
import { useRef, useState } from "react"; import { useRef, useState } from "react";
import { SUPPORTED_EXTENSIONS } from "../constants";
interface FileDropZoneProps { interface FileDropZoneProps {
onFileSelected: (file: File) => void; onFileSelected: (file: File) => void;
@ -32,11 +33,7 @@ export function FileDropZone({ onFileSelected }: FileDropZoneProps) {
setIsDragging(false); setIsDragging(false);
const files = Array.from(e.dataTransfer.files); const files = Array.from(e.dataTransfer.files);
const nroFile = files.find((file) => file.name.endsWith(".nro")); if (files.length > 0) {
if (nroFile) {
onFileSelected(nroFile);
} else if (files.length > 0) {
onFileSelected(files[0]); onFileSelected(files[0]);
} }
}; };
@ -81,7 +78,6 @@ export function FileDropZone({ onFileSelected }: FileDropZoneProps) {
<input <input
ref={fileInputRef} ref={fileInputRef}
type="file" type="file"
accept=".nro"
onChange={handleFileInput} onChange={handleFileInput}
className="hidden" className="hidden"
/> />
@ -90,9 +86,11 @@ export function FileDropZone({ onFileSelected }: FileDropZoneProps) {
<FileDown size={48} strokeWidth={1.5} /> <FileDown size={48} strokeWidth={1.5} />
</div> </div>
<h3 className="text-switch-text text-xl font-normal"> <h3 className="text-switch-text text-xl font-normal">
{isDragging ? "Drop file now" : "Select NRO File"} {isDragging ? "Drop file now" : "Select File"}
</h3> </h3>
<p className="text-switch-text-info">Drag & drop or click to browse</p> <p className="text-switch-text-info">
Drag & drop or click to browse ({SUPPORTED_EXTENSIONS.join(", ")})
</p>
</div> </div>
</div> </div>
); );

4
src/constants.ts Normal file
View File

@ -0,0 +1,4 @@
export const SUPPORTED_EXTENSIONS = [".nro", ".ovl"] as const;
export type SupportedExtension = (typeof SUPPORTED_EXTENSIONS)[number];

View File

@ -64,8 +64,16 @@ export function PatcherPage({ appendSuffix }: PatcherPageProps) {
let downloadName = currentFile.name; let downloadName = currentFile.name;
if (appendSuffix) { if (appendSuffix) {
downloadName = downloadName.replace(/\.nro$/i, "_patched.nro"); const extensionMatch = downloadName.match(/\.(nro|ovl)$/i);
if (downloadName === currentFile.name) downloadName += "_patched.nro"; if (extensionMatch) {
const ext = extensionMatch[1].toLowerCase();
downloadName = downloadName.replace(
new RegExp(`\\.${ext}$`, "i"),
`_patched.${ext}`,
);
} else {
downloadName += "_patched";
}
} }
a.download = downloadName; a.download = downloadName;