Skip to content

Commit

Permalink
#skip-ci v0.0.7 beta candidate
Browse files Browse the repository at this point in the history
- installer now also updates clouds, render distance, chat height and volumes
- added dedicated `options.txt` parser
- added legacy minecraft installation path
- logs now include installer version
- split files in `src/providers/` into dedicated files for each function
  • Loading branch information
jgaribsin committed Jan 10, 2024
1 parent 80a0802 commit 01b78be
Show file tree
Hide file tree
Showing 13 changed files with 146 additions and 119 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.0.6",
"version": "0.0.7",
"description": "Drehmal, Minecraft map installer",
"productName": "Drehmal Installer",
"author": "majorlue",
Expand Down
5 changes: 4 additions & 1 deletion src-electron/electron-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const path = require('path');
const os = require('os');
const fs = require('fs');

import { version } from '../package.json';

// Optional, initialize the logger for any renderer process
log.initialize({ spyRendererConsole: true });
const currDate = dayjs().format('DD-MM-YYYY');
Expand Down Expand Up @@ -34,7 +36,7 @@ log.transports.file.format = '[{h}:{i}:{s}.{ms}] [{level}] {text}';
log.errorHandler.startCatching();
log.eventLogger.startLogging();

log.info('Logger initialised');
log.info(`Installer v${version}: Logger initialised`);

let mainWindow: BrowserWindow | undefined;

