Skip to content

Commit

Permalink
patcher can now use online patches, improved running as node applicat…
Browse files Browse the repository at this point in the history
…ion or cli tool

Possible release candidate
  • Loading branch information
Matthbo committed Jan 16, 2021
1 parent 8569366 commit 65d07ab
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 24 deletions.
3 changes: 3 additions & 0 deletions app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { main } from "./lib/index";

main();
24 changes: 15 additions & 9 deletions lib/go.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,24 @@ export class GO {
async patch(online: boolean){
console.log(chalk.blueBright("Patching files"));

if(online){
// TODO download patches from github
}
let mappings: { [index: string]: string };

const mappings = JSON.parse(await fsPromises.readFile(this.patcherLocation + '/mapping.json', "utf8")),
patchesLocation = path.normalize(this.patcherLocation + "/patches/");
if(online){
const basePatcherUrl = "https://raw.githubusercontent.com/Matthbo/GrandeOmega-patcher/master/patcher";
mappings = await (await fetch(basePatcherUrl + "/mapping.json")).json();

for (const patchFileLocation in mappings){
const sourceFileLocation = mappings[patchFileLocation],
patchFile = await fsPromises.readFile(patchesLocation + patchFileLocation);
for(const [fileName, sourceFileLocation] of Object.entries(mappings)){
const patchFile = await (await fetch(`${basePatcherUrl}/patches/${fileName}`)).buffer();
await fsPromises.writeFile(this.baseLocation + `/${sourceFileLocation}`, patchFile);
}
} else {
const patchesLocation = path.normalize(this.patcherLocation + "/patches/");
mappings = JSON.parse(await fsPromises.readFile(this.patcherLocation + '/mapping.json', "utf8"));

await fsPromises.writeFile(this.baseLocation + `/${sourceFileLocation}`, patchFile);
for(const [fileName, sourceFileLocation] of Object.entries(mappings)){
const patchFile = await fsPromises.readFile(patchesLocation + fileName);
await fsPromises.writeFile(this.baseLocation + `/${sourceFileLocation}`, patchFile);
}
}
}
}
14 changes: 5 additions & 9 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import chalk from "chalk";
import { promises as fsPromises } from "fs";
import path from "path";
import { promisify } from "util";
import rimraf from "rimraf";
import { Downloader } from "./downloader";
import { GO } from "./go";

async function main() {
export async function main() {
try {
const dl = new Downloader(__dirname + "/../tmp", __dirname + "/../GO"),
go = new GO(__dirname + "/../GO", __dirname + "/../patcher");
Expand Down Expand Up @@ -44,24 +46,18 @@ export async function remoteMain(goDir: string){
await go.patch(true);
await go.installDependencies();

console.log(chalk.blueBright("Cleaning up"));
await cleanUp(goDir + "/tmp");

console.log(chalk.blueBright("Finished"));
} catch(error) {
console.error(chalk.redBright(`Failed to patch Grande Omega!\n${error.stack}`));
await cleanUp(goDir + "/tmp");
}
}

async function cleanUp(outDir: string){
outDir = path.normalize(outDir);

try{
await fsPromises.unlink(outDir + "/go.zip").catch(error => { if(error.code !== "ENOENT") throw error });
await promisify(rimraf)(outDir).catch(error => { if(error.code !== "ENOENT") throw error });
} catch(error){
console.error(chalk.redBright(`Failed to clean up!\n${error.stack}`));
}
}

main();
}
111 changes: 111 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 13 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
{
"name": "grandeomega-patcher",
"version": "0.0.2",
"version": "1.0.0",
"description": "A dependency patcher for Grande Omega",
"main": "index.js",
"types": "index.d.ts",
"bin": {
"go-patcher": "bin/cli.js",
"gopatcher": "bin/cli.js"
},
"files": [
"bin",
"lib",
"index.*"
],
"private": true,
"scripts": {
"build": "tsc",
"clean": "tsc -b --clean",
"start": "ts-node lib/index",
"start": "ts-node app.ts",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Matthbo",
Expand All @@ -17,12 +26,14 @@
"adm-zip": "^0.4.16",
"chalk": "^4.1.0",
"node-fetch": "^2.6.1",
"rimraf": "^3.0.2",
"typescript": "^4.1.3"
},
"devDependencies": {
"@types/adm-zip": "^0.4.33",
"@types/node": "^14.14.20",
"@types/node-fetch": "^2.5.7",
"@types/rimraf": "^3.0.0",
"ts-node": "^9.1.1"
}
}
15 changes: 11 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@ A dependency patcher for Grande Omega.
The objective of this tool is to patch Grande Omega's dependencies, removing unnecessary dependencies, updating dependencies and most importantly: Fix electron for Linux users.

Planned abilities:
- [ ] Runnable by a cli
- [ ] Run patcher on an existing GO location
- [x] Runnable as a cli tool on an existing GO location
- [ ] Call as a dependency (to be test)

## How to use
## Install as cli tool
1. Make sure you have [Node.js v10+](https://nodejs.org/)
2. Install using `npm i -g grandeomega-patcher`
3. Open a CMD/Powershell/Terminal window
4. Go to a folder containing Grande Omega
5. Run using `go-patcher` or `gopatcher`

## Install as Node.js application
1. Make sure you have [Node.js v10+](https://nodejs.org/)
2. Download / clone this repo
3. Install dependencies using `npm install` (or `npm i` for short)
Expand All @@ -17,7 +24,7 @@ Planned abilities:
## What it does
1. Checks Grande Omega version (if available)

On older version:
On older version (as Node.js application):
1. Downloads the newest Grande Omega zip file
2. Extracts it to the `GO/` folder
2. Patches Grande Omega files
Expand Down

0 comments on commit 65d07ab

Please sign in to comment.