From eeaaa22e55b4de8dda907d6b7afbd6b19a0ad887 Mon Sep 17 00:00:00 2001 From: Bitl Date: Sun, 24 Jul 2022 14:39:49 -0700 Subject: [PATCH] centralize asset fixer functions. add error for loading places in binary format --- .../StorageAndFunctions/GlobalFuncs.cs | 2 + Novetus/NovetusLauncher/Forms/SDK/AssetSDK.cs | 166 +++++++----------- 2 files changed, 70 insertions(+), 98 deletions(-) diff --git a/Novetus/NovetusCore/StorageAndFunctions/GlobalFuncs.cs b/Novetus/NovetusCore/StorageAndFunctions/GlobalFuncs.cs index b2fecff..6d7d602 100644 --- a/Novetus/NovetusCore/StorageAndFunctions/GlobalFuncs.cs +++ b/Novetus/NovetusCore/StorageAndFunctions/GlobalFuncs.cs @@ -2111,9 +2111,11 @@ public class GlobalFuncs } else if (GlobalVars.UserConfiguration.FirstServerLaunch) { +#pragma warning disable CS0219 // Variable is assigned but its value is never used string hostingTips = "For your first time hosting a server, make sure your server's port forwarded (set up in your router), going through a tunnel server, or running from UPnP.\n" + "If your port is forwarded or you are going through a tunnel server, make sure your port is set up as UDP, not TCP.\n" + "Roblox does NOT use TCP, only UDP. However, if your server doesn't work with just UDP, feel free to set up TCP too as that might help the issue in some cases."; +#pragma warning restore CS0219 // Variable is assigned but its value is never used #if LAUNCHER MessageBox.Show(hostingTips, "Novetus - Hosting Tips", MessageBoxButtons.OK, MessageBoxIcon.Information); #elif CMD diff --git a/Novetus/NovetusLauncher/Forms/SDK/AssetSDK.cs b/Novetus/NovetusLauncher/Forms/SDK/AssetSDK.cs index d99cca8..95769a8 100644 --- a/Novetus/NovetusLauncher/Forms/SDK/AssetSDK.cs +++ b/Novetus/NovetusLauncher/Forms/SDK/AssetSDK.cs @@ -376,7 +376,13 @@ public partial class AssetSDK : Form return openFileDialog1; } - public void DownloadFromScript(string filepath, string savefilepath, string inGameDir) + void ProgressChangedEvent() + { + AssetFixer_ProgressBar.Value += 1; + AssetFixer_ProgressLabel.Text = "Progress: " + AssetFixer_ProgressBar.Value.ToString() + "/" + AssetFixer_ProgressBar.Maximum.ToString(); + } + + public void FixURLSOrDownloadFromScript(string filepath, string savefilepath, string inGameDir, bool useURLs, string url) { string[] file = File.ReadAllLines(filepath); @@ -396,36 +402,54 @@ public partial class AssetSDK : Form continue; } - if (line.Contains("http://") || line.Contains("https://")) + string oneline = Regex.Replace(line, @"\t|\n|\r", ""); + AssetLocalization_StatusText.Text = (!useURLs ? "Localizing " : "Fixing " ) + oneline; + AssetLocalization_StatusText.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + + if (!useURLs) { - string oneline = Regex.Replace(line, @"\t|\n|\r", ""); - AssetLocalization_StatusText.Text = "Localizing " + oneline; - AssetLocalization_StatusText.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; - - //https://stackoverflow.com/questions/10576686/c-sharp-regex-pattern-to-extract-urls-from-given-string-not-full-html-urls-but - List links = new List(); - var linkParser = new Regex(@"\b(?:https?://|www\.)\S+\b", RegexOptions.Compiled | RegexOptions.IgnoreCase); - foreach (Match m in linkParser.Matches(line)) + if (line.Contains("http://") || line.Contains("https://")) { - string link = m.Value; - links.Add(link); + //https://stackoverflow.com/questions/10576686/c-sharp-regex-pattern-to-extract-urls-from-given-string-not-full-html-urls-but + List links = new List(); + var linkParser = new Regex(@"\b(?:https?://|www\.)\S+\b", RegexOptions.Compiled | RegexOptions.IgnoreCase); + foreach (Match m in linkParser.Matches(line)) + { + string link = m.Value; + links.Add(link); + } + + foreach (string link in links) + { + string newurl = ((!link.Contains("http://") || !link.Contains("https://")) ? "https://" : "") + + "assetdelivery.roblox.com/v1/asset/?id="; + string urlReplaced = newurl.Contains("https://") ? link.Replace("http://", "").Replace("https://", "") : link.Replace("http://", "https://"); + string urlFixed = GlobalFuncs.FixURLString(urlReplaced, newurl); + + string peram = "id="; + + if (urlFixed.Contains(peram)) + { + string IDVal = urlFixed.After(peram); + string OriginalIDVal = link.After(peram); + RobloxXML.DownloadFilesFromNode(urlFixed, savefilepath, "", IDVal); + file[index - 1] = file[index - 1].Replace(link, inGameDir + OriginalIDVal); + } + } } - - foreach (string link in links) + } + else + { + if ((line.Contains("http://") || line.Contains("https://")) && !line.Contains(url)) { - string newurl = ((!link.Contains("http://") || !link.Contains("https://")) ? "https://" : "") - + "assetdelivery.roblox.com/v1/asset/?id="; - string urlReplaced = newurl.Contains("https://") ? link.Replace("http://", "").Replace("https://", "") : link.Replace("http://", "https://"); - string urlFixed = GlobalFuncs.FixURLString(urlReplaced, newurl); + string oldurl = line; + string urlFixed = GlobalFuncs.FixURLString(oldurl, url); string peram = "id="; if (urlFixed.Contains(peram)) { - string IDVal = urlFixed.After(peram); - string OriginalIDVal = link.After(peram); - RobloxXML.DownloadFilesFromNode(urlFixed, savefilepath, "", IDVal); - file[index - 1] = file[index - 1].Replace(link, inGameDir + OriginalIDVal); + file[index - 1] = urlFixed; } } } @@ -438,7 +462,6 @@ public partial class AssetSDK : Form errors += 1; GlobalFuncs.LogPrint("ASSETFIX|FILE " + path + " LINE #" + (index) + " " + ex.Message, 2); GlobalFuncs.LogPrint("ASSETFIX|Asset might be private or unavailable."); - //MessageBox.Show("Error: Unable to localize the asset. " + ex.Message + "\n\nLine: " + line, "Novetus Asset SDK - Error", MessageBoxButtons.OK, MessageBoxIcon.Error); ProgressChangedEvent(); continue; } @@ -447,81 +470,21 @@ public partial class AssetSDK : Form File.WriteAllLines(filepath, file); } - public void FixURLSInScript(string filepath, string url) - { - string[] file = File.ReadAllLines(filepath); - - int index = 0; - - AssetFixer_ProgressBar.Maximum = file.Length; - - foreach (var line in file) - { - ++index; - - try - { - if (line.Contains("www.w3.org") || line.Contains("roblox.xsd")) - { - ProgressChangedEvent(); - continue; - } - - if ((line.Contains("http://") || line.Contains("https://")) && !line.Contains(url)) - { - string oneline = Regex.Replace(line, @"\t|\n|\r", ""); - AssetLocalization_StatusText.Text = "Fixing " + oneline; - AssetLocalization_StatusText.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; - - string oldurl = line; - string urlFixed = GlobalFuncs.FixURLString(oldurl, url); - - string peram = "id="; - - if (urlFixed.Contains(peram)) - { - file[index - 1] = urlFixed; - } - } - - ProgressChangedEvent(); - } - catch (Exception ex) - { - GlobalFuncs.LogExceptions(ex); - errors += 1; - GlobalFuncs.LogPrint("ASSETFIX|FILE " + path + " LINE #" + (index) + " " + ex.Message, 2); - GlobalFuncs.LogPrint("ASSETFIX|Asset might be private or unavailable."); - //MessageBox.Show("Error: Unable to fix the URL. " + ex.Message + "\n\nLine: " + line, "Novetus Asset SDK - Error", MessageBoxButtons.OK, MessageBoxIcon.Error); - ProgressChangedEvent(); - continue; - } - } - - File.WriteAllLines(filepath, file); - } - - void ProgressChangedEvent() - { - AssetFixer_ProgressBar.Value += 1; - AssetFixer_ProgressLabel.Text = "Progress: " + AssetFixer_ProgressBar.Value.ToString() + "/" + AssetFixer_ProgressBar.Maximum.ToString(); - } - - public void FixURLSOrDownloadFromScript(string filepath, string savefilepath, string inGameDir, bool useURLs, string url) - { - if (useURLs) - { - FixURLSInScript(filepath, url); - } - else - { - DownloadFromScript(filepath, savefilepath, inGameDir); - } - } - public void LocalizeAsset(RobloxFileType type, BackgroundWorker worker, string path, string itemname, string meshname, bool useURLs = false, string remoteurl = "") { - if (GlobalVars.UserConfiguration.AssetSDKFixerSaveBackups) + bool error = false; + string[] file = File.ReadAllLines(path); + + foreach (var line in file) + { + if (line.Contains("