public BackupManager(string leaguePath)
 {
     _leaguePath   = leaguePath;
     _archivePath  = LeagueLocations.GetArchivePath(leaguePath);
     _backupPath   = LeagueLocations.GetBackupPath(leaguePath);
     _manifestPath = LeagueLocations.GetManifestPath(leaguePath);
 }
Exemple #2
0
        private void LoadManifestPaths()
        {
            Console.WriteLine("Loading file info...");
            Manifest    = ReleaseManifest.LoadFromFile(LeagueLocations.GetManifestPath(_leaguePath));
            _indexTable = new Dictionary <string, ReleaseManifestFileEntry>();

            for (int i = 0; i < Manifest.Files.Length; i++)
            {
                if (Manifest.Files[i].EntityType != 4)
                {
                    _indexTable[Manifest.Files[i].FullName] = Manifest.Files[i];
                }
            }
        }
Exemple #3
0
        private void WriteStateInfo()
        {
            //Make sure our directory exists
            if (!Directory.Exists(LeagueLocations.GetModPath(_leaguePath)))
            {
                Directory.CreateDirectory(LeagueLocations.GetModPath(_leaguePath));
            }

            // Backup manifest
            if (File.Exists(LeagueLocations.GetManifestStatePath(_leaguePath)))
            {
                File.Delete(LeagueLocations.GetManifestStatePath(_leaguePath));
            }

            File.Copy(LeagueLocations.GetManifestPath(_leaguePath), LeagueLocations.GetManifestStatePath(_leaguePath));

            var writer = new ArchiveStateWriter();

            writer.WriteArchiveStates(_archiveStates.Values.ToArray(), LeagueLocations.GetArchiveStatePath(_leaguePath));
            Manifest.SaveChanges();
        }
Exemple #4
0
        public void Revert()
        {
            if (_archiveStates.Count == 0)
            {
                return;
            }

            var states = _archiveStates.Values.ToArray();


            // Reverse archives
            for (int i = 0; i < states.Length; i++)
            {
                var archive = _archiveTable[states[i].ArchivePath];
                foreach (var entry in states[i].OriginalValues)
                {
                    archive.Files[entry.Key] = entry.Value;
                }
                _writer.WriteArchive(archive, archive.FilePath);
                _writer.SetDataLength(archive, states[i].OriginalLength);
                archive.DataLength = states[i].OriginalLength;
            }

            // Reverse manifest
            File.WriteAllBytes(LeagueLocations.GetManifestPath(_leaguePath), File.ReadAllBytes(LeagueLocations.GetManifestStatePath(_leaguePath)));
            File.Delete(LeagueLocations.GetManifestStatePath(_leaguePath));

            // Clear local variables and save them
            _archiveStates = new Dictionary <string, ArchiveState>();
            Manifest       = ReleaseManifest.LoadFromFile(LeagueLocations.GetManifestPath(_leaguePath));
            LoadManifestPaths();
            WriteStateInfo();

            // Remove the corrupt data flag if it exists
            if (File.Exists(LeagueLocations.GetCorruptFlagPath(_leaguePath)))
            {
                File.Delete(LeagueLocations.GetCorruptFlagPath(_leaguePath));
            }
        }