Expand All @@ -46,6 +48,7 @@ function createWindow() {
icon: path.resolve(__dirname, 'icons/icon.png'), // tray icon
width: 1000,
height: 600,
resizable: false,
useContentSize: true,
webPreferences: {
nodeIntegration: true,
Expand Down
3 changes: 3 additions & 0 deletions src/components/CloseInstaller.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ const launchButton = ref(false);
const platform: Ref<NodeJS.Platform | undefined> = ref();
const windowsLocations: string[] = [
// Microsoft Store install location
'C:\\XboxGames\\Minecraft Launcher\\Content\\Minecraft.exe',
// Legacy install location
'C:\\Program Files (x86)\\Minecraft',
];
let windowsPath = '';
Expand Down
8 changes: 3 additions & 5 deletions src/components/MultiplayerInstall.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@
import { storeToRefs } from 'pinia';
import ProgressBox from 'src/components/ProgressBox.vue';
import { ProgressBox as ProgressBoxType, Shard } from 'src/components/models';
import {
downloadMods,
downloadResourcePack,
installFabric,
} from 'src/providers/InstallFabric';
import { downloadMods } from 'src/providers/DownloadMods';
import { downloadResourcePack } from 'src/providers/DownloadResourcePack';
import { installFabric } from 'src/providers/InstallFabric';
import { useSourcesStore } from 'src/stores/SourcesStore';
import { useStateStore } from 'src/stores/StateStore';
import { ref } from 'vue';
Expand Down
8 changes: 3 additions & 5 deletions src/components/SingleplayerInstall.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,10 @@ import {
Shard,
ShardsBox,
} from 'src/components/models';
import { downloadMods } from 'src/providers/DownloadMods';
import { downloadResourcePack } from 'src/providers/DownloadResourcePack';
import { downloadShards } from 'src/providers/DownloadShards';
import {
downloadMods,
downloadResourcePack,
installFabric,
} from 'src/providers/InstallFabric';
import { installFabric } from 'src/providers/InstallFabric';
import { useInstallerStore } from 'src/stores/InstallerStore';
import { useSourcesStore } from 'src/stores/SourcesStore';
import { useStateStore } from 'src/stores/StateStore';
Expand Down
2 changes: 1 addition & 1 deletion src/components/SocialsGrid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const socials: Ref<Socials[]> = ref([
img: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAeCAYAAABuUU38AAAACXBIWXMAAAsTAAALEwEAmpwYAAACIUlEQVRYhe2YwW7aQBCGvzGWmuYApqghrxCllKrHphJS+gBIPRDlVfoAeZXIHCp4gCKQmh6rpnmJUInY4ZDkkLA9IFs23kC8No2R+p2s3Vl7fs94Zr3Sc4e0Oy363ZFiA2l3WtLvjhClFP3uSIkITvXlc/uVCt+7RSlFu9MS6blDBWBZQsXZLCHX/i2z2TyRbIDqq+1wslYrP49XKZlMpuGL965u5kICAhFbZTu5skDcTe+p1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7y8VgrlIdUeTPGCm0Rhx+A5CoA5I6co+b67cuHHsK9IsoqlJGFBer0q4lzUxeRCYLZkKQykjyW7iKyDTSYrbiuh4HCcLjoMP+BCA434oHVB2hGwimlo5zlLIhsdgJAMcd1ggCgG++oJDts2wnOwAAAABJRU5ErkJggg==',
url: 'https://discord.com/invite/n6VVwDFp?utm_source=Discord%20Widget&utm_medium=Connect',
url: 'https://discord.gg/xFsRQsDnuj',
},
{
name: 'website',
Expand Down
8 changes: 5 additions & 3 deletions src/providers/DownloadFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ const fs = require('fs');
import { Ref } from 'vue';
const path = require('path');

function downloadFile(url: string, savePath: string, ref?: Ref): Promise<void> {
export function downloadFile(
url: string,
savePath: string,
ref?: Ref
): Promise<void> {
return new Promise((resolve, reject) => {
const name = savePath.split(path.sep).pop();
const file = fs.createWriteStream(savePath);
Expand Down Expand Up @@ -71,5 +75,3 @@ function downloadFile(url: string, savePath: string, ref?: Ref): Promise<void> {
});
});
}

export { downloadFile };
51 changes: 51 additions & 0 deletions src/providers/DownloadMods.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { storeToRefs } from 'pinia';
import { useInstallerStore } from 'src/stores/InstallerStore';
import { useSourcesStore } from 'src/stores/SourcesStore';
import { useStateStore } from 'src/stores/StateStore';
import { Ref } from 'vue';
import { downloadFile } from './DownloadFile';
const fs = require('fs');
const path = require('path');

export async function downloadMods(ref: Ref) {
const startTime = Date.now();

const { launcher } = storeToRefs(useSourcesStore());
const { minecraftDir } = storeToRefs(useInstallerStore());
const { processingMods } = storeToRefs(useStateStore());

const modList = launcher.value.modList;
const modLoader = launcher.value.fabric.name;
const totalMods = modList.length;
let downloaded = 0;

const modsPath = path.join(minecraftDir.value, 'mods');
if (!fs.existsSync(modsPath)) fs.mkdirSync(modsPath, { recursive: true });

async function processArray(mods: typeof modList): Promise<void> {
for (const mod of mods) {
const { name, mod_version, mc_version, source } = mod;
const modName =
name + ' - ' + modLoader + mod_version + '-' + mc_version + '.jar';
console.log(`Downloading ${modName} to ${modsPath}`);
const modPath = path.join(modsPath, modName);
await downloadFile(source, modPath);
downloaded++;
const progress = downloaded / totalMods;
const percent = (progress * 100).toFixed(1);

ref.value.progress = progress;
ref.value.percent = percent;
// Note: Roughly 21 character limit, consider truncating mod name
ref.value.label = `Downloading: ${name}`;

const taken = Date.now() - startTime;
console.log(`downloaded mod ${downloaded}/${totalMods} in ${taken}ms`);
}
}
await processArray(modList);
ref.value.label = 'Mods successfully downloaded!';
ref.value.img =
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAeCAYAAABuUU38AAAACXBIWXMAAAsTAAALEwEAmpwYAAACqElEQVRYhdVYzY7SUBT+Tu1CTWRaG4UncKMOxOWMhhg37khYwBgT43P4ADyIiSawMLBzA0LUWRLGv4VPwMwECjVhiJYeF6W1pTBD7+2Mw7e67b0993733HvOd0r1ahuFUh6NWoexgSiU8tSodUDMjEatw0QETb/2v9cVCyPzBMyMQilPVK+2GQAUhbClbRaR8egEjuMeJBUA9JvX/U7DSElP8OJp59T+1+/z0nMMBpa/8eZw4hLx4JG4mlKjX8ZALqOv7Ov1TWn7U8uGYaQwGFj+u4hFkUnKO02/zQBq+09OHb+324LDDFpz/LI1Ti079E4FxbKxFPfSGq6Qa+jn8NeZ47fTmt/u9U35BRCgkgST8m4TzPF39NW7B6HnZw9bmDkc244HAqC4zhVDNq1DIXmX3r+tQVXk7Ciyi0jgZCYCKSIOMxTJnfRAkp4VioOVYhffjsZ4++mx0KSlQJQjANX53agUu+j1TaG7IhzQbccR/TSUZw4OE4haIHEiIijvtsDMyGV0KY9GwRdLJBvIHw4nK7YTIbI332lvaYtnPOiJ78djvPmYlCf+IREiwUz95XAU6c+mNZ/kzDmfsicRIl6mrhS72E5roagEuES/Ho1Q/SyWudeBMBFVWZ2CglGJ4YZYGSm0DqhebbNXjxhGKpb6fZnvYPLHjtyJSrHrtw/6pp8nVqG00wQRYnlsatm+jDeHE7nMfse4kYjWymV0Xz2L4lzC76K6vQjIi8ZLohqlPOLtvFeXeDhLKy1GNdE6JIhEjlY2HdBOa1R8yWutJUSmlh27bl+8E88ffcDM4YgMUYjgsHglGFzjIkIrHgwsGEZq6cA4uHtra+n737MZfhxb0vYBhP6gAPM84j0E/29tAszhxG8ruDzVqgzIO1oEgIMMNwgEAH8Bhif2yStQayoAAAAOZVhJZk1NACoAAAAIAAAAAAAAANJTkwAAAABJRU5ErkJggg==';
processingMods.value = false;
}
33 changes: 33 additions & 0 deletions src/providers/DownloadResourcePack.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { storeToRefs } from 'pinia';
import { useInstallerStore } from 'src/stores/InstallerStore';
import { useSourcesStore } from 'src/stores/SourcesStore';
import { useStateStore } from 'src/stores/StateStore';
import { Ref } from 'vue';
import { downloadFile } from './DownloadFile';
import { updateMinecraftOpts } from './UpdateMinecraftOpts';
const path = require('path');

export async function downloadResourcePack(ref: Ref) {
const { resourcePack } = storeToRefs(useSourcesStore());
const { minecraftDir } = storeToRefs(useInstallerStore());
const { processingResourcepack } = storeToRefs(useStateStore());
ref.value.label = 'Downloading resource pack';

// NOTE: if changing this, edit the value in src/providers/UpdateMinecraftOpts.ts
const rpName = `Drehmal Resource Pack v${resourcePack.value.version}.zip`;
const filePath = path.join(minecraftDir.value, 'resourcepacks', rpName);
console.log(`Downloading resource pack to: ${filePath}`);
downloadFile(resourcePack.value.source, filePath, ref).then(() => {
ref.value.label = 'Updating video settings';

const optionsFilePath = path.join(minecraftDir.value, 'options.txt');

console.log(`Updating Minecraft options in file: ${optionsFilePath}`);
updateMinecraftOpts(optionsFilePath);

ref.value.label = 'Resource pack downloaded!';

console.log('Updated Resource Pack order and video settings');
processingResourcepack.value = false;
});
}
4 changes: 1 addition & 3 deletions src/providers/DownloadShards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ShardsBox } from 'src/components/models';
import { Ref } from 'vue';
const path = require('path');

function downloadShards(
export function downloadShards(
url: string,
savePath: string,
ref: Ref<ShardsBox>
Expand Down Expand Up @@ -74,5 +74,3 @@ function downloadShards(
});
});
}

export { downloadShards };
28 changes: 0 additions & 28 deletions src/providers/ExtractFile.ts

This file was deleted.

72 changes: 0 additions & 72 deletions src/providers/InstallFabric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,75 +92,3 @@ export async function installFabric(ref: Ref) {
});
});
}
export async function downloadMods(ref: Ref) {
const startTime = Date.now();

const { launcher } = storeToRefs(useSourcesStore());
const { minecraftDir } = storeToRefs(useInstallerStore());
const { processingMods } = storeToRefs(useStateStore());

const modList = launcher.value.modList;
const modLoader = launcher.value.fabric.name;
const totalMods = modList.length;
let downloaded = 0;

const modsPath = path.join(minecraftDir.value, 'mods');
if (!fs.existsSync(modsPath)) fs.mkdirSync(modsPath, { recursive: true });

async function processArray(mods: typeof modList): Promise<void> {
for (const mod of mods) {
const { name, mod_version, mc_version, source } = mod;
const modName =
name + ' - ' + modLoader + mod_version + '-' + mc_version + '.jar';
console.log(`Downloading ${modName} to ${modsPath}`);
const modPath = path.join(modsPath, modName);
await downloadFile(source, modPath);
downloaded++;
const progress = downloaded / totalMods;
const percent = (progress * 100).toFixed(1);

ref.value.progress = progress;
ref.value.percent = percent;
// Note: Roughly 21 character limit, consider truncating mod name
ref.value.label = `Downloading: ${name}`;

const taken = Date.now() - startTime;
console.log(`downloaded mod ${downloaded}/${totalMods} in ${taken}ms`);
}
}
await processArray(modList);
ref.value.label = 'Mods successfully downloaded!';
ref.value.img =
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAeCAYAAABuUU38AAAACXBIWXMAAAsTAAALEwEAmpwYAAACqElEQVRYhdVYzY7SUBT+Tu1CTWRaG4UncKMOxOWMhhg37khYwBgT43P4ADyIiSawMLBzA0LUWRLGv4VPwMwECjVhiJYeF6W1pTBD7+2Mw7e67b0993733HvOd0r1ahuFUh6NWoexgSiU8tSodUDMjEatw0QETb/2v9cVCyPzBMyMQilPVK+2GQAUhbClbRaR8egEjuMeJBUA9JvX/U7DSElP8OJp59T+1+/z0nMMBpa/8eZw4hLx4JG4mlKjX8ZALqOv7Ov1TWn7U8uGYaQwGFj+u4hFkUnKO02/zQBq+09OHb+324LDDFpz/LI1Ti079E4FxbKxFPfSGq6Qa+jn8NeZ47fTmt/u9U35BRCgkgST8m4TzPF39NW7B6HnZw9bmDkc244HAqC4zhVDNq1DIXmX3r+tQVXk7Ciyi0jgZCYCKSIOMxTJnfRAkp4VioOVYhffjsZ4++mx0KSlQJQjANX53agUu+j1TaG7IhzQbccR/TSUZw4OE4haIHEiIijvtsDMyGV0KY9GwRdLJBvIHw4nK7YTIbI332lvaYtnPOiJ78djvPmYlCf+IREiwUz95XAU6c+mNZ/kzDmfsicRIl6mrhS72E5roagEuES/Ho1Q/SyWudeBMBFVWZ2CglGJ4YZYGSm0DqhebbNXjxhGKpb6fZnvYPLHjtyJSrHrtw/6pp8nVqG00wQRYnlsatm+jDeHE7nMfse4kYjWymV0Xz2L4lzC76K6vQjIi8ZLohqlPOLtvFeXeDhLKy1GNdE6JIhEjlY2HdBOa1R8yWutJUSmlh27bl+8E88ffcDM4YgMUYjgsHglGFzjIkIrHgwsGEZq6cA4uHtra+n737MZfhxb0vYBhP6gAPM84j0E/29tAszhxG8ruDzVqgzIO1oEgIMMNwgEAH8Bhif2yStQayoAAAAOZVhJZk1NACoAAAAIAAAAAAAAANJTkwAAAABJRU5ErkJggg==';
processingMods.value = false;
}

