mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
cache nexus info when validating mod links
This commit is contained in:
parent
4dcbee6fdc
commit
7be81d9a98
@ -27,6 +27,8 @@ namespace Wabbajack.Common
|
||||
}
|
||||
}
|
||||
|
||||
public static string NexusCacheDirectory = "nexus_link_cache";
|
||||
|
||||
public static string WABBAJACK_INCLUDE = "WABBAJACK_INCLUDE";
|
||||
|
||||
public static String AppName = "Wabbajack";
|
||||
|
@ -363,7 +363,7 @@ namespace Wabbajack
|
||||
Status($"Getting Nexus info for {found.Name}");
|
||||
try
|
||||
{
|
||||
var link = NexusAPI.GetNexusDownloadLink((NexusMod)result, NexusKey);
|
||||
var link = NexusAPI.GetNexusDownloadLink((NexusMod)result, NexusKey, true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -65,8 +65,10 @@ namespace Wabbajack
|
||||
return _baseHttpClient;
|
||||
}
|
||||
|
||||
public static string GetNexusDownloadLink(NexusMod archive, string apikey)
|
||||
public static string GetNexusDownloadLink(NexusMod archive, string apikey, bool cache=true)
|
||||
{
|
||||
if (cache && TryGetCachedLink(archive, apikey, out string result)) return result;
|
||||
|
||||
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
|
||||
var client = BaseNexusClient(apikey);
|
||||
string url;
|
||||
@ -79,6 +81,24 @@ namespace Wabbajack
|
||||
}
|
||||
}
|
||||
|
||||
private static bool TryGetCachedLink(NexusMod archive, string apikey, out string result)
|
||||
{
|
||||
if (!(Directory.Exists(Consts.NexusCacheDirectory)))
|
||||
Directory.CreateDirectory(Consts.NexusCacheDirectory);
|
||||
|
||||
|
||||
string path = Path.Combine(Consts.NexusCacheDirectory, $"link-{archive.GameName}-{archive.ModID}-{archive.FileID}.txt");
|
||||
if (!File.Exists(path) || DateTime.Now - new FileInfo(path).LastWriteTime > new TimeSpan(24, 0, 0))
|
||||
{
|
||||
File.Delete(path);
|
||||
result = GetNexusDownloadLink(archive, apikey, false);
|
||||
File.WriteAllText(path, result);
|
||||
return true;
|
||||
}
|
||||
result = File.ReadAllText(path);
|
||||
return true;
|
||||
}
|
||||
|
||||
private static string ConvertGameName(string gameName)
|
||||
{
|
||||
if (gameName == "SkyrimSE") return "skyrimspecialedition";
|
||||
|
Loading…
Reference in New Issue
Block a user