Beispiel #1
0
        public StashResult StashCloudSave(ClusterConfigSection cluster, long steamId, string tagName)
        {
            try
            {
                var sourcePath = Path.Combine(cluster.SavePath, $"{steamId}");
                var targetPath = Path.Combine(cluster.SavePath, $"{steamId}.stash_{tagName}");
                if (!File.Exists(sourcePath))
                {
                    return(StashResult.SourceMissing);
                }
                if (File.Exists(targetPath))
                {
                    return(StashResult.TargetExists);
                }

                File.Move(sourcePath, targetPath);
            }
            catch
            {
                /*ignore exceptions*/
                return(StashResult.MoveFailed);
            }

            return(StashResult.Successfull);
        }
Beispiel #2
0
        public List <BackupListEntity> GetCloudBackupFilesForSteamId(ClusterConfigSection cluster, long steamId)
        {
            var result = new List <BackupListEntity>();

            var backupDirPath = cluster.SavePath;
            var backupDir     = new DirectoryInfo(backupDirPath);
            var files         = backupDir.GetFiles($"{steamId}.*", SearchOption.AllDirectories).Where(x => !x.Name.Equals(steamId.ToString())).ToArray();

            if (files == null)
            {
                return(result);
            }

            foreach (var file in files)
            {
                var a    = file.FullName.Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
                var b    = backupDirPath.Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
                var path = Path.Combine(a.Merge(b, (_a, _b) => new { a = _a, b = _b }).SkipWhile(x => x.a.Equals(x.b, StringComparison.OrdinalIgnoreCase)).Select(x => x.a).ToArray());

                var entry = new FromServerBackupListEntity
                {
                    Path         = Path.Combine("current", path),
                    FullPath     = file.FullName,
                    ByteSize     = file.Length,
                    DateModified = DateTime.Now,
                    Files        = new[] { path }
                };

                result.Add(entry);
            }

            return(result);
        }
Beispiel #3
0
        public SavegameBackupResult CreateBackup(ServerConfigSection server, ClusterConfigSection cluster)
        {
            if (!File.Exists(server.SaveFilePath))
            {
                Logging.Log($@"Savegame backup was requested but there are no files to backup (saveFilePath: ""{server.SaveFilePath}"", clusterSavePath: ""{cluster?.SavePath ?? "-"}"")", GetType(), LogLevel.DEBUG);
                return(null);
            }

            var dir = Path.GetDirectoryName(server.SaveFilePath);

            string[] arkprofiles = null;
            string[] arktribes   = null;
            string[] clusters    = null;
            var      files       = new[]
            {
                new Tuple <string, string, string[]>("", "", new [] { server.SaveFilePath }),
                Directory.Exists(dir) ? new Tuple <string, string, string[]>("", "", arkprofiles             = Directory.GetFiles(dir, "*.arkprofile", SearchOption.TopDirectoryOnly)) : null,
                Directory.Exists(dir) ? new Tuple <string, string, string[]>("", "", arktribes               = Directory.GetFiles(dir, "*.arktribe", SearchOption.TopDirectoryOnly)) : null,
                cluster != null ? new Tuple <string, string, string[]>(cluster.SavePath, "cluster", clusters = Directory.GetFiles(cluster.SavePath, "*", SearchOption.AllDirectories)) : null
            }.Where(x => x != null && x.Item2 != null).ToArray();

            var backupDir = Path.Combine(_config.Backups.BackupsDirectoryPath, server.Key, DateTime.Now.ToString("yyyy-MM"));

            if (!Directory.Exists(backupDir))
            {
                Directory.CreateDirectory(backupDir);
            }

            var path = Path.Combine(backupDir, "save_" + DateTime.Now.ToString("yyyy-MM-dd.HH.mm.ss.ffff") + ".zip");

            string[] results = null;
            try
            {
                results = FileHelper.CreateDotNetZipArchive(files, path);
            }
            catch (Exception ex)
            {
                Logging.LogException("Failed to create savegame backup archive", ex, GetType(), LogLevel.ERROR, ExceptionLevel.Ignored);
                return(null);
            }

            return(new SavegameBackupResult
            {
                ArchivePaths = results,
                FilesInBackup = files.SelectMany(x => x.Item3).ToArray(),
                SaveGameCount = 1,
                ArkprofileCount = arkprofiles?.Length ?? 0,
                ArktribeCount = arktribes?.Length ?? 0,
                ClusterCount = clusters?.Length ?? 0
            });
        }
