diff --git a/hpl-toolbox-0.1.1.vsix b/hpl-toolbox-0.1.1.vsix index 6347af2..d837217 100644 Binary files a/hpl-toolbox-0.1.1.vsix and b/hpl-toolbox-0.1.1.vsix differ diff --git a/src/tools/base64Scanner.ts b/src/tools/base64Scanner.ts index 66959ee..2741be1 100644 --- a/src/tools/base64Scanner.ts +++ b/src/tools/base64Scanner.ts @@ -29,19 +29,39 @@ export function openBase64Scanner(_context: vscode.ExtensionContext) { if (picked && picked[0]) { panel.webview.postMessage({ type: 'folderPicked', path: picked[0].fsPath }); } + } else if (msg.type === 'pickFiles') { + const picked = await vscode.window.showOpenDialog({ + canSelectFolders: false, + canSelectFiles: true, + canSelectMany: true, + openLabel: 'Select Files', + filters: { 'HTML': ['html', 'htm'] }, + }); + if (picked && picked.length) { + panel.webview.postMessage({ type: 'filesPicked', paths: picked.map(u => u.fsPath) }); + } } else if (msg.type === 'scan') { - const folder: string = msg.folder; - if (!folder || !fs.existsSync(folder)) { - panel.webview.postMessage({ type: 'results', results: [], error: 'Invalid folder' }); + const folder: string | undefined = msg.folder; + const files: string[] | undefined = msg.files; + let targets: string[] = []; + let baseDir = ''; + if (files && files.length) { + targets = files.filter(f => fs.existsSync(f)); + baseDir = targets.length ? commonBaseDir(targets) : ''; + } else if (folder && fs.existsSync(folder)) { + targets = await collectHtmlFiles(folder); + baseDir = folder; + } else { + panel.webview.postMessage({ type: 'results', results: [], error: 'Pick a folder or files first' }); return; } - const htmlFiles = await collectHtmlFiles(folder); const results: { file: string; ok: boolean; assets: string[] }[] = []; - for (const file of htmlFiles) { + for (const file of targets) { try { const content = fs.readFileSync(file, 'utf8'); const offenders = findNonBase64Assets(content); - results.push({ file: path.relative(folder, file), ok: offenders.length === 0, assets: offenders }); + const display = baseDir ? path.relative(baseDir, file) || path.basename(file) : file; + results.push({ file: display, ok: offenders.length === 0, assets: offenders }); } catch { // skip unreadable } @@ -51,6 +71,16 @@ export function openBase64Scanner(_context: vscode.ExtensionContext) { }); } +function commonBaseDir(files: string[]): string { + if (files.length === 0) return ''; + if (files.length === 1) return path.dirname(files[0]); + const split = files.map(f => path.dirname(f).split(path.sep)); + const first = split[0]; + let i = 0; + while (i < first.length && split.every(parts => parts[i] === first[i])) i++; + return first.slice(0, i).join(path.sep); +} + async function collectHtmlFiles(root: string): Promise { const out: string[] = []; const stack: string[] = [root]; @@ -132,9 +162,11 @@ function getHtml(): string {

Base64 Asset Scanner

- + +
+