export async function downloadResourcePack(ref: Ref) {
const { resourcePack } = storeToRefs(useSourcesStore());
const { minecraftDir } = storeToRefs(useInstallerStore());
const { processingResourcepack } = storeToRefs(useStateStore());
ref.value.label = 'Downloading resource pack';

const rpName = `Drehmal Resource Pack v${resourcePack.value.version}.zip`;
const filePath = path.join(minecraftDir.value, 'resourcepacks', rpName);
console.log(`Downloading resource pack to: ${filePath}`);
downloadFile(resourcePack.value.source, filePath, ref).then(() => {
ref.value.label = 'Updating resource pack order';

const optionsFilePath = path.join(minecraftDir.value, 'options.txt');
const data = fs.readFileSync(optionsFilePath).toString().split('\n');
const resourceOptIndex = data.findIndex(
(item: string[]) => item.indexOf('resourcePacks:') !== -1
);
data[
resourceOptIndex
] = `resourcePacks:["vanilla","Fabric Mods","file/${rpName}"]`;

console.log(`Updating resource pack order in file: ${optionsFilePath}`);
fs.writeFileSync(optionsFilePath, data.join('\n'), 'utf-8');
ref.value.label = 'Resource pack downloaded!';

console.log('Updated Resource Pack order');
processingResourcepack.value = false;
});
}
41 changes: 41 additions & 0 deletions src/providers/UpdateMinecraftOpts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { storeToRefs } from 'pinia';
import { useSourcesStore } from 'src/stores/SourcesStore';

