mirror of
https://github.com/alula/hbpatcher.git
synced 2025-11-24 10:34:55 +00:00
Add support for .ovl file extension and refactor it slightly
This commit is contained in:
parent
a2a5a2995a
commit
74b699cc3c
@ -1,5 +1,6 @@
|
||||
import { FileDown } from "lucide-react";
|
||||
import { useRef, useState } from "react";
|
||||
import { SUPPORTED_EXTENSIONS } from "../constants";
|
||||
|
||||
interface FileDropZoneProps {
|
||||
onFileSelected: (file: File) => void;
|
||||
@ -32,11 +33,7 @@ export function FileDropZone({ onFileSelected }: FileDropZoneProps) {
|
||||
setIsDragging(false);
|
||||
|
||||
const files = Array.from(e.dataTransfer.files);
|
||||
const nroFile = files.find((file) => file.name.endsWith(".nro"));
|
||||
|
||||
if (nroFile) {
|
||||
onFileSelected(nroFile);
|
||||
} else if (files.length > 0) {
|
||||
if (files.length > 0) {
|
||||
onFileSelected(files[0]);
|
||||
}
|
||||
};
|
||||
@ -81,7 +78,6 @@ export function FileDropZone({ onFileSelected }: FileDropZoneProps) {
|
||||
<input
|
||||
ref={fileInputRef}
|
||||
type="file"
|
||||
accept=".nro"
|
||||
onChange={handleFileInput}
|
||||
className="hidden"
|
||||
/>
|
||||
@ -90,9 +86,11 @@ export function FileDropZone({ onFileSelected }: FileDropZoneProps) {
|
||||
<FileDown size={48} strokeWidth={1.5} />
|
||||
</div>
|
||||
<h3 className="text-switch-text text-xl font-normal">
|
||||
{isDragging ? "Drop file now" : "Select NRO File"}
|
||||
{isDragging ? "Drop file now" : "Select File"}
|
||||
</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>
|
||||
);
|
||||
|
||||
4
src/constants.ts
Normal file
4
src/constants.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export const SUPPORTED_EXTENSIONS = [".nro", ".ovl"] as const;
|
||||
|
||||
export type SupportedExtension = (typeof SUPPORTED_EXTENSIONS)[number];
|
||||
|
||||
@ -64,8 +64,16 @@ export function PatcherPage({ appendSuffix }: PatcherPageProps) {
|
||||
|
||||
let downloadName = currentFile.name;
|
||||
if (appendSuffix) {
|
||||
downloadName = downloadName.replace(/\.nro$/i, "_patched.nro");
|
||||
if (downloadName === currentFile.name) downloadName += "_patched.nro";
|
||||
const extensionMatch = downloadName.match(/\.(nro|ovl)$/i);
|
||||
if (extensionMatch) {
|
||||
const ext = extensionMatch[1].toLowerCase();
|
||||
downloadName = downloadName.replace(
|
||||
new RegExp(`\\.${ext}$`, "i"),
|
||||
`_patched.${ext}`,
|
||||
);
|
||||
} else {
|
||||
downloadName += "_patched";
|
||||
}
|
||||
}
|
||||
|
||||
a.download = downloadName;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user