Beispiel #1
0
        public static bool SaveLastLoadedTime(string sessionPath, DateTime lastLoadedTime)
        {
            MyObjectBuilder_LastLoadedTimes builder = null;
            Dictionary <string, DateTime>   times;

            if (File.Exists(LastLoadedTimesPath) && Sandbox.Common.ObjectBuilders.Serializer.MyObjectBuilderSerializer.DeserializeXML(LastLoadedTimesPath, out builder))
            {
                times = builder.LastLoaded.Dictionary;
            }
            else
            {
                times = new Dictionary <string, DateTime>(1);
            }

            times[sessionPath] = lastLoadedTime;

            if (builder == null)
            {
                builder = Sandbox.Common.ObjectBuilders.Serializer.MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_LastLoadedTimes>();
            }

            if (builder.LastLoaded == null)
            {
                builder.LastLoaded = new SerializableDictionary <string, DateTime>(times);
            }
            else
            {
                builder.LastLoaded.Dictionary = times;
            }

            return(Sandbox.Common.ObjectBuilders.Serializer.MyObjectBuilderSerializer.SerializeXML(LastLoadedTimesPath, false, builder));
        }
Beispiel #2
0
        private IEnumerable <WorldResource> FindSaveFiles(string lastLoadedPath, string userName, SaveWorldType saveType, UserDataPath dataPath)
        {
            var lastLoadedFile = Path.Combine(lastLoadedPath, SpaceEngineersConsts.LoadLoadedFilename);
            var list           = new List <WorldResource>();

            // Ignore any other base Save paths without the LastLoaded file.
            if (File.Exists(lastLoadedFile))
            {
                MyObjectBuilder_LastLoadedTimes lastLoaded = null;
                try
                {
                    lastLoaded = SpaceEngineersApi.ReadSpaceEngineersFile <MyObjectBuilder_LastLoadedTimes>(lastLoadedFile);
                }
                catch { }
                var savePaths = Directory.GetDirectories(lastLoadedPath);

                // Still check every potential game world path.
                foreach (var savePath in savePaths)
                {
                    var saveResource = LoadSaveFromPath(savePath, userName, saveType, dataPath);
                    if (lastLoaded != null)
                    {
                        var last = lastLoaded.LastLoaded.Dictionary.FirstOrDefault(d => d.Key.Equals(savePath, StringComparison.OrdinalIgnoreCase));
                        if (last.Key != null)
                        {
                            saveResource.LastLoadTime = last.Value;
                        }
                    }

                    // This should still allow Games to be copied into the Save path manually.

                    saveResource.LoadCheckpoint();
                    list.Add(saveResource);
                }
            }

            return(list);
        }