Example #1
0
        private static async Task LoadBackupFile(bool updateMode = false)
        {
            OpenFileDialog openFiledialog = new OpenFileDialog();

            openFiledialog.Title            = "Choose your Backup File";
            openFiledialog.InitialDirectory = FProp.Default.FOutput_Path + "\\Backups\\";
            openFiledialog.Multiselect      = false;
            openFiledialog.Filter           = "FBKP Files (*.fbkp)|*.fbkp|All Files (*.*)|*.*";
            if (openFiledialog.ShowDialog() == true)
            {
                DebugHelper.WriteLine($".PAKs: Loading {openFiledialog.FileName} as the backup file");
                new UpdateMyProcessEvents("Comparing Files", "Waiting").Update();

                FPakEntry[] BackupEntries;
                using (FileStream fileStream = new FileStream(openFiledialog.FileName, FileMode.Open))
                    using (BinaryReader reader = new BinaryReader(fileStream))
                    {
                        DebugHelper.WriteLine(".PAKs: Populating FPakEntry[] for the backup file");

                        List <FPakEntry> entries = new List <FPakEntry>();
                        while (reader.BaseStream.Position < reader.BaseStream.Length)
                        {
                            // we must follow this order
                            long   offset                 = reader.ReadInt64();
                            long   size                   = reader.ReadInt64();
                            long   uncompressedSize       = reader.ReadInt64();
                            bool   encrypted              = reader.ReadBoolean();
                            long   structSize             = reader.ReadInt32();
                            string name                   = reader.ReadString();
                            long   compressionMethodIndex = reader.ReadInt32();

                            // we actually only need name and uncompressedSize to compare
                            FPakEntry entry = new FPakEntry(name, offset, size, uncompressedSize, new byte[20], null, 0, 0, 0);
                            entries.Add(entry);
                        }
                        BackupEntries = entries.ToArray();
                    }

                if (BackupEntries.Any())
                {
                    DebugHelper.WriteLine(".PAKs: FPakEntry[] for the backup file is populated");

                    List <FPakEntry> LocalEntries = new List <FPakEntry>();
                    foreach (FPakEntry[] PAKsFileInfos in PAKEntries.PAKToDisplay.Values)
                    {
                        PAKsFileInfos.ToList().ForEach(x => LocalEntries.Add(x));
                    }
                    PAKEntries.PAKToDisplay.Clear();
                    DebugHelper.WriteLine(".PAKs: FPakEntry[] for the local .PAKs is populated");

                    //FILTER WITH THE OVERRIDED EQUALS METHOD (CHECKING FILE NAME AND FILE UNCOMPRESSED SIZE)
                    DebugHelper.WriteLine($".PAKs: Comparing...\t File Size Check: {FProp.Default.FDiffFileSize}");
                    IEnumerable <FPakEntry> newAssets = LocalEntries.Except(BackupEntries);
                    DebugHelper.WriteLine(".PAKs: Compared");

                    //ADD TO TREE
                    DebugHelper.WriteLine(".PAKs: Filling Treeview with differentiated assets");
                    foreach (FPakEntry entry in newAssets)
                    {
                        string onlyFolders = entry.Name.Substring(0, entry.Name.LastIndexOf('/'));
                        await FWindow.FMain.Dispatcher.InvokeAsync(() =>
                        {
                            TreeViewUtility.PopulateTreeView(srt, onlyFolders.Substring(1));
                        });
                    }

                    //ONLY LOAD THE DIFFERENCE WHEN WE CLICK ON A FOLDER
                    FWindow.FCurrentPAK = "ComparedPAK-WindowsClient.pak";
                    PAKEntries.PAKToDisplay.Add("ComparedPAK-WindowsClient.pak", newAssets.ToArray());
                    await FWindow.FMain.Dispatcher.InvokeAsync(() =>
                    {
                        FWindow.FMain.ViewModel = srt;
                    });

                    DebugHelper.WriteLine(".PAKs: Treeview filled");

                    await FWindow.FMain.Dispatcher.InvokeAsync(() =>
                    {
                        FWindow.FMain.TreeView_Main.IsEnabled     = true;
                        FWindow.FMain.MI_LoadAllPAKs.IsEnabled    = true;
                        FWindow.FMain.MI_BackupPAKs.IsEnabled     = true;
                        FWindow.FMain.MI_DifferenceMode.IsEnabled = true;
                        if (updateMode)
                        {
                            FWindow.FMain.MI_UpdateMode.IsEnabled = true;
                        }
                    });

                    //PRINT REMOVED IF NO FILE SIZE CHECK
                    if (!FProp.Default.FDiffFileSize)
                    {
                        DebugHelper.WriteLine(".PAKs: Checking deleted items");
                        new UpdateMyProcessEvents("Checking deleted items", "Waiting").Update();
                        IEnumerable <FPakEntry> removedAssets = BackupEntries.Except(LocalEntries.ToArray());

                        List <string> removedItems = new List <string>();
                        foreach (FPakEntry entry in removedAssets)
                        {
                            if (entry.Name.StartsWith("/FortniteGame/Content/Athena/Items/Cosmetics/"))
                            {
                                removedItems.Add(entry.Name.Substring(0, entry.Name.LastIndexOf(".")));
                            }
                        }

                        if (removedItems.Count > 0)
                        {
                            DebugHelper.WriteLine(".PAKs: Items Removed/Renamed:");
                            new UpdateMyConsole("Items Removed/Renamed:", CColors.Red, true).Append();
                            removedItems.Distinct().ToList().ForEach(e => {
                                new UpdateMyConsole($"    - {e.Substring(1)}", CColors.White, true).Append();
                                DebugHelper.WriteLine($"    - {e.Substring(1)}");
                            });
                        }
                    }

                    DebugHelper.WriteLine(".PAKs: PAK files have been compared successfully");
                    new UpdateMyProcessEvents("All PAK files have been compared successfully", "Success").Update();
                    umIsOk = true;
                }
                else
                {
                    DebugHelper.WriteLine(".PAKs: FPakEntry[] for the backup file is empty");
                }
            }
            else
            {
                DebugHelper.WriteLine(".PAKs: User canceled when he got asked to select a backup file");

                new UpdateMyConsole("You change your mind pretty fast but it's fine ", CColors.White).Append();
                new UpdateMyConsole("all paks have been loaded instead", CColors.Blue, true).Append();
                FillTreeView(true);

                await FWindow.FMain.Dispatcher.InvokeAsync(() =>
                {
                    FWindow.FMain.TreeView_Main.IsEnabled     = true;
                    FWindow.FMain.MI_LoadAllPAKs.IsEnabled    = true;
                    FWindow.FMain.MI_BackupPAKs.IsEnabled     = true;
                    FWindow.FMain.MI_DifferenceMode.IsEnabled = true;
                    FWindow.FMain.MI_DifferenceMode.IsChecked = false;
                    if (updateMode)
                    {
                        FWindow.FMain.MI_UpdateMode.IsEnabled = true;
                        FWindow.FMain.MI_UpdateMode.IsChecked = false;
                    }
                });
            }
        }
