mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
73 lines
2.0 KiB
C#
73 lines
2.0 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.IO;
|
|||
|
using System.IO.Compression;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using VFS;
|
|||
|
using Wabbajack.Common;
|
|||
|
|
|||
|
namespace Wabbajack.Lib
|
|||
|
{
|
|||
|
public class VortexInstaller
|
|||
|
{
|
|||
|
public string ModListArchive { get; }
|
|||
|
public ModList ModList { get; }
|
|||
|
|
|||
|
public VirtualFileSystem VFS => VirtualFileSystem.VFS;
|
|||
|
|
|||
|
public VortexInstaller(string archive, ModList modList)
|
|||
|
{
|
|||
|
ModListArchive = archive;
|
|||
|
ModList = modList;
|
|||
|
}
|
|||
|
|
|||
|
public void Info(string msg)
|
|||
|
{
|
|||
|
Utils.Log(msg);
|
|||
|
}
|
|||
|
|
|||
|
public void Status(string msg)
|
|||
|
{
|
|||
|
WorkQueue.Report(msg, 0);
|
|||
|
}
|
|||
|
|
|||
|
private void Error(string msg)
|
|||
|
{
|
|||
|
Utils.Log(msg);
|
|||
|
throw new Exception(msg);
|
|||
|
}
|
|||
|
|
|||
|
public byte[] LoadBytesFromPath(string path)
|
|||
|
{
|
|||
|
using (var fs = new FileStream(ModListArchive, FileMode.Open, FileAccess.Read, FileShare.Read))
|
|||
|
using (var ar = new ZipArchive(fs, ZipArchiveMode.Read))
|
|||
|
using (var ms = new MemoryStream())
|
|||
|
{
|
|||
|
var entry = ar.GetEntry(path);
|
|||
|
using (var e = entry.Open())
|
|||
|
e.CopyTo(ms);
|
|||
|
return ms.ToArray();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public static ModList LoadFromFile(string path)
|
|||
|
{
|
|||
|
using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
|
|||
|
using (var ar = new ZipArchive(fs, ZipArchiveMode.Read))
|
|||
|
{
|
|||
|
var entry = ar.GetEntry("modlist");
|
|||
|
if (entry == null)
|
|||
|
{
|
|||
|
entry = ar.GetEntry("modlist.json");
|
|||
|
using (var e = entry.Open())
|
|||
|
return e.FromJSON<ModList>();
|
|||
|
}
|
|||
|
using (var e = entry.Open())
|
|||
|
return e.FromCERAS<ModList>(ref CerasConfig.Config);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|