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:
@@ -4,7 +4,6 @@ using System.Collections.Generic;
|
||||
using SabreTools.Library.Data;
|
||||
using SabreTools.Library.DatItems;
|
||||
using SabreTools.Library.IO;
|
||||
using SabreTools.Library.Tools;
|
||||
|
||||
namespace SabreTools.Library.Filtering
|
||||
{
|
||||
@@ -26,27 +25,6 @@ namespace SabreTools.Library.Filtering
|
||||
|
||||
#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>
|
||||
/// Populate the dictionary from an INI file
|
||||
/// </summary>
|
||||
@@ -59,7 +37,7 @@ namespace SabreTools.Library.Filtering
|
||||
/// the value is boolean. If there's another section name, then that is set
|
||||
/// as the value instead.
|
||||
/// </remarks>
|
||||
public void PopulateFromFile(string ini)
|
||||
public bool PopulateFromFile(string ini)
|
||||
{
|
||||
// Prepare all intenral variables
|
||||
IniReader ir = ini.GetIniReader(false);
|
||||
@@ -67,7 +45,7 @@ namespace SabreTools.Library.Filtering
|
||||
|
||||
// If we got a null reader, just return
|
||||
if (ir == null)
|
||||
return;
|
||||
return false;
|
||||
|
||||
// Otherwise, read the file to the end
|
||||
try
|
||||
@@ -107,15 +85,26 @@ namespace SabreTools.Library.Filtering
|
||||
|
||||
// Add the new mapping
|
||||
Mappings[key].Add(value);
|
||||
|
||||
// Read the next line in
|
||||
ir.ReadNextLine();
|
||||
}
|
||||
|
||||
// Otherwise, just read the next line
|
||||
else
|
||||
{
|
||||
ir.ReadNextLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Globals.Logger.Warning($"Exception found while parsing '{ini}': {ex}");
|
||||
return false;
|
||||
}
|
||||
|
||||
ir.Dispose();
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user