-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: handle ROMs with headers when calculating checksums (#47)
- Loading branch information
Showing
63 changed files
with
886 additions
and
341 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
end_of_line = lf |
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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
# Stop `core.autocrlf true` | ||
*.lnx binary | ||
*.nes binary | ||
*.rom binary |
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 |
---|---|---|
|
@@ -106,7 +106,8 @@ dist | |
|
||
# Custom | ||
build/ | ||
demo-magic.sh | ||
*.bat | ||
*.sh | ||
|
||
# DATs | ||
*.dat | ||
|
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
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 |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
"keywords": [ | ||
"1g1r", | ||
"emulation", | ||
"logiqx", | ||
"no-intro", | ||
"roms" | ||
], | ||
|
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
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
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
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
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
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
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
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,60 @@ | ||
import async, { AsyncResultCallback } from 'async'; | ||
|
||
import ProgressBar, { Symbols } from '../console/progressBar.js'; | ||
import Constants from '../constants.js'; | ||
import File from '../types/files/file.js'; | ||
import FileHeader from '../types/files/fileHeader.js'; | ||
import Options from '../types/options.js'; | ||
|
||
// TODO(cemmer): put debug statements in here | ||
export default class HeaderProcessor { | ||
private readonly options: Options; | ||
|
||
private readonly progressBar: ProgressBar; | ||
|
||
constructor(options: Options, progressBar: ProgressBar) { | ||
this.options = options; | ||
this.progressBar = progressBar; | ||
} | ||
|
||
async process(inputRomFiles: File[]): Promise<File[]> { | ||
await this.progressBar.logInfo('Processing file headers'); | ||
|
||
await this.progressBar.setSymbol(Symbols.HASHING); | ||
await this.progressBar.reset(inputRomFiles.length); | ||
|
||
return async.mapLimit( | ||
inputRomFiles, | ||
Constants.ROM_HEADER_HASHER_THREADS, | ||
async (inputFile, callback: AsyncResultCallback<File, Error>) => { | ||
await this.progressBar.increment(); | ||
|
||
// Don't do anything if the file already has a header | ||
if (inputFile.getFileHeader()) { | ||
return callback(null, inputFile); | ||
} | ||
|
||
// Can get FileHeader from extension, use that | ||
const headerForExtension = FileHeader.getForFilename(inputFile.getExtractedFilePath()); | ||
if (headerForExtension) { | ||
const fileWithHeader = await inputFile.withFileHeader(headerForExtension).resolve(); | ||
return callback(null, fileWithHeader); | ||
} | ||
|
||
// Should get FileHeader from File, try to | ||
if (this.options.shouldReadFileForHeader(inputFile.getExtractedFilePath())) { | ||
const headerForFile = await inputFile | ||
.extract(async (localFile) => FileHeader.getForFileContents(localFile)); | ||
if (headerForFile) { | ||
const fileWithHeader = await inputFile.withFileHeader(headerForFile).resolve(); | ||
return callback(null, fileWithHeader); | ||
} | ||
await this.progressBar.logWarn(`Couldn't detect header for ${inputFile.toString()}`); | ||
} | ||
|
||
// Should not get FileHeader | ||
return callback(null, inputFile); | ||
}, | ||
); | ||
} | ||
} |
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
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
Oops, something went wrong.