diff --git a/PoE-MxFilterGen/Properties/AssemblyInfo.cs b/PoE-MxFilterGen/Properties/AssemblyInfo.cs index 2f24fac..d809034 100644 --- a/PoE-MxFilterGen/Properties/AssemblyInfo.cs +++ b/PoE-MxFilterGen/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // 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: AssemblyVersion("8.1.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/PoE-MxFilterGen/json/settings.cs b/PoE-MxFilterGen/json/settings.cs index a69749f..f746bfb 100644 --- a/PoE-MxFilterGen/json/settings.cs +++ b/PoE-MxFilterGen/json/settings.cs @@ -12,7 +12,9 @@ namespace PoE_MxFilterGen.json { public string git { get; set; } public string api { get; set; } - public int minimumValue { get; set; } + public int uniqueValue { get; set; } + public int fossilValue { get; set; } + public int cardValue { get; set; } public bool verbose { get; set; } public bool ssf { get; set; } public string section { get; set; } @@ -20,28 +22,23 @@ namespace PoE_MxFilterGen.json class settings { - public static string GetGIT() + + public static int GetUniqueValue() { SETTINGS j = JsonConvert.DeserializeObject(File.ReadAllText("settings.json")); - return j.git; + return j.uniqueValue; } - public static string GetAPI() + public static int GetFossilValue() { SETTINGS j = JsonConvert.DeserializeObject(File.ReadAllText("settings.json")); - return j.api; + return j.fossilValue; } - public static int GetMinimumValue() + public static int GetCardValue() { SETTINGS j = JsonConvert.DeserializeObject(File.ReadAllText("settings.json")); - return j.minimumValue; - } - - public static bool GetVerbose() - { - SETTINGS j = JsonConvert.DeserializeObject(File.ReadAllText("settings.json")); - return j.verbose; + return j.cardValue; } public static string GetSection() @@ -50,22 +47,14 @@ namespace PoE_MxFilterGen.json return j.section; } - public static bool GetSSF() - { - SETTINGS j = JsonConvert.DeserializeObject(File.ReadAllText("settings.json")); - return j.ssf; - } - public static void WriteSection(string section) { SETTINGS js = JsonConvert.DeserializeObject(File.ReadAllText($@"settings.json")); SETTINGS se = new SETTINGS { - git = js.git, - api = js.api, - minimumValue = js.minimumValue, - verbose = js.verbose, - ssf = js.ssf, + uniqueValue = js.uniqueValue, + fossilValue = js.fossilValue, + cardValue = js.cardValue, section = section }; var raw = JsonConvert.SerializeObject(se, Formatting.Indented); diff --git a/PoE-MxFilterGen/main.cs b/PoE-MxFilterGen/main.cs index fba1a79..7b11616 100644 --- a/PoE-MxFilterGen/main.cs +++ b/PoE-MxFilterGen/main.cs @@ -9,6 +9,7 @@ using System.Security.Cryptography; using System.Security.Policy; using System.Text; using System.Threading.Tasks; +using System.Xml; using static System.Net.Mime.MediaTypeNames; namespace PoE_MxFilterGen @@ -17,7 +18,7 @@ namespace PoE_MxFilterGen { private static DateTime dt = DateTime.Now; - public static string version = "8.0.0"; + public static string version = "8.2.0"; public static string fDate = string.Format("{0}-{1}-{2}", dt.Day, dt.Month, dt.Year); public static string api = ""; @@ -68,10 +69,18 @@ namespace PoE_MxFilterGen web.DownloadFile("https://raw.githubusercontent.com/mikxqc/PoE-MxFilter-Data/master/json/mxfiltergen_temp_settings.json", "settings.json"); } - //web.DownloadFile("https://raw.githubusercontent.com/mikxqc/PoE-MxFilter-Data/master/bin/mxfiltergen_updater.exe", "PoE-MxFilterGen-Updater.exe"); - msg.Splash(); + //Update Logic + msg.CMW("Checking for update...",true,1); + string remote_version = web.ReadString(@"https://raw.githubusercontent.com/mikxqc/PoE-MxFilter-Data/master/txt/mxfiltergen_version.txt"); + if (remote_version != version && deb == false) + { + web.DownloadFile("https://raw.githubusercontent.com/mikxqc/PoE-MxFilter-Data/master/bin/mxfiltergen_updater.exe", "PoE-MxFilterGen-Updater.exe"); + Process.Start("PoE-MxFilterGen-Updater.exe"); + Process.GetCurrentProcess().Kill(); + } + // Get current league from MxD var ls = web.ReadString("https://raw.githubusercontent.com/mikxqc/PoE-MxFilter-Data/master/json/mxfiltergen_var.json"); REMVAR lj = JsonConvert.DeserializeObject(ls); @@ -79,150 +88,135 @@ namespace PoE_MxFilterGen api = $"https://poe.ninja/api/data/"; - 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}", league), true, 1); - msg.CMW(string.Format("Minimum Value: {0}c", json.settings.GetMinimumValue().ToString()), true, 1); - msg.CMW(string.Format("Verbose: {0}", json.settings.GetVerbose().ToString()), true, 1); - msg.CMW(string.Format("SSF: {0}", json.settings.GetSSF().ToString()), true, 1); + msg.CMW($"League: {league}", true, 1); + msg.CMW($"Min. Unique Value - {json.settings.GetUniqueValue()}c", true, 1); + msg.CMW($"Min. Fossil Value - {json.settings.GetFossilValue()}c", true, 1); + msg.CMW($"Min. Card Value - {json.settings.GetCardValue()}c", true, 1); - // Check for updates - string remote_version = web.ReadString(@"https://raw.githubusercontent.com/mikxqc/PoE-MxFilter-Data/master/txt/mxfiltergen_version.txt"); - //msg.CMW(remote_version,true,3); - if (deb == false) - { - //Process.Start("PoE-MxFilterGen-Updater.exe"); - //Process.GetCurrentProcess().Kill(); - } else - { - // Check if all the required dir exists - msg.CMW($"Checking for required dirs...",true,1); - if (!Directory.Exists(@"data\")) + // Check if all the required dir exists + msg.CMW($"Checking for required dirs...", true, 1); + if (!Directory.Exists(@"data\")) + { + Directory.CreateDirectory(@"data\"); + } + if (!Directory.Exists(@"gen\")) + { + Directory.CreateDirectory(@"gen\"); + } + if (!Directory.Exists(@"structure\")) + { + Directory.CreateDirectory(@"structure\"); + } + + // Clean all generated data + msg.CMW($"Cleaning the base dirs...", true, 1); + CleanDirData(); + + // 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_Normal.filter"); + File.Delete($@"{path}\My Games\Path of Exile\MxFilter_Strict.filter"); + File.Delete($@"{path}\My Games\Path of Exile\MxFilter_Strict_NSNLC.filter"); + + // Get latest poe.ninja api + msg.CMW($"Downloading the latest API data from poe.ninja...", true, 1); + + web.SaveString(api + $"itemoverview?league={league}&type=UniqueArmour&language=en", "data/ninja.armour.json"); + web.SaveString(api + $"itemoverview?league={league}&type=UniqueWeapon&language=en", "data/ninja.weapon.json"); + web.SaveString(api + $"itemoverview?league={league}&type=UniqueAccessory&language=en", "data/ninja.accessory.json"); + web.SaveString(api + $"itemoverview?league={league}&type=DivinationCard&language=en", "data/ninja.card.json"); + web.SaveString(api + $"currencyoverview?league={league}&type=Currency&language=en", "data/ninja.currency.json"); + web.SaveString(api + $"itemoverview?league={league}&type=Fossil&language=en", "data/ninja.fossil.json"); + + // Generate Filter Array + string[] filters; + filters = new string[] { "Normal", "Strict", "Strict_NSNLC" }; + + foreach (string f in filters) + { + // Setup basic variable + string filter_name = "MxFilter"; + + // Get the structure list + var js = web.ReadString($@"{giturl}/PoE-MxFilter-Structure/master/{f}.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. + msg.CMW($@"Generating the {f} filter using {j.structures.Count} source(s)...", true, 1); + ftotal = j.structures.Count; + foreach (var sec in j.structures) { - Directory.CreateDirectory(@"data\"); - } - if (!Directory.Exists(@"gen\")) - { - Directory.CreateDirectory(@"gen\"); - } - if (!Directory.Exists(@"structure\")) - { - Directory.CreateDirectory(@"structure\"); - } - - // Clean all generated data - msg.CMW($"Cleaning the base dirs...", true, 1); - CleanDirData(); - - // 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_Normal.filter"); - File.Delete($@"{path}\My Games\Path of Exile\MxFilter_Strict.filter"); - if (File.Exists($@"{path}\My Games\Path of Exile\MxFilter.filter")) { 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(api + $"itemoverview?league={league}&type=UniqueArmour&language=en", "data/ninja.armour.json"); - web.SaveString(api + $"itemoverview?league={league}&type=UniqueWeapon&language=en", "data/ninja.weapon.json"); - web.SaveString(api + $"itemoverview?league={league}&type=UniqueAccessory&language=en", "data/ninja.accessory.json"); - web.SaveString(api + $"itemoverview?league={league}&type=DivinationCard&language=en", "data/ninja.card.json"); - web.SaveString(api + $"currencyoverview?league={league}&type=Currency&language=en", "data/ninja.currency.json"); - web.SaveString(api + $"itemoverview?league={league}&type=Fossil&language=en", "data/ninja.fossil.json"); - - // Get Theme File(s) - web.DownloadFile($@"{giturl}/PoE-MxFilter-Structure/master/Chancing.json", @"structure\Chancing.json"); - - // Generate Filter Array - string[] filters; - if (json.settings.GetSSF()) { filters = new string[] { "SSF" }; } else { filters = new string[] { "Normal", "Strict" }; } - - foreach(string f in filters) - { - // Setup basic variable - string filter_name = "MxFilter"; - - // Get the structure list - var js = web.ReadString($@"{giturl}/PoE-MxFilter-Structure/master/{f}.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. - msg.CMW($@"Generating the {f} filter using {j.structures.Count} source(s)...", true, 1); - ftotal = j.structures.Count; - foreach (var sec in j.structures) + if (sec.gen == true) { - if (sec.gen == true) + fprog = fprog + 1; + msg.drawProgress(fprog, ftotal); + //msg.CMW(string.Format("REMOTE_GEN {0}", sec.section), true, 1); + web.DownloadFile($@"{giturl}/PoE-MxFilter-Structure/master/{f}/{sec.section}.dll", $@"structure\{sec.section}.dll"); + json.settings.WriteSection(sec.section); + var bytes = GenerateAssemblyAndGetRawBytes(sec.section); + + var appDomain = AppDomain.CreateDomain(sec.section, null, new AppDomainSetup { - fprog = fprog + 1; - msg.drawProgress(fprog, ftotal); - //msg.CMW(string.Format("REMOTE_GEN {0}", sec.section), true, 1); - web.DownloadFile($@"{giturl}/PoE-MxFilter-Structure/master/{f}/{sec.section}.dll", $@"structure\{sec.section}.dll"); - json.settings.WriteSection(sec.section); - var bytes = GenerateAssemblyAndGetRawBytes(sec.section); + ShadowCopyFiles = "true", + LoaderOptimization = LoaderOptimization.MultiDomainHost + }); - var appDomain = AppDomain.CreateDomain(sec.section, null, new AppDomainSetup - { - ShadowCopyFiles = "true", - LoaderOptimization = LoaderOptimization.MultiDomainHost - }); + var assmblyLoaderType = typeof(AssmeblyLoader); + var assemblyLoader = (IAssemblyLoader)appDomain.CreateInstanceFromAndUnwrap(assmblyLoaderType.Assembly.Location, assmblyLoaderType.FullName); + assemblyLoader.Load(bytes); - var assmblyLoaderType = typeof(AssmeblyLoader); - var assemblyLoader = (IAssemblyLoader)appDomain.CreateInstanceFromAndUnwrap(assmblyLoaderType.Assembly.Location, assmblyLoaderType.FullName); - assemblyLoader.Load(bytes); - - AppDomain.Unload(appDomain); - } - else - { - fprog = fprog + 1; - msg.drawProgress(fprog, ftotal); - //msg.CMW($@"REMOTE_GET {sec.section}", true, 1); - web.SaveString($@"{giturl}/PoE-MxFilter-Structure/master/{f}/{sec.section}.filter", $"structure/{sec.section}.filter"); - } + AppDomain.Unload(appDomain); } - - // Create the final filter. - msg.CMW($@"Creating the final filter...", true, 1); - foreach (var sec in j.structures) + else { - if (sec.gen == true) - { - File.AppendAllText($@"{path}\My Games\Path of Exile\{filter_name}_{f}.filter", File.ReadAllText(string.Format("gen\\{0}.filter", sec.section))); - File.AppendAllText($@"{path}\My Games\Path of Exile\{filter_name}_{f}.filter", "" + Environment.NewLine); - File.AppendAllText($@"{path}\My Games\Path of Exile\{filter_name}_{f}.filter", "" + Environment.NewLine); - } - else - { - File.AppendAllText($@"{path}\My Games\Path of Exile\{filter_name}_{f}.filter", string.Format("# Section: {0}", sec.section) + Environment.NewLine); - File.AppendAllText($@"{path}\My Games\Path of Exile\{filter_name}_{f}.filter", "" + Environment.NewLine); - File.AppendAllText($@"{path}\My Games\Path of Exile\{filter_name}_{f}.filter", File.ReadAllText(string.Format("structure\\{0}.filter", sec.section))); - File.AppendAllText($@"{path}\My Games\Path of Exile\{filter_name}_{f}.filter", "" + Environment.NewLine); - File.AppendAllText($@"{path}\My Games\Path of Exile\{filter_name}_{f}.filter", "" + Environment.NewLine); - } + fprog = fprog + 1; + msg.drawProgress(fprog, ftotal); + //msg.CMW($@"REMOTE_GET {sec.section}", true, 1); + web.SaveString($@"{giturl}/PoE-MxFilter-Structure/master/{f}/{sec.section}.filter", $"structure/{sec.section}.filter"); } - ftotal = 0; - fprog = 0; - CleanDir(); - } - - // Download the sounds from the remote list - msg.CMW($@"Downloading the latest sound...", true, 1); - var sl = web.ReadString("https://raw.githubusercontent.com/mikxqc/PoE-MxFilter-Data/master/json/mxfiltergen_sound.json"); - REMSND slj = JsonConvert.DeserializeObject(sl); - stotal = slj.sound.Count; - foreach (string s in slj.sound) - { - sprog = sprog + 1; - msg.drawProgress(sprog, stotal); - if (File.Exists($@"{path}\My Games\Path of Exile\{s}")) { File.Delete($@"{path}\My Games\Path of Exile\{s}"); } - web.DownloadFile($"https://raw.githubusercontent.com/mikxqc/PoE-MxFilter-Data/master/mp3/{s}",$@"{path}\My Games\Path of Exile\{s}"); } - // Clean all generated data - CleanDirData(); - } + // Create the final filter. + msg.CMW($@"Creating the final filter...", true, 1); + foreach (var sec in j.structures) + { + if (sec.gen == true) + { + File.AppendAllText($@"{path}\My Games\Path of Exile\{filter_name}_{f}.filter", File.ReadAllText(string.Format("gen\\{0}.filter", sec.section))); + File.AppendAllText($@"{path}\My Games\Path of Exile\{filter_name}_{f}.filter", "" + Environment.NewLine); + File.AppendAllText($@"{path}\My Games\Path of Exile\{filter_name}_{f}.filter", "" + Environment.NewLine); + } + else + { + File.AppendAllText($@"{path}\My Games\Path of Exile\{filter_name}_{f}.filter", string.Format("# Section: {0}", sec.section) + Environment.NewLine); + File.AppendAllText($@"{path}\My Games\Path of Exile\{filter_name}_{f}.filter", "" + Environment.NewLine); + File.AppendAllText($@"{path}\My Games\Path of Exile\{filter_name}_{f}.filter", File.ReadAllText(string.Format("structure\\{0}.filter", sec.section))); + File.AppendAllText($@"{path}\My Games\Path of Exile\{filter_name}_{f}.filter", "" + Environment.NewLine); + File.AppendAllText($@"{path}\My Games\Path of Exile\{filter_name}_{f}.filter", "" + Environment.NewLine); + } + } + ftotal = 0; + fprog = 0; + CleanDir(); + } + + // Download the sounds from the remote list + msg.CMW($@"Downloading the latest sound...", true, 1); + var sl = web.ReadString("https://raw.githubusercontent.com/mikxqc/PoE-MxFilter-Data/master/json/mxfiltergen_sound.json"); + REMSND slj = JsonConvert.DeserializeObject(sl); + stotal = slj.sound.Count; + foreach (string s in slj.sound) + { + sprog = sprog + 1; + msg.drawProgress(sprog, stotal); + if (File.Exists($@"{path}\My Games\Path of Exile\{s}")) { File.Delete($@"{path}\My Games\Path of Exile\{s}"); } + web.DownloadFile($"https://raw.githubusercontent.com/mikxqc/PoE-MxFilter-Data/master/mp3/{s}", $@"{path}\My Games\Path of Exile\{s}"); + } + + // Clean all generated data + CleanDirData(); } private static byte[] GenerateAssemblyAndGetRawBytes(string dll) @@ -264,6 +258,11 @@ namespace PoE_MxFilterGen file.Delete(); } } + + private static void AutoUpdater_ApplicationExitEvent() + { + System.Environment.Exit(-1); + } } public interface IAssemblyLoader @@ -280,8 +279,8 @@ 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 = new object[] { json.settings.GetSection(), json.settings.GetAPI(), main.league, json.settings.GetMinimumValue() }; + Object[] ob = new object[] { json.settings.GetSection(), "tobedeleted", main.league, json.settings.GetUniqueValue(), json.settings.GetFossilValue(), json.settings.GetCardValue() }; mi.Invoke(o, ob); } - } + } } diff --git a/PoE-MxFilterGen/obj/Debug/mxfiltergen.exe b/PoE-MxFilterGen/obj/Debug/mxfiltergen.exe index c7b824f..a4fb9f7 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 3d01962..952289f 100644 Binary files a/PoE-MxFilterGen/obj/Debug/mxfiltergen.pdb and b/PoE-MxFilterGen/obj/Debug/mxfiltergen.pdb differ diff --git a/PoE-MxFilterGen/web.cs b/PoE-MxFilterGen/web.cs index 0689c13..e1c2fde 100644 --- a/PoE-MxFilterGen/web.cs +++ b/PoE-MxFilterGen/web.cs @@ -66,7 +66,6 @@ namespace PoE_MxFilterGen ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; - var str = ""; try { Uri uri = new Uri(url);