@@ -643,52 +643,121 @@ public void actionClick_importPlaylist(object sender, EventArgs e)
643643 {
644644 OpenFileDialog openDialog = new OpenFileDialog
645645 {
646- Filter = "JSON Files (*.json)|*.json|All Files (*.*)|*.*" ,
646+ Filter = "JSON or MPL Files (*.json;*.mpl )|*.json;*.mpl|JSON Files (*.json)|*.json|MPL Files (*.mpl)|*.mpl |All Files (*.*)|*.*" ,
647647 DefaultExt = "json"
648648 } ;
649649
650- if ( openDialog . ShowDialog ( ) == DialogResult . OK )
650+ if ( openDialog . ShowDialog ( ) != DialogResult . OK )
651+ return ;
652+
653+ string filePath = openDialog . FileName ;
654+ string extension = Path . GetExtension ( filePath ) . ToLowerInvariant ( ) ;
655+
656+ if ( extension == ".mpl" )
651657 {
652- var ( success , maps , importedCount , skippedCount , errorMessage ) =
653- mapInstanceManager . ImportPlaylistFromJson ( openDialog . FileName ) ;
658+ ImportMplPlaylist ( filePath ) ;
659+ return ;
660+ }
654661
655- if ( ! success )
656- {
657- MessageBox . Show ( errorMessage , "Import Error" ,
658- MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
659- return ;
660- }
662+ // Default: JSON import
663+ var ( success , maps , importedCount , skippedCount , errorMessage ) =
664+ mapInstanceManager . ImportPlaylistFromJson ( filePath ) ;
665+
666+ if ( ! success )
667+ {
668+ MessageBox . Show ( errorMessage , "Import Error" ,
669+ MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
670+ return ;
671+ }
672+
673+ dataGridView_currentMaps . Rows . Clear ( ) ;
674+
675+ foreach ( var map in maps )
676+ {
677+ int rowIndex = dataGridView_currentMaps . Rows . Add (
678+ dataGridView_currentMaps . Rows . Count + 1 ,
679+ map . MapName ,
680+ map . MapFile ,
681+ map . ModType ,
682+ map . MapType ,
683+ objectGameTypes . GetShortName ( map . MapType )
684+ ) ;
685+
686+ DataGridViewRow newRow = dataGridView_currentMaps . Rows [ rowIndex ] ;
687+ newRow . Cells [ 1 ] . ToolTipText = $ "Map File: { map . MapFile } ";
688+ }
689+
690+ string message = $ "Import complete.\n \n Imported: { importedCount } maps";
691+ if ( skippedCount > 0 )
692+ {
693+ message += $ "\n Skipped: { skippedCount } unavailable maps";
694+ }
695+ message += "\n \n Remember to save the playlist to apply changes." ;
661696
662- // Clear current playlist
663- dataGridView_currentMaps . Rows . Clear ( ) ;
697+ MessageBox . Show ( message , "Import Complete" ,
698+ MessageBoxButtons . OK , MessageBoxIcon . Information ) ;
699+ }
700+
701+ // Helper for MPL import
702+ private void ImportMplPlaylist ( string filePath )
703+ {
704+ var lines = File . ReadAllLines ( filePath , Encoding . GetEncoding ( 1252 ) ) ;
705+ var DefaultMaps = mapInstance . DefaultMaps ;
706+ var CustomMaps = mapInstance . CustomMaps ;
707+ int importedCount = 0 , skippedCount = 0 ;
664708
665- // Add imported maps to grid
666- foreach ( var map in maps )
709+ dataGridView_currentMaps . Rows . Clear ( ) ;
710+
711+ foreach ( var line in lines )
712+ {
713+ if ( string . IsNullOrWhiteSpace ( line ) ) continue ;
714+
715+ var parts = line . Split ( new [ ] { "[-]" } , StringSplitOptions . None ) ;
716+ if ( parts . Length != 3 )
667717 {
668- int rowIndex = dataGridView_currentMaps . Rows . Add (
669- dataGridView_currentMaps . Rows . Count + 1 ,
670- map . MapName ,
671- map . MapFile ,
672- map . ModType ,
673- map . MapType ,
674- objectGameTypes . GetShortName ( map . MapType )
675- ) ;
676-
677- DataGridViewRow newRow = dataGridView_currentMaps . Rows [ rowIndex ] ;
678- newRow . Cells [ 1 ] . ToolTipText = $ "Map File: { map . MapFile } ";
718+ skippedCount ++ ;
719+ continue ;
679720 }
680721
681- // Show results
682- string message = $ "Import complete.\n \n Imported: { importedCount } maps";
683- if ( skippedCount > 0 )
722+ if ( ! int . TryParse ( parts [ 0 ] , out int mapType ) ) { skippedCount ++ ; continue ; }
723+ if ( ! int . TryParse ( parts [ 1 ] , out int modType ) ) { skippedCount ++ ; continue ; }
724+ string fileName = parts [ 2 ] . Trim ( ) ;
725+
726+ var map1 = DefaultMaps . FirstOrDefault ( m =>
727+ m . MapType == mapType &&
728+ string . Equals ( m . MapFile , fileName , StringComparison . OrdinalIgnoreCase ) ) ;
729+
730+ var map2 = CustomMaps . FirstOrDefault ( m =>
731+ m . MapType == mapType &&
732+ string . Equals ( m . MapFile , fileName , StringComparison . OrdinalIgnoreCase ) ) ;
733+
734+ if ( map1 == null && map2 == null )
684735 {
685- message += $ "\n Skipped: { skippedCount } unavailable maps";
736+ skippedCount ++ ;
737+ continue ;
686738 }
687- message += "\n \n Remember to save the playlist to apply changes." ;
688739
689- MessageBox . Show ( message , "Import Complete" ,
690- MessageBoxButtons . OK , MessageBoxIcon . Information ) ;
740+ var map = map1 ?? map2 ! ;
741+
742+ int rowIndex = dataGridView_currentMaps . Rows . Add (
743+ dataGridView_currentMaps . Rows . Count + 1 ,
744+ map . MapName ,
745+ map . MapFile ,
746+ map . ModType ,
747+ map . MapType ,
748+ objectGameTypes . GetShortName ( map . MapType )
749+ ) ;
750+
751+ dataGridView_currentMaps . Rows [ rowIndex ] . Cells [ 1 ] . ToolTipText = $ "Map File: { map . MapFile } ";
752+ importedCount ++ ;
691753 }
754+
755+ string message = $ "MPL Import complete.\n \n Imported: { importedCount } maps";
756+ if ( skippedCount > 0 )
757+ message += $ "\n Skipped: { skippedCount } unavailable or invalid maps";
758+ message += "\n \n Remember to save the playlist to apply changes." ;
759+
760+ MessageBox . Show ( message , "MPL Import Complete" , MessageBoxButtons . OK , MessageBoxIcon . Information ) ;
692761 }
693762
694763 /// <summary>
0 commit comments