const fs = require('fs');

export function updateMinecraftOpts(filename: string) {
// Parse options file into an array of strings for each line
const lines: string[] = fs.readFileSync(filename, 'utf-8').split('\n');
// Create object to store the options as a json object for easy access
const options: Record<string, string> = {};
// add each option to the created object
lines.forEach((line) => {
const [key, value] = line.split(':');
if (key && value) {
options[key.trim()] = value.trim();
}
});

const { resourcePack } = storeToRefs(useSourcesStore());
const rpName = `Drehmal Resource Pack v${resourcePack.value.version}.zip`;

// modify options here
// update resource pack order to include Drehmal's pack at the top
options['resourcePacks'] = `["vanilla","Fabric Mods","file/${rpName}"]`;
// disable clouds, gets in the way of towers/structures
options['renderClouds'] = 'false';
// increase render distance to required minimum (consider scale based on memory allocation)
if (parseInt(options['renderDistance']) < 8) options['renderDistance'] = '8';
// maximise unfocused chat size so players can properly use menus
options['chatHeightUnfocused'] = '1.0';
// ensure custom music is enabled
options['soundCategory_music'] = '1.0';
options['soundCategory_record'] = '1.0';

let newOptions = '';
Object.keys(options).forEach(
(key) => (newOptions += `${key}:${options[key]}\n`)
);

fs.writeFileSync(filename, newOptions);
}

0 comments on commit 01b78be

Please sign in to comment.