Skip to content

Commit 2bb9568

Browse files
Added a import projects from TKMM button
1 parent 09ca28b commit 2bb9568

3 files changed

Lines changed: 72 additions & 0 deletions

File tree

docs/release-notes/0.0.2-beta.1.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- Font viewer
1212
- TKMM option support
1313
- Set project root
14+
- Import projects from TKMM
1415

1516
# Bug Fixes
1617
- Canonical syncing only happens when file contents are **modified** *(not when you hit ctrl + s in an unmodified file.)*

package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,11 @@
258258
"title": "TOTK: Add Projects via File Explorer",
259259
"icon": "$(folder-opened)"
260260
},
261+
{
262+
"command": "totk-editor.importTKMMProjects",
263+
"title": "TOTK: Import TKMM Projects",
264+
"icon": "$(cloud-download)"
265+
},
261266
{
262267
"command": "totk-editor.refreshArchives",
263268
"title": "TOTK: Refresh Projects",
@@ -494,6 +499,11 @@
494499
"when": "view == totk-editor.archives",
495500
"group": "navigation"
496501
},
502+
{
503+
"command": "totk-editor.importTKMMProjects",
504+
"when": "view == totk-editor.archives",
505+
"group": "navigation"
506+
},
497507
{
498508
"command": "totk-editor.refreshArchives",
499509
"when": "view == totk-editor.archives",

src/archiveTree.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,11 +438,72 @@ export function registerArchiveTree(context: vscode.ExtensionContext): ArchiveTr
438438
}
439439
};
440440

441+
const importTKMMProjects = async (): Promise<void> => {
442+
const recentJsonPaths: string[] = [];
443+
const homeDir = require('os').homedir();
444+
if (process.platform === 'win32' && process.env.LOCALAPPDATA) {
445+
recentJsonPaths.push(path.join(process.env.LOCALAPPDATA, '.tk-studio', 'recent.json'));
446+
} else {
447+
recentJsonPaths.push(path.join(homeDir, '.local', 'share', 'tk-studio', 'recent.json'));
448+
recentJsonPaths.push(path.join(homeDir, '.local', 'share', '.tk-studio', 'recent.json'));
449+
recentJsonPaths.push(path.join(homeDir, '.config', 'tk-studio', 'recent.json'));
450+
recentJsonPaths.push(path.join(homeDir, '.config', '.tk-studio', 'recent.json'));
451+
recentJsonPaths.push(path.join(homeDir, '.tk-studio', 'recent.json'));
452+
recentJsonPaths.push(path.join(homeDir, 'Library', 'Application Support', 'tk-studio', 'recent.json'));
453+
recentJsonPaths.push(path.join(homeDir, 'Library', 'Application Support', '.tk-studio', 'recent.json'));
454+
}
455+
456+
let foundPath: string | undefined;
457+
for (const p of recentJsonPaths) {
458+
try {
459+
const stat = await vscode.workspace.fs.stat(vscode.Uri.file(p));
460+
if (stat.type === vscode.FileType.File) {
461+
foundPath = p;
462+
break;
463+
}
464+
} catch {
465+
// Ignore
466+
}
467+
}
468+
469+
if (!foundPath) {
470+
void vscode.window.showWarningMessage('TOTK Archives: Could not find TKMM recent.json. Please make sure you have opened projects in TKMM before.');
471+
return;
472+
}
473+
474+
try {
475+
const data = await vscode.workspace.fs.readFile(vscode.Uri.file(foundPath));
476+
const projects = JSON.parse(Buffer.from(data).toString('utf-8')) as string[];
477+
if (Array.isArray(projects)) {
478+
let addedCount = 0;
479+
for (const p of projects) {
480+
try {
481+
const stat = await vscode.workspace.fs.stat(vscode.Uri.file(p));
482+
if (stat.type === vscode.FileType.Directory) {
483+
await provider.addRoot(vscode.Uri.file(p));
484+
addedCount++;
485+
}
486+
} catch {
487+
// Project directory might have been deleted or moved
488+
}
489+
}
490+
void focusArchiveSidebar();
491+
void vscode.window.showInformationMessage(`TOTK Archives: Imported ${addedCount} TKMM project(s).`);
492+
} else {
493+
void vscode.window.showErrorMessage('TOTK Archives: Invalid format in TKMM recent.json.');
494+
}
495+
} catch (error) {
496+
const message = error instanceof Error ? error.message : String(error);
497+
void vscode.window.showErrorMessage(`TOTK Archives: Failed to read TKMM recent.json: ${message}`);
498+
}
499+
};
500+
441501
context.subscriptions.push(
442502
vscode.commands.registerCommand('totk-editor.addWorkspaceToArchives', addWorkspaceToArchives),
443503
// Backwards-compat alias for an older mistyped command id.
444504
vscode.commands.registerCommand('totk-edit.addWorkspaceToArchives', addWorkspaceToArchives),
445505
vscode.commands.registerCommand('totk-editor.addProjectFolders', addProjectFolders),
506+
vscode.commands.registerCommand('totk-editor.importTKMMProjects', importTKMMProjects),
446507
);
447508

448509
context.subscriptions.push(

0 commit comments

Comments
 (0)