filenames

This commit is contained in:
2026-05-27 22:42:19 +08:00
parent 92de00b52e
commit 3f86aeaf0c
2 changed files with 59 additions and 7 deletions

View File

@@ -9,6 +9,7 @@ const store: { panel: vscode.WebviewPanel | null } = { panel: null };
interface ConvertOptions {
sourcePath: string;
outputDir: string;
baseName?: string;
networks: string[];
}
@@ -38,7 +39,7 @@ export function openPlayworksConverter(_context: vscode.ExtensionContext) {
if (!picked?.[0]) return;
const srcPath = picked[0].fsPath;
const dir = path.dirname(srcPath);
panel.webview.postMessage({ type: 'sourcePicked', path: srcPath, dir });
panel.webview.postMessage({ type: 'sourcePicked', path: srcPath, dir, baseName: sourceBaseName(srcPath) });
break;
}
case 'pickOutput': {
@@ -111,10 +112,17 @@ function sourceBaseName(sourcePath: string): string {
.replace(/_(?:un|al|is|fb|gg|mo|vu|mtg|tt)$/, '');
}
function outputBaseName(opts: ConvertOptions): string {
const rawBaseName = opts.baseName?.trim() || sourceBaseName(opts.sourcePath);
const withoutExtension = rawBaseName.replace(/\.html?$/i, '');
const safeBaseName = path.basename(withoutExtension).replace(/[<>:"/\\|?*]/g, '_').trim();
return safeBaseName || sourceBaseName(opts.sourcePath);
}
async function convertNetwork(html: string, opts: ConvertOptions, network: string): Promise<string> {
const transformed = transformHtml(html, network);
const needsZip = ZIPPED_NETWORKS.has(network);
const baseName = sourceBaseName(opts.sourcePath);
const baseName = outputBaseName(opts);
const htmlFileName = `${baseName}_${network}.html`;
const outputDir = path.join(opts.outputDir, NETWORK_OUTPUT_FOLDERS[network] ?? network);
fs.mkdirSync(outputDir, { recursive: true });
@@ -384,6 +392,13 @@ function getHtml(): string {
</div>
</div>
<div class="section">
<div class="section-label">Base Filename</div>
<div class="row">
<input id="baseName" type="text" placeholder="Base filename..." />
</div>
</div>
<div class="section">
<div class="section-label">Output Folder</div>
<div class="row">
@@ -417,6 +432,7 @@ function getHtml(): string {
const srcEl = document.getElementById('src');
const outEl = document.getElementById('outDir');
const baseNameEl = document.getElementById('baseName');
const convertBtn = document.getElementById('convert');
const openOutBtn = document.getElementById('openOut');
const statusEl = document.getElementById('status');
@@ -424,7 +440,7 @@ function getHtml(): string {
function updateConvertBtn() {
const hasNet = [...document.querySelectorAll('.net-cb')].some(c => c.checked);
convertBtn.disabled = !srcEl.value || !outEl.value || !hasNet;
convertBtn.disabled = !srcEl.value || !outEl.value || !baseNameEl.value.trim() || !hasNet;
}
document.getElementById('pickSrc').addEventListener('click', () => vscode.postMessage({ type: 'pickSource' }));
@@ -439,6 +455,7 @@ function getHtml(): string {
});
document.querySelectorAll('.net-cb').forEach(c => c.addEventListener('change', updateConvertBtn));
outEl.addEventListener('input', updateConvertBtn);
baseNameEl.addEventListener('input', updateConvertBtn);
openOutBtn.addEventListener('click', () => {
if (outputDir) vscode.postMessage({ type: 'openOutput', dir: outputDir });
@@ -461,6 +478,7 @@ function getHtml(): string {
opts: {
sourcePath: srcEl.value,
outputDir: outEl.value,
baseName: baseNameEl.value,
networks,
},
});
@@ -470,6 +488,7 @@ function getHtml(): string {
const msg = event.data;
if (msg.type === 'sourcePicked') {
srcEl.value = msg.path;
baseNameEl.value = msg.baseName || '';
if (!outEl.value && msg.dir) {
outEl.value = msg.dir;
outputDir = msg.dir;