mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Fix INI import; logic
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
using SabreTools.Library.Data;
|
||||||
|
using SabreTools.Library.Tools;
|
||||||
|
|
||||||
namespace SabreTools.Library.Filtering
|
namespace SabreTools.Library.Filtering
|
||||||
{
|
{
|
||||||
public class ExtraIni
|
public class ExtraIni
|
||||||
@@ -24,7 +27,20 @@ namespace SabreTools.Library.Filtering
|
|||||||
foreach (string input in inputs)
|
foreach (string input in inputs)
|
||||||
{
|
{
|
||||||
ExtraIniItem item = new ExtraIniItem();
|
ExtraIniItem item = new ExtraIniItem();
|
||||||
item.PopulateFromInput(input);
|
|
||||||
|
// If we don't even have a possible field and file combination
|
||||||
|
if (!input.Contains(":"))
|
||||||
|
{
|
||||||
|
Globals.Logger.Warning($"'{input}` is not a valid INI extras string. Valid INI extras strings are of the form 'key:value'. Please refer to README.1ST or the help feature for more details.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
string inputTrimmed = input.Trim('"', ' ', '\t');
|
||||||
|
string fieldString = inputTrimmed.Split(':')[0].ToLowerInvariant().Trim('"', ' ', '\t');
|
||||||
|
string fileString = inputTrimmed.Substring(fieldString.Length + 1).Trim('"', ' ', '\t');
|
||||||
|
|
||||||
|
item.Field = fieldString.AsField();
|
||||||
|
if (item.PopulateFromFile(fileString))
|
||||||
Items.Add(item);
|
Items.Add(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ using System.Collections.Generic;
|
|||||||
using SabreTools.Library.Data;
|
using SabreTools.Library.Data;
|
||||||
using SabreTools.Library.DatItems;
|
using SabreTools.Library.DatItems;
|
||||||
using SabreTools.Library.IO;
|
using SabreTools.Library.IO;
|
||||||
using SabreTools.Library.Tools;
|
|
||||||
|
|
||||||
namespace SabreTools.Library.Filtering
|
namespace SabreTools.Library.Filtering
|
||||||
{
|
{
|
||||||
@@ -26,27 +25,6 @@ namespace SabreTools.Library.Filtering
|
|||||||
|
|
||||||
#region Extras Population
|
#region Extras Population
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Populate item using a field:file input
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="ini">Field and file combination</param>
|
|
||||||
public void PopulateFromInput(string ini)
|
|
||||||
{
|
|
||||||
// If we don't even have a possible field and file combination
|
|
||||||
if (!ini.Contains(":"))
|
|
||||||
{
|
|
||||||
Globals.Logger.Warning($"'{ini}` is not a valid INI extras string. Valid INI extras strings are of the form 'key:value'. Please refer to README.1ST or the help feature for more details.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
string iniTrimmed = ini.Trim('"', ' ', '\t');
|
|
||||||
string iniFieldString = iniTrimmed.Split(':')[0].ToLowerInvariant().Trim('"', ' ', '\t');
|
|
||||||
string iniFileString = iniTrimmed.Substring(iniFieldString.Length + 1).Trim('"', ' ', '\t');
|
|
||||||
|
|
||||||
Field = iniFieldString.AsField();
|
|
||||||
PopulateFromFile(iniFileString);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Populate the dictionary from an INI file
|
/// Populate the dictionary from an INI file
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -59,7 +37,7 @@ namespace SabreTools.Library.Filtering
|
|||||||
/// the value is boolean. If there's another section name, then that is set
|
/// the value is boolean. If there's another section name, then that is set
|
||||||
/// as the value instead.
|
/// as the value instead.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public void PopulateFromFile(string ini)
|
public bool PopulateFromFile(string ini)
|
||||||
{
|
{
|
||||||
// Prepare all intenral variables
|
// Prepare all intenral variables
|
||||||
IniReader ir = ini.GetIniReader(false);
|
IniReader ir = ini.GetIniReader(false);
|
||||||
@@ -67,7 +45,7 @@ namespace SabreTools.Library.Filtering
|
|||||||
|
|
||||||
// If we got a null reader, just return
|
// If we got a null reader, just return
|
||||||
if (ir == null)
|
if (ir == null)
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
// Otherwise, read the file to the end
|
// Otherwise, read the file to the end
|
||||||
try
|
try
|
||||||
@@ -107,15 +85,26 @@ namespace SabreTools.Library.Filtering
|
|||||||
|
|
||||||
// Add the new mapping
|
// Add the new mapping
|
||||||
Mappings[key].Add(value);
|
Mappings[key].Add(value);
|
||||||
|
|
||||||
|
// Read the next line in
|
||||||
|
ir.ReadNextLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise, just read the next line
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ir.ReadNextLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Globals.Logger.Warning($"Exception found while parsing '{ini}': {ex}");
|
Globals.Logger.Warning($"Exception found while parsing '{ini}': {ex}");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ir.Dispose();
|
ir.Dispose();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
Reference in New Issue
Block a user