mirror of
https://github.com/marcrobledo/RomPatcher.js.git
synced 2025-06-27 16:25:54 +00:00
added settings screen with new features
This commit is contained in:
parent
a45e635696
commit
e13da86290
18 changed files with 433 additions and 215 deletions
160
js/RomPatcher.js
160
js/RomPatcher.js
|
@ -1,4 +1,4 @@
|
|||
/* Rom Patcher JS v20210920 - Marc Robledo 2016-2021 - http://www.marcrobledo.com/license */
|
||||
/* Rom Patcher JS v20220319 - Marc Robledo 2016-2022 - http://www.marcrobledo.com/license */
|
||||
|
||||
const TOO_BIG_ROM_SIZE=67108863;
|
||||
const HEADERS_INFO=[
|
||||
|
@ -21,7 +21,6 @@ else if(location.protocol==='https:' && 'serviceWorker' in navigator && window.l
|
|||
|
||||
|
||||
var romFile, patchFile, patch, romFile1, romFile2, tempFile, headerSize, oldHeader;
|
||||
var userLanguage;
|
||||
|
||||
var CAN_USE_WEB_WORKERS=true;
|
||||
var webWorkerApply,webWorkerCreate,webWorkerCrc;
|
||||
|
@ -94,7 +93,7 @@ try{
|
|||
/* Shortcuts */
|
||||
function addEvent(e,ev,f){e.addEventListener(ev,f,false)}
|
||||
function el(e){return document.getElementById(e)}
|
||||
function _(str){return userLanguage[str] || str}
|
||||
function _(str){return (LOCALIZATION[AppSettings.langCode] && LOCALIZATION[AppSettings.langCode][str]) || LOCALIZATION['en'][str] || str}
|
||||
|
||||
|
||||
|
||||
|
@ -190,19 +189,19 @@ function _parseROM(){
|
|||
setTabApplyEnabled(false);
|
||||
}else{
|
||||
if(headerSize=canHaveFakeHeader(romFile)){
|
||||
el('row-addheader').className='row';
|
||||
el('row-addheader').className='row m-b';
|
||||
if(headerSize<1024){
|
||||
el('headersize').innerHTML=headerSize+'b';
|
||||
}else{
|
||||
el('headersize').innerHTML=parseInt(headerSize/1024)+'kb';
|
||||
}
|
||||
el('row-removeheader').className='row hide';
|
||||
el('row-removeheader').className='row m-b hide';
|
||||
}else if(headerSize=hasHeader(romFile)){
|
||||
el('row-addheader').className='row hide';
|
||||
el('row-removeheader').className='row';
|
||||
el('row-addheader').className='row m-b hide';
|
||||
el('row-removeheader').className='row m-b';
|
||||
}else{
|
||||
el('row-addheader').className='row hide';
|
||||
el('row-removeheader').className='row hide';
|
||||
el('row-addheader').className='row m-b hide';
|
||||
el('row-removeheader').className='row m-b hide';
|
||||
}
|
||||
|
||||
updateChecksums(romFile, 0);
|
||||
|
@ -211,23 +210,73 @@ function _parseROM(){
|
|||
|
||||
|
||||
|
||||
function setLanguage(langCode){
|
||||
if(typeof LOCALIZATION[langCode]==='undefined')
|
||||
langCode='en';
|
||||
|
||||
userLanguage=LOCALIZATION[langCode];
|
||||
|
||||
document.documentElement.lang=langCode;
|
||||
|
||||
var translatableElements=document.querySelectorAll('*[data-localize]');
|
||||
for(var i=0; i<translatableElements.length; i++){
|
||||
translatableElements[i].innerHTML=_(translatableElements[i].dataset.localize);
|
||||
|
||||
var UI={
|
||||
localize:function(){
|
||||
if(typeof LOCALIZATION[AppSettings.langCode]==='undefined')
|
||||
return false;
|
||||
|
||||
var translatableElements=document.querySelectorAll('*[data-localize]');
|
||||
for(var i=0; i<translatableElements.length; i++){
|
||||
translatableElements[i].innerHTML=_(translatableElements[i].dataset.localize);
|
||||
}
|
||||
},
|
||||
showDialog:function(id){
|
||||
el('dialog-backdrop').className='show';
|
||||
el(id+'-dialog').className='dialog show';
|
||||
},
|
||||
hideDialog:function(id){
|
||||
el('dialog-backdrop').className='';
|
||||
el(id+'-dialog').className='dialog';
|
||||
},
|
||||
isDialogOpen:function(id){
|
||||
return el(id+'-dialog').className==='dialog show';
|
||||
},
|
||||
setLightTheme:function(val){
|
||||
if(val){
|
||||
document.body.className='light';
|
||||
}else{
|
||||
document.body.className='';
|
||||
}
|
||||
}
|
||||
|
||||
if(typeof localStorage!=='undefined'){
|
||||
localStorage.setItem('rompatcher-js-lang', langCode);
|
||||
};
|
||||
|
||||
var AppSettings={
|
||||
langCode:(typeof navigator.userLanguage==='string')? navigator.userLanguage.substr(0,2) : 'en',
|
||||
outputFileNameMatch:false,
|
||||
lightTheme:false,
|
||||
|
||||
load:function(){
|
||||
if(typeof localStorage!=='undefined' && localStorage.getItem('rompatcher-js-settings')){
|
||||
try{
|
||||
var loadedSettings=JSON.parse(localStorage.getItem('rompatcher-js-settings'));
|
||||
|
||||
if(typeof loadedSettings.langCode==='string' && typeof LOCALIZATION[loadedSettings.langCode]){
|
||||
this.langCode=loadedSettings.langCode;
|
||||
el('select-language').value=this.langCode;
|
||||
}
|
||||
if(loadedSettings.outputFileNameMatch===true){
|
||||
this.outputFileNameMatch=loadedSettings.outputFileNameMatch;
|
||||
el('switch-output-name').className='switch enabled';
|
||||
}
|
||||
if(loadedSettings.lightTheme===true){
|
||||
this.lightTheme=loadedSettings.lightTheme;
|
||||
el('switch-theme').className='switch enabled';
|
||||
UI.setLightTheme(true);
|
||||
}
|
||||
}catch(ex){
|
||||
console.error('Error while loading settings: '+ex.message);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
save:function(){
|
||||
if(typeof localStorage!=='undefined')
|
||||
localStorage.setItem('rompatcher-js-settings', JSON.stringify(this));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/* initialize app */
|
||||
addEvent(window,'load',function(){
|
||||
|
@ -243,12 +292,9 @@ addEvent(window,'load',function(){
|
|||
document.getElementsByTagName('head')[0].appendChild(script);
|
||||
}
|
||||
|
||||
/* language */
|
||||
var langCode=(navigator.language || navigator.userLanguage).substr(0,2);
|
||||
if(typeof localStorage!=='undefined' && localStorage.getItem('rompatcher-js-lang'))
|
||||
langCode=localStorage.getItem('rompatcher-js-lang');
|
||||
el('select-language').value=langCode;
|
||||
setLanguage(langCode);
|
||||
/* load settings */
|
||||
AppSettings.load();
|
||||
UI.localize();
|
||||
|
||||
|
||||
el('row-file-patch').title=_('compatible_formats')+' IPS, UPS, APS, BPS, RUP, PPF, MOD (Paper Mario Star Rod), xdelta';
|
||||
|
@ -346,6 +392,55 @@ addEvent(window,'load',function(){
|
|||
|
||||
|
||||
/* event listeners */
|
||||
addEvent(el('button-settings'), 'click', function(){
|
||||
UI.showDialog('settings');
|
||||
});
|
||||
addEvent(window, 'keyup', function(evt){
|
||||
if(evt.keyCode===27 && UI.isDialogOpen('settings')){
|
||||
UI.hideDialog('settings');
|
||||
}
|
||||
});
|
||||
addEvent(el('settings-dialog'), 'click', function(evt){
|
||||
evt.stopPropagation();
|
||||
});
|
||||
addEvent(el('zip-dialog'), 'click', function(evt){
|
||||
evt.stopPropagation();
|
||||
});
|
||||
addEvent(el('settings-close-dialog'), 'click', function(){
|
||||
UI.hideDialog('settings');
|
||||
});
|
||||
addEvent(el('dialog-backdrop'), 'click', function(){
|
||||
if(UI.isDialogOpen('settings')){
|
||||
UI.hideDialog('settings');
|
||||
}
|
||||
});
|
||||
addEvent(el('select-language'), 'change', function(){
|
||||
AppSettings.langCode=this.value;
|
||||
AppSettings.save();
|
||||
UI.localize();
|
||||
});
|
||||
addEvent(el('switch-output-name'), 'click', function(){
|
||||
if(this.className==='switch enabled'){
|
||||
this.className='switch disabled';
|
||||
AppSettings.outputFileNameMatch=false;
|
||||
}else{
|
||||
this.className='switch enabled';
|
||||
AppSettings.outputFileNameMatch=true;
|
||||
}
|
||||
AppSettings.save();
|
||||
});
|
||||
addEvent(el('switch-theme'), 'click', function(){
|
||||
if(this.className==='switch enabled'){
|
||||
this.className='switch disabled';
|
||||
AppSettings.lightTheme=false;
|
||||
}else{
|
||||
this.className='switch enabled';
|
||||
AppSettings.lightTheme=true;
|
||||
}
|
||||
UI.setLightTheme(AppSettings.lightTheme);
|
||||
AppSettings.save();
|
||||
});
|
||||
|
||||
addEvent(el('input-file-rom'), 'change', function(){
|
||||
setTabApplyEnabled(false);
|
||||
romFile=new MarcFile(this, _parseROM);
|
||||
|
@ -365,9 +460,6 @@ addEvent(window,'load',function(){
|
|||
addEvent(el('button-create'), 'click', function(){
|
||||
createPatch(romFile1, romFile2, el('select-patch-type').value);
|
||||
});
|
||||
addEvent(el('select-language'), 'change', function(){
|
||||
setLanguage(this.value);
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
@ -507,7 +599,11 @@ function _readPatchFile(){
|
|||
|
||||
|
||||
function preparePatchedRom(originalRom, patchedRom, headerSize){
|
||||
patchedRom.fileName=originalRom.fileName.replace(/\.([^\.]*?)$/, ' (patched).$1');
|
||||
if(AppSettings.outputFileNameMatch){
|
||||
patchedRom.fileName=patchFile.fileName.replace(/\.\w+$/i, (/\.\w+$/i.test(originalRom.fileName)? originalRom.fileName.match(/\.\w+$/i)[0] : ''));
|
||||
}else{
|
||||
patchedRom.fileName=originalRom.fileName.replace(/\.([^\.]*?)$/, ' (patched).$1');
|
||||
}
|
||||
patchedRom.fileType=originalRom.fileType;
|
||||
if(headerSize){
|
||||
if(el('checkbox-removeheader').checked){
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* UPS module for Rom Patcher JS v20180930 - Marc Robledo 2017-2018 - http://www.marcrobledo.com/license */
|
||||
/* UPS module for Rom Patcher JS v20220315 - Marc Robledo 2017-2022 - http://www.marcrobledo.com/license */
|
||||
/* File format specification: http://www.romhacking.net/documents/392/ */
|
||||
|
||||
const UPS_MAGIC='UPS1';
|
||||
|
@ -58,12 +58,13 @@ UPS.prototype.apply=function(romFile, validate){
|
|||
}
|
||||
|
||||
/* fix the glitch that cut the end of the file if it's larger than the changed file patch was originally created with */
|
||||
sizeOutput = this.sizeOutput
|
||||
sizeInput = this.sizeInput
|
||||
/* more info: https://github.com/marcrobledo/RomPatcher.js/pull/40#issuecomment-1069087423 */
|
||||
sizeOutput = this.sizeOutput;
|
||||
sizeInput = this.sizeInput;
|
||||
if(!validate && sizeInput < romFile.fileSize){
|
||||
sizeInput = romFile.fileSize
|
||||
sizeInput = romFile.fileSize;
|
||||
if(sizeOutput < sizeInput){
|
||||
sizeOutput = sizeInput
|
||||
sizeOutput = sizeInput;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -210,4 +211,4 @@ function createUPSFromFiles(original, modified){
|
|||
patch.checksumInput=crc32(original);
|
||||
patch.checksumOutput=crc32(modified);
|
||||
return patch
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
/* ZIP module for Rom Patcher JS v20220109 - Marc Robledo 2016-2022 - http://www.marcrobledo.com/license */
|
||||
/* ZIP module for Rom Patcher JS v20220319 - Marc Robledo 2016-2022 - http://www.marcrobledo.com/license */
|
||||
|
||||
const ZIP_MAGIC='\x50\x4b\x03\x04';
|
||||
|
||||
|
@ -62,7 +62,7 @@ var ZIPManager=(function(){
|
|||
}
|
||||
}
|
||||
|
||||
if(customPatch){
|
||||
if(customPatch){
|
||||
if(customPatch.patches){
|
||||
for(var i=0; i<customPatch.patches.length; i++){
|
||||
for(var j=0; j<filteredEntries.length; j++){
|
||||
|
@ -107,17 +107,15 @@ var ZIPManager=(function(){
|
|||
setTabApplyEnabled(false);
|
||||
}else{
|
||||
var _evtClickDialogEntry=function(evt){
|
||||
document.body.removeChild(this.parentElement.parentElement.parentElement);
|
||||
UI.hideDialog('zip');
|
||||
_unzipEntry(this.zipEntry, sourceFile);
|
||||
}
|
||||
|
||||
if(filteredEntries.length>1){
|
||||
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'
|
||||
document.getElementById('zip-dialog-message').innerHTML=_(sourceFile===romFile?'rom_file':'patch_file');
|
||||
|
||||
var zipList=document.getElementById('zip-dialog-file-list');
|
||||
zipList.innerHTML='';
|
||||
for(var i=0; i<filteredEntries.length; i++){
|
||||
var li=document.createElement('li');
|
||||
li.zipEntry=filteredEntries[i];
|
||||
|
@ -125,15 +123,14 @@ var ZIPManager=(function(){
|
|||
addEvent(li, 'click', _evtClickDialogEntry);
|
||||
zipList.appendChild(li);
|
||||
}
|
||||
zipDialog.innerHTML=_(sourceFile===romFile?'rom_file':'patch_file');
|
||||
zipDialog.appendChild(zipList);
|
||||
zipOverlay.appendChild(zipDialog);
|
||||
document.body.appendChild(zipOverlay);
|
||||
|
||||
UI.showDialog('zip');
|
||||
}else if(filteredEntries.length===1){
|
||||
_unzipEntry(filteredEntries[0], sourceFile);
|
||||
}else{
|
||||
if(sourceFile===romFile){
|
||||
romFile=null;
|
||||
setMessage('apply', _('no_valid_file_found'), 'error');
|
||||
}else if(sourceFile===patchFile){
|
||||
patchFile=null;
|
||||
setMessage('apply', _('error_invalid_patch'), 'error');
|
||||
|
|
35
js/locale.js
35
js/locale.js
|
@ -1,6 +1,9 @@
|
|||
const LOCALIZATION={
|
||||
'en':{
|
||||
'creator_mode': 'Creator mode',
|
||||
'settings': 'Settings',
|
||||
'alternate_output_name': 'Use patch name for output',
|
||||
'light_theme': 'Light theme',
|
||||
|
||||
'apply_patch': 'Apply patch',
|
||||
'rom_file': 'ROM file:',
|
||||
|
@ -28,6 +31,9 @@ const LOCALIZATION={
|
|||
},
|
||||
'es':{
|
||||
'creator_mode': 'Modo creador',
|
||||
'settings': 'Configuración',
|
||||
'alternate_output_name': 'Guardar con nombre del parche',
|
||||
'light_theme': 'Tema claro',
|
||||
|
||||
'apply_patch': 'Aplicar parche',
|
||||
'rom_file': 'Archivo ROM:',
|
||||
|
@ -56,6 +62,9 @@ const LOCALIZATION={
|
|||
},
|
||||
'nl':{
|
||||
'creator_mode': 'Creator-modus',
|
||||
'settings': 'Settings',
|
||||
'alternate_output_name': 'Use patch name for output',
|
||||
'light_theme': 'Light theme',
|
||||
|
||||
'apply_patch': 'Pas patch toe',
|
||||
'rom_file': 'ROM bestand:',
|
||||
|
@ -83,6 +92,9 @@ const LOCALIZATION={
|
|||
},
|
||||
'sv':{
|
||||
'creator_mode': 'Skaparläge',
|
||||
'settings': 'Settings',
|
||||
'alternate_output_name': 'Use patch name for output',
|
||||
'light_theme': 'Light theme',
|
||||
|
||||
'apply_patch': 'Tillämpa korrigeringsfil',
|
||||
'rom_file': 'ROM-fil:',
|
||||
|
@ -110,6 +122,9 @@ const LOCALIZATION={
|
|||
},
|
||||
'ca':{
|
||||
'creator_mode': 'Mode creador',
|
||||
'settings': 'Configuració',
|
||||
'alternate_output_name': 'Desar amb nom del pedaç',
|
||||
'light_theme': 'Tema clar',
|
||||
|
||||
'apply_patch': 'Aplicar pedaç',
|
||||
'rom_file': 'Arxiu ROM:',
|
||||
|
@ -137,6 +152,9 @@ const LOCALIZATION={
|
|||
},
|
||||
'ru':{
|
||||
'creator_mode': 'Режим создания',
|
||||
'settings': 'Settings',
|
||||
'alternate_output_name': 'Use patch name for output',
|
||||
'light_theme': 'Light theme',
|
||||
|
||||
'apply_patch': 'Применить патч',
|
||||
'rom_file': 'Файл ROM:',
|
||||
|
@ -164,6 +182,9 @@ const LOCALIZATION={
|
|||
},
|
||||
'de':{
|
||||
'creator_mode': 'Erstellmodus',
|
||||
'settings': 'Settings',
|
||||
'alternate_output_name': 'Use patch name for output',
|
||||
'light_theme': 'Light theme',
|
||||
|
||||
'apply_patch': 'Patch anwenden',
|
||||
'rom_file': 'ROM-Datei:',
|
||||
|
@ -191,6 +212,9 @@ const LOCALIZATION={
|
|||
},
|
||||
'pt-br':{
|
||||
'creator_mode': 'Modo criador',
|
||||
'settings': 'Settings',
|
||||
'alternate_output_name': 'Use patch name for output',
|
||||
'light_theme': 'Light theme',
|
||||
|
||||
'apply_patch': 'Aplicar patch',
|
||||
'rom_file': 'Arquivo ROM:',
|
||||
|
@ -218,6 +242,9 @@ const LOCALIZATION={
|
|||
},
|
||||
'ja':{
|
||||
'creator_mode': '作成モード',
|
||||
'settings': 'Settings',
|
||||
'alternate_output_name': 'Use patch name for output',
|
||||
'light_theme': 'Light theme',
|
||||
|
||||
'apply_patch': 'パッチを当て',
|
||||
'rom_file': 'ROMファィル:',
|
||||
|
@ -245,6 +272,9 @@ const LOCALIZATION={
|
|||
},
|
||||
'fr':{
|
||||
'creator_mode': 'Mode créateur',
|
||||
'settings': 'Settings',
|
||||
'alternate_output_name': 'Use patch name for output',
|
||||
'light_theme': 'Light theme',
|
||||
|
||||
'apply_patch': 'Appliquer le patch',
|
||||
'rom_file': 'Fichier ROM:',
|
||||
|
@ -270,8 +300,11 @@ const LOCALIZATION={
|
|||
'error_invalid_patch': 'Fichier patch invalide',
|
||||
'warning_too_big': 'L\'utilisation de gros fichiers n\'est pas recommandée.'
|
||||
},
|
||||
'zh_CN':{
|
||||
'zh-cn':{
|
||||
'creator_mode': '创建模式',
|
||||
'settings': 'Settings',
|
||||
'alternate_output_name': 'Use patch name for output',
|
||||
'light_theme': 'Light theme',
|
||||
|
||||
'apply_patch': '打补丁',
|
||||
'rom_file': 'ROM文件:',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue