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(); } }
internal static void DeleteBackupsOlderThan(GridBackupPlugin plugin, int deleteBackupsOlderThanDays) { if (deleteBackupsOlderThanDays <= 0) { return; } MyAPIGateway.Parallel.StartBackground(() => { Log.Info("Start deleting backups older than " + deleteBackupsOlderThanDays + " days were deleted."); string path = plugin.CreatePath(); DirectoryInfo dir = new DirectoryInfo(path); var directoryList = dir.GetDirectories("*", SearchOption.TopDirectoryOnly); var checkTime = DateTime.Now.AddDays(-deleteBackupsOlderThanDays); foreach (var playerDir in directoryList) { var gridList = playerDir.GetDirectories("*", SearchOption.TopDirectoryOnly); foreach (var gridDir in gridList) { try { var fileList = gridDir.GetFiles("*.*", SearchOption.TopDirectoryOnly); foreach (var file in fileList) { if (file.CreationTime < checkTime) { file.Delete(); } } if (gridDir.GetFileSystemInfos("*", SearchOption.TopDirectoryOnly).Length == 0) { gridDir.Delete(false); } } catch (Exception e) { Log.Error(e, "Error on deleting backups older than " + deleteBackupsOlderThanDays + " days!"); } } if (playerDir.GetFileSystemInfos("*", SearchOption.TopDirectoryOnly).Length == 0) { playerDir.Delete(false); } } Log.Info("Backups older than " + deleteBackupsOlderThanDays + " days were deleted."); }); }
public void Update() { try { UpdateCount++; if (UpdateCount > Plugin.Config.DelayTicksBetweenExports) { UpdateCount = 0; } if (UpdateCount != 0) { return; } stopwatch.Start(); /* We just peek, as we visit this player multiple times. */ long playerId = stack.Peek(); ConcurrentBag <List <MyCubeGrid> > gridGroups = GridFinder.FindGridList(playerId, Plugin.Config.BackupConnections); string path = Plugin.CreatePath(); foreach (List <MyCubeGrid> grids in gridGroups) { try { /* * if false is returned we already exported the gird and * need to continue with the next one * * If true is returned we added a new grid to the list and therefore * end this tick. */ if (BackupSingleGrid(playerId, grids, path)) { return; } } catch (Exception e) { Log.Warn(e, "Could not export grids"); } } /* If we reach the end of this for loop this player is basically done. so off of the stack it goes */ stack.Pop(); } finally { stopwatch.Stop(); } }
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); }