From e4c37c5d5dc734fb94149af4a6273f35f818bdca Mon Sep 17 00:00:00 2001
From: yuuko <yuuko@partyvan.io>
Date: Sun, 24 Nov 2024 00:49:25 -0800
Subject: chore: rework depotdownloader patches for 2.7

---
 .../0001-emit-json-in-.DepotDownload.patch         | 51 ----------------------
 ...2-ProtoManifest-sort-files-in-constructor.patch | 24 ----------
 .../2_5/0001-emit-json-in-.DepotDownload.patch     | 51 ++++++++++++++++++++++
 ...2-ProtoManifest-sort-files-in-constructor.patch | 24 ++++++++++
 ...1-ProtoManifest-sort-files-in-constructor.patch | 24 ++++++++++
 .../2_7/0002-emit-json-in-.DepotDownload.patch     | 50 +++++++++++++++++++++
 srcds-pkgs/depotdownloader-json/default.nix        | 21 ++++++---
 7 files changed, 163 insertions(+), 82 deletions(-)
 delete mode 100644 srcds-pkgs/depotdownloader-json/0001-emit-json-in-.DepotDownload.patch
 delete mode 100644 srcds-pkgs/depotdownloader-json/0002-ProtoManifest-sort-files-in-constructor.patch
 create mode 100644 srcds-pkgs/depotdownloader-json/2_5/0001-emit-json-in-.DepotDownload.patch
 create mode 100644 srcds-pkgs/depotdownloader-json/2_5/0002-ProtoManifest-sort-files-in-constructor.patch
 create mode 100644 srcds-pkgs/depotdownloader-json/2_7/0001-ProtoManifest-sort-files-in-constructor.patch
 create mode 100644 srcds-pkgs/depotdownloader-json/2_7/0002-emit-json-in-.DepotDownload.patch

