public static void Run() { var manager = new ArchiveFileManager(LeagueLocations.GetLeaguePath()); var search = new ManifestSearch(manager); manager.Revert(); //var filename1 = "DATA/Items/Icons2D/1053_Vampiric_Scepter.dds"; var filename1 = "DATA/Items/Icons2D/3078_Trinity_Force.dds"; var filename2 = "DATA/Items/Icons2D/3077_Tiamat.dds"; //var filename2 = "DATA/Items/Icons2D/3078_Trinity_Force.dds"; var file1 = manager.ReadFile(filename1); var file2 = manager.ReadFile(filename2); File.WriteAllBytes(@"C:\File 1 Test 1.dds", file1.Uncompress()); File.WriteAllBytes(@"C:\File 2 Test 1.dds", file2.Uncompress()); manager.BeginWriting(); manager.WriteFile(filename1, false, file2); manager.WriteFile(filename2, false, file1); manager.EndWriting(); file1 = manager.ReadFile(filename1); file2 = manager.ReadFile(filename2); File.WriteAllBytes(@"C:\File 1 Test 2.dds", file1.Uncompress()); File.WriteAllBytes(@"C:\File 2 Test 2.dds", file2.Uncompress()); //CompileAssetLists(search); }
private void LoadArchives() { Console.WriteLine("Indexing files..."); _archiveTable = new Dictionary <string, Archive>(); _fileTable = new Dictionary <string, List <Archive> >(); var files = Directory.EnumerateFiles(LeagueLocations.GetArchivePath(_leaguePath), "*.raf", SearchOption.AllDirectories).ToArray(); for (int i = 0; i < files.Length; i++) { var archive = _reader.ReadArchive(files[i]); _archiveTable[archive.FilePath] = archive; foreach (var kvp in archive.Files) { if (!_fileTable.ContainsKey(kvp.Key)) { _fileTable[kvp.Key] = new List <Archive>(); _fileTable[kvp.Key].Add(archive); } else if (_indexTable.ContainsKey(kvp.Key) && _indexTable[kvp.Key].ArchiveId == archive.GetManagerIndex()) { _fileTable[kvp.Key].Add(archive); } } } }
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; }
public BackupManager(string leaguePath) { _leaguePath = leaguePath; _archivePath = LeagueLocations.GetArchivePath(leaguePath); _backupPath = LeagueLocations.GetBackupPath(leaguePath); _manifestPath = LeagueLocations.GetManifestPath(leaguePath); }
private void LoadArchiveStates() { Console.WriteLine("Loading state info..."); _archiveStates = new Dictionary <string, ArchiveState>(); if (File.Exists(LeagueLocations.GetArchiveStatePath(_leaguePath))) { var states = new ArchiveStateReader().ReadArchiveStates(LeagueLocations.GetArchiveStatePath(_leaguePath)); for (int i = 0; i < states.Length; i++) { _archiveStates[states[i].ArchivePath] = states[i]; } } }
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]; } } }
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(); }
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)); } }
static void Main(string[] args) { Console.Title = "League Scrambler"; string leaguePath = ""; if (File.Exists("leaguepath.txt")) { var bytes = File.ReadAllBytes("leaguepath.txt"); leaguePath = ASCIIEncoding.ASCII.GetString(bytes, 0, bytes.Length); } else { leaguePath = LeagueLocations.GetLeaguePath(); } var flag = false; // Make sure the path is valid, if not, ask for user to select it manually. Keep repeating until user exits or selects a proper file. while (string.IsNullOrEmpty(leaguePath) || !Directory.Exists(leaguePath) || !File.Exists(leaguePath + "lol.launcher.exe")) { MessageBox.Show("Couldn't automatically detect your League of Legends installation path, please select it manually.", "Error", MessageBoxButtons.OK); OpenFileDialog dialog = new OpenFileDialog(); dialog.Title = "League of Legends Installation Path"; dialog.Filter = "Leagu of Legends Launcher|lol.launcher.exe"; dialog.FilterIndex = 0; dialog.Multiselect = false; dialog.AutoUpgradeEnabled = true; DialogResult result = dialog.ShowDialog(); if (result == DialogResult.OK) { // We only want the directory name. Also add the backslash to keep it consistent with what we get from the registry automatically. leaguePath = Path.GetDirectoryName(dialog.FileName) + "\\"; flag = true; } else { // Ask the user if he'd like to exit since he didn't select a file. result = MessageBox.Show("No file was selected, would you like to exit?", "Error", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { return; } } } // Save the location if it was manually selected if (flag) { File.WriteAllBytes("leaguepath.txt", ASCIIEncoding.ASCII.GetBytes(leaguePath)); } if (!Directory.Exists(LeagueLocations.GetModPath(leaguePath))) { Directory.CreateDirectory(LeagueLocations.GetModPath(leaguePath)); } var log = new Log(LeagueLocations.GetModPath(leaguePath) + "Log.txt"); log.LogLine(new string('#', 100)); log.LogLine("NEW SESSION STARTED"); log.LogLine(new string('#', 100)); Console.SetOut(log); // Launch the interface try { Interface ui = new Interface(leaguePath); ui.Initialize(); ui.Run(); } catch (Exception e) { log.LogLine(new string('#', 50)); log.LogLine("ERROR OCCURRED"); log.LogLine(new string('#', 50)); Console.WriteLine(e.Message); Console.WriteLine(e.Source); Console.WriteLine(e.StackTrace); log.LogLine(new string('#', 50)); Console.WriteLine("An error has occurred and it has been logged. Please refer to the troubleshooting section found at https://github.com/MythicManiac/League-of-Legends"); Console.WriteLine("Press any key to exit..."); Console.ReadKey(); } }