mirror of
https://github.com/marcrobledo/RomPatcher.js.git
synced 2025-06-27 16:25:54 +00:00
improved SNES header check
This commit is contained in:
parent
e70052e963
commit
860a2c33c4
3 changed files with 15 additions and 10 deletions
|
@ -1,5 +1,9 @@
|
||||||
/* RomPatcher.js v20180511 - Marc Robledo 2016-2018 - http://www.marcrobledo.com/license */
|
/* RomPatcher.js v20180920 - Marc Robledo 2016-2018 - http://www.marcrobledo.com/license */
|
||||||
var MAX_ROM_SIZE=33554432;
|
var MAX_ROM_SIZE=33554432;
|
||||||
|
var MORE_SNES_SIZES_HEADERLESS=[786432,1310720,1572864,2621440,3145728,5242880,6291456];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var romFile, headeredRomFile, unheaderedRomFile, patch, romFile1, romFile2, tempFile;
|
var romFile, headeredRomFile, unheaderedRomFile, patch, romFile1, romFile2, tempFile;
|
||||||
/* Shortcuts */
|
/* Shortcuts */
|
||||||
function addEvent(e,ev,f){e.addEventListener(ev,f,false)}
|
function addEvent(e,ev,f){e.addEventListener(ev,f,false)}
|
||||||
|
@ -29,10 +33,10 @@ addEvent(window,'load',function(){
|
||||||
unheaderedRomFile=null;
|
unheaderedRomFile=null;
|
||||||
headeredRomFile=null;
|
headeredRomFile=null;
|
||||||
|
|
||||||
if(isSnesRom(romFile.fileName) && isPowerOfTwo(romFile.fileSize)){
|
if(isSNESHeaderless(romFile)){
|
||||||
el('row-addheader').style.display='flex';
|
el('row-addheader').style.display='flex';
|
||||||
el('row-removeheader').style.display='none';
|
el('row-removeheader').style.display='none';
|
||||||
}else if(isSnesRom(romFile.fileName) && isHeadered(romFile.fileSize, 512)){
|
}else if(isSNESHeadered(romFile)){
|
||||||
el('row-addheader').style.display='none';
|
el('row-addheader').style.display='none';
|
||||||
el('row-removeheader').style.display='flex';
|
el('row-removeheader').style.display='flex';
|
||||||
}else{
|
}else{
|
||||||
|
@ -91,9 +95,10 @@ addEvent(window,'load',function(){
|
||||||
//setTab(1);
|
//setTab(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
function isSnesRom(fileName){return /\.(smc|sfc|fig|swc)$/.test(fileName)}
|
function isPowerOfTwo(romFile){return romFile.fileSize && (romFile.fileSize & (romFile.fileSize-1))===0}
|
||||||
function isPowerOfTwo(fileSize){return (fileSize & (fileSize-1))===0}
|
function isSNESExtension(romFile){return /\.(smc|sfc|fig|swc)$/.test(romFile.fileName)}
|
||||||
function isHeadered(fileSize,headerSize){return isPowerOfTwo(fileSize-headerSize)}
|
function isSNESHeaderless(romFile){return isSNESExtension(romFile) && (isPowerOfTwo(romFile) || MORE_SNES_SIZES_HEADERLESS.indexOf(romFile.fileSize)>=0)}
|
||||||
|
function isSNESHeadered(romFile){return isSNESExtension(romFile) && (isPowerOfTwo(romFile.fileSize-512) || MORE_SNES_SIZES_HEADERLESS.indexOf(romFile.fileSize-512)>=0)}
|
||||||
|
|
||||||
|
|
||||||
function updateChecksums(file){
|
function updateChecksums(file){
|
||||||
|
@ -127,8 +132,8 @@ function _readPatchFile(){
|
||||||
patch=readAPSFile(tempFile);
|
patch=readAPSFile(tempFile);
|
||||||
}else if(tempFile.readString(0,4)===BPS_MAGIC){
|
}else if(tempFile.readString(0,4)===BPS_MAGIC){
|
||||||
patch=readBPSFile(tempFile);
|
patch=readBPSFile(tempFile);
|
||||||
}/*else if(tempFile.readString(0,4)===APSGBA_MAGIC){
|
}/*else if(tempFile.readInt(0)===XDELTA_MAGIC){
|
||||||
patch=readAPSGBAFile(tempFile);
|
patch=readXDeltaFile(tempFile);
|
||||||
}*/else {
|
}*/else {
|
||||||
MarcDialogs.alert('Invalid IPS/UPS/APS/BPS file');
|
MarcDialogs.alert('Invalid IPS/UPS/APS/BPS file');
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ limitations under the License.
|
||||||
mod by marcrobledo, original from: https://github.com/GoogleChrome/samples/blob/gh-pages/service-worker/basic/service-worker.js
|
mod by marcrobledo, original from: https://github.com/GoogleChrome/samples/blob/gh-pages/service-worker/basic/service-worker.js
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const PRECACHE_ID='v20180919';
|
const PRECACHE_ID='v20180920';
|
||||||
const PRECACHE_FILES=[
|
const PRECACHE_FILES=[
|
||||||
'index.html','./',
|
'index.html','./',
|
||||||
'RomPatcher.css',
|
'RomPatcher.css',
|
||||||
|
|
|
@ -103,7 +103,7 @@
|
||||||
|
|
||||||
<!-- FOOTER -->
|
<!-- FOOTER -->
|
||||||
<footer>
|
<footer>
|
||||||
Rom Patcher JS <small>rev20180919</small> by <a href="/">Marc Robledo</a>
|
Rom Patcher JS <small>rev20180920</small> by <a href="/">Marc Robledo</a>
|
||||||
<br />
|
<br />
|
||||||
<i class="icon github"></i> <a href="https://github.com/marcrobledo/RomPatcher.js/" target="_blank">See on GitHub</a>
|
<i class="icon github"></i> <a href="https://github.com/marcrobledo/RomPatcher.js/" target="_blank">See on GitHub</a>
|
||||||
<i class="icon heart"></i> <a href="https://www.paypal.me/marcrobledo/5" target="_blank" rel="nofollow">Donate</a>
|
<i class="icon heart"></i> <a href="https://www.paypal.me/marcrobledo/5" target="_blank" rel="nofollow">Donate</a>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue