Skip to content

Commit

Permalink
fixed failed installs on linux/mac, added launcher profile guard
Browse files Browse the repository at this point in the history
- 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)
  • Loading branch information
jgaribsin committed Jan 20, 2024
1 parent 69ce125 commit fd6cfda
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
17 changes: 17 additions & 0 deletions src-electron/ipcListeners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -87,6 +88,22 @@ ipcMain.handle('minecraftNotWin', () => {
spawn('minecraft-launcher');
});

/*
Linux: /home/<USER>/.minecraft
Mac: /Library/Application Support/minecraft
Windows: C:\Users\<USER>\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 () =>
Expand Down
7 changes: 2 additions & 5 deletions src/pages/InstallComplete.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
45 changes: 44 additions & 1 deletion src/pages/InstallPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,57 @@
</template>

<script setup lang="ts">
import SingleplayerInstall from 'src/components/SingleplayerInstall.vue';
import MultiplayerInstall from 'src/components/MultiplayerInstall.vue';
import ServerInstall from 'src/components/ServerInstall.vue';
import SingleplayerInstall from 'src/components/SingleplayerInstall.vue';
import { storeToRefs } from 'pinia';
import { useQuasar } from 'quasar';
import { useInstallerStore } from 'src/stores/InstallerStore';
import { useStateStore } from 'src/stores/StateStore';
import { onMounted } from 'vue';
import { useRouter } from 'vue-router';
const fs = require('fs');
const path = require('path');
const { installType } = storeToRefs(useStateStore());
console.log(`Using install type: ${installType.value}`);
const { minecraftDir } = storeToRefs(useInstallerStore());
const router = useRouter();
const q = useQuasar();
const launcherProfilesPath = path.join(
minecraftDir.value,
'launcher_profiles.json'
);
async function validateLauncher() {
console.log(`Checking launcher profile file: ${launcherProfilesPath}`);
if (!fs.existsSync(launcherProfilesPath))
await new Promise<void>((resolve) => {
console.log('Launcher profile file not found...');
q.dialog({
title: 'Profile file not found',
html: true,
message:
'Minecraft Launcher profile file not found. ' +
"Please ensure you've run Minecraft at least once or select an appropriate installation folder!<br/><br/>" +
'Use the button below to go back and either launch then close Minecraft, or select a different installation folder.',
ok: 'Go Back',
persistent: true,
dark: true,
}).onOk(() => {
// resolve promise, then return to previous page
resolve();
router.back();
});
});
else console.log('Launcher profile file found!');
}
// Only validate launcher profile file if installing singleplayer or multiplayer
if (installType.value === 'singleplayer' || installType.value === 'multiplayer')
onMounted(validateLauncher);
</script>
<style scoped lang="sass"></style>
6 changes: 5 additions & 1 deletion src/pages/WelcomePage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down
5 changes: 5 additions & 0 deletions src/providers/DownloadResourcePack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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(() => {
Expand Down

0 comments on commit fd6cfda

Please sign in to comment.