2019-12-02 16:44:24 +00:00
|
|
|
|
using System;
|
2019-12-14 17:30:52 +00:00
|
|
|
|
using System.Collections.Generic;
|
2019-12-02 16:44:24 +00:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
2019-12-14 17:30:52 +00:00
|
|
|
|
using System.Text;
|
2019-12-02 16:44:24 +00:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Wabbajack.Common;
|
2020-01-03 17:22:50 +00:00
|
|
|
|
using Wabbajack.Common.StoreHandlers;
|
2019-12-02 16:44:24 +00:00
|
|
|
|
using Wabbajack.Lib.Validation;
|
|
|
|
|
|
|
|
|
|
namespace Wabbajack.Lib.Downloaders
|
|
|
|
|
{
|
|
|
|
|
public class SteamWorkshopDownloader : IUrlDownloader
|
|
|
|
|
{
|
|
|
|
|
private SteamWorkshopItem _item;
|
|
|
|
|
|
2019-12-07 03:50:50 +00:00
|
|
|
|
public async Task<AbstractDownloadState> GetDownloaderState(dynamic archiveINI)
|
2019-12-02 16:44:24 +00:00
|
|
|
|
{
|
|
|
|
|
var id = archiveINI?.General?.itemID;
|
|
|
|
|
var steamID = archiveINI?.General?.steamID;
|
|
|
|
|
var size = archiveINI?.General?.itemSize;
|
|
|
|
|
_item = new SteamWorkshopItem
|
|
|
|
|
{
|
|
|
|
|
ItemID = id != null ? int.Parse(id) : 0,
|
|
|
|
|
Size = size != null ? int.Parse(size) : 0,
|
|
|
|
|
Game = steamID != null ? GameRegistry.GetBySteamID(int.Parse(steamID)) : null
|
|
|
|
|
};
|
|
|
|
|
return new State {Item = _item};
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-07 02:45:13 +00:00
|
|
|
|
public async Task Prepare()
|
2019-12-02 16:44:24 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public AbstractDownloadState GetDownloaderState(string url)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class State : AbstractDownloadState
|
|
|
|
|
{
|
|
|
|
|
public SteamWorkshopItem Item { get; set; }
|
2020-01-01 16:19:06 +00:00
|
|
|
|
public override object[] PrimaryKey { get => new object[] {Item.Game, Item.ItemID}; }
|
|
|
|
|
|
2019-12-02 16:44:24 +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-02 16:44:24 +00:00
|
|
|
|
{
|
2020-01-03 17:22:50 +00:00
|
|
|
|
var currentLib = Item.Game.Universe;
|
2019-12-02 16:44:24 +00:00
|
|
|
|
|
2020-01-03 17:22:50 +00:00
|
|
|
|
var downloadFolder = Path.Combine(currentLib, "workshop", "downloads", Item.Game.ID.ToString());
|
|
|
|
|
var contentFolder = Path.Combine(currentLib, "workshop", "content", Item.Game.ID.ToString());
|
2019-12-02 16:44:24 +00:00
|
|
|
|
var p = new Process
|
|
|
|
|
{
|
|
|
|
|
StartInfo = new ProcessStartInfo
|
|
|
|
|
{
|
2020-01-03 17:22:50 +00:00
|
|
|
|
FileName = Path.Combine(StoreHandler.Instance.SteamHandler.SteamPath, "steam.exe"),
|
2019-12-02 16:44:24 +00:00
|
|
|
|
CreateNoWindow = true,
|
2020-01-03 17:22:50 +00:00
|
|
|
|
Arguments = $"console +workshop_download_item {Item.Game.ID} {Item.ItemID}"
|
2019-12-02 16:44:24 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
p.Start();
|
|
|
|
|
|
|
|
|
|
//TODO: async
|
|
|
|
|
var finished = false;
|
|
|
|
|
while (!finished)
|
|
|
|
|
{
|
|
|
|
|
if(!Directory.Exists(Path.Combine(downloadFolder, Item.ItemID.ToString())))
|
|
|
|
|
if (Directory.Exists(Path.Combine(contentFolder, Item.ItemID.ToString())))
|
|
|
|
|
finished = true;
|
|
|
|
|
|
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
}
|
2020-01-18 19:57:26 +00:00
|
|
|
|
|
|
|
|
|
return true;
|
2019-12-02 16:44:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-13 22:55:55 +00:00
|
|
|
|
public override async Task<bool> Verify(Archive a)
|
2019-12-02 16:44:24 +00:00
|
|
|
|
{
|
|
|
|
|
//TODO: find a way to verify steam workshop items
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override IDownloader GetDownloader()
|
|
|
|
|
{
|
|
|
|
|
return DownloadDispatcher.GetInstance<SteamWorkshopDownloader>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string GetReportEntry(Archive a)
|
|
|
|
|
{
|
|
|
|
|
return $"* Steam - [{Item.ItemID}]";
|
|
|
|
|
}
|
2020-01-11 04:15:53 +00:00
|
|
|
|
|
|
|
|
|
public override string[] GetMetaIni()
|
|
|
|
|
{
|
|
|
|
|
return new[]
|
|
|
|
|
{
|
|
|
|
|
"[General]",
|
|
|
|
|
$"itemID={Item.ItemID}",
|
|
|
|
|
$"steamID={Item.Game.Game.MetaData().SteamIDs.First()}",
|
|
|
|
|
$"itemSize={Item.Size}"
|
|
|
|
|
};
|
|
|
|
|
}
|
2019-12-02 16:44:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|