1
0
Fork 0
mirror of https://github.com/marcrobledo/RomPatcher.js.git synced 2025-06-27 16:25:54 +00:00

added zip extension check, fixing #53

This commit is contained in:
Marc Robledo 2023-02-04 08:11:57 +01:00
parent 83ddcd23fc
commit 0769fae972
5 changed files with 17 additions and 10 deletions

View file

@ -1,9 +1,9 @@
MIT License MIT License
Copyright (c) 2017-2022 Marc Robledo Copyright (c) 2017-2023 Marc Robledo
This project incorporates components from Octicons This project incorporates components from Octicons
(https://github.com/primer/octicons/) Copyright (c) 2022 GitHub Inc., (https://github.com/primer/octicons/) Copyright (c) 2023 GitHub Inc.,
also released under MIT license. also released under MIT license.
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy

View file

@ -14,7 +14,7 @@
*/ */
var PRECACHE_ID='rom-patcher-js'; var PRECACHE_ID='rom-patcher-js';
var PRECACHE_VERSION='v27'; var PRECACHE_VERSION='v27b';
var PRECACHE_URLS=[ var PRECACHE_URLS=[
'/RomPatcher.js/','/RomPatcher.js/index.html', '/RomPatcher.js/','/RomPatcher.js/index.html',
'/RomPatcher.js/manifest.json', '/RomPatcher.js/manifest.json',

View file

@ -179,7 +179,7 @@
<button id="button-settings" class="button-outer"><img src="style/icon_settings.svg" class="icon settings" /> <span data-localize="settings">Settings</span></button> <button id="button-settings" class="button-outer"><img src="style/icon_settings.svg" class="icon settings" /> <span data-localize="settings">Settings</span></button>
</div> </div>
Rom Patcher JS <small>v2.7</small> by <a href="/">Marc Robledo</a> Rom Patcher JS <small>v2.7.1</small> by <a href="/">Marc Robledo</a>
<br /> <br />
<img src="style/icon_github.svg" class="icon github" /> <a href="https://github.com/marcrobledo/RomPatcher.js/" target="_blank">See on GitHub</a> <img src="style/icon_github.svg" class="icon github" /> <a href="https://github.com/marcrobledo/RomPatcher.js/" target="_blank">See on GitHub</a>
<img src="style/icon_heart.svg" class="icon heart" /> <a href="https://www.paypal.me/marcrobledo/5" target="_blank" rel="nofollow">Donate</a> <img src="style/icon_heart.svg" class="icon heart" /> <a href="https://www.paypal.me/marcrobledo/5" target="_blank" rel="nofollow">Donate</a>

View file

@ -1,4 +1,4 @@
/* MODDED VERSION OF MarcFile.js v20181020 - Marc Robledo 2014-2018 - http://www.marcrobledo.com/license */ /* MODDED VERSION OF MarcFile.js v20230202 - Marc Robledo 2014-2023 - http://www.marcrobledo.com/license */
function MarcFile(source, onLoad){ function MarcFile(source, onLoad){
if(typeof source==='object' && source.files) /* get first file only if source is input with multiple files */ if(typeof source==='object' && source.files) /* get first file only if source is input with multiple files */
@ -146,6 +146,13 @@ MarcFile.prototype.save=function(){
} }
MarcFile.prototype.getExtension=function(){
var ext=this.fileName? this.fileName.toLowerCase().match(/\.(\w+)$/) : '';
return ext? ext[1] : '';
}
MarcFile.prototype.readU8=function(){ MarcFile.prototype.readU8=function(){
this._lastRead=this._u8array[this.offset]; this._lastRead=this._u8array[this.offset];

View file

@ -1,4 +1,4 @@
/* Rom Patcher JS v20221110 - Marc Robledo 2016-2022 - http://www.marcrobledo.com/license */ /* Rom Patcher JS v20230202 - Marc Robledo 2016-2023 - http://www.marcrobledo.com/license */
const TOO_BIG_ROM_SIZE=67108863; const TOO_BIG_ROM_SIZE=67108863;
const HEADERS_INFO=[ const HEADERS_INFO=[
@ -141,7 +141,7 @@ function fetchPatch(customPatchIndex, compressedFileIndex){
patchFile=CUSTOM_PATCHER[customPatchIndex].fetchedFile=new MarcFile(arrayBuffer); patchFile=CUSTOM_PATCHER[customPatchIndex].fetchedFile=new MarcFile(arrayBuffer);
patchFile.fileName=customPatch.file.replace(/^.*[\/\\]/g,''); patchFile.fileName=customPatch.file.replace(/^.*[\/\\]/g,'');
if(patchFile.readString(4).startsWith(ZIP_MAGIC)) if(patchFile.getExtension()==='zip' && patchFile.readString(4).startsWith(ZIP_MAGIC))
ZIPManager.parseFile(CUSTOM_PATCHER[customPatchIndex].fetchedFile, compressedFileIndex); ZIPManager.parseFile(CUSTOM_PATCHER[customPatchIndex].fetchedFile, compressedFileIndex);
else else
parseCustomPatch(CUSTOM_PATCHER[customPatchIndex]); parseCustomPatch(CUSTOM_PATCHER[customPatchIndex]);
@ -161,7 +161,7 @@ function fetchPatch(customPatchIndex, compressedFileIndex){
patchFile=CUSTOM_PATCHER[customPatchIndex].fetchedFile=new MarcFile(xhr.response); patchFile=CUSTOM_PATCHER[customPatchIndex].fetchedFile=new MarcFile(xhr.response);
patchFile.fileName=customPatch.file.replace(/^.*[\/\\]/g,''); patchFile.fileName=customPatch.file.replace(/^.*[\/\\]/g,'');
if(patchFile.readString(4).startsWith(ZIP_MAGIC)) if(patchFile.getExtension()==='zip' && patchFile.readString(4).startsWith(ZIP_MAGIC))
ZIPManager.parseFile(CUSTOM_PATCHER[customPatchIndex].fetchedFile, compressedFileIndex); ZIPManager.parseFile(CUSTOM_PATCHER[customPatchIndex].fetchedFile, compressedFileIndex);
else else
parseCustomPatch(CUSTOM_PATCHER[customPatchIndex]); parseCustomPatch(CUSTOM_PATCHER[customPatchIndex]);
@ -184,7 +184,7 @@ function _parseROM(){
el('checkbox-addheader').checked=false; el('checkbox-addheader').checked=false;
el('checkbox-removeheader').checked=false; el('checkbox-removeheader').checked=false;
if(romFile.readString(4).startsWith(ZIP_MAGIC)){ if(romFile.getExtension()==='zip' && romFile.readString(4).startsWith(ZIP_MAGIC)){
ZIPManager.parseFile(romFile); ZIPManager.parseFile(romFile);
setTabApplyEnabled(false); setTabApplyEnabled(false);
}else{ }else{
@ -653,7 +653,7 @@ function _readPatchFile(){
patchFile.littleEndian=false; patchFile.littleEndian=false;
var header=patchFile.readString(6); var header=patchFile.readString(6);
if(header.startsWith(ZIP_MAGIC)){ if(patchFile.getExtension()==='zip' && header.startsWith(ZIP_MAGIC)){
patch=false; patch=false;
validateSource(); validateSource();
setTabApplyEnabled(false); setTabApplyEnabled(false);