diff --git a/.vs/PoE-MxFilterGen/v15/.suo b/.vs/PoE-MxFilterGen/v15/.suo index 6642611..5475b5a 100644 Binary files a/.vs/PoE-MxFilterGen/v15/.suo and b/.vs/PoE-MxFilterGen/v15/.suo differ diff --git a/PoE-MxFilterGen/json/settings.cs b/PoE-MxFilterGen/json/settings.cs index 5d4356d..1dde224 100644 --- a/PoE-MxFilterGen/json/settings.cs +++ b/PoE-MxFilterGen/json/settings.cs @@ -12,7 +12,6 @@ namespace PoE_MxFilterGen.json { public string git { get; set; } public string api { get; set; } - public string league { get; set; } public int confidence { get; set; } public int minimumValue { get; set; } public int chancingMinValue { get; set; } @@ -35,12 +34,6 @@ namespace PoE_MxFilterGen.json return j.api; } - public static string GetLeague() - { - SETTINGS j = JsonConvert.DeserializeObject(File.ReadAllText("settings.json")); - return j.league; - } - public static int GetConfidence() { SETTINGS j = JsonConvert.DeserializeObject(File.ReadAllText("settings.json")); @@ -84,7 +77,6 @@ namespace PoE_MxFilterGen.json { git = js.git, api = js.api, - league = js.league, confidence = js.confidence, minimumValue = js.minimumValue, chancingMinValue = js.chancingMinValue, diff --git a/PoE-MxFilterGen/main.cs b/PoE-MxFilterGen/main.cs index 2aa1b19..119dc92 100644 --- a/PoE-MxFilterGen/main.cs +++ b/PoE-MxFilterGen/main.cs @@ -1,6 +1,7 @@ using Newtonsoft.Json; using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; @@ -8,6 +9,7 @@ using System.Security.Cryptography; using System.Security.Policy; using System.Text; using System.Threading.Tasks; +using static System.Net.Mime.MediaTypeNames; namespace PoE_MxFilterGen { @@ -15,13 +17,25 @@ namespace PoE_MxFilterGen { private static DateTime dt = DateTime.Now; - public static string version = "4.3.0"; + public static string version = "5.0.0"; public static string fDate = string.Format("{0}-{1}-{2}", dt.Day, dt.Month, dt.Year); public static string section = ""; + public static string league = ""; + public static string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); private static string giturl = json.settings.GetGIT(); + public class REMVAR + { + public string league { get; set; } + } + + public class REMSND + { + public List sound { get; set; } + } + public class STRUCTURE { public string section { get; set; } @@ -39,129 +53,158 @@ namespace PoE_MxFilterGen static void Main(string[] args) { msg.Splash(); + + // Get current league from MxD + var ls = web.ReadString("https://data.mxnet.xyz/poe/json/mxfiltergen_var.json"); + REMVAR lj = JsonConvert.DeserializeObject(ls); + league = lj.league; + msg.CMW(league, true, 1); + msg.CMW(string.Format("GIT: {0}", json.settings.GetGIT()), true, 1); msg.CMW(string.Format("API: {0}", json.settings.GetAPI()), true, 1); - msg.CMW(string.Format("League: {0}", json.settings.GetLeague()), true, 1); + msg.CMW(string.Format("League: {0}", league), true, 1); msg.CMW(string.Format("Confidence: {0}", json.settings.GetConfidence().ToString()), true, 1); msg.CMW(string.Format("Minimum Value: {0}c", json.settings.GetMinimumValue().ToString()), true, 1); msg.CMW(string.Format("Chancing Min. Value: {0}c", json.settings.GetChancingMinValue().ToString()), true, 1); msg.CMW(string.Format("Verbose: {0}", json.settings.GetVerbose().ToString()), true, 1); msg.CMW(string.Format("Strict: {0}", json.settings.GetStrict().ToString()), true, 1); - // Check if all the required dir exists - if (!Directory.Exists(@"data\")) + // Check for updates + string remote_version = web.ReadString(@"https://data.mxnet.xyz/poe/txt/mxfiltergen_version.txt"); + if (version != remote_version) + { + Process.Start("PoE-MxFilterGen-Updater.exe"); + //Process.GetCurrentProcess().Kill(); + } else { - Directory.CreateDirectory(@"data\"); - } - if (!Directory.Exists(@"gen\")) - { - Directory.CreateDirectory(@"gen\"); - } - if (!Directory.Exists(@"filter\")) - { - Directory.CreateDirectory(@"filter\"); - } - if (!Directory.Exists(@"structure\")) - { - Directory.CreateDirectory(@"structure\"); - } - - // Clean all generated data - DirectoryInfo dataDir = new DirectoryInfo(@"data\"); - DirectoryInfo genDir = new DirectoryInfo(@"gen\"); - DirectoryInfo filterDir = new DirectoryInfo(@"filter\"); - DirectoryInfo strucDir = new DirectoryInfo(@"structure\"); - foreach (FileInfo file in dataDir.GetFiles()) - { - file.Delete(); - } - foreach (FileInfo file in genDir.GetFiles()) - { - file.Delete(); - } - foreach (FileInfo file in filterDir.GetFiles()) - { - file.Delete(); - } - foreach (FileInfo file in strucDir.GetFiles()) - { - file.Delete(); - } - - // Get latest poe.ninja api - web.SaveString(json.settings.GetAPI() + "GetUniqueArmourOverview?league=" + json.settings.GetLeague(), "data/ninja.armour.json"); - web.SaveString(json.settings.GetAPI() + "GetUniqueWeaponOverview?league=" + json.settings.GetLeague(), "data/ninja.weapon.json"); - web.SaveString(json.settings.GetAPI() + "GetUniqueAccessoryOverview?league=" + json.settings.GetLeague(), "data/ninja.accessory.json"); - web.SaveString(json.settings.GetAPI() + "GetUniqueMapOverview?league=" + json.settings.GetLeague(), "data/ninja.map.json"); - web.SaveString(json.settings.GetAPI() + "GetDivinationCardsOverview?league=" + json.settings.GetLeague(), "data/ninja.card.json"); - - // Setup basic variable - string structure_name = $"{json.settings.GetLeague()}"; - string filter_name = "MxFilter"; - - // Get the structure list - var js = web.ReadString($@"{giturl}/PoE-MxFilter-Structure/master/{structure_name}.json"); - RootStructure j = JsonConvert.DeserializeObject(js); - - // Read the structure one by one to process gen - // Generator (dlls) are downloaded from the web and executed in a separate AppDomain before the AD is unloaded to execute a new generator. - // As we CAN'T unload an assembly, using AppDomains is the only way we can load/unload multiple assembly in a row. - foreach (var sec in j.structures) - { - if (sec.gen == true) + // Check if all the required dir exists + msg.CMW($"Checking for required dirs...",true,1); + if (!Directory.Exists(@"data\")) { - msg.CMW(string.Format("REMOTE_GEN {0}", sec.section), true, 1); - web.DownloadFile($@"{giturl}/PoE-MxFilter-Structure/master/{structure_name}/{sec.section}.dll", $@"structure\{sec.section}.dll"); - json.settings.WriteSection(sec.section); - var bytes = GenerateAssemblyAndGetRawBytes(sec.section); + Directory.CreateDirectory(@"data\"); + } + if (!Directory.Exists(@"gen\")) + { + Directory.CreateDirectory(@"gen\"); + } + if (!Directory.Exists(@"structure\")) + { + Directory.CreateDirectory(@"structure\"); + } - var appDomain = AppDomain.CreateDomain(sec.section, null, new AppDomainSetup + // Clean all generated data + msg.CMW($"Cleaning the base dirs...", true, 1); + DirectoryInfo dataDir = new DirectoryInfo(@"data\"); + DirectoryInfo genDir = new DirectoryInfo(@"gen\"); + DirectoryInfo strucDir = new DirectoryInfo(@"structure\"); + foreach (FileInfo file in dataDir.GetFiles()) + { + file.Delete(); + } + foreach (FileInfo file in genDir.GetFiles()) + { + file.Delete(); + } + foreach (FileInfo file in strucDir.GetFiles()) + { + file.Delete(); + } + + // Clean the latest generated filter from settings path + msg.CMW($"Cleaning the last filter from path...", true, 1); + File.Delete($@"{path}\My Games\Path of Exile\MxFilter.filter"); + + // Get latest poe.ninja api + msg.CMW($"Downloading the latest API data from poe.ninja...", true, 1); + web.SaveString(json.settings.GetAPI() + "GetUniqueArmourOverview?league=" + league, "data/ninja.armour.json"); + web.SaveString(json.settings.GetAPI() + "GetUniqueWeaponOverview?league=" + league, "data/ninja.weapon.json"); + web.SaveString(json.settings.GetAPI() + "GetUniqueAccessoryOverview?league=" + league, "data/ninja.accessory.json"); + web.SaveString(json.settings.GetAPI() + "GetUniqueMapOverview?league=" + league, "data/ninja.map.json"); + web.SaveString(json.settings.GetAPI() + "GetDivinationCardsOverview?league=" + league, "data/ninja.card.json"); + + // Setup basic variable + string structure_name = $"{league}"; + string filter_name = "MxFilter"; + + // Get the structure list + var js = web.ReadString($@"{giturl}/PoE-MxFilter-Structure/master/{structure_name}.json"); + RootStructure j = JsonConvert.DeserializeObject(js); + + // Get Theme File(s) + web.DownloadFile($@"{giturl}/PoE-MxFilter-Structure/master/{structure_name}/Chancing.json", @"structure\Chancing.json"); + + // Read the structure one by one to process gen + // Generator (dlls) are downloaded from the web and executed in a separate AppDomain before the AD is unloaded to execute a new generator. + // As we CAN'T unload an assembly, using AppDomains is the only way we can load/unload multiple assembly in a row. + msg.CMW($@"Generating the filter using {j.structures.Count} data...", true, 1); + foreach (var sec in j.structures) + { + if (sec.gen == true) { - ShadowCopyFiles = "true", - LoaderOptimization = LoaderOptimization.MultiDomainHost - }); + //msg.CMW(string.Format("REMOTE_GEN {0}", sec.section), true, 1); + web.DownloadFile($@"{giturl}/PoE-MxFilter-Structure/master/{structure_name}/{sec.section}.dll", $@"structure\{sec.section}.dll"); + json.settings.WriteSection(sec.section); + var bytes = GenerateAssemblyAndGetRawBytes(sec.section); - var assmblyLoaderType = typeof(AssmeblyLoader); - var assemblyLoader = (IAssemblyLoader)appDomain.CreateInstanceFromAndUnwrap(assmblyLoaderType.Assembly.Location, assmblyLoaderType.FullName); - assemblyLoader.Load(bytes); + var appDomain = AppDomain.CreateDomain(sec.section, null, new AppDomainSetup + { + ShadowCopyFiles = "true", + LoaderOptimization = LoaderOptimization.MultiDomainHost + }); - AppDomain.Unload(appDomain); + var assmblyLoaderType = typeof(AssmeblyLoader); + var assemblyLoader = (IAssemblyLoader)appDomain.CreateInstanceFromAndUnwrap(assmblyLoaderType.Assembly.Location, assmblyLoaderType.FullName); + assemblyLoader.Load(bytes); + + AppDomain.Unload(appDomain); + } + else + { + //msg.CMW($@"REMOTE_GET {sec.section}", true, 1); + web.SaveString($@"{giturl}/PoE-MxFilter-Structure/master/{structure_name}/{sec.section}.filter", $"structure/{sec.section}.filter"); + } } - else + + // Create the final filter. + msg.CMW($@"Creating the final filter...", true, 1); + foreach (var sec in j.structures) { - msg.CMW($@"REMOTE_GET {sec.section}", true, 1); - web.SaveString($@"{giturl}/PoE-MxFilter-Structure/master/{structure_name}/{sec.section}.filter", $"structure/{sec.section}.filter"); + if (sec.gen == true) + { + File.AppendAllText($@"{path}\My Games\Path of Exile\{filter_name}.filter", File.ReadAllText(string.Format("gen\\{0}.filter", sec.section))); + File.AppendAllText($@"{path}\My Games\Path of Exile\{filter_name}.filter", "" + Environment.NewLine); + File.AppendAllText($@"{path}\My Games\Path of Exile\{filter_name}.filter", "" + Environment.NewLine); + } + else + { + File.AppendAllText($@"{path}\My Games\Path of Exile\{filter_name}.filter", string.Format("# Section: {0}", sec.section) + Environment.NewLine); + File.AppendAllText($@"{path}\My Games\Path of Exile\{filter_name}.filter", "" + Environment.NewLine); + File.AppendAllText($@"{path}\My Games\Path of Exile\{filter_name}.filter", File.ReadAllText(string.Format("structure\\{0}.filter", sec.section))); + File.AppendAllText($@"{path}\My Games\Path of Exile\{filter_name}.filter", "" + Environment.NewLine); + File.AppendAllText($@"{path}\My Games\Path of Exile\{filter_name}.filter", "" + Environment.NewLine); + } } - } - // Create the final filter. - foreach (var sec in j.structures) - { - if (sec.gen == true) + // Download the sounds from the remote list + msg.CMW($@"Downloading the latest sound...", true, 1); + var sl = web.ReadString("https://data.mxnet.xyz/poe/json/mxfiltergen_sound.json"); + REMSND slj = JsonConvert.DeserializeObject(sl); + foreach (string s in slj.sound) { - File.AppendAllText($@"filter\{filter_name}.filter", File.ReadAllText(string.Format("gen\\{0}.filter", sec.section))); - File.AppendAllText($@"filter\{filter_name}.filter", "" + Environment.NewLine); - File.AppendAllText($@"filter\{filter_name}.filter", "" + Environment.NewLine); + if (File.Exists($@"{path}\My Games\Path of Exile\{s}")) { File.Delete($@"{path}\My Games\Path of Exile\{s}"); } + web.DownloadFile($"https://data.mxnet.xyz/poe/mp3/{s}",$@"{path}\My Games\Path of Exile\{s}"); } - else - { - File.AppendAllText($@"filter\{filter_name}.filter", string.Format("# Section: {0}", sec.section) + Environment.NewLine); - File.AppendAllText($@"filter\{filter_name}.filter", "" + Environment.NewLine); - File.AppendAllText($@"filter\{filter_name}.filter", File.ReadAllText(string.Format("structure\\{0}.filter", sec.section))); - File.AppendAllText($@"filter\{filter_name}.filter", "" + Environment.NewLine); - File.AppendAllText($@"filter\{filter_name}.filter", "" + Environment.NewLine); - } - } - // Clean all generated data - foreach (FileInfo file in genDir.GetFiles()) - { - file.Delete(); - } - foreach (FileInfo file in strucDir.GetFiles()) - { - file.Delete(); - } + // Clean all generated data + foreach (FileInfo file in genDir.GetFiles()) + { + file.Delete(); + } + foreach (FileInfo file in strucDir.GetFiles()) + { + file.Delete(); + } + } } private static byte[] GenerateAssemblyAndGetRawBytes(string dll) @@ -186,7 +229,7 @@ namespace PoE_MxFilterGen Type type = AppDomain.CurrentDomain.GetAssemblies().SelectMany(t => t.GetTypes()).Where(t => String.Equals(t.Name, "Generator", StringComparison.Ordinal)).First(); object o = Activator.CreateInstance(type); MethodInfo mi = o.GetType().GetMethod("Gen"); - Object[] ob = { json.settings.GetSection(), json.settings.GetAPI(), json.settings.GetLeague(), json.settings.GetMinimumValue(), json.settings.GetChancingMinValue(), json.settings.GetConfidence() }; + Object[] ob = { json.settings.GetSection(), json.settings.GetAPI(), main.league, json.settings.GetMinimumValue(), json.settings.GetChancingMinValue(), json.settings.GetConfidence() }; mi.Invoke(o, ob); } } diff --git a/PoE-MxFilterGen/obj/Debug/PoE-MxFilterGen.csproj.FileListAbsolute.txt b/PoE-MxFilterGen/obj/Debug/PoE-MxFilterGen.csproj.FileListAbsolute.txt index ac3250f..d6cee1c 100644 --- a/PoE-MxFilterGen/obj/Debug/PoE-MxFilterGen.csproj.FileListAbsolute.txt +++ b/PoE-MxFilterGen/obj/Debug/PoE-MxFilterGen.csproj.FileListAbsolute.txt @@ -24,3 +24,13 @@ E:\_MxGit\PoE\PoE-MxFilterGen\PoE-MxFilterGen\obj\Debug\PoE-MxFilterGen.csproj.C E:\_MxGit\PoE\PoE-MxFilterGen\PoE-MxFilterGen\obj\Debug\PoE-MxFilterGen.csproj.CopyComplete E:\_MxGit\PoE\PoE-MxFilterGen\PoE-MxFilterGen\obj\Debug\mxfiltergen.exe E:\_MxGit\PoE\PoE-MxFilterGen\PoE-MxFilterGen\obj\Debug\mxfiltergen.pdb +E:\_MxGitHub\PoE-MxFilterGen\PoE-MxFilterGen\bin\Debug\mxfiltergen.exe.config +E:\_MxGitHub\PoE-MxFilterGen\PoE-MxFilterGen\bin\Debug\mxfiltergen.exe +E:\_MxGitHub\PoE-MxFilterGen\PoE-MxFilterGen\bin\Debug\mxfiltergen.pdb +E:\_MxGitHub\PoE-MxFilterGen\PoE-MxFilterGen\bin\Debug\Newtonsoft.Json.dll +E:\_MxGitHub\PoE-MxFilterGen\PoE-MxFilterGen\bin\Debug\Newtonsoft.Json.xml +E:\_MxGitHub\PoE-MxFilterGen\PoE-MxFilterGen\obj\Debug\PoE-MxFilterGen.csproj.CoreCompileInputs.cache +E:\_MxGitHub\PoE-MxFilterGen\PoE-MxFilterGen\obj\Debug\PoE-MxFilterGen.csproj.CopyComplete +E:\_MxGitHub\PoE-MxFilterGen\PoE-MxFilterGen\obj\Debug\mxfiltergen.exe +E:\_MxGitHub\PoE-MxFilterGen\PoE-MxFilterGen\obj\Debug\mxfiltergen.pdb +E:\_MxGitHub\PoE-MxFilterGen\PoE-MxFilterGen\obj\Debug\PoE-MxFilterGen.csprojAssemblyReference.cache diff --git a/PoE-MxFilterGen/obj/Debug/PoE-MxFilterGen.csprojResolveAssemblyReference.cache b/PoE-MxFilterGen/obj/Debug/PoE-MxFilterGen.csprojResolveAssemblyReference.cache deleted file mode 100644 index dc8b69b..0000000 Binary files a/PoE-MxFilterGen/obj/Debug/PoE-MxFilterGen.csprojResolveAssemblyReference.cache and /dev/null differ diff --git a/PoE-MxFilterGen/obj/Debug/mxfiltergen.exe b/PoE-MxFilterGen/obj/Debug/mxfiltergen.exe index 9b0816b..cd8685a 100644 Binary files a/PoE-MxFilterGen/obj/Debug/mxfiltergen.exe and b/PoE-MxFilterGen/obj/Debug/mxfiltergen.exe differ diff --git a/PoE-MxFilterGen/obj/Debug/mxfiltergen.pdb b/PoE-MxFilterGen/obj/Debug/mxfiltergen.pdb index 170d159..265651c 100644 Binary files a/PoE-MxFilterGen/obj/Debug/mxfiltergen.pdb and b/PoE-MxFilterGen/obj/Debug/mxfiltergen.pdb differ