Skip to content

Commit

Permalink
Dynamic display of mods and 3rdparty content
Browse files Browse the repository at this point in the history
- Added dynamic display for mods count
- Added dynamic display for 3rdparty content DLC
- Category combobox now gets populated
- newModInfo file now has more fields to populated
- load_mods_info now populates the new fields in the newModInfo
- fixed a bug where if the mod file contains the word "name" before the actual line with the name of the mod that would have been displayed in modslist
  • Loading branch information
Xferno2 committed Jan 17, 2021
1 parent ddb718d commit 721ffb1
Show file tree
Hide file tree
Showing 4 changed files with 19,334 additions and 38 deletions.
31 changes: 15 additions & 16 deletions Hoi4 Launcher/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

149 changes: 130 additions & 19 deletions Hoi4 Launcher/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net.Http;
using System.Timers;
using Timer = System.Timers.Timer;

namespace Hoi4_Launcher
{
Expand All @@ -24,14 +26,16 @@ public partial class Form1 : Form
private static string Hoi4_Enb_Mods = Path.Combine(Hoi4_Doc, "dlc_load.json");
private static string Hoi4_Mods = Path.Combine(Hoi4_Doc, "mod");
private static dlcModel[] dis_dlc = null;
private static int modsCount;

private static LHSettings gameSettings = new LHSettings();

Timer updateUI = new Timer(100);

static launchSettings data = new launchSettings();
public Form1()
{
InitializeComponent();
dis_dlc = GetDLCs();
load();
}

private void Form1_Load(object sender, EventArgs e)
Expand All @@ -48,29 +52,59 @@ public launchSettings load_items()
}

public List<newModInfo> load_mods_info() {
string[] stringSeparators = new string[] { "\n\t" };
List<newModInfo> mods = new List<newModInfo>();
DirectoryInfo d = new DirectoryInfo(Hoi4_Mods);
FileInfo[] Files = d.GetFiles("*.mod");
foreach (FileInfo file in Files)
{
var mod = new newModInfo();
mod.gameRegestryMod = "mod/" + file.Name;
//if (mod.gameRegestryMod == "mod/ugc_1368243403.mod")
//{
// Debugger.Break();
//}
var modFiles = File.ReadAllLines(file.FullName);
var modFileWhole = File.ReadAllText(file.FullName);
foreach (var modFile in modFiles) {
if (modFile.Contains("name")) {
if (modFile.Contains("name=")) {
mod.displayName = modFile.Split('=')[1].Replace("\"", "");
break;
}
if (modFile.Contains("supported_version="))
{
mod.supported_version = modFile.Split('=')[1].Replace("\"", "");
}
if (modFile.Contains("remote_file_id="))
{
mod.remote_fileid = modFile.Split('=')[1].Replace("\"", "");
}
if (modFile.Contains("tags={"))
{
List<string> tagsList = new List<string>();
var tagsNotFormated = removeBrackets(modFileWhole, "tags={", "}",false);
var tagsFormated = tagsNotFormated.Split(stringSeparators, StringSplitOptions.None);
foreach (var tag in tagsFormated) {
if (tag != "")
{ var currentTag = removeBrackets(tag, "\"", "\"");
tagsList.Add(currentTag);
bool isItemInList = false;
foreach (var listItem in categoriesBox.Items) {
if (listItem.ToString().ToLower() == currentTag.ToLower()) {
isItemInList = true;
}
}
if(!isItemInList)
categoriesBox.Items.Add(currentTag);
}
}
mod.tags = tagsList;
}
}
mods.Add(mod);
}
return mods;
}

private void BackgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
}

private void load() {
//Load Mods
var items = load_items();
Expand All @@ -82,7 +116,8 @@ private void BackgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
if (items.enabled_mods.Contains(mod.gameRegestryMod)) { enabled = true; enabled_mods++; }
list_mods.Items.Add(mod.displayName, enabled);
}
label_mods.Text = "Mods: " + enabled_mods + "/" + mods.Count;
modsCount = mods.Count;
updateModsCount(enabled_mods, modsCount);

//Load DLC
foreach (var dlc in dis_dlc) {
Expand All @@ -92,19 +127,14 @@ private void BackgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
}
//Load LHSetthings
string data = File.ReadAllText(@"launcher-settings.json");
var obj = JsonConvert.DeserializeObject<LHSettings>(data);
label_version.Text += " " + obj.version;
gameSettings = JsonConvert.DeserializeObject<LHSettings>(data);
label_version.Text += " " + gameSettings.version;
}
private void TextBox1_TextChanged(object sender, EventArgs e)
{

}

private void Button_play_Click(object sender, EventArgs e)
{

}

public void SerializeConfig(object x)
{
JsonSerializerSettings settings = new JsonSerializerSettings();
Expand All @@ -127,9 +157,8 @@ public string GetURL(string url)
}

public dlcModel[] GetDLCs() {
List<dlcModel> dlcs = new List<dlcModel>();
var path = Path.Combine(Directory.GetCurrentDirectory(), "dlc");

List<dlcModel> dlcs = new List<dlcModel>();
foreach (var dir in Directory.GetDirectories(path)) {
try
{
Expand Down Expand Up @@ -187,6 +216,88 @@ private void userControl11_Load(object sender, EventArgs e)
{

}
}

private string removeBrackets(string text, string from, string to , bool tolast =true) {
int pFrom = text.IndexOf(from) + from.Length;
int pTo = 0;
if (tolast)
{
pTo = text.LastIndexOf(to);
}
else {
pTo = text.IndexOf(to);
}
try {
return text.Substring(pFrom, pTo - pFrom);
} catch (Exception ex) {
return "";
}
}

private void Form1_Load_1(object sender, EventArgs e)
{
dis_dlc = GetDLCs();
load();
updateUI.Elapsed += updateUI_DoWork;
updateUI.Start();
}

private void updateUI_DoWork(object sender, ElapsedEventArgs e)
{
try
{
this.InvokeEx(x => updateUIinvokable());
}
catch (Exception ex) { }
}

private void updateModsCount(int count, int maxCount) {
label_mods.Text = "Mods: " + count + "/" + maxCount;
}

private void updateUIinvokable()
{
if (tabControl1.SelectedTab == tabPage3)
{
updateModsCount(list_mods.CheckedItems.Count, modsCount);
}
else if (tabControl1.SelectedTab == tabPage2)
{
checkFor3rdParty();
}
}
private void checkFor3rdParty()
{
bool is3rdParty = false;
foreach (var dlc in dis_dlc)
{
if (dlc._3rdparty && list_dlc.CheckedItems.Contains(dlc.name))
{
is3rdParty = true;
break;
}
else
is3rdParty = false;
}
userControl11._3rdParty = is3rdParty;
}

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
}
}
}
public static class ISynchronizeInvokeExtensions
{
public static void InvokeEx<T>(this T @this, Action<T> action) where T : ISynchronizeInvoke
{
if (@this.InvokeRequired)
{
@this.Invoke(action, new object[] { @this });
}
else
{
action(@this);
}
}
}
Loading

0 comments on commit 721ffb1

Please sign in to comment.