diff --git a/NovetusLauncher/NovetusFuncs/CodeExtensions.cs b/NovetusLauncher/NovetusFuncs/CodeExtensions.cs index c0e3d35..3a31c80 100644 --- a/NovetusLauncher/NovetusFuncs/CodeExtensions.cs +++ b/NovetusLauncher/NovetusFuncs/CodeExtensions.cs @@ -107,4 +107,62 @@ public static class ArrayHelper return result; } +} + +//dotnetperls +static class SubstringExtensions +{ + /// + /// Get string value between [first] a and [last] b. + /// + public static string Between(this string value, string a, string b) + { + int posA = value.IndexOf(a); + int posB = value.LastIndexOf(b); + if (posA == -1) + { + return ""; + } + if (posB == -1) + { + return ""; + } + int adjustedPosA = posA + a.Length; + if (adjustedPosA >= posB) + { + return ""; + } + return value.Substring(adjustedPosA, posB - adjustedPosA); + } + + /// + /// Get string value after [first] a. + /// + public static string Before(this string value, string a) + { + int posA = value.IndexOf(a); + if (posA == -1) + { + return ""; + } + return value.Substring(0, posA); + } + + /// + /// Get string value after [last] a. + /// + public static string After(this string value, string a) + { + int posA = value.LastIndexOf(a); + if (posA == -1) + { + return ""; + } + int adjustedPosA = posA + a.Length; + if (adjustedPosA >= value.Length) + { + return ""; + } + return value.Substring(adjustedPosA); + } } \ No newline at end of file diff --git a/NovetusLauncher/NovetusFuncs/RobloxXMLLocalizer.cs b/NovetusLauncher/NovetusFuncs/RobloxXMLLocalizer.cs index d4d535d..68d5027 100644 --- a/NovetusLauncher/NovetusFuncs/RobloxXMLLocalizer.cs +++ b/NovetusLauncher/NovetusFuncs/RobloxXMLLocalizer.cs @@ -64,11 +64,15 @@ public static class RobloxXMLLocalizer { //do whatever with your value string url = item3.Value; - DownloadFilesFromNode(url, outputPath, fileext); - if (url.Contains('=')) + string urlFixed = url.Replace("&", "&").Replace("amp;", "&"); + //MessageBox.Show(urlFixed, "Novetus Asset Localizer", MessageBoxButtons.OK, MessageBoxIcon.Information); + string peram = "id="; + + if (urlFixed.Contains(peram)) { - string[] substrings = url.Split('='); - item3.Value = inGameDir + substrings[1] + fileext; + string IDVal = urlFixed.After(peram); + DownloadFilesFromNode(urlFixed, outputPath, fileext, IDVal); + item3.Value = inGameDir + IDVal + fileext; } } } @@ -86,24 +90,19 @@ public static class RobloxXMLLocalizer } } - private static void DownloadFilesFromNode(string url, string path, string fileext) + private static void DownloadFilesFromNode(string url, string path, string fileext, string id) { - if (url.Contains('=')) + if (!string.IsNullOrWhiteSpace(id)) { - string[] substrings = url.Split('='); + Downloader download = new Downloader(url, id); - if (!string.IsNullOrWhiteSpace(substrings[1])) + try { - Downloader download = new Downloader(url, substrings[1]); - - try - { - download.InitDownload(path, fileext); - } - catch (Exception ex) when (!Env.Debugging) - { - MessageBox.Show("The download has experienced an error: " + ex.Message, "Novetus Asset Localizer", MessageBoxButtons.OK, MessageBoxIcon.Information); - } + download.InitDownload(path, fileext); + } + catch (Exception ex) when (!Env.Debugging) + { + MessageBox.Show("The download has experienced an error: " + ex.Message, "Novetus Asset Localizer", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }