Skip to content

Commit bc95ea5

Browse files
committed
feat(vscode): persist dump state and add export tooling
1 parent 03cfcf7 commit bc95ea5

14 files changed

Lines changed: 3323 additions & 131 deletions

File tree

resx-vscode/media-src/main.ts

Lines changed: 1465 additions & 61 deletions
Large diffs are not rendered by default.

resx-vscode/media-src/payloads.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export function unwrapListPayload<T>(payload: unknown, key: string): T[] {
2+
if (Array.isArray(payload)) {
3+
return payload as T[];
4+
}
5+
if (payload && typeof payload === 'object') {
6+
const value = (payload as Record<string, unknown>)[key];
7+
if (Array.isArray(value)) {
8+
return value as T[];
9+
}
10+
}
11+
return [];
12+
}
13+
14+
export function unwrapObjectPayload<T>(payload: unknown, key: string): T | null {
15+
if (!payload || typeof payload !== 'object') {
16+
return null;
17+
}
18+
const record = payload as Record<string, unknown>;
19+
const nested = record[key];
20+
if (nested && typeof nested === 'object') {
21+
return nested as T;
22+
}
23+
return record as T;
24+
}

resx-vscode/media-src/tables.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ export function sortTable(th: HTMLTableCellElement, tbl: HTMLTableElement): void
6868
}
6969

7070
function compareTableValues(a: string, b: string): number {
71+
const bigintPattern = /^[-+]?(?:0x[0-9a-f]+|\d+)$/i;
72+
if (bigintPattern.test(a) && bigintPattern.test(b)) {
73+
try {
74+
const na = BigInt(a);
75+
const nb = BigInt(b);
76+
if (na < nb) return -1;
77+
if (na > nb) return 1;
78+
return 0;
79+
} catch {}
80+
}
7181
const na = a.startsWith('0x') ? parseInt(a, 16) : parseFloat(a);
7282
const nb = b.startsWith('0x') ? parseInt(b, 16) : parseFloat(b);
7383
if (!isNaN(na) && !isNaN(nb)) return na - nb;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const TOP_TABS = new Set([
2+
'overview',
3+
'entry',
4+
'triage',
5+
'sections',
6+
'exports',
7+
'imports',
8+
'symbols',
9+
'types',
10+
'dump',
11+
'dev',
12+
]);
13+
14+
const DUMP_TABS = new Set(['disasm', 'calls', 'xrefs', 'strings', 'cfg', 'recomp', 'hex']);
15+
16+
export interface PersistedUiState {
17+
topTab: string;
18+
dumpSubTab: string;
19+
asmMetaWidth: number;
20+
}
21+
22+
export function coercePersistedUiState(raw: unknown): PersistedUiState {
23+
const data = raw && typeof raw === 'object' ? raw as Record<string, unknown> : {};
24+
const topTab = typeof data.topTab === 'string' && TOP_TABS.has(data.topTab)
25+
? data.topTab
26+
: 'overview';
27+
const dumpSubTab = typeof data.dumpSubTab === 'string' && DUMP_TABS.has(data.dumpSubTab)
28+
? data.dumpSubTab
29+
: 'disasm';
30+
const asmMetaWidth = Number.isFinite(Number(data.asmMetaWidth))
31+
? Math.max(160, Math.min(520, Number(data.asmMetaWidth)))
32+
: 280;
33+
return {
34+
topTab,
35+
dumpSubTab,
36+
asmMetaWidth,
37+
};
38+
}
39+
40+
export function buildPersistedUiState(state: Partial<PersistedUiState>): PersistedUiState {
41+
return coercePersistedUiState(state);
42+
}

0 commit comments

Comments
 (0)