diff --git a/_cache_service_worker.js b/_cache_service_worker.js index c60c891..886bcad 100644 --- a/_cache_service_worker.js +++ b/_cache_service_worker.js @@ -29,7 +29,7 @@ caches.keys().then(function(cacheNames){ }); var PRECACHE_ID='rom-patcher-js'; -var PRECACHE_VERSION='v12'; +var PRECACHE_VERSION='v14'; var PRECACHE_URLS=[ '/RomPatcher.js/','/RomPatcher.js/index.html', '/RomPatcher.js/manifest.json', @@ -48,7 +48,6 @@ var PRECACHE_URLS=[ '/RomPatcher.js/js/zip.js/zip.js', '/RomPatcher.js/js/zip.js/z-worker.js', '/RomPatcher.js/js/zip.js/inflate.js', - '/RomPatcher.js/js/formats/zip.js', '/RomPatcher.js/js/formats/ips.js', '/RomPatcher.js/js/formats/ups.js', '/RomPatcher.js/js/formats/aps.js', @@ -56,7 +55,8 @@ var PRECACHE_URLS=[ '/RomPatcher.js/js/formats/rup.js', '/RomPatcher.js/js/formats/ppf.js', '/RomPatcher.js/js/formats/pmsr.js', - '/RomPatcher.js/js/formats/vcdiff.js' + '/RomPatcher.js/js/formats/vcdiff.js', + '/RomPatcher.js/js/formats/zip.js' ]; diff --git a/index.html b/index.html index 56302a4..40ebf38 100644 --- a/index.html +++ b/index.html @@ -41,55 +41,42 @@ + + - - - - - + ];*/ + -->
@@ -113,13 +100,13 @@
MD5:
SHA-1:
-
+
-
+
() @@ -186,18 +173,19 @@
- Rom Patcher JS v2.4 by Marc Robledo + Rom Patcher JS v2.5 by Marc Robledo
See on GitHub Donate diff --git a/js/RomPatcher.js b/js/RomPatcher.js index 37863c8..25bb1f9 100644 --- a/js/RomPatcher.js +++ b/js/RomPatcher.js @@ -1,4 +1,4 @@ -/* Rom Patcher JS v20201106 - Marc Robledo 2016-2020 - http://www.marcrobledo.com/license */ +/* Rom Patcher JS v20210920 - Marc Robledo 2016-2021 - http://www.marcrobledo.com/license */ const TOO_BIG_ROM_SIZE=67108863; const HEADERS_INFO=[ @@ -15,13 +15,12 @@ const HEADERS_INFO=[ const FORCE_HTTPS=true; if(FORCE_HTTPS && location.protocol==='http:') location.href=window.location.href.replace('http:','https:'); -else if(location.protocol==='https:' && 'serviceWorker' in navigator) +else if(location.protocol==='https:' && 'serviceWorker' in navigator && window.location.hostname==='www.marcrobledo.com') navigator.serviceWorker.register('/RomPatcher.js/_cache_service_worker.js', {scope: '/RomPatcher.js/'}); var romFile, patchFile, patch, romFile1, romFile2, tempFile, headerSize, oldHeader; -var fetchedPatches; var userLanguage; var CAN_USE_WEB_WORKERS=true; @@ -99,42 +98,78 @@ function _(str){return userLanguage[str] || str} -function fetchPatch(uri){ + + +/* custom patcher */ +function isCustomPatcherEnabled(){ + return typeof CUSTOM_PATCHER!=='undefined' && typeof CUSTOM_PATCHER==='object' && CUSTOM_PATCHER.length +} +function parseCustomPatch(customPatch){ + patchFile=customPatch.fetchedFile; + patchFile.seek(0); + _readPatchFile(); + + if(typeof patch.validateSource === 'undefined'){ + if(typeof customPatch.crc==='number'){ + patch.validateSource=function(romFile,headerSize){ + return customPatch.crc===crc32(romFile, headerSize) + } + }else if(typeof customPatch.crc==='object'){ + patch.validateSource=function(romFile,headerSize){ + for(var i=0; i result.arrayBuffer()) // Gets the response and returns it as a blob .then(arrayBuffer => { - fetchedPatches[patchURI]=patchFile=new MarcFile(arrayBuffer); - fetchedPatches[patchURI].fileName=patchURI.replace(/^(.*?\/)+/g, ''); - _readPatchFile(); + patchFile=CUSTOM_PATCHER[customPatchIndex].fetchedFile=new MarcFile(arrayBuffer); + patchFile.fileName=customPatch.file.replace(/^.*[\/\\]/g,''); + + if(patchFile.readString(4).startsWith(ZIP_MAGIC)) + ZIPManager.parseFile(CUSTOM_PATCHER[customPatchIndex].fetchedFile, compressedFileIndex); + else + parseCustomPatch(CUSTOM_PATCHER[customPatchIndex]); + + setMessage('apply'); }) .catch(function(evt){ - setMessage('apply', _('error_downloading'), 'error'); - //setMessage('apply', evt.message, 'error'); + setMessage('apply', (_('error_downloading')/* + evt.message */).replace('%s', CUSTOM_PATCHER[customPatchIndex].file.replace(/^.*[\/\\]/g,'')), 'error'); }); }else{ var xhr=new XMLHttpRequest(); - xhr.open('GET', patchURI, true); + xhr.open('GET', uri, true); xhr.responseType='arraybuffer'; xhr.onload=function(evt){ if(this.status===200){ - fetchedPatches[patchURI]=patchFile=new MarcFile(xhr.response); - fetchedPatches[patchURI].fileName=patchURI.replace(/^(.*?\/)+/g, ''); - _readPatchFile(); + patchFile=CUSTOM_PATCHER[customPatchIndex].fetchedFile=new MarcFile(xhr.response); + patchFile.fileName=customPatch.file.replace(/^.*[\/\\]/g,''); + + if(patchFile.readString(4).startsWith(ZIP_MAGIC)) + ZIPManager.parseFile(CUSTOM_PATCHER[customPatchIndex].fetchedFile, compressedFileIndex); + else + parseCustomPatch(CUSTOM_PATCHER[customPatchIndex]); + + setMessage('apply'); }else{ - setMessage('apply', _('error_downloading')+' ('+this.status+')', 'error'); + setMessage('apply', _('error_downloading').replace('%s', CUSTOM_PATCHER[customPatchIndex].file.replace(/^.*[\/\\]/g,''))+' ('+this.status+')', 'error'); } }; @@ -146,29 +181,28 @@ function fetchPatch(uri){ } } - function _parseROM(){ el('checkbox-addheader').checked=false; el('checkbox-removeheader').checked=false; if(romFile.readString(4).startsWith(ZIP_MAGIC)){ - parseZIPFile(romFile); + ZIPManager.parseFile(romFile); setTabApplyEnabled(false); }else{ if(headerSize=canHaveFakeHeader(romFile)){ - el('row-addheader').style.display='flex'; + el('row-addheader').className='row'; if(headerSize<1024){ el('headersize').innerHTML=headerSize+'b'; }else{ el('headersize').innerHTML=parseInt(headerSize/1024)+'kb'; } - el('row-removeheader').style.display='none'; + el('row-removeheader').className='row hide'; }else if(headerSize=hasHeader(romFile)){ - el('row-addheader').style.display='none'; - el('row-removeheader').style.display='flex'; + el('row-addheader').className='row hide'; + el('row-removeheader').className='row'; }else{ - el('row-addheader').style.display='none'; - el('row-removeheader').style.display='none'; + el('row-addheader').className='row hide'; + el('row-removeheader').className='row hide'; } updateChecksums(romFile, 0); @@ -182,8 +216,8 @@ function setLanguage(langCode){ langCode='en'; userLanguage=LOCALIZATION[langCode]; - - document.documentElement.lang = langCode; + + document.documentElement.lang=langCode; var translatableElements=document.querySelectorAll('*[data-localize]'); for(var i=0; i>> 0; //if file is bigger than 512Mb*8, value is bigger than 32 bits, so it needs two words to store its length _md5cycle(state,tail); for(var i=0;i1){ - var zipOverlay=document.createElement('div'); - zipOverlay.className='zip-overlay'; - var zipDialog=document.createElement('div'); - zipDialog.className='zip-dialog'; - var zipList=document.createElement('ul'); - zipList.className='zipped-files' - for(var i=0; i1){ + var zipOverlay=document.createElement('div'); + zipOverlay.className='zip-overlay'; + var zipDialog=document.createElement('div'); + zipDialog.className='zip-dialog'; + var zipList=document.createElement('ul'); + zipList.className='zipped-files' + for(var i=0; i