Ejemplo n.º 1
0
        public void Restore(bool removeBackup)
        {
            var title    = Console.Title;
            var archives = Directory.EnumerateFiles(_backupPath, "*.raf", SearchOption.AllDirectories).ToArray();

            for (int i = 0; i < archives.Length; i++)
            {
                Console.Title = string.Format("Restoring archives... {0} / {1} done", i + 1, archives.Length);

                var target = _archivePath + archives[i].Remove(0, _backupPath.Length);

                if (!Directory.Exists(Path.GetDirectoryName(target)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(target));
                }

                CopyFile(archives[i], target, true, removeBackup);
                CopyFile(archives[i] + ".dat", target + ".dat", true, removeBackup);
            }

            CopyFile(_backupPath + "releasemanifest", _manifestPath, true, removeBackup);

            if (File.Exists(LeagueLocations.GetCorruptFlagPath(_leaguePath)))
            {
                File.Delete(LeagueLocations.GetCorruptFlagPath(_leaguePath));
            }

            Console.Title = title;
        }
Ejemplo n.º 2
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));
            }
        }