@@ -44,12 +44,14 @@ public WorldGeneratorDialog(InstanceManager instanceManager)
4444 _instanceManager = instanceManager ;
4545 InitializeComponent ( ) ;
4646 _loadLocalization ( ) ;
47- var scenarios = MyLocalCache . GetAvailableWorldInfos ( new List < string > { Path . Combine ( MyFileSystem . ContentPath , "CustomWorlds" ) } ) ;
48- foreach ( var tup in scenarios )
47+
48+ string worldsDir = Path . Combine ( MyFileSystem . ContentPath , "CustomWorlds" ) ;
49+ var result = new List < Tuple < string , MyWorldInfo > > ( ) ;
50+
51+ GetWorldInfo ( worldsDir , result ) ;
52+
53+ foreach ( var tup in result )
4954 {
50- if ( tup . Item2 == null )
51- continue ;
52-
5355 string directory = tup . Item1 ;
5456 MyWorldInfo info = tup . Item2 ;
5557 var sessionNameId = MyStringId . GetOrCompute ( info . SessionName ) ;
@@ -58,22 +60,13 @@ public WorldGeneratorDialog(InstanceManager instanceManager)
5860 checkpoint . OnlineMode = MyOnlineModeEnum . PUBLIC ;
5961 // Keen, why do random checkpoints point to the SBC and not the folder!
6062 directory = directory . Replace ( "Sandbox.sbc" , "" ) ;
61- _checkpoints . Add ( new PremadeCheckpointItem { Name = localizedName , Icon = Path . Combine ( directory , "thumb.jpg" ) , Path = directory , Checkpoint = checkpoint } ) ;
62- }
63-
64- /*
65- var premadeCheckpoints = Directory.EnumerateDirectories(Path.Combine("Content", "CustomWorlds"));
66- foreach (var path in premadeCheckpoints)
67- {
68- var thumbPath = Path.GetFullPath(Directory.EnumerateFiles(path).First(x => x.Contains("thumb")));
69-
7063 _checkpoints . Add ( new PremadeCheckpointItem
7164 {
72- Path = path,
73- Icon = thumbPath,
74- Name = Path.GetFileName(path)
65+ Name = localizedName , Icon = Path . Combine ( directory , "thumb.jpg" ) , Path = directory ,
66+ Checkpoint = checkpoint
7567 } ) ;
76- }*/
68+ }
69+
7770 PremadeCheckpoints . ItemsSource = _checkpoints ;
7871 }
7972
@@ -113,6 +106,91 @@ private void PremadeCheckpoints_SelectionChanged(object sender, SelectionChanged
113106 _currentItem = selected ;
114107 SettingsView . DataContext = new SessionSettingsViewModel ( _currentItem . Checkpoint . Settings ) ;
115108 }
109+
110+ private void GetWorldInfo ( string savesPath , List < Tuple < string , MyWorldInfo > > result )
111+ {
112+ foreach ( var saveDir in Directory . GetDirectories ( savesPath , "*" , SearchOption . TopDirectoryOnly ) )
113+ {
114+ bool newScenario = Directory . GetFiles ( saveDir , "*.scf" , SearchOption . TopDirectoryOnly ) . Length == 1 ;
115+
116+ if ( newScenario )
117+ {
118+ bool isCompatible ;
119+ string platformSessionPath = null ;
120+
121+
122+ if ( ! Sandbox . Game . MyPlatformGameSettings . CONSOLE_COMPATIBLE )
123+ {
124+ platformSessionPath = MyLocalCache . GetSessionPathFromScenario ( saveDir , false , out isCompatible ) ;
125+ if ( platformSessionPath != null && isCompatible )
126+ {
127+ AddWorldInfo ( result , platformSessionPath , saveDir , " [PC]" ) ;
128+ }
129+ }
130+
131+ string xboxPlatformSessionPath = MyLocalCache . GetSessionPathFromScenario ( saveDir , true , out isCompatible ) ;
132+ if ( xboxPlatformSessionPath != null && isCompatible )
133+ {
134+ AddWorldInfo ( result , xboxPlatformSessionPath , saveDir , " [XBOX]" ) ;
135+ }
136+
137+ if ( platformSessionPath == null && xboxPlatformSessionPath == null && isCompatible )
138+ {
139+ AddWorldInfo ( result , saveDir , saveDir , "" ) ;
140+ }
141+ }
142+ else
143+ {
144+ foreach ( var file in Directory . GetFiles ( saveDir , MyLocalCache . CHECKPOINT_FILE , SearchOption . AllDirectories ) )
145+ {
146+ var checkpointDir = Path . GetDirectoryName ( file ) ;
147+ if ( checkpointDir . ToLower ( ) . Contains ( "backup" ) )
148+ continue ;
149+
150+ AddWorldInfo ( result , file , saveDir , "" ) ;
151+ }
152+ }
153+
154+ }
155+ }
156+
157+ private static void AddWorldInfo ( List < Tuple < string , MyWorldInfo > > result , string sessionDir , string saveDir , string namePostfix )
158+ {
159+ MyWorldInfo worldInfo = null ;
160+ var worldConfiguration = MyLocalCache . LoadWorldConfiguration ( sessionDir ) ;
161+ if ( worldConfiguration == null )
162+ {
163+ worldInfo = MyLocalCache . LoadWorldInfoFromFile ( sessionDir ) ;
164+ }
165+ else
166+ {
167+ if ( string . IsNullOrEmpty ( worldConfiguration . SessionName ) || ! worldConfiguration . LastSaveTime . HasValue )
168+ {
169+ worldInfo = MyLocalCache . LoadWorldInfoFromFile ( sessionDir ) ;
170+ }
171+ else
172+ {
173+ worldInfo = new MyWorldInfo
174+ {
175+ SessionName = worldConfiguration . SessionName ,
176+ LastSaveTime = worldConfiguration . LastSaveTime . Value
177+ } ;
178+ }
179+
180+ if ( worldInfo != null && string . IsNullOrEmpty ( worldInfo . SessionName ) )
181+ {
182+ worldInfo . SessionName = Path . GetFileName ( sessionDir ) ;
183+ }
184+ }
185+
186+ if ( worldInfo != null )
187+ {
188+ worldInfo . SessionName += namePostfix ;
189+ }
190+
191+ worldInfo . SaveDirectory = saveDir ;
192+ result . Add ( Tuple . Create ( sessionDir , worldInfo ) ) ;
193+ }
116194 }
117195
118196 public class PremadeCheckpointItem
0 commit comments