@@ -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