Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tauri app conversion #70

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
WIP: Tauri app conversion
Iranon committed Jun 5, 2024
commit 1e2e84264e2cb3a2fa9c3ca8d55ebe46c7e2f36b
25 changes: 25 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
src-tauri/target
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
Empty file removed .nojekyll
Empty file.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Rom Patcher JS
A ROM patcher made in HTML5.
A ROM patcher made in HTML5 and built with [Tauri](https://tauri.app/).

**Features:**
* Supported formats:
@@ -26,3 +26,12 @@ A ROM patcher made in HTML5.
* [Radical Red](https://patch.radicalred.net/)
* [Rocket Edition](https://rocket-edition.com/download/)
* [SnapCameraPreservation](https://snapchatreverse.jaku.tv/snap/)


## For devs:

>*[Node.js](https://nodejs.org/) and [Rust](https://www.rust-lang.org/) required*

**Run `npm i` in order to install node modules**.

#### Run Vite dev server with `npm run dev` and build Tauri release with `npm run tauri build`.
94 changes: 0 additions & 94 deletions _cache_service_worker.js

This file was deleted.

573 changes: 335 additions & 238 deletions index.html

Large diffs are not rendered by default.

86 changes: 0 additions & 86 deletions js/worker_apply.js

This file was deleted.

23 changes: 0 additions & 23 deletions js/worker_crc.js

This file was deleted.

63 changes: 0 additions & 63 deletions js/worker_create.js

This file was deleted.

990 changes: 990 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "rompatcher",
"description": "A ROM patcher made in HTML5 built with tauri",
"private": true,
"version": "1.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview",
"tauri": "tauri"
},
"devDependencies": {
"@tauri-apps/cli": "^1.5.14",
"vite": "^5.2.0"
},
"author": {
"name": "Marc Robledo",
"url": "https://www.marcrobledo.com/"
},
"contributors": [
{
"name": "Iranon",
"url": "https://github.com/Iranon"
}
],
"license": "MIT",
"keywords": [
"ips",
"patcher",
"rom",
"romhacking",
"ups"
],
"homepage": "https://www.marcrobledo.com/RomPatcher.js/"
}
File renamed without changes.
146 changes: 19 additions & 127 deletions js/RomPatcher.js → public/scripts/RomPatcher.js
Original file line number Diff line number Diff line change
@@ -10,85 +10,8 @@ const HEADERS_INFO=[
];



/* service worker */
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 && 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 CAN_USE_WEB_WORKERS=true;
var webWorkerApply,webWorkerCreate,webWorkerCrc;
try{
webWorkerApply=new Worker('./js/worker_apply.js');
webWorkerApply.onmessage = event => { // listen for events from the worker
//retrieve arraybuffers back from webworker
if(!el('checkbox-removeheader').checked && !el('checkbox-addheader').checked){ //when adding/removing header we don't need the arraybuffer back since we made a copy previously
romFile._u8array=event.data.romFileU8Array;
romFile._dataView=new DataView(romFile._u8array.buffer);
}
patchFile._u8array=event.data.patchFileU8Array;
patchFile._dataView=new DataView(patchFile._u8array.buffer);

if(event.data.patchedRomU8Array)
preparePatchedRom(romFile, new MarcFile(event.data.patchedRomU8Array.buffer), headerSize);

setTabApplyEnabled(true);
if(event.data.errorMessage)
setMessage('apply', _(event.data.errorMessage.replace('Error: ','')), 'error');
else
setMessage('apply');
};
webWorkerApply.onerror = event => { // listen for events from the worker
setTabApplyEnabled(true);
setMessage('apply', _(event.message.replace('Error: ','')), 'error');
};



webWorkerCreate=new Worker('./js/worker_create.js');
webWorkerCreate.onmessage = event => { // listen for events from the worker
var newPatchFile=new MarcFile(event.data.patchFileU8Array);
newPatchFile.fileName=romFile2.fileName.replace(/\.[^\.]+$/,'')+'.'+el('select-patch-type').value;
newPatchFile.save();

setMessage('create');
setTabCreateEnabled(true);
};
webWorkerCreate.onerror = event => { // listen for events from the worker
setTabCreateEnabled(true);
setMessage('create', _(event.message.replace('Error: ','')), 'error');
};



webWorkerCrc=new Worker('./js/worker_crc.js');
webWorkerCrc.onmessage = event => { // listen for events from the worker
//console.log('received_crc');
el('crc32').innerHTML=padZeroes(event.data.crc32, 4);
el('md5').innerHTML=padZeroes(event.data.md5, 16);
romFile._u8array=event.data.u8array;
romFile._dataView=new DataView(event.data.u8array.buffer);

if(window.crypto&&window.crypto.subtle&&window.crypto.subtle.digest){
sha1(romFile);
}

validateSource();
setTabApplyEnabled(true);
};
webWorkerCrc.onerror = event => { // listen for events from the worker
setMessage('apply', event.message.replace('Error: ',''), 'error');
};
}catch(e){
CAN_USE_WEB_WORKERS=false;
}


/* Shortcuts */
function addEvent(e,ev,f){e.addEventListener(ev,f,false)}
@@ -286,16 +209,11 @@ var AppSettings={
/* initialize app */
addEvent(window,'load',function(){
/* zip-js web worker */
if(CAN_USE_WEB_WORKERS){
zip.useWebWorkers=true;
zip.workerScriptsPath='./js/zip.js/';
}else{
zip.useWebWorkers=false;
zip.useWebWorkers=false;

var script=document.createElement('script');
script.src='./js/zip.js/inflate.js';
document.getElementsByTagName('head')[0].appendChild(script);
}
var script=document.createElement('script');
script.src='scripts/zip.js/inflate.js';
document.getElementsByTagName('head')[0].appendChild(script);

/* load settings */
AppSettings.load();
@@ -532,26 +450,17 @@ function updateChecksums(file, startOffset, force){
el('crc32').innerHTML='Calculating...';
el('md5').innerHTML='Calculating...';

if(CAN_USE_WEB_WORKERS){
setTabApplyEnabled(false);
webWorkerCrc.postMessage({u8array:file._u8array, startOffset:startOffset}, [file._u8array.buffer]);

if(window.crypto&&window.crypto.subtle&&window.crypto.subtle.digest){
el('sha1').innerHTML='Calculating...';
}
}else{
window.setTimeout(function(){
el('crc32').innerHTML=padZeroes(crc32(file, startOffset), 4);
el('md5').innerHTML=padZeroes(md5(file, startOffset), 16);
window.setTimeout(function(){
el('crc32').innerHTML=padZeroes(crc32(file, startOffset), 4);
el('md5').innerHTML=padZeroes(md5(file, startOffset), 16);

validateSource();
setTabApplyEnabled(true);
}, 30);
validateSource();
setTabApplyEnabled(true);
}, 30);

if(window.crypto&&window.crypto.subtle&&window.crypto.subtle.digest){
el('sha1').innerHTML='Calculating...';
sha1(file);
}
if(window.crypto&&window.crypto.subtle&&window.crypto.subtle.digest){
el('sha1').innerHTML='Calculating...';
sha1(file);
}
}

@@ -765,31 +674,14 @@ function applyPatch(p,r,validateChecksums){
}
}

if(CAN_USE_WEB_WORKERS){
setMessage('apply', 'applying_patch', 'loading');
setTabApplyEnabled(false);

webWorkerApply.postMessage(
{
romFileU8Array:r._u8array,
patchFileU8Array:patchFile._u8array,
validateChecksums:validateChecksums
},[
r._u8array.buffer,
patchFile._u8array.buffer
]
);
setMessage('apply', 'applying_patch', 'loading');

}else{
setMessage('apply', 'applying_patch', 'loading');

try{
p.apply(r, validateChecksums);
preparePatchedRom(r, p.apply(r, validateChecksums), headerSize);
try{
p.apply(r, validateChecksums);
preparePatchedRom(r, p.apply(r, validateChecksums), headerSize);

}catch(e){
setMessage('apply', 'Error: '+_(e.message), 'error');
}
}catch(e){
setMessage('apply', 'Error: '+_(e.message), 'error');
}

}else{
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions src-tauri/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Generated by Cargo
# will have compiled files and executables
/target/
3,676 changes: 3,676 additions & 0 deletions src-tauri/Cargo.lock

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[package]
name = "app"
version = "0.1.0"
description = "A Tauri App"
authors = ["you"]
license = ""
repository = ""
default-run = "app"
edition = "2021"
rust-version = "1.60"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[build-dependencies]
tauri-build = { version = "1.5.2", features = [] }

[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.6.5", features = [] }

[features]
# this feature is used for production builds or when `devPath` points to the filesystem and the built-in dev server is disabled.
# If you use cargo directly instead of tauri's cli you can use this feature flag to switch between tauri's `dev` and `build` modes.
# DO NOT REMOVE!!
custom-protocol = [ "tauri/custom-protocol" ]
3 changes: 3 additions & 0 deletions src-tauri/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
tauri_build::build()
}
Binary file added src-tauri/icons/128x128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src-tauri/icons/128x128@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src-tauri/icons/32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src-tauri/icons/Square107x107Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src-tauri/icons/Square142x142Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src-tauri/icons/Square150x150Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src-tauri/icons/Square284x284Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src-tauri/icons/Square30x30Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src-tauri/icons/Square310x310Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src-tauri/icons/Square44x44Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src-tauri/icons/Square71x71Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src-tauri/icons/Square89x89Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src-tauri/icons/StoreLogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src-tauri/icons/icon.icns
Binary file not shown.
Binary file added src-tauri/icons/icon.ico
Binary file not shown.
Binary file added src-tauri/icons/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

fn main() {
tauri::Builder::default()
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
66 changes: 66 additions & 0 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"$schema": "../node_modules/@tauri-apps/cli/schema.json",
"build": {
"beforeBuildCommand": "npm run build",
"beforeDevCommand": "npm run dev",
"devPath": "http://localhost:5555",
"distDir": "../dist"
},
"package": {
"productName": "rompatcher",
"version": "1.0.0"
},
"tauri": {
"allowlist": {
"all": false
},
"bundle": {
"active": true,
"category": "DeveloperTool",
"copyright": "",
"deb": {
"depends": []
},
"externalBin": [],
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico"
],
"identifier": "com.tauri.rompatcher",
"longDescription": "",
"macOS": {
"entitlements": null,
"exceptionDomain": "",
"frameworks": [],
"providerShortName": null,
"signingIdentity": null
},
"resources": [],
"shortDescription": "",
"targets": "all",
"windows": {
"certificateThumbprint": null,
"digestAlgorithm": "sha256",
"timestampUrl": ""
}
},
"security": {
"csp": null
},
"updater": {
"active": false
},
"windows": [
{
"fullscreen": false,
"height": 600,
"resizable": true,
"title": "RomPatcher",
"width": 800
}
]
}
}
27 changes: 27 additions & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export default {
// prevent vite from obscuring rust errors
clearScreen: false,
// Tauri expects a fixed port, fail if that port is not available
server: {
port: 5555,
strictPort: true,
},
// to access the Tauri environment variables set by the CLI with information about the current target
envPrefix: [
"VITE_",
"TAURI_PLATFORM",
"TAURI_ARCH",
"TAURI_FAMILY",
"TAURI_PLATFORM_VERSION",
"TAURI_PLATFORM_TYPE",
"TAURI_DEBUG",
],
build: {
// Tauri uses Chromium on Windows and WebKit on macOS and Linux
target: process.env.TAURI_PLATFORM == "windows" ? "chrome105" : "safari13",
// don't minify for debug builds
minify: !process.env.TAURI_DEBUG ? "esbuild" : false,
// produce sourcemaps for debug builds
sourcemap: !!process.env.TAURI_DEBUG,
},
};