2019-12-14 17:30:52 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
2019-12-14 11:10:22 +00:00
|
|
|
|
using Alphaleonis.Win32.Filesystem;
|
|
|
|
|
using Wabbajack.Common;
|
|
|
|
|
using Wabbajack.Lib.Validation;
|
|
|
|
|
using File = Alphaleonis.Win32.Filesystem.File;
|
|
|
|
|
using Game = Wabbajack.Common.Game;
|
|
|
|
|
|
|
|
|
|
namespace Wabbajack.Lib.Downloaders
|
|
|
|
|
{
|
|
|
|
|
public class GameFileSourceDownloader : IDownloader
|
|
|
|
|
{
|
|
|
|
|
public async Task<AbstractDownloadState> GetDownloaderState(dynamic archiveINI)
|
|
|
|
|
{
|
|
|
|
|
var gameName = (string)archiveINI?.General?.gameName;
|
|
|
|
|
var gameFile = (string)archiveINI?.General?.gameFile;
|
|
|
|
|
|
|
|
|
|
if (gameFile == null || gameFile == null)
|
|
|
|
|
return null;
|
|
|
|
|
|
2020-02-13 12:29:59 +00:00
|
|
|
|
var game = GameRegistry.GetByFuzzyName(gameName);
|
2019-12-14 11:10:22 +00:00
|
|
|
|
if (game == null) return null;
|
|
|
|
|
|
|
|
|
|
var path = game.GameLocation();
|
|
|
|
|
var filePath = Path.Combine(path, gameFile);
|
2019-12-14 17:30:52 +00:00
|
|
|
|
|
2019-12-14 11:10:22 +00:00
|
|
|
|
if (!File.Exists(filePath))
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
var hash = filePath.FileHashCached();
|
|
|
|
|
|
|
|
|
|
return new State
|
|
|
|
|
{
|
2020-02-13 12:29:59 +00:00
|
|
|
|
Game = game.Game,
|
2019-12-14 11:10:22 +00:00
|
|
|
|
GameFile = gameFile,
|
|
|
|
|
Hash = hash,
|
2020-02-13 12:29:59 +00:00
|
|
|
|
GameVersion = game.InstalledVersion
|
2019-12-14 11:10:22 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task Prepare()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class State : AbstractDownloadState
|
|
|
|
|
{
|
|
|
|
|
public Game Game { get; set; }
|
|
|
|
|
public string GameFile { get; set; }
|
|
|
|
|
public string Hash { get; set; }
|
2020-01-03 17:00:57 +00:00
|
|
|
|
|
|
|
|
|
public string GameVersion { get; set; }
|
2019-12-14 11:10:22 +00:00
|
|
|
|
|
|
|
|
|
internal string SourcePath => Path.Combine(Game.MetaData().GameLocation(), GameFile);
|
|
|
|
|
|
2020-01-03 17:00:57 +00:00
|
|
|
|
public override object[] PrimaryKey { get => new object[] {Game, GameVersion, GameFile}; }
|
2020-01-01 16:19:06 +00:00
|
|
|
|
|
2019-12-14 11:10:22 +00:00
|
|
|
|
public override bool IsWhitelisted(ServerWhitelist whitelist)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-18 19:57:26 +00:00
|
|
|
|
public override async Task<bool> Download(Archive a, string destination)
|
2019-12-14 11:10:22 +00:00
|
|
|
|
{
|
|
|
|
|
using(var src = File.OpenRead(SourcePath))
|
2020-01-18 20:52:09 +00:00
|
|
|
|
using (var dest = File.Open(destination, System.IO.FileMode.Create))
|
2019-12-14 11:10:22 +00:00
|
|
|
|
{
|
|
|
|
|
var size = new FileInfo(SourcePath).Length;
|
|
|
|
|
src.CopyToWithStatus(size, dest, "Copying from Game folder");
|
|
|
|
|
}
|
2020-01-18 19:57:26 +00:00
|
|
|
|
return true;
|
2019-12-14 11:10:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-13 22:55:55 +00:00
|
|
|
|
public override async Task<bool> Verify(Archive a)
|
2019-12-14 11:10:22 +00:00
|
|
|
|
{
|
|
|
|
|
return File.Exists(SourcePath) && SourcePath.FileHashCached() == Hash;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override IDownloader GetDownloader()
|
|
|
|
|
{
|
|
|
|
|
return DownloadDispatcher.GetInstance<GameFileSourceDownloader>();
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-02 12:23:07 +00:00
|
|
|
|
public override string GetManifestURL(Archive a)
|
2020-02-02 12:15:29 +00:00
|
|
|
|
{
|
2020-02-02 12:23:07 +00:00
|
|
|
|
return null;
|
2020-02-02 12:15:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-11 04:15:53 +00:00
|
|
|
|
public override string[] GetMetaIni()
|
|
|
|
|
{
|
|
|
|
|
return new[] {"[General]", $"gameName={Game.MetaData().MO2ArchiveName}", $"gameFile={GameFile}"};
|
|
|
|
|
}
|
2019-12-14 11:10:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|