improved backup

This commit is contained in:
FunGamesLeaks 2019-10-28 22:15:55 +01:00
parent 8240be42e0
commit f98afbf64c
2 changed files with 30 additions and 15 deletions

View File

@ -1,19 +1,16 @@
using FModel.Methods.Utilities;
using PakReader;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Xml.Serialization;
using FProp = FModel.Properties.Settings;
namespace FModel.Methods.PAKs
{
static class BackupPAKs
{
public static readonly XmlSerializer serializer = new XmlSerializer(typeof(List<FPakEntry>));
private static readonly string BACKUP_FILE_PATH = FProp.Default.FOutput_Path + "\\Backups\\FortniteGame_" + DateTime.Now.ToString("MMddyyyy") + ".xml";
private static readonly string BACKUP_FILE_PATH = FProp.Default.FOutput_Path + "\\Backups\\FortniteGame_" + DateTime.Now.ToString("MMddyyyy") + ".fbkp";
public static async Task CreateBackupFile()
{
@ -30,7 +27,10 @@ namespace FModel.Methods.PAKs
{
if (PAKEntries.PAKEntriesList != null && PAKEntries.PAKEntriesList.Any())
{
List<FPakEntry> BackupList = new List<FPakEntry>();
new UpdateMyProcessEvents($"Writing {Path.GetFileName(BACKUP_FILE_PATH)}", "Waiting").Update();
Directory.CreateDirectory(Path.GetDirectoryName(BACKUP_FILE_PATH));
var fileStream = new FileStream(BACKUP_FILE_PATH, FileMode.Create);
var writer = new BinaryWriter(fileStream);
foreach (PAKInfosEntry Pak in PAKEntries.PAKEntriesList)
{
byte[] AESKey = null;
@ -59,18 +59,19 @@ namespace FModel.Methods.PAKs
foreach (FPakEntry entry in reader.FileInfos)
{
BackupList.Add(entry);
writer.Write(entry.Pos);
writer.Write(entry.Size);
writer.Write(entry.UncompressedSize);
writer.Write(entry.Encrypted);
writer.Write(entry.StructSize);
writer.Write(entry.Name);
writer.Write(entry.CompressionMethod);
}
}
}
}
new UpdateMyProcessEvents($"Writing {Path.GetFileName(BACKUP_FILE_PATH)}", "Waiting").Update();
Directory.CreateDirectory(Path.GetDirectoryName(BACKUP_FILE_PATH));
using (var fileStream = new FileStream(BACKUP_FILE_PATH, FileMode.Create))
{
serializer.Serialize(fileStream, BackupList);
}
fileStream.Close();
writer.Close();
if (new FileInfo(BACKUP_FILE_PATH).Length > 0) //HENCE WE CHECK THE LENGTH
{
new UpdateMyProcessEvents($"\\Backups\\{Path.GetFileName(BACKUP_FILE_PATH)} successfully created", "Success").Update();

View File

@ -238,7 +238,7 @@ namespace FModel.Methods.PAKs
openFiledialog.Title = "Choose your Backup File";
openFiledialog.InitialDirectory = FProp.Default.FOutput_Path + "\\Backups\\";
openFiledialog.Multiselect = false;
openFiledialog.Filter = "XML Files (*.xml)|*.xml|All Files (*.*)|*.*";
openFiledialog.Filter = "FBKP Files (*.fbkp)|*.fbkp|All Files (*.*)|*.*";
if (openFiledialog.ShowDialog() == true)
{
new UpdateMyProcessEvents("Comparing Files", "Waiting").Update();
@ -246,7 +246,21 @@ namespace FModel.Methods.PAKs
FPakEntry[] BackupEntries;
using (var fileStream = new FileStream(openFiledialog.FileName, FileMode.Open))
{
BackupEntries = ((List<FPakEntry>)BackupPAKs.serializer.Deserialize(fileStream)).ToArray();
List<FPakEntry> entries = new List<FPakEntry>();
var reader = new BinaryReader(fileStream);
while(reader.BaseStream.Position < reader.BaseStream.Length)
{
var 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())