From 46d118acc0d0f0fc1ff61b2e35bed49340a4d8cc Mon Sep 17 00:00:00 2001 From: Johannes Grimm Date: Tue, 30 Jan 2024 21:55:19 +0100 Subject: [PATCH 1/2] fix: corrupted download url Adding new url and versions for => 1.4 --- TerrariaSourceGetter/Program.cs | 78 +++++++++++++-------------------- 1 file changed, 31 insertions(+), 47 deletions(-) diff --git a/TerrariaSourceGetter/Program.cs b/TerrariaSourceGetter/Program.cs index ab3eb02..e92a73f 100644 --- a/TerrariaSourceGetter/Program.cs +++ b/TerrariaSourceGetter/Program.cs @@ -123,66 +123,51 @@ static void ExtractReferences(AssemblyInfo asmInfo, string targetDir) File.WriteAllBytes(Path.Combine(targetDir, $"{asmName}.dll"), r.GetResourceData()); } } + - const string BaseURL = "https://terraria.org/system/dedicated_servers/archives/000/000/{0:D3}/original/terraria-server-{1}.zip"; + const string BaseURL = "https://terraria.org/api/download/pc-dedicated-server/terraria-server-{0}.zip"; const string BaseFileName = "terraria-server-{0}"; - private static readonly Dictionary _versions = new Dictionary + private static readonly List _versions = new List() { - [39] = 1405, - [38] = 1404, - [37] = 1403, - [36] = 1402, - [35] = 1401, - - [34] = 1353, - [33] = 1352, - - [26] = 1344, - [25] = 1343, - [24] = 1342, - [23] = 1341, - [22] = 134, - - [21] = 1333, - [20] = 1332, - [19] = 1331, - [18] = 133, - - [15] = 1321, - [14] = 132, - - [13] = 1311, - [11] = 131, - - [11] = 131, - [9] = 1307, - [8] = 1306, - [7] = 1305, - [6] = 1304, - [5] = 1303, - [4] = 1302, - [3] = 1301, + 1423, + 143, + 1431, + 1432, + 1433, + 1434, + 1435, + 1436, + 144, + 1441, + 1442, + 1443, + 1444, + 1445, + 1446, + 1447, + 1448, + 14481, + 1449 }; static void DecompileDedicatedServer() { bool inputValid = false; - var versions = _versions.Select(p => (p.Key, p.Value)).ToList(); int selectedVersion = 0; while (!inputValid) { Console.Clear(); Console.WriteLine("Avaliable versions:"); - for (int i = 0; i < versions.Count; i++) + for (int i = 0; i < _versions.Count; i++) { - Console.WriteLine("{0, 3}. {1, 6}".FormatWith(i, versions[i].Value)); + Console.WriteLine("{0, 3}. {1, 6}".FormatWith(i, _versions[i])); } Console.WriteLine("Input the No. of the version you want to decompile:"); if (int.TryParse(Console.ReadLine(), out int v)) { - if (v >= 0 && v < versions.Count) + if (v >= 0 && v < _versions.Count) { selectedVersion = v; inputValid = true; @@ -190,25 +175,24 @@ static void DecompileDedicatedServer() } } - DecompileDedicatedServerOfVersion(versions[selectedVersion].Key); + DecompileDedicatedServerOfVersion(_versions[selectedVersion]); } static void DecompileDedicatedServerOfVersion(int versionNumber) { - var version = _versions[versionNumber]; - var fileName = $"{BaseFileName.FormatWith(version)}"; - var zipName = $"{BaseFileName.FormatWith(version)}.zip"; + var fileName = $"{BaseFileName.FormatWith(versionNumber)}"; + var zipName = $"{BaseFileName.FormatWith(versionNumber)}.zip"; if (File.Exists(zipName)) { Console.WriteLine("File existed, do you want to download it again? [y/N]"); if (Console.ReadKey().Key == ConsoleKey.Y) - DownloadDedicatedServerBin(BaseURL.FormatWith(versionNumber, version), zipName); + DownloadDedicatedServerBin(BaseURL.FormatWith(versionNumber), zipName); Console.WriteLine(); } else { - DownloadDedicatedServerBin(BaseURL.FormatWith(versionNumber, version), zipName); + DownloadDedicatedServerBin(BaseURL.FormatWith(versionNumber), zipName); } if (Directory.Exists(fileName)) @@ -224,7 +208,7 @@ static void DecompileDedicatedServerOfVersion(int versionNumber) } Console.WriteLine("Choose the platform you want to decompile: [W(Windows)/l(Linux)/m(Mac)/a(All)]"); - var commonDirPath = Path.GetFullPath(Path.Combine(fileName, version.ToString())); + var commonDirPath = Path.GetFullPath(Path.Combine(fileName, versionNumber.ToString())); switch (Console.ReadKey().Key) { case ConsoleKey.L: From bbd97e204ddf8bfec35c718f85d85a4e6c6a12e0 Mon Sep 17 00:00:00 2001 From: Johannes Grimm Date: Wed, 31 Jan 2024 17:07:26 +0100 Subject: [PATCH 2/2] fix: programm crash when file or directory already exist Added deleting file or directory when they already exist and user want to proceed --- TerrariaSourceGetter/Program.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/TerrariaSourceGetter/Program.cs b/TerrariaSourceGetter/Program.cs index e92a73f..cfa338d 100644 --- a/TerrariaSourceGetter/Program.cs +++ b/TerrariaSourceGetter/Program.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -187,7 +187,11 @@ static void DecompileDedicatedServerOfVersion(int versionNumber) { Console.WriteLine("File existed, do you want to download it again? [y/N]"); if (Console.ReadKey().Key == ConsoleKey.Y) + { + Console.WriteLine(); + File.Delete(zipName); DownloadDedicatedServerBin(BaseURL.FormatWith(versionNumber), zipName); + } Console.WriteLine(); } else @@ -199,8 +203,13 @@ static void DecompileDedicatedServerOfVersion(int versionNumber) { Console.WriteLine("There has been extracted files, do you want to extract it again? [y/N]"); if (Console.ReadKey().Key == ConsoleKey.Y) + { + Console.WriteLine(); + Directory.Delete(fileName, true); ExtractFiles(zipName, fileName); + } Console.WriteLine(); + } else {