More SuperDAT improvments

This commit is contained in:
Matt Nadareski
2016-05-17 16:53:02 -07:00
parent 4efbc82f81
commit 8994cf6f4c
2 changed files with 25 additions and 16 deletions

View File

@@ -221,8 +221,6 @@ namespace SabreTools
foreach (string path in _inputs) foreach (string path in _inputs)
{ {
// Set local paths and vars // Set local paths and vars
_tempDir = Environment.CurrentDirectory + Path.DirectorySeparatorChar + "temp" + DateTime.Now.ToString("yyyyMMddHHmmss") + Path.DirectorySeparatorChar;
_basePath = (File.Exists(path) ? path : path + Path.DirectorySeparatorChar); _basePath = (File.Exists(path) ? path : path + Path.DirectorySeparatorChar);
_basePath = Path.GetFullPath(_basePath); _basePath = Path.GetFullPath(_basePath);
@@ -245,9 +243,13 @@ namespace SabreTools
string basePathBackup = _basePath; string basePathBackup = _basePath;
foreach (string item in Directory.EnumerateDirectories(_basePath)) foreach (string item in Directory.EnumerateDirectories(_basePath))
{ {
_basePath = (File.Exists(item) ? item : item + Path.DirectorySeparatorChar); // If we're not in SuperDAT mode, then reset the base path
_basePath = Path.GetFullPath(_basePath); if (!_superDat)
{
_basePath = (File.Exists(item) ? item : item + Path.DirectorySeparatorChar);
_basePath = Path.GetFullPath(_basePath);
}
foreach (string subitem in Directory.EnumerateFiles(_basePath, "*", SearchOption.AllDirectories)) foreach (string subitem in Directory.EnumerateFiles(_basePath, "*", SearchOption.AllDirectories))
{ {
ProcessFile(subitem); ProcessFile(subitem);
@@ -334,9 +336,9 @@ namespace SabreTools
/// <param name="item">Filename of the item to be checked</param> /// <param name="item">Filename of the item to be checked</param>
private void ProcessFile(string item) private void ProcessFile(string item)
{ {
// Create the temporary output directory Console.WriteLine("basepath: " + _basePath);
DirectoryInfo di = Directory.CreateDirectory(_tempDir);
// Create the temporary output directory
bool encounteredErrors = true; bool encounteredErrors = true;
if (!_archivesAsFiles) if (!_archivesAsFiles)
{ {
@@ -348,6 +350,8 @@ namespace SabreTools
if (at == ArchiveType.Zip || at == ArchiveType.SevenZip || at == ArchiveType.Rar) if (at == ArchiveType.Zip || at == ArchiveType.SevenZip || at == ArchiveType.Rar)
{ {
_tempDir = Environment.CurrentDirectory + Path.DirectorySeparatorChar + "temp" + DateTime.Now.ToString("yyyyMMddHHmmss") + Path.DirectorySeparatorChar;
DirectoryInfo di = Directory.CreateDirectory(_tempDir);
IReader reader = archive.ExtractAllEntries(); IReader reader = archive.ExtractAllEntries();
reader.WriteAllToDirectory(_tempDir, ExtractOptions.ExtractFullPath); reader.WriteAllToDirectory(_tempDir, ExtractOptions.ExtractFullPath);
encounteredErrors = false; encounteredErrors = false;
@@ -435,6 +439,12 @@ namespace SabreTools
_logger.User("File added: " + entry + Environment.NewLine); _logger.User("File added: " + entry + Environment.NewLine);
} }
// Delete the temp directory
if (Directory.Exists(_tempDir))
{
Directory.Delete(_tempDir, true);
}
} }
// Otherwise, just get the info on the file itself // Otherwise, just get the info on the file itself
else if (!Directory.Exists(item) && File.Exists(item)) else if (!Directory.Exists(item) && File.Exists(item))
@@ -516,12 +526,6 @@ namespace SabreTools
_logger.Error(ex.ToString()); _logger.Error(ex.ToString());
} }
} }
// Delete the temp directory
if (Directory.Exists(_tempDir))
{
di.Delete(true);
}
} }
} }
} }

View File

@@ -142,9 +142,9 @@ namespace SabreTools.Helper
switch (headreader.Name) switch (headreader.Name)
{ {
case "name": case "name":
string readname = headreader.ReadElementContentAsString(); ; content = headreader.ReadElementContentAsString(); ;
datdata.Name = (datdata.Name == "" ? readname : ""); datdata.Name = (datdata.Name == "" ? content : datdata.Name);
superdat = superdat || readname.Contains(" - SuperDAT"); superdat = superdat || content.Contains(" - SuperDAT");
break; break;
case "description": case "description":
content = headreader.ReadElementContentAsString(); content = headreader.ReadElementContentAsString();
@@ -182,6 +182,11 @@ namespace SabreTools.Helper
content = headreader.ReadElementContentAsString(); content = headreader.ReadElementContentAsString();
datdata.Comment = (datdata.Comment == "" ? content : datdata.Comment); datdata.Comment = (datdata.Comment == "" ? content : datdata.Comment);
break; break;
case "type":
content = headreader.ReadElementContentAsString();
datdata.Type = (datdata.Type == "" ? content : datdata.Type);
superdat = superdat || content.Contains("SuperDAT");
break;
case "clrmamepro": case "clrmamepro":
if (headreader.GetAttribute("forcemerging") != null) if (headreader.GetAttribute("forcemerging") != null)
{ {