@@ -1204,52 +1204,53 @@ private Map<String, Object> importSingleFile(File file, DomainFolder folder, Lan
12041204 // Use AutoImporter to import the file
12051205 Project project = AppInfo .getActiveProject ();
12061206 MessageLog messageLog = new MessageLog ();
1207- var importResult = AutoImporter .importByUsingBestGuess (
1207+ LoadResults < Program > loadResults = AutoImporter .importByUsingBestGuess (
12081208 file , project , folder .getPathname () + "/" + programName , this , messageLog , TaskMonitor .DUMMY );
1209- List <DomainObject > importedObjects = new ArrayList <>();
1210- if (importResult != null ) {
1211- for (var obj : importResult ) {
1212- if (obj instanceof DomainObject ) {
1213- importedObjects .add ((DomainObject ) obj );
1214- }
1215- }
1216- }
12171209
1218- if (importedObjects . isEmpty () ) {
1210+ if (loadResults == null || loadResults . size () == 0 ) {
12191211 result .put ("success" , false );
12201212 result .put ("filePath" , file .getAbsolutePath ());
12211213 result .put ("error" , "No programs were imported from file" );
12221214 return result ;
12231215 }
12241216
1225- // Get the first imported program
1226- Program program = (Program ) importedObjects .get (0 );
1217+ // Save the loaded programs to the project
1218+ loadResults .save (project , this , messageLog , TaskMonitor .DUMMY );
1219+
1220+ // Get the primary imported program
1221+ Program program = loadResults .getPrimaryDomainObject ();
12271222 String programPath = program .getDomainFile ().getPathname ();
12281223
1229- // Run analysis if requested
1224+ // Run analysis on all loaded programs if requested
12301225 if (runAnalysis ) {
1231- int analysisTransactionID = program .startTransaction ("Import program analysis" );
1232- try {
1233- AutoAnalysisManager .getAnalysisManager (program ).startAnalysis (TaskMonitor .DUMMY );
1234- program .endTransaction (analysisTransactionID , true );
1235- } catch (Exception e ) {
1236- program .endTransaction (analysisTransactionID , false );
1237- // Log but don't fail the import due to analysis issues
1226+ for (Loaded <Program > loaded : loadResults ) {
1227+ Program loadedProgram = loaded .getDomainObject ();
1228+ int analysisTransactionID = loadedProgram .startTransaction ("Import program analysis" );
1229+ try {
1230+ AutoAnalysisManager .getAnalysisManager (loadedProgram ).startAnalysis (TaskMonitor .DUMMY );
1231+ loadedProgram .endTransaction (analysisTransactionID , true );
1232+ } catch (Exception e ) {
1233+ loadedProgram .endTransaction (analysisTransactionID , false );
1234+ // Log but don't fail the import due to analysis issues
1235+ }
12381236 }
12391237 }
12401238
1241- // Open program if requested
1239+ // Open all programs if requested
12421240 if (openProgram ) {
1243- openProgramInTool (program );
1241+ for (Loaded <Program > loaded : loadResults ) {
1242+ openProgramInTool (loaded .getDomainObject ());
1243+ }
12441244 }
12451245
12461246 result .put ("success" , true );
12471247 result .put ("filePath" , file .getAbsolutePath ());
12481248 result .put ("programPath" , programPath );
12491249 result .put ("programName" , programName );
1250+ result .put ("totalProgramsImported" , loadResults .size ());
12501251
1251- // Close the program reference
1252- program .release (this );
1252+ // Release the LoadResults (this will release all loaded programs)
1253+ loadResults .release (this );
12531254
12541255 } catch (Exception e ) {
12551256 result .put ("success" , false );
@@ -1273,52 +1274,53 @@ private Map<String, Object> importSingleFileFromArchive(FSRL fileFsrl, DomainFol
12731274 // Use AutoImporter to import from archive
12741275 Project project = AppInfo .getActiveProject ();
12751276 MessageLog messageLog = new MessageLog ();
1276- var importResult = AutoImporter .importByUsingBestGuess (
1277+ LoadResults < Program > loadResults = AutoImporter .importByUsingBestGuess (
12771278 fileFsrl , project , folder .getPathname () + "/" + programName , this , messageLog , TaskMonitor .DUMMY );
1278- List <DomainObject > importedObjects = new ArrayList <>();
1279- if (importResult != null ) {
1280- for (var obj : importResult ) {
1281- if (obj instanceof DomainObject ) {
1282- importedObjects .add ((DomainObject ) obj );
1283- }
1284- }
1285- }
12861279
1287- if (importedObjects . isEmpty () ) {
1280+ if (loadResults == null || loadResults . size () == 0 ) {
12881281 result .put ("success" , false );
12891282 result .put ("filePath" , fileFsrl .toString ());
12901283 result .put ("error" , "No programs were imported from archive file" );
12911284 return result ;
12921285 }
12931286
1294- // Get the first imported program
1295- Program program = (Program ) importedObjects .get (0 );
1287+ // Save the loaded programs to the project
1288+ loadResults .save (project , this , messageLog , TaskMonitor .DUMMY );
1289+
1290+ // Get the primary imported program
1291+ Program program = loadResults .getPrimaryDomainObject ();
12961292 String programPath = program .getDomainFile ().getPathname ();
12971293
1298- // Run analysis if requested
1294+ // Run analysis on all loaded programs if requested
12991295 if (runAnalysis ) {
1300- int analysisTransactionID = program .startTransaction ("Import program analysis" );
1301- try {
1302- AutoAnalysisManager .getAnalysisManager (program ).startAnalysis (TaskMonitor .DUMMY );
1303- program .endTransaction (analysisTransactionID , true );
1304- } catch (Exception e ) {
1305- program .endTransaction (analysisTransactionID , false );
1306- // Log but don't fail the import due to analysis issues
1296+ for (Loaded <Program > loaded : loadResults ) {
1297+ Program loadedProgram = loaded .getDomainObject ();
1298+ int analysisTransactionID = loadedProgram .startTransaction ("Import program analysis" );
1299+ try {
1300+ AutoAnalysisManager .getAnalysisManager (loadedProgram ).startAnalysis (TaskMonitor .DUMMY );
1301+ loadedProgram .endTransaction (analysisTransactionID , true );
1302+ } catch (Exception e ) {
1303+ loadedProgram .endTransaction (analysisTransactionID , false );
1304+ // Log but don't fail the import due to analysis issues
1305+ }
13071306 }
13081307 }
13091308
1310- // Open program if requested
1309+ // Open all programs if requested
13111310 if (openProgram ) {
1312- openProgramInTool (program );
1311+ for (Loaded <Program > loaded : loadResults ) {
1312+ openProgramInTool (loaded .getDomainObject ());
1313+ }
13131314 }
13141315
13151316 result .put ("success" , true );
13161317 result .put ("filePath" , fileFsrl .toString ());
13171318 result .put ("programPath" , programPath );
13181319 result .put ("programName" , programName );
1320+ result .put ("totalProgramsImported" , loadResults .size ());
13191321
1320- // Close the program reference
1321- program .release (this );
1322+ // Release the LoadResults (this will release all loaded programs)
1323+ loadResults .release (this );
13221324
13231325 } catch (Exception e ) {
13241326 result .put ("success" , false );
0 commit comments