Example #2
0
        private static async Task LoadBackupFile()
        {
            OpenFileDialog openFiledialog = new OpenFileDialog();

            openFiledialog.Title            = "Choose your Backup File";
            openFiledialog.InitialDirectory = FProp.Default.FOutput_Path + "\\Backups\\";
            openFiledialog.Multiselect      = false;
            openFiledialog.Filter           = "FBKP Files (*.fbkp)|*.fbkp|All Files (*.*)|*.*";
            if (openFiledialog.ShowDialog() == true)
            {
                new UpdateMyProcessEvents("Comparing Files", "Waiting").Update();

                FPakEntry[] BackupEntries;
                using (FileStream fileStream = new FileStream(openFiledialog.FileName, FileMode.Open))
                    using (BinaryReader reader = new BinaryReader(fileStream))
                    {
                        List <FPakEntry> entries = new List <FPakEntry>();
                        while (reader.BaseStream.Position < reader.BaseStream.Length)
                        {
                            FPakEntry entry = new FPakEntry();
                            entry.Pos               = reader.ReadInt64();
                            entry.Size              = reader.ReadInt64();
                            entry.UncompressedSize  = reader.ReadInt64();
                            entry.Encrypted         = reader.ReadBoolean();
                            entry.StructSize        = reader.ReadInt32();
                            entry.Name              = reader.ReadString();
                            entry.CompressionMethod = reader.ReadInt32();
                            entries.Add(entry);
                        }
                        BackupEntries = entries.ToArray();
                    }

                if (BackupEntries.Any())
                {
                    List <FPakEntry> LocalEntries = new List <FPakEntry>();
                    foreach (FPakEntry[] PAKsFileInfos in PAKEntries.PAKToDisplay.Values)
                    {
                        PAKsFileInfos.ToList().ForEach(x => LocalEntries.Add(x));
                    }
                    PAKEntries.PAKToDisplay.Clear();

                    //FILTER WITH THE OVERRIDED EQUALS METHOD (CHECKING FILE NAME AND FILE UNCOMPRESSED SIZE)
                    IEnumerable <FPakEntry> newAssets = LocalEntries.ToArray().Except(BackupEntries);

                    //ADD TO TREE
                    foreach (FPakEntry entry in newAssets)
                    {
                        string onlyFolders = entry.Name.Substring(0, entry.Name.LastIndexOf('/'));
                        await FWindow.FMain.Dispatcher.InvokeAsync(() =>
                        {
                            TreeViewUtility.PopulateTreeView(srt, onlyFolders.Substring(1));
                        });
                    }

                    //ONLY LOAD THE DIFFERENCE WHEN WE CLICK ON A FOLDER
                    FWindow.FCurrentPAK = "ComparedPAK-WindowsClient.pak";
                    PAKEntries.PAKToDisplay.Add("ComparedPAK-WindowsClient.pak", newAssets.ToArray());
                    await FWindow.FMain.Dispatcher.InvokeAsync(() =>
                    {
                        FWindow.FMain.ViewModel = srt;
                    });

                    new UpdateMyProcessEvents("All PAK files have been compared successfully", "Success").Update();
                }
            }
            else
            {
                new UpdateMyConsole("You change your mind pretty fast but it's fine ", CColors.White).Append();
                new UpdateMyConsole("all paks have been loaded instead", CColors.Blue, true).Append();
                FillTreeView(true);
            }
        }