-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
174 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ out | |
.DS_Store | ||
*.log* | ||
pnpm-lock.yaml | ||
package-lock.json | ||
package-lock.json | ||
data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export function descompress(args: any) { | ||
console.log(args); | ||
import { APPDIR } from "../.."; | ||
|
||
export async function descompress(_: any) { | ||
return APPDIR; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import fs from 'node:fs'; | ||
import path from 'node:path'; | ||
import { APPDIR } from '../../..'; | ||
|
||
export async function findFile(filename: string, extensions: string[], rootPath: string | undefined = undefined): Promise<string | undefined> { | ||
rootPath = rootPath ?? APPDIR; | ||
|
||
let files = fs.readdirSync(rootPath); | ||
|
||
for (const file of files) { | ||
if (file === 'app.asar') continue; | ||
let filepath = path.join(rootPath, file); | ||
let fileStat = fs.statSync(filepath); | ||
if (fileStat.isDirectory()) { | ||
let found = findFile(filename, extensions, filepath); | ||
if (found) return found; | ||
} | ||
|
||
if (fileStat.isFile()) { | ||
if (file === filename) return filepath; | ||
let found = extensions.find((ext) => { | ||
if (ext.startsWith('.')) ext = ext.substring(1); | ||
return file === `${filename}.${ext}`; | ||
}); | ||
if (found) return filepath; | ||
} | ||
} | ||
|
||
return undefined; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import fs from 'node:fs'; | ||
|
||
export async function createAppDir(dir: string, _: Electron.App) { | ||
try { | ||
if (!fs.existsSync(dir)) { | ||
fs.mkdirSync(dir, { recursive: true }); | ||
} | ||
} catch (e: any) { | ||
console.error(e.message); | ||
//app.exit(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import decompress from 'decompress' | ||
import { decompressedFile } from '../../interaces/decompressedFile' | ||
import fs from 'node:fs' | ||
import path from 'node:path' | ||
|
||
export async function decompressZip(zipFile: string, output: string) { | ||
try { | ||
let files: decompressedFile[] = await decompress(zipFile); | ||
files.forEach(async (file: decompressedFile) => { | ||
let outputPath = path.join(output, file.path); | ||
|
||
if (file.type === 'directory') { | ||
fs.mkdirSync(outputPath, { recursive: true }); | ||
fs.chmodSync(outputPath, file.mode); | ||
} | ||
|
||
let parentDir = path.dirname(outputPath); | ||
if (!fs.existsSync(parentDir)) fs.mkdirSync(parentDir); | ||
|
||
if (file.type === 'file') { | ||
await fs.writeFileSync(outputPath, file.data); | ||
await fs.chmodSync(outputPath, file.mode); | ||
await fs.utimesSync(outputPath, new Date(), file.mtime); | ||
} | ||
}); | ||
return true; | ||
} catch (e) { | ||
console.error(e); | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import path from "node:path"; | ||
import { CONFIGDIR, DATADIR, MODSDIR, MODSDIRWRAPPER, ZIPPATH } from "../.."; | ||
import fs from 'node:fs'; | ||
import { decompressZip } from "../modules/zip"; | ||
import { createAppDir } from "../modules/fs/mkdir"; | ||
|
||
export async function setupProject(app: Electron.App) { | ||
[CONFIGDIR, MODSDIRWRAPPER, DATADIR].forEach(async (dir) => { | ||
await createAppDir(dir, app); | ||
}); | ||
|
||
if (!fs.existsSync(path.join(MODSDIR, 'loader.exe'))) { | ||
let zipPath = await ZIPPATH(); | ||
if (zipPath) { | ||
await decompressZip(zipPath, MODSDIR); | ||
} else { | ||
alert(`Error decompressing Loader`); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
import { ipcMain } from "electron"; | ||
import { descompress } from "../app/mods/descompress"; | ||
import { APPDIR } from ".."; | ||
|
||
/** | ||
* Event Handler (IPC events emitted by front) | ||
* @param app Electron's Application | ||
*/ | ||
export default function handleEvent() { | ||
|
||
ipcMain.handle('hello', async (_, __) => { | ||
console.log('Hello from back'); | ||
return __dirname; | ||
return APPDIR; | ||
}); | ||
|
||
ipcMain.handle('descompress', async (_, args) => { | ||
descompress(args); | ||
return (await descompress(args)); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export interface decompressedFile { | ||
mode: number; | ||
mtime: Date; | ||
path: string; | ||
type: 'file' | 'directory'; | ||
data: Buffer; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,16 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<title>Tao Mod Manager</title> | ||
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP --> | ||
<meta | ||
http-equiv="Content-Security-Policy" | ||
content="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:" | ||
/> | ||
</head> | ||
|
||
<body class="bg-dark"> | ||
<div id="app"></div> | ||
<script type="module" src="./src/main.ts"></script> | ||
</body> | ||
</html> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<title>Tao Mod Manager</title> | ||
<meta http-equiv="Content-Security-Policy" | ||
content="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:" /> | ||
</head> | ||
|
||
<body class="bg-dark"> | ||
<div id="app"></div> | ||
<script type="module" src="./src/main.ts"></script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters