diff --git a/HearthDb.CardDefsDownloader/HearthDb.CardDefsDownloader.csproj b/HearthDb.CardDefsDownloader/HearthDb.CardDefsDownloader.csproj
new file mode 100644
index 0000000..918adb6
--- /dev/null
+++ b/HearthDb.CardDefsDownloader/HearthDb.CardDefsDownloader.csproj
@@ -0,0 +1,9 @@
+
+
+
+ netcoreapp3.1
+ 8
+ Exe
+
+
+
diff --git a/HearthDb.CardDefsDownloader/Program.cs b/HearthDb.CardDefsDownloader/Program.cs
new file mode 100644
index 0000000..391e55d
--- /dev/null
+++ b/HearthDb.CardDefsDownloader/Program.cs
@@ -0,0 +1,31 @@
+using System;
+using System.IO;
+using System.Net;
+using System.Net.Http;
+using System.Net.Http.Headers;
+
+namespace HearthDb.CardDefsDownloader
+{
+ class Program
+ {
+ static void Main(string[] args)
+ {
+ Console.WriteLine(args[0]);
+ var httpClient = new HttpClient(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate });
+
+ // CardDefs.base.xml contains non localized tags and enUS tag
+ // Other languages can be found under e.g. CardDefs.deDE.xml
+ using var request = new HttpRequestMessage(HttpMethod.Get, "https://api.hearthstonejson.com/v1/latest/CardDefs.base.xml");
+ request.Headers.AcceptEncoding.Add(new StringWithQualityHeaderValue("gzip"));
+ request.Headers.AcceptEncoding.Add(new StringWithQualityHeaderValue("deflate"));
+
+ var response = httpClient.SendAsync(request).Result;
+ var data = response.Content.ReadAsStringAsync().Result;
+ File.WriteAllText(Path.Combine(args[0], "CardDefs.base.xml"), data);
+
+ var etag = response.Headers.ETag.Tag;
+ var lastModified = response.Content.Headers.LastModified;
+ File.WriteAllText(Path.Combine(args[0], "CardDefs.base.etag"), $"{etag}\n{lastModified.ToString()}");
+ }
+ }
+}
\ No newline at end of file
diff --git a/HearthDb.Tests/CardDefsLoadTest.cs b/HearthDb.Tests/CardDefsLoadTest.cs
index f6724ee..0a2c805 100644
--- a/HearthDb.Tests/CardDefsLoadTest.cs
+++ b/HearthDb.Tests/CardDefsLoadTest.cs
@@ -36,5 +36,11 @@ public void LoadCards_CorrectlyAssemblesData()
Assert.AreEqual("Flame Lance", Cards.All["AT_001"].GetLocName(Locale.enUS));
Assert.AreEqual("Flammenlanze", Cards.All["AT_001"].GetLocName(Locale.deDE));
}
+
+ [TestMethod]
+ public void HasEtag()
+ {
+ Assert.IsNotNull(Cards.GetBaseCardDefsETag());
+ }
}
}
\ No newline at end of file
diff --git a/HearthDb.sln b/HearthDb.sln
index 5773565..286e4c3 100644
--- a/HearthDb.sln
+++ b/HearthDb.sln
@@ -11,6 +11,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HearthDb.EnumsGenerator", "
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HearthDb.Tests", "HearthDb.Tests\HearthDb.Tests.csproj", "{875316D1-C4C3-48BD-BDAE-3727269B2A67}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HearthDb.CardDefsDownloader", "HearthDb.CardDefsDownloader\HearthDb.CardDefsDownloader.csproj", "{92DBA109-DF71-4874-827A-20B00EABB57D}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -51,6 +53,14 @@ Global
{875316D1-C4C3-48BD-BDAE-3727269B2A67}.Release|Any CPU.Build.0 = Release|Any CPU
{875316D1-C4C3-48BD-BDAE-3727269B2A67}.Release|x86.ActiveCfg = Release|Any CPU
{875316D1-C4C3-48BD-BDAE-3727269B2A67}.Release|x86.Build.0 = Release|Any CPU
+ {92DBA109-DF71-4874-827A-20B00EABB57D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {92DBA109-DF71-4874-827A-20B00EABB57D}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {92DBA109-DF71-4874-827A-20B00EABB57D}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {92DBA109-DF71-4874-827A-20B00EABB57D}.Debug|x86.Build.0 = Debug|Any CPU
+ {92DBA109-DF71-4874-827A-20B00EABB57D}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {92DBA109-DF71-4874-827A-20B00EABB57D}.Release|Any CPU.Build.0 = Release|Any CPU
+ {92DBA109-DF71-4874-827A-20B00EABB57D}.Release|x86.ActiveCfg = Release|Any CPU
+ {92DBA109-DF71-4874-827A-20B00EABB57D}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/HearthDb/Cards.cs b/HearthDb/Cards.cs
index 618da68..633ac12 100644
--- a/HearthDb/Cards.cs
+++ b/HearthDb/Cards.cs
@@ -41,6 +41,21 @@ public static class Cards
public static string Build { get; private set; }
+ private static (string Etag, string LastModified)? _baseCardDefsEtag;
+ public static (string Etag, string LastModified) GetBaseCardDefsETag()
+ {
+ if(_baseCardDefsEtag == null)
+ {
+ using var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("HearthDb.CardDefs.base.etag");
+ if (stream == null)
+ return (null, null);
+ using var reader = new StreamReader(stream);
+ var text = reader.ReadToEnd().Split('\n');
+ _baseCardDefsEtag = (text[0], text[1]);
+ }
+ return _baseCardDefsEtag.Value;
+ }
+
static Cards()
{
if(Config.AutoLoadCardDefs)
diff --git a/HearthDb/HearthDb.csproj b/HearthDb/HearthDb.csproj
index cd82c23..aa2c024 100644
--- a/HearthDb/HearthDb.csproj
+++ b/HearthDb/HearthDb.csproj
@@ -1,4 +1,4 @@
-
+
netstandard2.0
@@ -20,6 +20,9 @@
$(RootNamespace).CardDefs.base.xml
+
+ $(RootNamespace).CardDefs.base.etag
+
@@ -29,15 +32,12 @@
-
-
https://api.hearthstonejson.com/v1/latest/CardDefs.base.xml
-
-
-
+
+