mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Partition Write a little
This commit is contained in:
@@ -3405,25 +3405,8 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <returns>True if the DAT was written correctly, false otherwise</returns>
|
/// <returns>True if the DAT was written correctly, false otherwise</returns>
|
||||||
public bool Write(string outDir, bool norename = true, bool stats = false, bool ignoreblanks = false, bool overwrite = true)
|
public bool Write(string outDir, bool norename = true, bool stats = false, bool ignoreblanks = false, bool overwrite = true)
|
||||||
{
|
{
|
||||||
// Force a statistics recheck, just in case
|
// If we have nothing writable, abort
|
||||||
Items.RecalculateStats();
|
if (!HasWritable())
|
||||||
|
|
||||||
// If there's nothing there, abort
|
|
||||||
if (Items.TotalCount == 0)
|
|
||||||
{
|
|
||||||
Globals.Logger.User("There were no items to write out!");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get a count of all removed items
|
|
||||||
long removed = 0;
|
|
||||||
foreach (string key in Items.Keys)
|
|
||||||
{
|
|
||||||
removed += Items[key].Count(i => i.Remove);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If every item is removed, abort
|
|
||||||
if (Items.TotalCount == removed)
|
|
||||||
{
|
{
|
||||||
Globals.Logger.User("There were no items to write out!");
|
Globals.Logger.User("There were no items to write out!");
|
||||||
return false;
|
return false;
|
||||||
@@ -3440,38 +3423,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Make sure that the three essential fields are filled in
|
// Make sure that the three essential fields are filled in
|
||||||
if (string.IsNullOrWhiteSpace(Header.FileName) && string.IsNullOrWhiteSpace(Header.Name) && string.IsNullOrWhiteSpace(Header.Description))
|
EnsureHeaderFields();
|
||||||
{
|
|
||||||
Header.FileName = Header.Name = Header.Description = "Default";
|
|
||||||
}
|
|
||||||
else if (string.IsNullOrWhiteSpace(Header.FileName) && string.IsNullOrWhiteSpace(Header.Name) && !string.IsNullOrWhiteSpace(Header.Description))
|
|
||||||
{
|
|
||||||
Header.FileName = Header.Name = Header.Description;
|
|
||||||
}
|
|
||||||
else if (string.IsNullOrWhiteSpace(Header.FileName) && !string.IsNullOrWhiteSpace(Header.Name) && string.IsNullOrWhiteSpace(Header.Description))
|
|
||||||
{
|
|
||||||
Header.FileName = Header.Description = Header.Name;
|
|
||||||
}
|
|
||||||
else if (string.IsNullOrWhiteSpace(Header.FileName) && !string.IsNullOrWhiteSpace(Header.Name) && !string.IsNullOrWhiteSpace(Header.Description))
|
|
||||||
{
|
|
||||||
Header.FileName = Header.Description;
|
|
||||||
}
|
|
||||||
else if (!string.IsNullOrWhiteSpace(Header.FileName) && string.IsNullOrWhiteSpace(Header.Name) && string.IsNullOrWhiteSpace(Header.Description))
|
|
||||||
{
|
|
||||||
Header.Name = Header.Description = Header.FileName;
|
|
||||||
}
|
|
||||||
else if (!string.IsNullOrWhiteSpace(Header.FileName) && string.IsNullOrWhiteSpace(Header.Name) && !string.IsNullOrWhiteSpace(Header.Description))
|
|
||||||
{
|
|
||||||
Header.Name = Header.Description;
|
|
||||||
}
|
|
||||||
else if (!string.IsNullOrWhiteSpace(Header.FileName) && !string.IsNullOrWhiteSpace(Header.Name) && string.IsNullOrWhiteSpace(Header.Description))
|
|
||||||
{
|
|
||||||
Header.Description = Header.Name;
|
|
||||||
}
|
|
||||||
else if (!string.IsNullOrWhiteSpace(Header.FileName) && !string.IsNullOrWhiteSpace(Header.Name) && !string.IsNullOrWhiteSpace(Header.Description))
|
|
||||||
{
|
|
||||||
// Nothing is needed
|
|
||||||
}
|
|
||||||
|
|
||||||
// Output initial statistics, for kicks
|
// Output initial statistics, for kicks
|
||||||
if (stats)
|
if (stats)
|
||||||
@@ -3765,6 +3717,61 @@ namespace SabreTools.Library.DatFiles
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ensure that FileName, Name, and Description are filled with some value
|
||||||
|
/// </summary>
|
||||||
|
private void EnsureHeaderFields()
|
||||||
|
{
|
||||||
|
// Empty FileName
|
||||||
|
if (string.IsNullOrWhiteSpace(Header.FileName))
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(Header.Name) && string.IsNullOrWhiteSpace(Header.Description))
|
||||||
|
Header.FileName = Header.Name = Header.Description = "Default";
|
||||||
|
|
||||||
|
else if (string.IsNullOrWhiteSpace(Header.Name) && !string.IsNullOrWhiteSpace(Header.Description))
|
||||||
|
Header.FileName = Header.Name = Header.Description;
|
||||||
|
|
||||||
|
else if (!string.IsNullOrWhiteSpace(Header.Name) && string.IsNullOrWhiteSpace(Header.Description))
|
||||||
|
Header.FileName = Header.Description = Header.Name;
|
||||||
|
|
||||||
|
else if (!string.IsNullOrWhiteSpace(Header.Name) && !string.IsNullOrWhiteSpace(Header.Description))
|
||||||
|
Header.FileName = Header.Description;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filled FileName
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(Header.Name) && string.IsNullOrWhiteSpace(Header.Description))
|
||||||
|
Header.Name = Header.Description = Header.FileName;
|
||||||
|
|
||||||
|
else if (string.IsNullOrWhiteSpace(Header.Name) && !string.IsNullOrWhiteSpace(Header.Description))
|
||||||
|
Header.Name = Header.Description;
|
||||||
|
|
||||||
|
else if (!string.IsNullOrWhiteSpace(Header.Name) && string.IsNullOrWhiteSpace(Header.Description))
|
||||||
|
Header.Description = Header.Name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get if the DatFile has any writable items
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>True if there are any writable items, false otherwise</returns>
|
||||||
|
private bool HasWritable()
|
||||||
|
{
|
||||||
|
// Force a statistics recheck, just in case
|
||||||
|
Items.RecalculateStats();
|
||||||
|
|
||||||
|
// If there's nothing there, abort
|
||||||
|
if (Items.TotalCount == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// If every item is removed, abort
|
||||||
|
if (Items.TotalCount == Items.RemovedCount)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user