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 { 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
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;
|
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;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user