using System;
using System.IO;
namespace NHSE.Core;
///
/// Logic for loading decrypted game files.
///
///
public static class GameFileLoader
{
///
/// Loads a copy of the 's files in their decrypted state from the requested .
///
/// Save Data to load
/// Path to load from
public static void Load(this HorizonSave sav, string path)
{
sav.Main.Load(path);
foreach (var p in sav.Players)
{
var dir = Path.Combine(path, p.DirectoryName);
p.Load(dir);
}
}
///
/// Loads a copy of the 's files in their decrypted state from the requested .
///
/// Save Data to load
/// Path to load from
public static void Load(this Player player, string path)
{
foreach (var pair in player)
pair.Load(path);
}
///
/// Loads the 's files in their decrypted state from the requested .
///
/// Save Data to load
/// Path to load from
public static void Load(this EncryptedFilePair pair, string path)
{
Load(path, pair.Data, pair.NameData);
}
private static void Load(string path, Span data, string name)
{
if (!Directory.Exists(path))
return;
var file = Path.Combine(path, name);
if (!File.Exists(file))
return;
var import = File.ReadAllBytes(file);
if (data.Length != import.Length)
return;
import.CopyTo(data);
}
}