Enable flat writing using header value

This commit is contained in:
Matt Nadareski
2020-08-28 20:46:12 -07:00
parent 6f76051399
commit 2a5a5516d9
3 changed files with 29 additions and 6 deletions

View File

@@ -2369,9 +2369,12 @@ namespace SabreTools.Library.DatFiles
outputFormat = OutputFormat.TorrentZip; outputFormat = OutputFormat.TorrentZip;
break; break;
case PackingFlag.Unzip: case PackingFlag.Unzip:
case PackingFlag.Partial:
outputFormat = OutputFormat.Folder; outputFormat = OutputFormat.Folder;
break; break;
// TODO: Check what output format would be for Partial and Flat case PackingFlag.Flat:
outputFormat = OutputFormat.ParentFolder;
break;
} }
} }
@@ -2388,6 +2391,7 @@ namespace SabreTools.Library.DatFiles
switch (outputFormat) switch (outputFormat)
{ {
case OutputFormat.Folder: case OutputFormat.Folder:
case OutputFormat.ParentFolder:
format = "directory"; format = "directory";
break; break;
case OutputFormat.TapeArchive: case OutputFormat.TapeArchive:
@@ -2559,9 +2563,12 @@ namespace SabreTools.Library.DatFiles
outputFormat = OutputFormat.TorrentZip; outputFormat = OutputFormat.TorrentZip;
break; break;
case PackingFlag.Unzip: case PackingFlag.Unzip:
case PackingFlag.Partial:
outputFormat = OutputFormat.Folder; outputFormat = OutputFormat.Folder;
break; break;
// TODO: Check what output format would be for Partial and Flat case PackingFlag.Flat:
outputFormat = OutputFormat.ParentFolder;
break;
} }
} }
@@ -2578,6 +2585,7 @@ namespace SabreTools.Library.DatFiles
switch (outputFormat) switch (outputFormat)
{ {
case OutputFormat.Folder: case OutputFormat.Folder:
case OutputFormat.ParentFolder:
format = "directory"; format = "directory";
break; break;
case OutputFormat.TapeArchive: case OutputFormat.TapeArchive:
@@ -2855,7 +2863,7 @@ namespace SabreTools.Library.DatFiles
} }
// Get a generic stream for the file // Get a generic stream for the file
Stream fileStream = new MemoryStream(); Stream fileStream = null;
// If we have a zipfile, extract the stream to memory // If we have a zipfile, extract the stream to memory
if (isZip != null) if (isZip != null)

View File

@@ -1283,6 +1283,7 @@ namespace SabreTools.Library.FileTypes
{ {
// Currently implemented // Currently implemented
Folder, Folder,
ParentFolder,
TorrentZip, TorrentZip,
TorrentGzip, TorrentGzip,
TorrentGzipRomba, TorrentGzipRomba,

View File

@@ -20,6 +20,11 @@ namespace SabreTools.Library.FileTypes
protected List<BaseFile> _children; protected List<BaseFile> _children;
/// <summary>
/// Flag specific to Folder to omit Machine name from output path
/// </summary>
private bool writeToParent = false;
#endregion #endregion
#region Constructors #region Constructors
@@ -27,10 +32,12 @@ namespace SabreTools.Library.FileTypes
/// <summary> /// <summary>
/// Create a new folder with no base file /// Create a new folder with no base file
/// </summary> /// </summary>
public Folder() /// <param name="writeToParent">True to write directly to parent, false otherwise</param>
public Folder(bool writeToParent = false)
: base() : base()
{ {
this.Type = FileType.Folder; this.Type = FileType.Folder;
this.writeToParent = writeToParent;
} }
/// <summary> /// <summary>
@@ -55,7 +62,10 @@ namespace SabreTools.Library.FileTypes
switch (outputFormat) switch (outputFormat)
{ {
case OutputFormat.Folder: case OutputFormat.Folder:
return new Folder(); return new Folder(false);
case OutputFormat.ParentFolder:
return new Folder(true);
case OutputFormat.TapeArchive: case OutputFormat.TapeArchive:
return new TapeArchive(); return new TapeArchive();
@@ -332,7 +342,11 @@ namespace SabreTools.Library.FileTypes
FileStream outputStream = null; FileStream outputStream = null;
// Get the output folder name from the first rebuild rom // Get the output folder name from the first rebuild rom
string fileName = Path.Combine(outDir, Sanitizer.RemovePathUnsafeCharacters(rom.Machine.Name), Sanitizer.RemovePathUnsafeCharacters(rom.Name)); string fileName;
if (writeToParent)
fileName = Path.Combine(outDir, Sanitizer.RemovePathUnsafeCharacters(rom.Name));
else
fileName = Path.Combine(outDir, Sanitizer.RemovePathUnsafeCharacters(rom.Machine.Name), Sanitizer.RemovePathUnsafeCharacters(rom.Name));
try try
{ {