Exemplo n.º 1
0
 /// <summary>
 /// Cleans up old autosaves.
 /// </summary>
 /// <param name="filename">The file name that is being saved.</param>
 private void CleanAutosaves(string filename)
 {
     if (!Klei.GenericGameSettings.instance.keepAllAutosaves)
     {
         var saveFiles = SaveLoader.GetSaveFiles(Path.GetDirectoryName(filename));
         // Clean up old autosaves and their preview images
         for (int i = saveFiles.Count - 1; i >= SaveLoader.MAX_AUTOSAVE_FILES - 1; i--)
         {
             string autoName = saveFiles[i], autoImage = Path.ChangeExtension(
                 autoName, ".png");
             try {
                 PUtil.LogDebug("Deleting old autosave: " + autoName);
                 File.Delete(autoName);
             } catch (Exception e) {
                 PUtil.LogWarning("Problem deleting old autosave: " + autoName);
                 PUtil.LogExcWarn(e);
             }
             try {
                 if (File.Exists(autoImage))
                 {
                     File.Delete(autoImage);
                 }
             } catch (Exception e) {
                 PUtil.LogWarning("Problem deleting old screenshot: " + autoImage);
                 PUtil.LogExcWarn(e);
             }
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Cleans up old autosaves.
        /// </summary>
        private void CleanAutosaves()
        {
            var inst = SaveLoader.Instance;

            if (!Klei.GenericGameSettings.instance.keepAllAutosaves && inst != null)
            {
                string autoSavePath = GetActiveAutoSavePath(), colonyID = inst.GameInfo.
                                                                          colonyGuid.ToString();
                var autoSaveFiles = ListPool <string, BackgroundAutosave> .Allocate();

                // Clean up old autosaves and their preview images
                foreach (var candidate in SaveLoader.GetSaveFiles(autoSavePath, true))
                {
                    var info = SaveGame.GetFileInfo(candidate.path);
                    if (info != null)
                    {
                        string uniqueID = SaveGame.GetSaveUniqueID(info.second);
                        if (uniqueID == colonyID)
                        {
                            autoSaveFiles.Add(candidate.path);
                        }
                    }
                }
                for (int i = autoSaveFiles.Count - 1; i >= SaveLoader.MAX_AUTOSAVE_FILES - 1;
                     i--)
                {
                    string autoName = autoSaveFiles[i], autoImage = Path.ChangeExtension(
                        autoName, ".png");
                    try {
                        PUtil.LogDebug("Deleting old autosave: " + autoName);
                        File.Delete(autoName);
                    } catch (Exception e) {
                        PUtil.LogWarning("Error deleting old autosave: " + autoName);
                        PUtil.LogExcWarn(e);
                    }
                    try {
                        if (File.Exists(autoImage))
                        {
                            File.Delete(autoImage);
                        }
                    } catch (Exception e) {
                        PUtil.LogWarning("Error deleting old screenshot: " + autoImage);
                        PUtil.LogExcWarn(e);
                    }
                }
                autoSaveFiles.Recycle();
            }
        }