-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switched to ctrtool for extracting CIAs, since HackingToolkit9ds was …
…not working for some ROMs.
- Loading branch information
1 parent
9481cf7
commit 750263c
Showing
3 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
FinModelUtility/UniversalModelExtractor/src/platforms/threeDs/tools/CtrtoolCiaExtractor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using fin.io; | ||
using fin.log; | ||
using fin.util.asserts; | ||
|
||
using uni.platforms.gcn.tools; | ||
using uni.util.cmd; | ||
|
||
|
||
namespace uni.platforms.threeDs.tools { | ||
public class CtrtoolCiaExtractor { | ||
private static readonly object CTRTOOL_LOCK = new(); | ||
|
||
public bool Run(ISystemFile romFile, out IFileHierarchy hierarchy) { | ||
Asserts.Equal( | ||
".cia", | ||
romFile.Extension, | ||
$"Cannot dump ROM because it is not a CIA: {romFile}"); | ||
Asserts.True( | ||
romFile.Exists, | ||
$"Cannot dump ROM because it does not exist: {romFile}"); | ||
|
||
var didChange = false; | ||
|
||
var finalDirectoryPath = romFile.FullNameWithoutExtension; | ||
var finalDirectory = new FinDirectory(finalDirectoryPath); | ||
if (!finalDirectory.Exists) { | ||
didChange = true; | ||
|
||
lock (CtrtoolCiaExtractor.CTRTOOL_LOCK) { | ||
var beforeFiles = ThreeDsToolsConstants.CTRTOOL_DIRECTORY | ||
.GetExistingFiles() | ||
.ToHashSet(); | ||
var beforeSubdirs = ThreeDsToolsConstants | ||
.CTRTOOL_DIRECTORY | ||
.GetExistingSubdirs() | ||
.ToHashSet(); | ||
|
||
var directoryPath = Path.Join( | ||
ThreeDsToolsConstants.CTRTOOL_DIRECTORY.FullName, | ||
"romfs"); | ||
var directory = new FinDirectory(directoryPath); | ||
|
||
if (!directory.Exists) { | ||
this.DumpRom_(romFile); | ||
Asserts.True(directory.Exists, | ||
$"Failed to find expected ROM filesystem output directory. There may be something with the following CIA: {romFile.FullName}"); | ||
} | ||
|
||
Directory.Move(directoryPath, finalDirectoryPath); | ||
Asserts.True(finalDirectory.Exists, | ||
$"Directory was not created: {finalDirectory}"); | ||
|
||
var afterFiles = ThreeDsToolsConstants.CTRTOOL_DIRECTORY | ||
.GetExistingFiles() | ||
.ToArray(); | ||
var afterSubdirs = ThreeDsToolsConstants.CTRTOOL_DIRECTORY | ||
.GetExistingSubdirs() | ||
.ToArray(); | ||
|
||
// Cleans up unneeded files & directories | ||
foreach (var afterFile in afterFiles) { | ||
if (!beforeFiles.Contains(afterFile)) { | ||
afterFile.Delete(); | ||
} | ||
} | ||
|
||
foreach (var afterSubdir in afterSubdirs) { | ||
if (!beforeSubdirs.Contains(afterSubdir)) { | ||
afterSubdir.Delete(true); | ||
} | ||
} | ||
} | ||
} | ||
|
||
hierarchy = new FileHierarchy(finalDirectory); | ||
return didChange; | ||
} | ||
|
||
private void DumpRom_(ISystemFile romFile) { | ||
var logger = Logging.Create<CtrtoolCiaExtractor>(); | ||
logger.LogInformation($"Dumping ROM {romFile}..."); | ||
|
||
Files.RunInDirectory( | ||
ThreeDsToolsConstants.CTRTOOL_DIRECTORY, | ||
() => { | ||
ProcessUtil.ExecuteBlockingSilently( | ||
ThreeDsToolsConstants.EXTRACT_CIA_BAT, | ||
$"\"{romFile.FullName}\""); | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters