384 lines
19 KiB
C#
384 lines
19 KiB
C#
using Newtonsoft.Json;
|
|
using PoE_MxFilterGen.generator;
|
|
using PoE_MxFilterGen.json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace PoE_MxFilterGen
|
|
{
|
|
internal class main
|
|
{
|
|
private static DateTime dt = DateTime.Now;
|
|
public static string version = "11.0.1";
|
|
public static string fDate = string.Format("{0}-{1}-{2}", (object)main.dt.Day, (object)main.dt.Month, (object)main.dt.Year);
|
|
public static string api = "";
|
|
public static string giturl = "https://mxgit.ovh/mikx";
|
|
public static string section = "";
|
|
public static string league = "";
|
|
public static string path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
|
|
public static int fprog = 0;
|
|
public static int ftotal = 0;
|
|
public static int sprog = 0;
|
|
public static int stotal = 0;
|
|
public static bool debug = false;
|
|
public static bool install;
|
|
public static bool compile = false;
|
|
public static string ipath;
|
|
public static string docpath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
|
|
|
|
private static void Main(string[] args)
|
|
{
|
|
if (args.Count() >= 1)
|
|
{
|
|
if (args[0].Contains("--compile"))
|
|
{
|
|
compile = true;
|
|
}
|
|
}
|
|
if (!Directory.Exists("data"))
|
|
{
|
|
Directory.CreateDirectory("data");
|
|
}
|
|
if (!Directory.Exists("gen"))
|
|
{
|
|
Directory.CreateDirectory("gen");
|
|
}
|
|
if (!Directory.Exists("structure"))
|
|
{
|
|
Directory.CreateDirectory("structure");
|
|
}
|
|
if (!Directory.Exists("out"))
|
|
{
|
|
Directory.CreateDirectory("out");
|
|
}
|
|
if (!File.Exists("settings.json"))
|
|
{
|
|
msg.CMW("ERROR: settings.json not found! Downloading a template...", true, 3);
|
|
web.DownloadFile("https://mxpoe.ovh/mxfilter/mxfiltergen_settings.json", "settings.json");
|
|
}
|
|
msg.Splash("MxFilterGen", "mikx");
|
|
main.CleanDirData();
|
|
main.league = settings.GetLeague();
|
|
main.api = "https://poe.ninja/api/data/";
|
|
msg.CMW("League: " + main.league, true, 1);
|
|
msg.CMW(string.Format("Min. Unique Value - {0}c", (object)settings.GetUniqueValue()), true, 1);
|
|
msg.CMW(string.Format("Min. Fossil Value - {0}c", (object)settings.GetFossilValue()), true, 1);
|
|
msg.CMW(string.Format("Min. Card Value - {0}c", (object)settings.GetCardValue()), true, 1);
|
|
msg.CMW("Checking for required dirs...", true, 1);
|
|
msg.CMW("Cleaning the base dirs...", true, 1);
|
|
main.CleanDirData();
|
|
msg.CMW("Cleaning the last filter from path...", true, 1);
|
|
foreach (string filter in structures.Filters()) {
|
|
if (File.Exists("out/MxFilter_" + filter + ".filter"))
|
|
{
|
|
File.Delete("out/MxFilter_" + filter + ".filter");
|
|
}
|
|
}
|
|
msg.CMW("Downloading the latest API data from poe.ninja...", true, 1);
|
|
web.SaveString(main.api + "itemoverview?league=" + main.league + "&type=UniqueArmour&language=en", "data/ninja.armour.json");
|
|
web.SaveString(main.api + "itemoverview?league=" + main.league + "&type=UniqueWeapon&language=en", "data/ninja.weapon.json");
|
|
web.SaveString(main.api + "itemoverview?league=" + main.league + "&type=UniqueAccessory&language=en", "data/ninja.accessory.json");
|
|
web.SaveString(main.api + "itemoverview?league=" + main.league + "&type=DivinationCard&language=en", "data/ninja.card.json");
|
|
web.SaveString(main.api + "currencyoverview?league=" + main.league + "&type=Currency&language=en", "data/ninja.currency.json");
|
|
web.SaveString(main.api + "itemoverview?league=" + main.league + "&type=Fossil&language=en", "data/ninja.fossil.json");
|
|
web.SaveString(main.api + "itemoverview?league=" + main.league + "&type=BaseType&language=en", "data/ninja.base.json");
|
|
foreach (string filter in structures.Filters())
|
|
{
|
|
if(!Directory.Exists($@"out\{filter}")) { Directory.CreateDirectory($@"out\{filter}"); }
|
|
if (Directory.Exists($@"out\{filter}"))
|
|
{
|
|
var fout = Directory.GetFiles($@"out\{filter}");
|
|
foreach (var f in fout)
|
|
{
|
|
File.Delete(f);
|
|
}
|
|
}
|
|
string str = "MxFilter";
|
|
int sc = structures.Structures().Length;
|
|
msg.CMW(string.Format("Generating the {0} filter using {1} source(s)...", filter, sc), true, 1);
|
|
main.ftotal = sc;
|
|
foreach (var structure in structures.Structures())
|
|
{
|
|
++main.fprog;
|
|
msg.drawProgress(main.fprog, main.ftotal);
|
|
settings.WriteSection(structure);
|
|
string section = structure;
|
|
int fossilValue = settings.GetFossilValue();
|
|
int cardValue = settings.GetCardValue();
|
|
int uniqueValue = settings.GetUniqueValue();
|
|
int tierValue = settings.GetTierValue();
|
|
bool tier1HAxe = settings.GetTier1HAxe();
|
|
bool tier2HAxe = settings.GetTier2HAxe();
|
|
bool tierBow = settings.GetTierBow();
|
|
bool tierClaw = settings.GetTierClaw();
|
|
bool tierDagger = settings.GetTierDagger();
|
|
bool tier1HMace = settings.GetTier1HMace();
|
|
bool tier2HMace = settings.GetTier2HMace();
|
|
bool tierSceptre = settings.GetTierSceptre();
|
|
bool tierStaff = settings.GetTierStaff();
|
|
bool tier1HSword = settings.GetTier1HSword();
|
|
bool tier2HSword = settings.GetTier2HSword();
|
|
bool tierWand = settings.GetTierWand();
|
|
bool tierBody = settings.GetTierBody();
|
|
bool tierBoots = settings.GetTierBoots();
|
|
bool tierGloves = settings.GetTierGloves();
|
|
bool tierHelmet = settings.GetTierHelmet();
|
|
bool tierShield = settings.GetTierShield();
|
|
bool tierQuiver = settings.GetTierQuiver();
|
|
install = settings.GetInstall();
|
|
ipath = settings.GetPath();
|
|
List<string> tierBaseInclude = settings.GetTierBaseInclude();
|
|
List<string> tierBaseExclude = settings.GetTierBaseExclude();
|
|
if (section.Contains("(GEN)"))
|
|
{
|
|
if (!compile)
|
|
{
|
|
switch (structure)
|
|
{
|
|
case "DIVINATIONCARD(GEN)":
|
|
card.Gen(section, cardValue);
|
|
break;
|
|
case "EXPENSIVEUNIQUE(GEN)(Accessories)":
|
|
accessory.Gen(section, uniqueValue);
|
|
break;
|
|
case "EXPENSIVEUNIQUE(GEN)(Armours)":
|
|
armour.Gen(section, uniqueValue);
|
|
break;
|
|
case "EXPENSIVEUNIQUE(GEN)(Weapons)":
|
|
weapon.Gen(section, uniqueValue);
|
|
break;
|
|
case "FOSSIL(GEN)":
|
|
fossil.Gen(section, fossilValue);
|
|
break;
|
|
case "Tiers(GEN)":
|
|
tier.Gen(section, tierValue, tier1HAxe, tier2HAxe, tierBow, tierClaw, tierDagger, tier1HMace, tier2HMace, tierSceptre, tierStaff, tier1HSword, tier2HSword, tierWand, tierBody, tierBoots, tierGloves, tierHelmet, tierShield, tierQuiver, tierBaseInclude, tierBaseExclude);
|
|
break;
|
|
}
|
|
}
|
|
} else
|
|
{
|
|
compiler.section.Compile(section, filter);
|
|
}
|
|
}
|
|
msg.CMW("Creating the final filter...", true, 1);
|
|
string outp = "out/" + str + "_" + filter + ".filter";
|
|
////////// Splash //////////
|
|
File.AppendAllText(outp, $"#### Filson - PoE Item Filter JSON Parsing - MxFilterGen v{main.version}{Environment.NewLine}");
|
|
File.AppendAllText(outp, $"#### Filson and MxFilterGen are developped by mikx.{Environment.NewLine}");
|
|
File.AppendAllText(outp, $"#### MxGit: https://mxgit.ovh/mikx/PoE-MxFilterGen{Environment.NewLine}");
|
|
File.AppendAllText(outp, $"#### MxPoE: https://mxpoe.ovh/{Environment.NewLine}");
|
|
File.AppendAllText(outp, $"#### Contact: mikx@mxpoe.ovh / http://discord.mxg.ovh{Environment.NewLine}");
|
|
File.AppendAllText(outp, $"{Environment.NewLine}");
|
|
File.AppendAllText(outp, $"#### SECTIONS{Environment.NewLine}");
|
|
foreach (var s in structures.Structures())
|
|
{
|
|
File.AppendAllText(outp, $"# {s}{Environment.NewLine}");
|
|
}
|
|
File.AppendAllText(outp, $"{Environment.NewLine}");
|
|
foreach (var structure in structures.Structures())
|
|
{
|
|
switch (structure)
|
|
{
|
|
case "DIVINATIONCARD(GEN)":
|
|
File.AppendAllText("out/" + str + "_" + filter + ".filter", File.ReadAllText(string.Format("gen/" + structure + ".filter")));
|
|
File.AppendAllText("out/" + str + "_" + filter + ".filter", Environment.NewLine ?? "");
|
|
break;
|
|
case "EXPENSIVEUNIQUE(GEN)(Accessories)":
|
|
File.AppendAllText("out/" + str + "_" + filter + ".filter", File.ReadAllText(string.Format("gen/" + structure + ".filter")));
|
|
File.AppendAllText("out/" + str + "_" + filter + ".filter", Environment.NewLine ?? "");
|
|
break;
|
|
case "EXPENSIVEUNIQUE(GEN)(Armours)":
|
|
File.AppendAllText("out/" + str + "_" + filter + ".filter", File.ReadAllText(string.Format("gen/" + structure + ".filter")));
|
|
File.AppendAllText("out/" + str + "_" + filter + ".filter", Environment.NewLine ?? "");
|
|
break;
|
|
case "EXPENSIVEUNIQUE(GEN)(Weapons)":
|
|
File.AppendAllText("out/" + str + "_" + filter + ".filter", File.ReadAllText(string.Format("gen/" + structure + ".filter")));
|
|
File.AppendAllText("out/" + str + "_" + filter + ".filter", Environment.NewLine ?? "");
|
|
break;
|
|
case "FOSSIL(GEN)":
|
|
File.AppendAllText("out/" + str + "_" + filter + ".filter", File.ReadAllText(string.Format("gen/" + structure + ".filter")));
|
|
File.AppendAllText("out/" + str + "_" + filter + ".filter", Environment.NewLine ?? "");
|
|
break;
|
|
case "Tiers(GEN)":
|
|
File.AppendAllText("out/" + str + "_" + filter + ".filter", File.ReadAllText(string.Format("gen/" + structure + ".filter")));
|
|
File.AppendAllText("out/" + str + "_" + filter + ".filter", Environment.NewLine ?? "");
|
|
break;
|
|
case "Tiers - Caster (DATA)":
|
|
File.AppendAllText("out/" + str + "_" + filter + ".filter", File.ReadAllText(string.Format("gen/" + structure + ".filter")));
|
|
File.AppendAllText("out/" + str + "_" + filter + ".filter", Environment.NewLine ?? "");
|
|
break;
|
|
default:
|
|
File.AppendAllText("out/" + str + "_" + filter + ".filter", string.Format("#### SECTION: {0}", (object)structure) + Environment.NewLine);
|
|
File.AppendAllText("out/" + str + "_" + filter + ".filter", File.ReadAllText(string.Format("out/" + filter + "/" + structure + ".filter")));
|
|
File.AppendAllText("out/" + str + "_" + filter + ".filter", Environment.NewLine ?? "");
|
|
break;
|
|
}
|
|
}
|
|
main.ftotal = 0;
|
|
main.fprog = 0;
|
|
//main.CleanDir();
|
|
CurrencyValueOut();
|
|
}
|
|
if (debug)
|
|
{
|
|
Console.ReadKey();
|
|
}
|
|
else if (!debug && install)
|
|
{
|
|
msg.CMW("INFO: install is true and will act as a personal filter generator.", true, 2);
|
|
foreach (var f in structures.Filters())
|
|
{
|
|
if (File.Exists($@"{docpath}\My Games\Path of Exile\MxFilter_{f}.filter"))
|
|
{
|
|
File.Copy($@"{docpath}\My Games\Path of Exile\MxFilter_{f}.filter", $@"{docpath}\My Games\Path of Exile\MxFilter_{f}.filter.backup", true);
|
|
File.Delete($@"{docpath}\My Games\Path of Exile\MxFilter_{f}.filter");
|
|
}
|
|
}
|
|
if (ipath == "" || ipath == null)
|
|
{
|
|
msg.CMW("ERROR: install is true but there is no path given, using default windows path.", true, 3);
|
|
foreach (var f in structures.Filters())
|
|
{
|
|
File.Copy($"out/MxFilter_{f}.filter", $@"{docpath}\My Games\Path of Exile\MxFilter_{f}.filter");
|
|
}
|
|
foreach (var s in Directory.EnumerateFiles("sound"))
|
|
{
|
|
string sf = Path.GetFileName(s);
|
|
File.Copy($"{s}", $@"{docpath}\My Games\Path of Exile\{sf}", true);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
foreach (var f in structures.Filters())
|
|
{
|
|
File.Copy($"out/MxFilter_{f}.filter", $@"{ipath}\MxFilter_{f}.filter");
|
|
}
|
|
foreach (var s in Directory.EnumerateFiles("sound"))
|
|
{
|
|
File.Copy($"sound/{s}", $@"{ipath}\{s}");
|
|
}
|
|
}
|
|
} else
|
|
{
|
|
msg.CMW("INFO: install is false and will act as a remote generator.", true, 2);
|
|
}
|
|
}
|
|
|
|
public static void CurrencyValueOut()
|
|
{
|
|
foreach (LineCurrency line in JsonConvert.DeserializeObject<RootCurrency>(File.ReadAllText("data/ninja.currency.json", Encoding.UTF8)).lines)
|
|
{
|
|
string currencyTypeName = line.currencyTypeName;
|
|
|
|
if (currencyTypeName == "Divine Orb")
|
|
{
|
|
string fc = line.chaosEquivalent.ToString();
|
|
File.WriteAllText("out/Market/divine.txt", fc);
|
|
}
|
|
|
|
if (currencyTypeName == "Exalted Orb")
|
|
{
|
|
string fc = line.chaosEquivalent.ToString();
|
|
File.WriteAllText("out/Market/exalted.txt", fc);
|
|
}
|
|
|
|
if (currencyTypeName == "Orb of Annulment")
|
|
{
|
|
string fc = line.chaosEquivalent.ToString();
|
|
File.WriteAllText("out/Market/annulment.txt", fc);
|
|
}
|
|
|
|
if (currencyTypeName == "Orb of Alteration")
|
|
{
|
|
string fc = line.chaosEquivalent.ToString();
|
|
File.WriteAllText("out/Market/alteration.txt", fc);
|
|
}
|
|
|
|
if (currencyTypeName == "Orb of Fusing")
|
|
{
|
|
string fc = line.chaosEquivalent.ToString();
|
|
File.WriteAllText("out/Market/fusing.txt", fc);
|
|
}
|
|
|
|
if (currencyTypeName == "Chromatic Orb")
|
|
{
|
|
string fc = line.chaosEquivalent.ToString();
|
|
File.WriteAllText("out/Market/chromatic.txt", fc);
|
|
}
|
|
|
|
if (currencyTypeName == "Jeweller's Orb")
|
|
{
|
|
string fc = line.chaosEquivalent.ToString();
|
|
File.WriteAllText("out/Market/jeweller.txt", fc);
|
|
}
|
|
|
|
if (currencyTypeName == "Orb of Alchemy")
|
|
{
|
|
string fc = line.chaosEquivalent.ToString();
|
|
File.WriteAllText("out/Market/alchemy.txt", fc);
|
|
}
|
|
|
|
if (currencyTypeName == "Cartographer's Chisel")
|
|
{
|
|
string fc = line.chaosEquivalent.ToString();
|
|
File.WriteAllText("out/Market/chisel.txt", fc);
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void CleanDirData()
|
|
{
|
|
DirectoryInfo directoryInfo1 = new DirectoryInfo("data");
|
|
DirectoryInfo directoryInfo2 = new DirectoryInfo("gen");
|
|
foreach (FileSystemInfo file in directoryInfo1.GetFiles())
|
|
file.Delete();
|
|
if(!compile)
|
|
{
|
|
foreach (FileSystemInfo file in directoryInfo2.GetFiles())
|
|
file.Delete();
|
|
}
|
|
}
|
|
|
|
public static void CleanDir()
|
|
{
|
|
if (!compile)
|
|
{
|
|
foreach (FileSystemInfo file in new DirectoryInfo("gen").GetFiles())
|
|
file.Delete();
|
|
}
|
|
}
|
|
|
|
private static void AutoUpdater_ApplicationExitEvent() => Environment.Exit(-1);
|
|
|
|
public class REMVAR
|
|
{
|
|
public string league { get; set; }
|
|
}
|
|
|
|
public class REMSND
|
|
{
|
|
public List<string> sound { get; set; }
|
|
}
|
|
|
|
public class STRUCTURE
|
|
{
|
|
public string section { get; set; }
|
|
|
|
public bool gen { get; set; }
|
|
|
|
public bool @static { get; set; }
|
|
|
|
public bool remote { get; set; }
|
|
|
|
public string url { get; set; }
|
|
}
|
|
|
|
public class RootStructure
|
|
{
|
|
public List<main.STRUCTURE> structures { get; set; }
|
|
}
|
|
}
|
|
} |