Beispiel #4
0
        public SavegameBackupResult CreateClusterBackupForSteamId(ClusterConfigSection cluster, long steamId)
        {
            if (cluster == null || string.IsNullOrEmpty(cluster.SavePath) || !Directory.Exists(cluster.SavePath))
            {
                return(null);
            }

            string[] clusters = null;
            var      files = new[] { new Tuple <string, string, string[]>(cluster.SavePath, "cluster", clusters = Directory.GetFiles(cluster.SavePath, $"{steamId}*", SearchOption.AllDirectories)) }.ToArray();

            if (!(clusters?.Length > 0))
            {
                return(null);
            }

            var backupDir = Path.Combine(_config.Backups.BackupsDirectoryPath, cluster.Key, DateTime.Now.ToString("yyyy-MM"));

            if (!Directory.Exists(backupDir))
            {
                Directory.CreateDirectory(backupDir);
            }

            var path = Path.Combine(backupDir, $"cluster_{steamId}_" + DateTime.Now.ToString("yyyy-MM-dd.HH.mm.ss.ffff") + ".zip");

            string[] results = null;
            try
            {
                results = FileHelper.CreateDotNetZipArchive(files, path);
            }
            catch (Exception ex)
            {
                Logging.LogException($"Failed to create cluster backup archive for steamid {steamId}", ex, GetType(), LogLevel.ERROR, ExceptionLevel.Ignored);
                return(null);
            }

            return(new SavegameBackupResult
            {
                ArchivePaths = results,
                FilesInBackup = files.SelectMany(x => x.Item3).ToArray(),
                SaveGameCount = 0,
                ArkprofileCount = 0,
                ArktribeCount = 0,
                ClusterCount = clusters.Length
            });
        }
Beispiel #5
0
        /// <summary>
        /// Collect all cloud save backup file entries
        /// </summary>
        /// <returns></returns>
        List <BackupListEntity> GetBackupFiles(ClusterConfigSection clusterConfig, string[] serverKeys, long steamId, int?forHash = null)
        {
            // collect backup archives that have cloud saves for a given player
            var clusterFilePathForPlayer = $"cluster/{steamId}";
            var clusterFileFilterFunc    = new Func <string, bool>(x => x.StartsWith(clusterFilePathForPlayer, StringComparison.OrdinalIgnoreCase));
            var result = _savegameBackupService.GetBackupsList(
                new[] { clusterConfig.Key }.Concat(serverKeys).ToArray(),
                (fi, be) => ((forHash.HasValue && be.Path.GetHashCode() == forHash.Value) || !forHash.HasValue) && fi.LastWriteTime >= DateTime.Now.AddDays(-7) && be.Files.Any(clusterFileFilterFunc)) ?? new List <Services.Data.BackupListEntity>();

            // filter out non cloud saves
            result.ForEach(x => x.Files = x.Files.Where(clusterFileFilterFunc).OrderBy(y => y).ToArray());

            // collect stashed/.tmpprofile/etc. cloud saves from the clusters directory on the server
            var cloudBackupFiles = _savegameBackupService.GetCloudBackupFilesForSteamId(clusterConfig, steamId);

            if (cloudBackupFiles?.Count > 0)
            {
                cloudBackupFiles.ForEach(x => x.Files = x.Files.OrderBy(y => y).ToArray());
                result.AddRange(cloudBackupFiles);
            }

            return(result);
        }
Beispiel #6
0
 public ArkClusterContext(ClusterConfigSection config, ArkAnonymizeData anonymizeData) : base(config.SavePath, true)
 {
     Config         = config;
     _anonymizeData = anonymizeData;
 }
Beispiel #7
0
 public ArkClusterContext(ClusterConfigSection config)
 {
     Config = config;
 }