diff --git a/srcds-pkgs/depotdownloader-json/0001-emit-json-in-.DepotDownload.patch b/srcds-pkgs/depotdownloader-json/0001-emit-json-in-.DepotDownload.patch
deleted file mode 100644
index 6a58ac6..0000000
--- a/srcds-pkgs/depotdownloader-json/0001-emit-json-in-.DepotDownload.patch
+++ /dev/null
@@ -1,51 +0,0 @@
-From 5ca2011ef9c6463c6e5953101792b663b6546373 Mon Sep 17 00:00:00 2001
-From: yuuko <yuuko@kurofuku.me>
-Date: Fri, 31 Mar 2023 16:03:32 -0700
-Subject: [PATCH] emit json in .DepotDownload
-
----
- DepotDownloader/ContentDownloader.cs | 1 +
- DepotDownloader/ProtoManifest.cs     | 8 ++++++++
- 2 files changed, 9 insertions(+)
-
-diff --git a/DepotDownloader/ContentDownloader.cs b/DepotDownloader/ContentDownloader.cs
-index 7cee83f7..3bf79aa5 100644
---- a/DepotDownloader/ContentDownloader.cs
-+++ b/DepotDownloader/ContentDownloader.cs
-@@ -929,6 +929,7 @@ namespace DepotDownloader
- 
-                     newProtoManifest = new ProtoManifest(depotManifest, depot.manifestId);
-                     newProtoManifest.SaveToFile(newManifestFileName, out checksum);
-+                    newProtoManifest.SaveToJSON(newManifestFileName.Replace(".bin", ".json"));
-                     File.WriteAllBytes(newManifestFileName + ".sha", checksum);
- 
-                     Console.WriteLine(" Done!");
-diff --git a/DepotDownloader/ProtoManifest.cs b/DepotDownloader/ProtoManifest.cs
-index 70389a05..c5e12cfc 100644
---- a/DepotDownloader/ProtoManifest.cs
-+++ b/DepotDownloader/ProtoManifest.cs
-@@ -2,6 +2,8 @@
- using System.Collections.Generic;
- using System.IO;
- using System.IO.Compression;
-+using System.Text;
-+using System.Text.Json;
- using ProtoBuf;
- using SteamKit2;
- 
-@@ -142,6 +144,12 @@ namespace DepotDownloader
-             }
-         }
- 
-+        public void SaveToJSON(string filename)
-+        {
-+            var jsonBytes = new UTF8Encoding(true).GetBytes(JsonSerializer.Serialize(this));
-+            File.Open(filename, FileMode.Create).Write(jsonBytes, 0, jsonBytes.Length);
-+        }
-+
-         public void SaveToFile(string filename, out byte[] checksum)
-         {
-             using (var ms = new MemoryStream())
--- 
-2.38.4
-
diff --git a/srcds-pkgs/depotdownloader-json/0002-ProtoManifest-sort-files-in-constructor.patch b/srcds-pkgs/depotdownloader-json/0002-ProtoManifest-sort-files-in-constructor.patch
deleted file mode 100644
index ac4fe97..0000000
--- a/srcds-pkgs/depotdownloader-json/0002-ProtoManifest-sort-files-in-constructor.patch
+++ /dev/null
@@ -1,24 +0,0 @@
-From 7c067e609efabd54039905dc35edf91afb6c5dad Mon Sep 17 00:00:00 2001
-From: yuuko <yuuko@kurofuku.me>
-Date: Wed, 1 Nov 2023 06:46:57 -0700
-Subject: [PATCH] ProtoManifest: sort files in constructor
-
----
- DepotDownloader/ProtoManifest.cs | 1 +
- 1 file changed, 1 insertion(+)
-
-diff --git a/DepotDownloader/ProtoManifest.cs b/DepotDownloader/ProtoManifest.cs
-index c5e12cfc..5f66595c 100644
---- a/DepotDownloader/ProtoManifest.cs
-+++ b/DepotDownloader/ProtoManifest.cs
-@@ -21,6 +21,7 @@ namespace DepotDownloader
-         public ProtoManifest(DepotManifest sourceManifest, ulong id) : this()
-         {
-             sourceManifest.Files.ForEach(f => Files.Add(new FileData(f)));
-+            Files.Sort((f1,f2) => f1.FileName.CompareTo(f2.FileName));
-             ID = id;
-             CreationTime = sourceManifest.CreationTime;
-         }
--- 
-2.42.0
-
diff --git a/srcds-pkgs/depotdownloader-json/2_5/0001-emit-json-in-.DepotDownload.patch b/srcds-pkgs/depotdownloader-json/2_5/0001-emit-json-in-.DepotDownload.patch
new file mode 100644
index 0000000..6a58ac6
--- /dev/null
+++ b/srcds-pkgs/depotdownloader-json/2_5/0001-emit-json-in-.DepotDownload.patch
@@ -0,0 +1,51 @@
+From 5ca2011ef9c6463c6e5953101792b663b6546373 Mon Sep 17 00:00:00 2001
+From: yuuko <yuuko@kurofuku.me>
+Date: Fri, 31 Mar 2023 16:03:32 -0700
+Subject: [PATCH] emit json in .DepotDownload
+
+---
+ DepotDownloader/ContentDownloader.cs | 1 +
+ DepotDownloader/ProtoManifest.cs     | 8 ++++++++
+ 2 files changed, 9 insertions(+)
+
+diff --git a/DepotDownloader/ContentDownloader.cs b/DepotDownloader/ContentDownloader.cs
+index 7cee83f7..3bf79aa5 100644
+--- a/DepotDownloader/ContentDownloader.cs
++++ b/DepotDownloader/ContentDownloader.cs
+@@ -929,6 +929,7 @@ namespace DepotDownloader
+ 
+                     newProtoManifest = new ProtoManifest(depotManifest, depot.manifestId);
+                     newProtoManifest.SaveToFile(newManifestFileName, out checksum);
++                    newProtoManifest.SaveToJSON(newManifestFileName.Replace(".bin", ".json"));
+                     File.WriteAllBytes(newManifestFileName + ".sha", checksum);
+ 
+                     Console.WriteLine(" Done!");
+diff --git a/DepotDownloader/ProtoManifest.cs b/DepotDownloader/ProtoManifest.cs
+index 70389a05..c5e12cfc 100644
+--- a/DepotDownloader/ProtoManifest.cs
++++ b/DepotDownloader/ProtoManifest.cs
+@@ -2,6 +2,8 @@
+ using System.Collections.Generic;
+ using System.IO;
+ using System.IO.Compression;
++using System.Text;
++using System.Text.Json;
+ using ProtoBuf;
+ using SteamKit2;
+ 
+@@ -142,6 +144,12 @@ namespace DepotDownloader
+             }
+         }
+ 
++        public void SaveToJSON(string filename)
++        {
++            var jsonBytes = new UTF8Encoding(true).GetBytes(JsonSerializer.Serialize(this));
++            File.Open(filename, FileMode.Create).Write(jsonBytes, 0, jsonBytes.Length);
++        }
++
+         public void SaveToFile(string filename, out byte[] checksum)
+         {
+             using (var ms = new MemoryStream())
+-- 
+2.38.4
+
diff --git a/srcds-pkgs/depotdownloader-json/2_5/0002-ProtoManifest-sort-files-in-constructor.patch b/srcds-pkgs/depotdownloader-json/2_5/0002-ProtoManifest-sort-files-in-constructor.patch
new file mode 100644
index 0000000..ac4fe97
--- /dev/null
+++ b/srcds-pkgs/depotdownloader-json/2_5/0002-ProtoManifest-sort-files-in-constructor.patch
@@ -0,0 +1,24 @@
+From 7c067e609efabd54039905dc35edf91afb6c5dad Mon Sep 17 00:00:00 2001
+From: yuuko <yuuko@kurofuku.me>
+Date: Wed, 1 Nov 2023 06:46:57 -0700
+Subject: [PATCH] ProtoManifest: sort files in constructor
+
+---
+ DepotDownloader/ProtoManifest.cs | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/DepotDownloader/ProtoManifest.cs b/DepotDownloader/ProtoManifest.cs
+index c5e12cfc..5f66595c 100644
+--- a/DepotDownloader/ProtoManifest.cs
++++ b/DepotDownloader/ProtoManifest.cs
+@@ -21,6 +21,7 @@ namespace DepotDownloader
+         public ProtoManifest(DepotManifest sourceManifest, ulong id) : this()
+         {
+             sourceManifest.Files.ForEach(f => Files.Add(new FileData(f)));
++            Files.Sort((f1,f2) => f1.FileName.CompareTo(f2.FileName));
+             ID = id;
+             CreationTime = sourceManifest.CreationTime;
+         }
+-- 
+2.42.0
+
diff --git a/srcds-pkgs/depotdownloader-json/2_7/0001-ProtoManifest-sort-files-in-constructor.patch b/srcds-pkgs/depotdownloader-json/2_7/0001-ProtoManifest-sort-files-in-constructor.patch
new file mode 100644
index 0000000..3cc62b8
--- /dev/null
+++ b/srcds-pkgs/depotdownloader-json/2_7/0001-ProtoManifest-sort-files-in-constructor.patch
@@ -0,0 +1,24 @@
+From 1ecf96ef85c9d2d14619da93bd5a5ce53a74d8ad Mon Sep 17 00:00:00 2001
+From: yuuko <yuuko@kurofuku.me>
+Date: Wed, 1 Nov 2023 06:46:57 -0700
+Subject: [PATCH 1/2] ProtoManifest: sort files in constructor
+
+---
+ DepotDownloader/ProtoManifest.cs | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/DepotDownloader/ProtoManifest.cs b/DepotDownloader/ProtoManifest.cs
+index b6eb010..260fdef 100644
+--- a/DepotDownloader/ProtoManifest.cs
++++ b/DepotDownloader/ProtoManifest.cs
+@@ -23,6 +23,7 @@ namespace DepotDownloader
+         public ProtoManifest(DepotManifest sourceManifest, ulong id) : this()
+         {
+             sourceManifest.Files.ForEach(f => Files.Add(new FileData(f)));
++            Files.Sort((f1,f2) => f1.FileName.CompareTo(f2.FileName));
+             ID = id;
+             CreationTime = sourceManifest.CreationTime;
+         }
+-- 
+2.47.0
+
diff --git a/srcds-pkgs/depotdownloader-json/2_7/0002-emit-json-in-.DepotDownload.patch b/srcds-pkgs/depotdownloader-json/2_7/0002-emit-json-in-.DepotDownload.patch
new file mode 100644
index 0000000..cd50e0b
--- /dev/null
+++ b/srcds-pkgs/depotdownloader-json/2_7/0002-emit-json-in-.DepotDownload.patch
@@ -0,0 +1,50 @@
+From 740cc23a0993d5a0d757aeb07762714b5e0a4fbe Mon Sep 17 00:00:00 2001
+From: yuuko <yuuko@partyvan.io>
+Date: Sun, 24 Nov 2024 00:43:33 -0800
+Subject: [PATCH 2/2] emit json in .DepotDownload
+
+---
+ DepotDownloader/ContentDownloader.cs | 1 +
+ DepotDownloader/ProtoManifest.cs     | 8 ++++++++
+ 2 files changed, 9 insertions(+)
+
+diff --git a/DepotDownloader/ContentDownloader.cs b/DepotDownloader/ContentDownloader.cs
+index 9042c39..bd1ec4a 100644
+--- a/DepotDownloader/ContentDownloader.cs
++++ b/DepotDownloader/ContentDownloader.cs
+@@ -876,6 +876,7 @@ namespace DepotDownloader
+ 
+                     newProtoManifest = new ProtoManifest(depotManifest, depot.ManifestId);
+                     newProtoManifest.SaveToFile(newManifestFileName, out var checksum);
++                    newProtoManifest.SaveToJSON(newManifestFileName.Replace(".bin", ".json"));
+                     File.WriteAllBytes(newManifestFileName + ".sha", checksum);
+ 
+                     Console.WriteLine(" Done!");
+diff --git a/DepotDownloader/ProtoManifest.cs b/DepotDownloader/ProtoManifest.cs
+index 260fdef..ffb0420 100644
+--- a/DepotDownloader/ProtoManifest.cs
++++ b/DepotDownloader/ProtoManifest.cs
+@@ -5,6 +5,8 @@ using System;
+ using System.Collections.Generic;
+ using System.IO;
+ using System.IO.Compression;
++using System.Text;
++using System.Text.Json;
+ using System.Security.Cryptography;
+ using ProtoBuf;
+ using SteamKit2;
+@@ -158,5 +160,11 @@ namespace DepotDownloader
+             using var ds = new DeflateStream(fs, CompressionMode.Compress);
+             ms.CopyTo(ds);
+         }
++
++        public void SaveToJSON(string filename)
++        {
++            var jsonBytes = new UTF8Encoding(true).GetBytes(JsonSerializer.Serialize(this));
++            File.Open(filename, FileMode.Create).Write(jsonBytes, 0, jsonBytes.Length);
++        }
+     }
+ }
+-- 
+2.47.0
+
diff --git a/srcds-pkgs/depotdownloader-json/default.nix b/srcds-pkgs/depotdownloader-json/default.nix
index c09422d..7ff0270 100644
--- a/srcds-pkgs/depotdownloader-json/default.nix
+++ b/srcds-pkgs/depotdownloader-json/default.nix
@@ -1,10 +1,17 @@
 { depotdownloader }:
 depotdownloader.overrideAttrs({ patches ? [], version, ... }: {
-  patches = assert builtins.elem version [ "2.4.7" "2.5.0" ]; patches ++ [
-    # with this, nix has access to the hashes in the manifest
-    ./0001-emit-json-in-.DepotDownload.patch
-    # the manifest can arrive out of order across requests to the same build!
-    # luckily that singular reproducibility snag is patched in 1 line.
-    ./0002-ProtoManifest-sort-files-in-constructor.patch
-  ];
+  patches = if builtins.elem version [ "2.4.7" "2.5.0"] then
+    [
+      # with this, nix has access to the hashes in the manifest
+      ./2_5/0001-emit-json-in-.DepotDownload.patch
+      # the manifest can arrive out of order across requests to the same build!
+      # luckily that singular reproducibility snag is patched in 1 line.
+      ./2_5/0002-ProtoManifest-sort-files-in-constructor.patch
+    ]
+  else if builtins.elem version [ "2.7.3" ] then
+    [
+      ./2_7/0001-ProtoManifest-sort-files-in-constructor.patch
+      ./2_7/0002-emit-json-in-.DepotDownload.patch
+    ]
+  else builtins.abort "version of DepotDownloader not covered by patches";
 })
-- 
cgit v1.2.3