public static void AddListEntriesToSb(GridBackupPlugin plugin, StringBuilder sb, long playerIdentity, int startIndex, bool outputPlayerName, out int nextIndex) { nextIndex = startIndex; string path = plugin.CreatePath(); path = plugin.CreatePathForPlayer(path, playerIdentity); DirectoryInfo gridDir = new DirectoryInfo(path); DirectoryInfo[] dirList = gridDir.GetDirectories("*", SearchOption.TopDirectoryOnly); if (outputPlayerName && dirList.Length > 0) { var identity = PlayerUtils.GetIdentityById(playerIdentity); sb.AppendLine(identity.DisplayName); } foreach (var file in dirList) { string dateString = GenerateDateString(file); sb.AppendLine((nextIndex++) + " " + file.Name + " - " + dateString); } if (outputPlayerName && dirList.Length > 0) { sb.AppendLine(); } }
private static bool BackupGrid(long playerId, string path, GridBackupPlugin plugin, string gridName, long entityId, List <MyObjectBuilder_CubeGrid> objectBuilders) { try { string pathForPlayer = plugin.CreatePathForPlayer(path, playerId); string pathForGrid = plugin.CreatePathForGrid(pathForPlayer, gridName, entityId); string fileName = DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss") + ".sbc"; string fileNameDaily = DAILY_PRAEFIX + "_" + DateTime.Now.ToString("yyyy_MM_dd") + ".sbc"; if (plugin.Config.NumberOfDailyBackupSaves > 0) { string dailyFile = Path.Combine(pathForGrid, fileNameDaily); if (!File.Exists(dailyFile)) { GridManager.SaveGrid(dailyFile, gridName, plugin.Config.KeepOriginalOwner, plugin.Config.BackupProjections, objectBuilders); } } string pathForFile = Path.Combine(pathForGrid, fileName); bool saved = GridManager.SaveGrid(pathForFile, gridName, plugin.Config.KeepOriginalOwner, plugin.Config.BackupProjections, objectBuilders); if (saved) { CleanUpDirectory(plugin, pathForGrid); } return(saved); } catch (Exception e) { Log.Error(e, "Error on Export Grid!"); return(false); } }
public static List <DirectoryInfo> FindRelevantGrids(GridBackupPlugin plugin, IEnumerable <long> playerIdentities) { List <DirectoryInfo> matchingGrids = new List <DirectoryInfo>(); foreach (long playerIdentity in playerIdentities) { string path = plugin.CreatePath(); path = plugin.CreatePathForPlayer(path, playerIdentity); DirectoryInfo gridDir = new DirectoryInfo(path); DirectoryInfo[] dirList = gridDir.GetDirectories("*", SearchOption.TopDirectoryOnly); matchingGrids.AddRange(dirList); } return(matchingGrids); }