Skip to content

Commit

Permalink
Brought back config.json Auto-add
Browse files Browse the repository at this point in the history
  • Loading branch information
papershredder432 committed Jan 28, 2023
1 parent 9e2fd36 commit d14a4d4
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 19 deletions.
12 changes: 12 additions & 0 deletions src/SPT-Manager/Models/ModInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace SPT_Manager.Models
{
public class ModInfo
{
public string Name { get; set; }
public string Author { get; set; }
public string Version { get; set; }
public string License { get; set; }
public string Main { get; set; }
public string AkiVersion { get; set; }
}
}
4 changes: 2 additions & 2 deletions src/SPT-Manager/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// 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.1.1")]
[assembly: AssemblyFileVersion("1.1.1")]
[assembly: AssemblyVersion("1.2.0")]
[assembly: AssemblyFileVersion("1.2.0")]
64 changes: 47 additions & 17 deletions src/SPT-Manager/SPTManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -87,7 +88,29 @@ private void btn_loadServerMods_Click(object sender, EventArgs e)
if (Database.GetModpack("Default") != null) return;

var folders = new DirectoryInfo($@"{SptDir}user\mods\").GetDirectories();
var mods = folders.Select(m => new Mod { Name = m.Name, ConfigLocation = "", Enabled = true }).ToList();
var mods = new List<Mod>();

var configJson = "";

foreach (var mod in folders)
{
var children = mod.GetFiles("config.json", SearchOption.AllDirectories);
if (children.Length != 0)
{
var directoryInfo = children.FirstOrDefault(x => x.Name == "config.json").Directory;
configJson = directoryInfo != null ? $@"{directoryInfo.FullName}\config.json" : "";
}

var newMod = new Mod
{
Name = mod.Name,
Enabled = true,
ConfigLocation = configJson
};
mods.Add(newMod);

configJson = "";
}

var modPack = new ModPack
{
Expand Down Expand Up @@ -138,7 +161,16 @@ private void btn_addMods_Click(object sender, EventArgs e)

if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath))
{
_modManager.AddMod(dirInf.Name, cmb_modpack.Text, "");
var configJson = "";

var children = dirInf.GetFiles("config.json", SearchOption.AllDirectories);
if (children.Length == 0)
{
var directoryInfo = children.FirstOrDefault(x => x.Name == "config.json").Directory;
configJson = directoryInfo != null ? $@"{directoryInfo.FullName}\config.json" : "";
}

_modManager.AddMod(dirInf.Name, cmb_modpack.Text, configJson);
}

var newPage = new TabPage($"page_{dirInf.Name}");
Expand Down Expand Up @@ -187,21 +219,19 @@ private void RefreshTable()

newPage.Controls.Add(chkBox);

if (!string.IsNullOrWhiteSpace(mod.ConfigLocation))
{
var streamReader = new StreamReader(mod.ConfigLocation).ReadToEnd();

var txt = new TextBox();
txt.Name = $"txt_{mod.Name}";
txt.Multiline = true;
txt.Location = new Point(0, txt.Location.Y + chkBox.Height);
txt.Width = newPage.Width;
txt.Height = newPage.Height;
txt.ScrollBars = ScrollBars.Vertical;
txt.Text = streamReader;
if (string.IsNullOrWhiteSpace(mod.ConfigLocation)) continue;
var streamReader = new StreamReader(mod.ConfigLocation).ReadToEnd();

var txt = new TextBox();
txt.Name = $"txt_{mod.Name}";
txt.Multiline = true;
txt.Location = new Point(0, txt.Location.Y + chkBox.Height);
txt.Width = newPage.Width;
txt.Height = newPage.Height;
txt.ScrollBars = ScrollBars.Vertical;
txt.Text = streamReader;

newPage.Controls.Add(txt);
}
newPage.Controls.Add(txt);
}
}

Expand Down Expand Up @@ -314,7 +344,7 @@ private void btn_loadPack_Click(object sender, EventArgs e)
}
}

prg_loadPack.Value = 0;
prg_loadPack.Value = 1;
prg_loadPack.Visible = false;
}

Expand Down

0 comments on commit d14a4d4

Please sign in to comment.