From fd6cfdad6b7db8fea6d58123cc83072c3629bf6e Mon Sep 17 00:00:00 2001 From: jgaribsin Date: Sat, 20 Jan 2024 11:35:28 -0700 Subject: [PATCH] fixed failed installs on linux/mac, added launcher profile guard - corrected default install path on linux/mac - now checks for the existence of `launcher_profiles.json` on the install page, prompting user if not found - creates resource pack directory if it does not exist (same behaviour as mods, saves) --- package.json | 2 +- src-electron/ipcListeners.ts | 17 ++++++++++ src/pages/InstallComplete.vue | 7 ++--- src/pages/InstallPage.vue | 45 ++++++++++++++++++++++++++- src/pages/WelcomePage.vue | 6 +++- src/providers/DownloadResourcePack.ts | 5 +++ 6 files changed, 74 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 9eae2d9..2f9fff5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "drehmal-installer", - "version": "0.1.0", + "version": "0.1.1", "description": "Drehmal, Minecraft map installer", "productName": "Drehmal Installer", "author": "jgaribsin", diff --git a/src-electron/ipcListeners.ts b/src-electron/ipcListeners.ts index 909faf3..a4af6d0 100644 --- a/src-electron/ipcListeners.ts +++ b/src-electron/ipcListeners.ts @@ -8,6 +8,7 @@ import { } from 'electron'; const { spawn } = require('child_process'); const os = require('os'); +const path = require('path'); let browserWindow: BrowserWindow; let app: typeof ElectronApp; @@ -87,6 +88,22 @@ ipcMain.handle('minecraftNotWin', () => { spawn('minecraft-launcher'); }); +/* +Linux: /home//.minecraft +Mac: /Library/Application Support/minecraft +Windows: C:\Users\\AppData\Roaming\.minecraft +*/ +ipcMain.handle('getMinecraftPath', () => { + switch (process.platform) { + case 'win32': + return path.join(app.getPath('appData'), '.minecraft'); + case 'darwin': + return path.join('/', 'Library', 'Application Support', 'minecraft'); + case 'linux': + return path.join(os.homedir(), '.minecraft'); + } +}); + ipcMain.handle( 'openFileDialog', async () => diff --git a/src/pages/InstallComplete.vue b/src/pages/InstallComplete.vue index 6b4c551..41dce3a 100644 --- a/src/pages/InstallComplete.vue +++ b/src/pages/InstallComplete.vue @@ -73,11 +73,8 @@ if (installType.value === 'server') { ipcRenderer.invoke('getPlatform').then((result: NodeJS.Platform) => { platform.value = result; - if (platform.value === 'win32') { - executable.value = 'server.bat'; - additionalText.value = - 'You may need to make it executable first. To do that, run "chmod +x server.sh" in the terminal.'; - } else { + if (platform.value === 'win32') executable.value = 'server.bat'; + else { executable.value = 'server.sh'; executableCmd.value = `chmod +x ${path.join( serverDir.value, diff --git a/src/pages/InstallPage.vue b/src/pages/InstallPage.vue index 201e604..de1ef39 100644 --- a/src/pages/InstallPage.vue +++ b/src/pages/InstallPage.vue @@ -13,14 +13,57 @@ diff --git a/src/pages/WelcomePage.vue b/src/pages/WelcomePage.vue index c44fe65..0ca90ac 100644 --- a/src/pages/WelcomePage.vue +++ b/src/pages/WelcomePage.vue @@ -22,11 +22,15 @@ useInstallerStore(); const { homeDir, appDir, minecraftDir, serverDir, shardsDir, memory } = storeToRefs(useInstallerStore()); +ipcRenderer.invoke('getMinecraftPath').then((minecraft) => { + console.log(`Got Minecraft path: ${minecraft}`); + minecraftDir.value = minecraft; +}); + ipcRenderer.invoke('getAppDataPath').then((appData) => { console.log(`Got AppData path: ${appData}`); homeDir.value = appData; appDir.value = path.join(appData, 'Drehmal Installer'); - minecraftDir.value = path.join(appData, '.minecraft'); shardsDir.value = path.join(appDir.value, 'shards'); memory.value = 4; }); diff --git a/src/providers/DownloadResourcePack.ts b/src/providers/DownloadResourcePack.ts index e8eb078..f0088f3 100644 --- a/src/providers/DownloadResourcePack.ts +++ b/src/providers/DownloadResourcePack.ts @@ -6,6 +6,7 @@ import { Ref } from 'vue'; import { downloadFile } from './DownloadFile'; import { updateMinecraftOpts } from './UpdateMinecraftOpts'; const path = require('path'); +const fs = require('fs'); export async function downloadResourcePack(ref: Ref) { const { resourcePack } = storeToRefs(useSourcesStore()); @@ -15,6 +16,10 @@ export async function downloadResourcePack(ref: Ref) { // NOTE: if changing this, edit the value in src/providers/UpdateMinecraftOpts.ts const rpName = `Drehmal Resource Pack v${resourcePack.value.version}.zip`; + // ensure the resourcepacks folder exists first (should be caught by the profile file validation, but just in case) + const rpFolder = path.join(minecraftDir.value, 'resourcepacks'); + if (!fs.existsSync(rpFolder)) fs.mkdirSync(rpFolder); + const filePath = path.join(minecraftDir.value, 'resourcepacks', rpName); console.log(`Downloading resource pack to: ${filePath}`); downloadFile(resourcePack.value.source, filePath, ref).then(() => {