From 72708d2c46a18f12775c74260ecc7c14fe7275e4 Mon Sep 17 00:00:00 2001 From: Bitl Date: Mon, 11 Nov 2019 12:13:54 -0700 Subject: [PATCH] More xml stuff --- NovetusLauncher/NovetusFuncs/AssetCacheDef.cs | 17 ++ NovetusLauncher/NovetusFuncs/Downloader.cs | 9 +- NovetusLauncher/NovetusFuncs/GlobalVars.cs | 46 +++-- .../NovetusFuncs/RobloxXMLLocalizer.cs | 104 +++++++++++ .../NovetusTest_FileDownloader.sln | 0 .../NovetusTest_FileDownloader/App.config | 0 .../NovetusTest_FileDownloader/Downloader.cs | 0 .../Form1.Designer.cs | 0 .../NovetusTest_FileDownloader/Form1.cs | 0 .../NovetusTest_FileDownloader/Form1.resx | 0 .../NovetusTest_FileDownloader.csproj | 0 .../NovetusTest_FileDownloader/Program.cs | 0 .../Properties/AssemblyInfo.cs | 0 .../Properties/Resources.Designer.cs | 0 .../Properties/Resources.resx | 0 .../Properties/Settings.Designer.cs | 0 .../Properties/Settings.settings | 0 ...etusTest_RobloxFileDownloaderAndSorter.sln | 22 +++ .../App.config | 0 .../Downloader.cs | 162 ++++++++++++++++++ ...sTest_RobloxFileDownloaderAndSorter.csproj | 64 +++++++ .../Program.cs | 22 +++ .../Properties/AssemblyInfo.cs | 36 ++++ .../RobloxXMLLocalizer.cs | 105 ++++++++++++ .../TestProgramVars.cs | 57 ++++++ .../NovetusTest_RobloxXMLFileParser.sln | 0 .../App.config | 6 + .../NovetusTest_RobloxXMLFileParser.csproj | 0 .../Program.cs | 0 .../Properties/AssemblyInfo.cs | 0 .../RobloxXMLParser.cs | 0 31 files changed, 632 insertions(+), 18 deletions(-) create mode 100644 NovetusLauncher/NovetusFuncs/AssetCacheDef.cs create mode 100644 NovetusLauncher/NovetusFuncs/RobloxXMLLocalizer.cs rename {NovetusTest_FileDownloader => Tests/NovetusTest_FileDownloader}/NovetusTest_FileDownloader.sln (100%) rename {NovetusTest_FileDownloader => Tests/NovetusTest_FileDownloader}/NovetusTest_FileDownloader/App.config (100%) rename {NovetusTest_FileDownloader => Tests/NovetusTest_FileDownloader}/NovetusTest_FileDownloader/Downloader.cs (100%) rename {NovetusTest_FileDownloader => Tests/NovetusTest_FileDownloader}/NovetusTest_FileDownloader/Form1.Designer.cs (100%) rename {NovetusTest_FileDownloader => Tests/NovetusTest_FileDownloader}/NovetusTest_FileDownloader/Form1.cs (100%) rename {NovetusTest_FileDownloader => Tests/NovetusTest_FileDownloader}/NovetusTest_FileDownloader/Form1.resx (100%) rename {NovetusTest_FileDownloader => Tests/NovetusTest_FileDownloader}/NovetusTest_FileDownloader/NovetusTest_FileDownloader.csproj (100%) rename {NovetusTest_FileDownloader => Tests/NovetusTest_FileDownloader}/NovetusTest_FileDownloader/Program.cs (100%) rename {NovetusTest_FileDownloader => Tests/NovetusTest_FileDownloader}/NovetusTest_FileDownloader/Properties/AssemblyInfo.cs (100%) rename {NovetusTest_FileDownloader => Tests/NovetusTest_FileDownloader}/NovetusTest_FileDownloader/Properties/Resources.Designer.cs (100%) rename {NovetusTest_FileDownloader => Tests/NovetusTest_FileDownloader}/NovetusTest_FileDownloader/Properties/Resources.resx (100%) rename {NovetusTest_FileDownloader => Tests/NovetusTest_FileDownloader}/NovetusTest_FileDownloader/Properties/Settings.Designer.cs (100%) rename {NovetusTest_FileDownloader => Tests/NovetusTest_FileDownloader}/NovetusTest_FileDownloader/Properties/Settings.settings (100%) create mode 100644 Tests/NovetusTest_RobloxFileDownloaderAndSorter/NovetusTest_RobloxFileDownloaderAndSorter.sln rename {NovetusTest_RobloxXMLFileParser/NovetusTest_RobloxXMLFileParser => Tests/NovetusTest_RobloxFileDownloaderAndSorter/NovetusTest_RobloxFileDownloaderAndSorter}/App.config (100%) create mode 100644 Tests/NovetusTest_RobloxFileDownloaderAndSorter/NovetusTest_RobloxFileDownloaderAndSorter/Downloader.cs create mode 100644 Tests/NovetusTest_RobloxFileDownloaderAndSorter/NovetusTest_RobloxFileDownloaderAndSorter/NovetusTest_RobloxFileDownloaderAndSorter.csproj create mode 100644 Tests/NovetusTest_RobloxFileDownloaderAndSorter/NovetusTest_RobloxFileDownloaderAndSorter/Program.cs create mode 100644 Tests/NovetusTest_RobloxFileDownloaderAndSorter/NovetusTest_RobloxFileDownloaderAndSorter/Properties/AssemblyInfo.cs create mode 100644 Tests/NovetusTest_RobloxFileDownloaderAndSorter/NovetusTest_RobloxFileDownloaderAndSorter/RobloxXMLLocalizer.cs create mode 100644 Tests/NovetusTest_RobloxFileDownloaderAndSorter/NovetusTest_RobloxFileDownloaderAndSorter/TestProgramVars.cs rename {NovetusTest_RobloxXMLFileParser => Tests/NovetusTest_RobloxXMLFileParser}/NovetusTest_RobloxXMLFileParser.sln (100%) create mode 100644 Tests/NovetusTest_RobloxXMLFileParser/NovetusTest_RobloxXMLFileParser/App.config rename {NovetusTest_RobloxXMLFileParser => Tests/NovetusTest_RobloxXMLFileParser}/NovetusTest_RobloxXMLFileParser/NovetusTest_RobloxXMLFileParser.csproj (100%) rename {NovetusTest_RobloxXMLFileParser => Tests/NovetusTest_RobloxXMLFileParser}/NovetusTest_RobloxXMLFileParser/Program.cs (100%) rename {NovetusTest_RobloxXMLFileParser => Tests/NovetusTest_RobloxXMLFileParser}/NovetusTest_RobloxXMLFileParser/Properties/AssemblyInfo.cs (100%) rename {NovetusTest_RobloxXMLFileParser => Tests/NovetusTest_RobloxXMLFileParser}/NovetusTest_RobloxXMLFileParser/RobloxXMLParser.cs (100%) diff --git a/NovetusLauncher/NovetusFuncs/AssetCacheDef.cs b/NovetusLauncher/NovetusFuncs/AssetCacheDef.cs new file mode 100644 index 0000000..ccff28c --- /dev/null +++ b/NovetusLauncher/NovetusFuncs/AssetCacheDef.cs @@ -0,0 +1,17 @@ +public class AssetCacheDef +{ + public AssetCacheDef(string clas, string[] id, string[] ext, string[] dir, string[] gamedir) + { + Class = clas; + Id = id; + Ext = ext; + Dir = dir; + GameDir = gamedir; + } + + public string Class { get; set; } + public string[] Id { get; set; } + public string[] Ext { get; set; } + public string[] Dir { get; set; } + public string[] GameDir { get; set; } +} \ No newline at end of file diff --git a/NovetusLauncher/NovetusFuncs/Downloader.cs b/NovetusLauncher/NovetusFuncs/Downloader.cs index 7a26677..3fd25ef 100644 --- a/NovetusLauncher/NovetusFuncs/Downloader.cs +++ b/NovetusLauncher/NovetusFuncs/Downloader.cs @@ -19,6 +19,13 @@ class Downloader fileFilter = filter; } + public Downloader(string url, string name) + { + fileName = name; + fileURL = url; + fileFilter = ""; + } + public void setDownloadOutcome(string text) { downloadOutcome = text; @@ -33,7 +40,7 @@ class Downloader { downloadOutcomeAddText = additionalText; - string outputfilename = fileName + "." + fileext; + string outputfilename = fileName + fileext; string fullpath = path + "\\" + outputfilename; try diff --git a/NovetusLauncher/NovetusFuncs/GlobalVars.cs b/NovetusLauncher/NovetusFuncs/GlobalVars.cs index b0bed66..4902207 100644 --- a/NovetusLauncher/NovetusFuncs/GlobalVars.cs +++ b/NovetusLauncher/NovetusFuncs/GlobalVars.cs @@ -19,8 +19,11 @@ public static class GlobalVars public static readonly string ConfigDir = BasePath + "\\config"; public static readonly string ClientDir = BasePath + "\\clients"; public static readonly string MapsDir = BasePath + "\\maps"; + public static readonly string BaseGameDir = "rbxasset://../../../"; + public static readonly string SharedDataGameDir = BaseGameDir + "shareddata/"; + public static readonly string MapGameDir = BaseGameDir + "maps/"; //customization - public static readonly string CustomPlayerDir = DataPath + "\\charcustom"; + public static readonly string CustomPlayerDir = DataPath + "\\charcustom"; public static readonly string hatdir = CustomPlayerDir + "\\hats"; public static readonly string facedir = CustomPlayerDir + "\\faces"; public static readonly string headdir = CustomPlayerDir + "\\heads"; @@ -28,22 +31,6 @@ public static class GlobalVars public static readonly string shirtdir = CustomPlayerDir + "\\shirts"; public static readonly string pantsdir = CustomPlayerDir + "\\pants"; public static readonly string extradir = CustomPlayerDir + "\\custom"; - //asset cache - public static readonly string AssetCacheDir = DataPath + "\\assetcache"; - public static readonly string AssetCacheDirSky = AssetCacheDir + "\\sky"; - public static readonly string AssetCacheDirFonts = AssetCacheDir + "\\fonts"; - public static readonly string AssetCacheDirSounds = AssetCacheDir + "\\sounds"; - public static readonly string AssetCacheDirTextures = AssetCacheDir + "\\textures"; - //game dirs - public static readonly string BaseGameDir = "rbxasset://../../../"; - public static readonly string SharedDataGameDir = BaseGameDir + "shareddata/"; - public static readonly string MapGameDir = BaseGameDir + "maps/"; - - public static readonly string AssetCacheGameDir = SharedDataGameDir + "assetcache/"; - public static readonly string AssetCacheFontsGameDir = AssetCacheGameDir + "fonts/"; - public static readonly string AssetCacheSkyGameDir = AssetCacheGameDir + "sky/"; - public static readonly string AssetCacheSoundsGameDir = AssetCacheGameDir + "sounds/"; - public static readonly string AssetCacheTexturesGameDir = AssetCacheGameDir + "textures/"; public static readonly string CharCustomGameDir = SharedDataGameDir + "charcustom/"; public static readonly string hatGameDir = CharCustomGameDir + "hats/"; @@ -53,6 +40,31 @@ public static class GlobalVars public static readonly string shirtGameDir = CharCustomGameDir + "shirts/"; public static readonly string pantsGameDir = CharCustomGameDir + "pants/"; public static readonly string extraGameDir = CharCustomGameDir + "custom/"; + //asset cache + public static readonly string AssetCacheDir = DataPath + "\\assetcache"; + public static readonly string AssetCacheDirSky = AssetCacheDir + "\\sky"; + public static readonly string AssetCacheDirFonts = AssetCacheDir + "\\fonts"; + public static readonly string AssetCacheDirSounds = AssetCacheDir + "\\sounds"; + public static readonly string AssetCacheDirTextures = AssetCacheDir + "\\textures"; + public static readonly string AssetCacheDirTexturesGUI = AssetCacheDirTextures + "\\gui"; + + public static readonly string AssetCacheGameDir = SharedDataGameDir + "assetcache/"; + public static readonly string AssetCacheFontsGameDir = AssetCacheGameDir + "fonts/"; + public static readonly string AssetCacheSkyGameDir = AssetCacheGameDir + "sky/"; + public static readonly string AssetCacheSoundsGameDir = AssetCacheGameDir + "sounds/"; + public static readonly string AssetCacheTexturesGameDir = AssetCacheGameDir + "textures/"; + public static readonly string AssetCacheTexturesGUIGameDir = AssetCacheTexturesGameDir + "gui/"; + + //defs + public static AssetCacheDef Fonts { get { return new AssetCacheDef("SpecialMesh", new string[] { "MeshId", "TextureId" }, new string[] { ".mesh", ".png" }, new string[] { AssetCacheDirFonts, AssetCacheDirTextures }, new string[] { AssetCacheFontsGameDir, AssetCacheTexturesGameDir }); } } + public static AssetCacheDef Sky { get { return new AssetCacheDef("Sky", new string[] { "SkyboxBk", "SkyboxDn", "SkyboxFt", "SkyboxLf", "SkyboxRt", "SkyboxUp" }, new string[] { ".png" }, new string[] { AssetCacheDirSky }, new string[] { AssetCacheSkyGameDir }); } } + public static AssetCacheDef Decal { get { return new AssetCacheDef("Decal", new string[] { "Texture" }, new string[] { ".png" }, new string[] { AssetCacheDirTextures }, new string[] { AssetCacheTexturesGameDir }); } } + public static AssetCacheDef Texture { get { return new AssetCacheDef("Texture", new string[] { "Texture" }, new string[] { ".png" }, new string[] { AssetCacheDirTextures }, new string[] { AssetCacheTexturesGameDir }); } } + public static AssetCacheDef HopperBin { get { return new AssetCacheDef("HopperBin", new string[] { "TextureId" }, new string[] { ".png" }, new string[] { AssetCacheDirTextures }, new string[] { AssetCacheTexturesGameDir }); } } + public static AssetCacheDef Tool { get { return new AssetCacheDef("Tool", new string[] { "TextureId" }, new string[] { ".png" }, new string[] { AssetCacheDirTextures }, new string[] { AssetCacheTexturesGameDir }); } } + public static AssetCacheDef Sound { get { return new AssetCacheDef("Sound", new string[] { "SoundId" }, new string[] { ".wav" }, new string[] { AssetCacheDirSounds }, new string[] { AssetCacheSoundsGameDir }); } } + public static AssetCacheDef ImageLabel { get { return new AssetCacheDef("ImageLabel", new string[] { "Image" }, new string[] { ".png" }, new string[] { AssetCacheDirTextures }, new string[] { AssetCacheTexturesGameDir }); } } + //item defs below public static string IP = "localhost"; public static string Version = ""; diff --git a/NovetusLauncher/NovetusFuncs/RobloxXMLLocalizer.cs b/NovetusLauncher/NovetusFuncs/RobloxXMLLocalizer.cs new file mode 100644 index 0000000..492eb84 --- /dev/null +++ b/NovetusLauncher/NovetusFuncs/RobloxXMLLocalizer.cs @@ -0,0 +1,104 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using System.Windows.Forms; +using System.Xml; +using System.Xml.Linq; + +public class RobloxXMLLocalizer +{ + public static void DownloadFromNodes(string filepath, AssetCacheDef assetdef, int idIndex, int extIndex, int outputPathIndex, int inGameDirIndex) + { + DownloadFromNodes(filepath, assetdef.Class, assetdef.Id[idIndex], assetdef.Ext[extIndex], assetdef.Dir[outputPathIndex], assetdef.GameDir[inGameDirIndex]); + } + + public static void DownloadFromNodes(string filepath, AssetCacheDef assetdef, int idIndex, int extIndex,string outputPath, int inGameDirIndex) + { + DownloadFromNodes(filepath, assetdef.Class, assetdef.Id[idIndex], assetdef.Ext[extIndex], outputPath, assetdef.GameDir[inGameDirIndex]); + } + + public static void DownloadFromNodes(string filepath, string itemClassValue, string itemIdValue, string fileext, string outputPath, string inGameDir) + { + string oldfile = File.ReadAllText(filepath); + string fixedfile = RemoveInvalidXmlChars(ReplaceHexadecimalSymbols(oldfile)); + XDocument doc = XDocument.Parse(fixedfile); + + try + { + var v = from nodes in doc.Descendants("Item") + where nodes.Attribute("class").Value == itemClassValue + select nodes; + + foreach (var item in v) + { + var v2 = from nodes in item.Descendants("Content") + where nodes.Attribute("name").Value == itemIdValue + select nodes; + + foreach (var item2 in v2) + { + var v3 = from nodes in item2.Descendants("url") + select nodes; + + foreach (var item3 in v3) + { + if (!item3.Value.Contains("rbxasset")) + { + //do whatever with your value + string url = item3.Value; + DownloadFilesFromNode(url, outputPath, fileext); + string[] substrings = url.Split('='); + item3.Value = inGameDir + substrings[1] + fileext; + } + } + } + } + + } + catch (Exception ex) + { + MessageBox.Show("The download has experienced an error: " + ex.Message, "Novetus Localizer", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + finally + { + doc.Save(filepath); + } + } + + private static void DownloadFilesFromNode(string url, string path, string fileext) + { + if (url.Contains('=')) + { + string[] substrings = url.Split('='); + + if (!string.IsNullOrWhiteSpace(substrings[1])) + { + Downloader download = new Downloader(url, substrings[1]); + + try + { + download.InitDownload(path, fileext); + } + catch (Exception ex) + { + MessageBox.Show("The download has experienced an error: " + ex.Message, "Novetus Localizer", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + } + } + + private static string RemoveInvalidXmlChars(string content) + { + return new string(content.Where(ch => XmlConvert.IsXmlChar(ch)).ToArray()); + } + + private static string ReplaceHexadecimalSymbols(string txt) + { + string r = "[\x00-\x08\x0B\x0C\x0E-\x1F\x26]"; + return Regex.Replace(txt, r, "", RegexOptions.Compiled); + } +} diff --git a/NovetusTest_FileDownloader/NovetusTest_FileDownloader.sln b/Tests/NovetusTest_FileDownloader/NovetusTest_FileDownloader.sln similarity index 100% rename from NovetusTest_FileDownloader/NovetusTest_FileDownloader.sln rename to Tests/NovetusTest_FileDownloader/NovetusTest_FileDownloader.sln diff --git a/NovetusTest_FileDownloader/NovetusTest_FileDownloader/App.config b/Tests/NovetusTest_FileDownloader/NovetusTest_FileDownloader/App.config similarity index 100% rename from NovetusTest_FileDownloader/NovetusTest_FileDownloader/App.config rename to Tests/NovetusTest_FileDownloader/NovetusTest_FileDownloader/App.config diff --git a/NovetusTest_FileDownloader/NovetusTest_FileDownloader/Downloader.cs b/Tests/NovetusTest_FileDownloader/NovetusTest_FileDownloader/Downloader.cs similarity index 100% rename from NovetusTest_FileDownloader/NovetusTest_FileDownloader/Downloader.cs rename to Tests/NovetusTest_FileDownloader/NovetusTest_FileDownloader/Downloader.cs diff --git a/NovetusTest_FileDownloader/NovetusTest_FileDownloader/Form1.Designer.cs b/Tests/NovetusTest_FileDownloader/NovetusTest_FileDownloader/Form1.Designer.cs similarity index 100% rename from NovetusTest_FileDownloader/NovetusTest_FileDownloader/Form1.Designer.cs rename to Tests/NovetusTest_FileDownloader/NovetusTest_FileDownloader/Form1.Designer.cs diff --git a/NovetusTest_FileDownloader/NovetusTest_FileDownloader/Form1.cs b/Tests/NovetusTest_FileDownloader/NovetusTest_FileDownloader/Form1.cs similarity index 100% rename from NovetusTest_FileDownloader/NovetusTest_FileDownloader/Form1.cs rename to Tests/NovetusTest_FileDownloader/NovetusTest_FileDownloader/Form1.cs diff --git a/NovetusTest_FileDownloader/NovetusTest_FileDownloader/Form1.resx b/Tests/NovetusTest_FileDownloader/NovetusTest_FileDownloader/Form1.resx similarity index 100% rename from NovetusTest_FileDownloader/NovetusTest_FileDownloader/Form1.resx rename to Tests/NovetusTest_FileDownloader/NovetusTest_FileDownloader/Form1.resx diff --git a/NovetusTest_FileDownloader/NovetusTest_FileDownloader/NovetusTest_FileDownloader.csproj b/Tests/NovetusTest_FileDownloader/NovetusTest_FileDownloader/NovetusTest_FileDownloader.csproj similarity index 100% rename from NovetusTest_FileDownloader/NovetusTest_FileDownloader/NovetusTest_FileDownloader.csproj rename to Tests/NovetusTest_FileDownloader/NovetusTest_FileDownloader/NovetusTest_FileDownloader.csproj diff --git a/NovetusTest_FileDownloader/NovetusTest_FileDownloader/Program.cs b/Tests/NovetusTest_FileDownloader/NovetusTest_FileDownloader/Program.cs similarity index 100% rename from NovetusTest_FileDownloader/NovetusTest_FileDownloader/Program.cs rename to Tests/NovetusTest_FileDownloader/NovetusTest_FileDownloader/Program.cs diff --git a/NovetusTest_FileDownloader/NovetusTest_FileDownloader/Properties/AssemblyInfo.cs b/Tests/NovetusTest_FileDownloader/NovetusTest_FileDownloader/Properties/AssemblyInfo.cs similarity index 100% rename from NovetusTest_FileDownloader/NovetusTest_FileDownloader/Properties/AssemblyInfo.cs rename to Tests/NovetusTest_FileDownloader/NovetusTest_FileDownloader/Properties/AssemblyInfo.cs diff --git a/NovetusTest_FileDownloader/NovetusTest_FileDownloader/Properties/Resources.Designer.cs b/Tests/NovetusTest_FileDownloader/NovetusTest_FileDownloader/Properties/Resources.Designer.cs similarity index 100% rename from NovetusTest_FileDownloader/NovetusTest_FileDownloader/Properties/Resources.Designer.cs rename to Tests/NovetusTest_FileDownloader/NovetusTest_FileDownloader/Properties/Resources.Designer.cs diff --git a/NovetusTest_FileDownloader/NovetusTest_FileDownloader/Properties/Resources.resx b/Tests/NovetusTest_FileDownloader/NovetusTest_FileDownloader/Properties/Resources.resx similarity index 100% rename from NovetusTest_FileDownloader/NovetusTest_FileDownloader/Properties/Resources.resx rename to Tests/NovetusTest_FileDownloader/NovetusTest_FileDownloader/Properties/Resources.resx diff --git a/NovetusTest_FileDownloader/NovetusTest_FileDownloader/Properties/Settings.Designer.cs b/Tests/NovetusTest_FileDownloader/NovetusTest_FileDownloader/Properties/Settings.Designer.cs similarity index 100% rename from NovetusTest_FileDownloader/NovetusTest_FileDownloader/Properties/Settings.Designer.cs rename to Tests/NovetusTest_FileDownloader/NovetusTest_FileDownloader/Properties/Settings.Designer.cs diff --git a/NovetusTest_FileDownloader/NovetusTest_FileDownloader/Properties/Settings.settings b/Tests/NovetusTest_FileDownloader/NovetusTest_FileDownloader/Properties/Settings.settings similarity index 100% rename from NovetusTest_FileDownloader/NovetusTest_FileDownloader/Properties/Settings.settings rename to Tests/NovetusTest_FileDownloader/NovetusTest_FileDownloader/Properties/Settings.settings diff --git a/Tests/NovetusTest_RobloxFileDownloaderAndSorter/NovetusTest_RobloxFileDownloaderAndSorter.sln b/Tests/NovetusTest_RobloxFileDownloaderAndSorter/NovetusTest_RobloxFileDownloaderAndSorter.sln new file mode 100644 index 0000000..3e67c54 --- /dev/null +++ b/Tests/NovetusTest_RobloxFileDownloaderAndSorter/NovetusTest_RobloxFileDownloaderAndSorter.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25420.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NovetusTest_RobloxFileDownloaderAndSorter", "NovetusTest_RobloxFileDownloaderAndSorter\NovetusTest_RobloxFileDownloaderAndSorter.csproj", "{5625D44D-4592-4926-8EFD-76FCC5437971}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5625D44D-4592-4926-8EFD-76FCC5437971}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5625D44D-4592-4926-8EFD-76FCC5437971}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5625D44D-4592-4926-8EFD-76FCC5437971}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5625D44D-4592-4926-8EFD-76FCC5437971}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/NovetusTest_RobloxXMLFileParser/NovetusTest_RobloxXMLFileParser/App.config b/Tests/NovetusTest_RobloxFileDownloaderAndSorter/NovetusTest_RobloxFileDownloaderAndSorter/App.config similarity index 100% rename from NovetusTest_RobloxXMLFileParser/NovetusTest_RobloxXMLFileParser/App.config rename to Tests/NovetusTest_RobloxFileDownloaderAndSorter/NovetusTest_RobloxFileDownloaderAndSorter/App.config diff --git a/Tests/NovetusTest_RobloxFileDownloaderAndSorter/NovetusTest_RobloxFileDownloaderAndSorter/Downloader.cs b/Tests/NovetusTest_RobloxFileDownloaderAndSorter/NovetusTest_RobloxFileDownloaderAndSorter/Downloader.cs new file mode 100644 index 0000000..3fd25ef --- /dev/null +++ b/Tests/NovetusTest_RobloxFileDownloaderAndSorter/NovetusTest_RobloxFileDownloaderAndSorter/Downloader.cs @@ -0,0 +1,162 @@ +using System; +using System.Net; +using System.Windows.Forms; +using System.IO; + +class Downloader +{ + private string fileURL; + private string fileName; + private string fileFilter; + private string downloadOutcome; + private string downloadOutcomeAddText; + private static string downloadOutcomeException; + + public Downloader(string url, string name, string filter) + { + fileName = name; + fileURL = url; + fileFilter = filter; + } + + public Downloader(string url, string name) + { + fileName = name; + fileURL = url; + fileFilter = ""; + } + + public void setDownloadOutcome(string text) + { + downloadOutcome = text; + } + + public string getDownloadOutcome() + { + return downloadOutcome; + } + + public void InitDownload(string path, string fileext, string additionalText = "") + { + downloadOutcomeAddText = additionalText; + + string outputfilename = fileName + fileext; + string fullpath = path + "\\" + outputfilename; + + try + { + int read = DownloadFile(fileURL, fullpath); + downloadOutcome = "File " + outputfilename + " downloaded! " + read + " bytes written! " + downloadOutcomeAddText + downloadOutcomeException; + } + catch (Exception ex) + { + downloadOutcome = "Error when downloading file: " + ex.Message; + } + } + + public void InitDownload(string additionalText = "") + { + downloadOutcomeAddText = additionalText; + + SaveFileDialog saveFileDialog1 = new SaveFileDialog() + { + FileName = fileName, + //"Compressed zip files (*.zip)|*.zip|All files (*.*)|*.*" + Filter = fileFilter, + Title = "Save " + fileName + }; + + if (saveFileDialog1.ShowDialog() == DialogResult.OK) + { + try + { + int read = DownloadFile(fileURL, saveFileDialog1.FileName); + downloadOutcome = "File " + Path.GetFileName(saveFileDialog1.FileName) + " downloaded! " + read + " bytes written! " + downloadOutcomeAddText + downloadOutcomeException; + } + catch (Exception ex) + { + downloadOutcome = "Error when downloading file: " + ex.Message; + } + } + } + + private static int DownloadFile(string remoteFilename, string localFilename) + { + //credit to Tom Archer (https://www.codeguru.com/columns/dotnettips/article.php/c7005/Downloading-Files-with-the-WebRequest-and-WebResponse-Classes.htm) + //and Brokenglass (https://stackoverflow.com/questions/4567313/uncompressing-gzip-response-from-webclient/4567408#4567408) + + // Function will return the number of bytes processed + // to the caller. Initialize to 0 here. + int bytesProcessed = 0; + + // Assign values to these objects here so that they can + // be referenced in the finally block + Stream remoteStream = null; + Stream localStream = null; + WebResponse response = null; + + // Use a try/catch/finally block as both the WebRequest and Stream + // classes throw exceptions upon error + try + { + ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls + | SecurityProtocolType.Tls11 + | SecurityProtocolType.Tls12 + | SecurityProtocolType.Ssl3; + // Create a request for the specified remote file name + HttpWebRequest request = (HttpWebRequest)WebRequest.Create(remoteFilename); + request.UserAgent = "Roblox/WinINet"; + request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate"); + request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; + if (request != null) + { + // Send the request to the server and retrieve the + // WebResponse object + response = request.GetResponse(); + if (response != null) + { + // Once the WebResponse object has been retrieved, + // get the stream object associated with the response's data + remoteStream = response.GetResponseStream(); + + // Create the local file + localStream = File.Create(localFilename); + + // Allocate a 1k buffer + byte[] buffer = new byte[1024]; + int bytesRead; + + // Simple do/while loop to read from stream until + // no bytes are returned + do + { + // Read data (up to 1k) from the stream + bytesRead = remoteStream.Read(buffer, 0, buffer.Length); + + // Write the data to the local file + localStream.Write(buffer, 0, bytesRead); + + // Increment total bytes processed + bytesProcessed += bytesRead; + } while (bytesRead > 0); + } + } + } + catch (Exception e) + { + downloadOutcomeException = " Exception detected: " + e.Message; + } + finally + { + // Close the response and streams objects here + // to make sure they're closed even if an exception + // is thrown at some point + if (response != null) response.Close(); + if (remoteStream != null) remoteStream.Close(); + if (localStream != null) localStream.Close(); + } + + // Return total bytes processed to caller. + return bytesProcessed; + } +} diff --git a/Tests/NovetusTest_RobloxFileDownloaderAndSorter/NovetusTest_RobloxFileDownloaderAndSorter/NovetusTest_RobloxFileDownloaderAndSorter.csproj b/Tests/NovetusTest_RobloxFileDownloaderAndSorter/NovetusTest_RobloxFileDownloaderAndSorter/NovetusTest_RobloxFileDownloaderAndSorter.csproj new file mode 100644 index 0000000..f76f767 --- /dev/null +++ b/Tests/NovetusTest_RobloxFileDownloaderAndSorter/NovetusTest_RobloxFileDownloaderAndSorter/NovetusTest_RobloxFileDownloaderAndSorter.csproj @@ -0,0 +1,64 @@ + + + + + Debug + AnyCPU + {5625D44D-4592-4926-8EFD-76FCC5437971} + Exe + Properties + NovetusTest_RobloxFileDownloaderAndSorter + NovetusTest_RobloxFileDownloaderAndSorter + v4.5.2 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Tests/NovetusTest_RobloxFileDownloaderAndSorter/NovetusTest_RobloxFileDownloaderAndSorter/Program.cs b/Tests/NovetusTest_RobloxFileDownloaderAndSorter/NovetusTest_RobloxFileDownloaderAndSorter/Program.cs new file mode 100644 index 0000000..156eadd --- /dev/null +++ b/Tests/NovetusTest_RobloxFileDownloaderAndSorter/NovetusTest_RobloxFileDownloaderAndSorter/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NovetusTest_RobloxFileDownloaderAndSorter +{ + class Program + { + static void Main(string[] args) + { + string path = GlobalVars.RootPath + "\\Test.rbxl"; + string exportpath = GlobalVars.RootPath + "\\Export"; + + Console.WriteLine("Meshes"); + RobloxXMLLocalizer.DownloadFromNodes(path, GlobalVars.Fonts, 0, 0, exportpath, 0); + Console.WriteLine("Finished!"); + Console.ReadLine(); + } + } +} diff --git a/Tests/NovetusTest_RobloxFileDownloaderAndSorter/NovetusTest_RobloxFileDownloaderAndSorter/Properties/AssemblyInfo.cs b/Tests/NovetusTest_RobloxFileDownloaderAndSorter/NovetusTest_RobloxFileDownloaderAndSorter/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..7d9fb7f --- /dev/null +++ b/Tests/NovetusTest_RobloxFileDownloaderAndSorter/NovetusTest_RobloxFileDownloaderAndSorter/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("NovetusTest_RobloxFileDownloaderAndSorter")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("NovetusTest_RobloxFileDownloaderAndSorter")] +[assembly: AssemblyCopyright("Copyright © 2019")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("5625d44d-4592-4926-8efd-76fcc5437971")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Tests/NovetusTest_RobloxFileDownloaderAndSorter/NovetusTest_RobloxFileDownloaderAndSorter/RobloxXMLLocalizer.cs b/Tests/NovetusTest_RobloxFileDownloaderAndSorter/NovetusTest_RobloxFileDownloaderAndSorter/RobloxXMLLocalizer.cs new file mode 100644 index 0000000..97a9ccd --- /dev/null +++ b/Tests/NovetusTest_RobloxFileDownloaderAndSorter/NovetusTest_RobloxFileDownloaderAndSorter/RobloxXMLLocalizer.cs @@ -0,0 +1,105 @@ +using NovetusTest_RobloxFileDownloaderAndSorter; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using System.Windows.Forms; +using System.Xml; +using System.Xml.Linq; + +public class RobloxXMLLocalizer +{ + public static void DownloadFromNodes(string filepath, AssetCacheDef assetdef, int idIndex, int extIndex, int outputPathIndex, int inGameDirIndex) + { + DownloadFromNodes(filepath, assetdef.Class, assetdef.Id[idIndex], assetdef.Ext[extIndex], assetdef.Dir[outputPathIndex], assetdef.GameDir[inGameDirIndex]); + } + + public static void DownloadFromNodes(string filepath, AssetCacheDef assetdef, int idIndex, int extIndex,string outputPath, int inGameDirIndex) + { + DownloadFromNodes(filepath, assetdef.Class, assetdef.Id[idIndex], assetdef.Ext[extIndex], outputPath, assetdef.GameDir[inGameDirIndex]); + } + + public static void DownloadFromNodes(string filepath, string itemClassValue, string itemIdValue, string fileext, string outputPath, string inGameDir) + { + string oldfile = File.ReadAllText(filepath); + string fixedfile = RemoveInvalidXmlChars(ReplaceHexadecimalSymbols(oldfile)); + XDocument doc = XDocument.Parse(fixedfile); + + try + { + var v = from nodes in doc.Descendants("Item") + where nodes.Attribute("class").Value == itemClassValue + select nodes; + + foreach (var item in v) + { + var v2 = from nodes in item.Descendants("Content") + where nodes.Attribute("name").Value == itemIdValue + select nodes; + + foreach (var item2 in v2) + { + var v3 = from nodes in item2.Descendants("url") + select nodes; + + foreach (var item3 in v3) + { + if (!item3.Value.Contains("rbxasset")) + { + //do whatever with your value + string url = item3.Value; + DownloadFilesFromNode(url, outputPath, fileext); + string[] substrings = url.Split('='); + item3.Value = inGameDir + substrings[1] + fileext; + } + } + } + } + + } + catch (Exception ex) + { + MessageBox.Show("The download has experienced an error: " + ex.Message, "Novetus Localizer", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + finally + { + doc.Save(filepath); + } + } + + private static void DownloadFilesFromNode(string url, string path, string fileext) + { + if (url.Contains('=')) + { + string[] substrings = url.Split('='); + + if (!string.IsNullOrWhiteSpace(substrings[1])) + { + Downloader download = new Downloader(url, substrings[1]); + + try + { + download.InitDownload(path, fileext); + } + catch (Exception ex) + { + MessageBox.Show("The download has experienced an error: " + ex.Message, "Novetus Localizer", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + } + } + + private static string RemoveInvalidXmlChars(string content) + { + return new string(content.Where(ch => XmlConvert.IsXmlChar(ch)).ToArray()); + } + + private static string ReplaceHexadecimalSymbols(string txt) + { + string r = "[\x00-\x08\x0B\x0C\x0E-\x1F\x26]"; + return Regex.Replace(txt, r, "", RegexOptions.Compiled); + } +} diff --git a/Tests/NovetusTest_RobloxFileDownloaderAndSorter/NovetusTest_RobloxFileDownloaderAndSorter/TestProgramVars.cs b/Tests/NovetusTest_RobloxFileDownloaderAndSorter/NovetusTest_RobloxFileDownloaderAndSorter/TestProgramVars.cs new file mode 100644 index 0000000..122f737 --- /dev/null +++ b/Tests/NovetusTest_RobloxFileDownloaderAndSorter/NovetusTest_RobloxFileDownloaderAndSorter/TestProgramVars.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace NovetusTest_RobloxFileDownloaderAndSorter +{ + public class AssetCacheDef + { + public AssetCacheDef(string clas, string[] id, string[] ext, string[] dir, string[] gamedir) + { + Class = clas; + Id = id; + Ext = ext; + Dir = dir; + GameDir = gamedir; + } + + public string Class { get; set; } + public string[] Id { get; set; } + public string[] Ext { get; set; } + public string[] Dir { get; set; } + public string[] GameDir { get; set; } + } + + class GlobalVars + { + public static readonly string RootPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); + public static readonly string BasePath = RootPath.Replace(@"\", @"\\"); + public static readonly string DataPath = BasePath + "\\shareddata"; + public static readonly string AssetCacheDir = DataPath + "\\assetcache"; + public static readonly string AssetCacheDirSky = AssetCacheDir + "\\sky"; + public static readonly string AssetCacheDirFonts = AssetCacheDir + "\\fonts"; + public static readonly string AssetCacheDirSounds = AssetCacheDir + "\\sounds"; + public static readonly string AssetCacheDirTextures = AssetCacheDir + "\\textures"; + + public static readonly string BaseGameDir = "rbxasset://../../../"; + public static readonly string SharedDataGameDir = BaseGameDir + "shareddata/"; + public static readonly string AssetCacheGameDir = SharedDataGameDir + "assetcache/"; + public static readonly string AssetCacheFontsGameDir = AssetCacheGameDir + "fonts/"; + public static readonly string AssetCacheSkyGameDir = AssetCacheGameDir + "sky/"; + public static readonly string AssetCacheSoundsGameDir = AssetCacheGameDir + "sounds/"; + public static readonly string AssetCacheTexturesGameDir = AssetCacheGameDir + "textures/"; + + public static AssetCacheDef Fonts { get { return new AssetCacheDef("SpecialMesh", new string[] { "MeshId", "TextureId"}, new string[] { ".mesh", ".png" }, new string[] { AssetCacheDirFonts, AssetCacheDirTextures }, new string[] { AssetCacheFontsGameDir, AssetCacheTexturesGameDir }); } } + public static AssetCacheDef Sky { get { return new AssetCacheDef("Sky", new string[] { "SkyboxBk", "SkyboxDn", "SkyboxFt", "SkyboxLf", "SkyboxRt", "SkyboxUp" }, new string[] { ".png" }, new string[] { AssetCacheDirSky }, new string[] { AssetCacheSkyGameDir }); } } + public static AssetCacheDef Decal { get { return new AssetCacheDef("Decal", new string[] { "Texture" }, new string[] { ".png" }, new string[] { AssetCacheDirTextures }, new string[] { AssetCacheTexturesGameDir }); } } + public static AssetCacheDef Texture { get { return new AssetCacheDef("Texture", new string[] { "Texture" }, new string[] { ".png" }, new string[] { AssetCacheDirTextures }, new string[] { AssetCacheTexturesGameDir }); } } + public static AssetCacheDef HopperBin { get { return new AssetCacheDef("HopperBin", new string[] { "TextureId" }, new string[] { ".png" }, new string[] { AssetCacheDirTextures }, new string[] { AssetCacheTexturesGameDir }); } } + public static AssetCacheDef Tool { get { return new AssetCacheDef("Tool", new string[] { "TextureId" }, new string[] { ".png" }, new string[] { AssetCacheDirTextures }, new string[] { AssetCacheTexturesGameDir }); } } + public static AssetCacheDef Sound { get { return new AssetCacheDef("Sound", new string[] { "SoundId" }, new string[] { ".wav" }, new string[] { AssetCacheDirSounds }, new string[] { AssetCacheSoundsGameDir }); } } + public static AssetCacheDef ImageLabel { get { return new AssetCacheDef("ImageLabel", new string[] { "Image" }, new string[] { ".png" }, new string[] { AssetCacheDirTextures }, new string[] { AssetCacheTexturesGameDir }); } } + } +} diff --git a/NovetusTest_RobloxXMLFileParser/NovetusTest_RobloxXMLFileParser.sln b/Tests/NovetusTest_RobloxXMLFileParser/NovetusTest_RobloxXMLFileParser.sln similarity index 100% rename from NovetusTest_RobloxXMLFileParser/NovetusTest_RobloxXMLFileParser.sln rename to Tests/NovetusTest_RobloxXMLFileParser/NovetusTest_RobloxXMLFileParser.sln diff --git a/Tests/NovetusTest_RobloxXMLFileParser/NovetusTest_RobloxXMLFileParser/App.config b/Tests/NovetusTest_RobloxXMLFileParser/NovetusTest_RobloxXMLFileParser/App.config new file mode 100644 index 0000000..88fa402 --- /dev/null +++ b/Tests/NovetusTest_RobloxXMLFileParser/NovetusTest_RobloxXMLFileParser/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/NovetusTest_RobloxXMLFileParser/NovetusTest_RobloxXMLFileParser/NovetusTest_RobloxXMLFileParser.csproj b/Tests/NovetusTest_RobloxXMLFileParser/NovetusTest_RobloxXMLFileParser/NovetusTest_RobloxXMLFileParser.csproj similarity index 100% rename from NovetusTest_RobloxXMLFileParser/NovetusTest_RobloxXMLFileParser/NovetusTest_RobloxXMLFileParser.csproj rename to Tests/NovetusTest_RobloxXMLFileParser/NovetusTest_RobloxXMLFileParser/NovetusTest_RobloxXMLFileParser.csproj diff --git a/NovetusTest_RobloxXMLFileParser/NovetusTest_RobloxXMLFileParser/Program.cs b/Tests/NovetusTest_RobloxXMLFileParser/NovetusTest_RobloxXMLFileParser/Program.cs similarity index 100% rename from NovetusTest_RobloxXMLFileParser/NovetusTest_RobloxXMLFileParser/Program.cs rename to Tests/NovetusTest_RobloxXMLFileParser/NovetusTest_RobloxXMLFileParser/Program.cs diff --git a/NovetusTest_RobloxXMLFileParser/NovetusTest_RobloxXMLFileParser/Properties/AssemblyInfo.cs b/Tests/NovetusTest_RobloxXMLFileParser/NovetusTest_RobloxXMLFileParser/Properties/AssemblyInfo.cs similarity index 100% rename from NovetusTest_RobloxXMLFileParser/NovetusTest_RobloxXMLFileParser/Properties/AssemblyInfo.cs rename to Tests/NovetusTest_RobloxXMLFileParser/NovetusTest_RobloxXMLFileParser/Properties/AssemblyInfo.cs diff --git a/NovetusTest_RobloxXMLFileParser/NovetusTest_RobloxXMLFileParser/RobloxXMLParser.cs b/Tests/NovetusTest_RobloxXMLFileParser/NovetusTest_RobloxXMLFileParser/RobloxXMLParser.cs similarity index 100% rename from NovetusTest_RobloxXMLFileParser/NovetusTest_RobloxXMLFileParser/RobloxXMLParser.cs rename to Tests/NovetusTest_RobloxXMLFileParser/NovetusTest_RobloxXMLFileParser/RobloxXMLParser.cs