From 75a7e0f713eb7c73142210819c9d95c7b4974db5 Mon Sep 17 00:00:00 2001 From: Daniel Scalzi Date: Mon, 13 Apr 2020 22:51:32 -0400 Subject: [PATCH] File structure refactor, move old files to old directory. Removed legacy config path support in ConfigManager. Moved model files to corresponding subdirectories, rather than being in an uber model directory. --- package.json | 2 +- src/main/asset/assetguardnew.ts | 0 .../model/mojang}/LauncherJson.ts | 4 +- .../model/mojang}/VersionJson.ts | 2 +- src/main/{ => config}/configmanager.ts | 38 +++++++++---------- .../config => config/model}/LauncherConfig.ts | 0 .../config => config/model}/ModConfig.ts | 0 .../config => config/model}/NewsCache.ts | 0 .../config => config/model}/SavedAccount.ts | 0 src/main/index.ts | 2 +- .../mojang => mojang/model}/auth/Agent.ts | 0 .../model}/auth/AuthPayload.ts | 2 +- .../mojang => mojang/model}/auth/Session.ts | 0 .../{type => model/internal}/Response.ts | 0 .../mojang/{type => model/internal}/Status.ts | 0 src/main/mojang/mojang.ts | 10 ++--- src/main/{ => old}/assetexec.ts | 0 src/main/{ => old}/assetguard.ts | 8 ++-- src/main/{ => old}/authmanager.ts | 6 +-- src/main/{ => old}/discordwrapper.ts | 0 src/main/{ => old}/distromanager.ts | 2 +- src/main/{ => old}/dropinmodutil.ts | 0 src/main/{ => old}/langloader.ts | 0 src/main/{ => old}/loggerutil.ts | 0 src/main/{ => old}/preloader.ts | 2 +- src/main/{ => old}/processbuilder.ts | 8 ++-- src/main/{ => old}/processbuilderold.js | 0 src/main/{ => old}/serverstatus.ts | 0 src/main/{ => util}/isdev.ts | 0 test/mojang/mojangTest.ts | 4 +- 30 files changed, 43 insertions(+), 47 deletions(-) create mode 100644 src/main/asset/assetguardnew.ts rename src/main/{model/mojang/index => asset/model/mojang}/LauncherJson.ts (93%) rename src/main/{model/mojang/index => asset/model/mojang}/VersionJson.ts (98%) rename src/main/{ => config}/configmanager.ts (94%) rename src/main/{model/internal/config => config/model}/LauncherConfig.ts (100%) rename src/main/{model/internal/config => config/model}/ModConfig.ts (100%) rename src/main/{model/internal/config => config/model}/NewsCache.ts (100%) rename src/main/{model/internal/config => config/model}/SavedAccount.ts (100%) rename src/main/{model/mojang => mojang/model}/auth/Agent.ts (100%) rename src/main/{model/mojang => mojang/model}/auth/AuthPayload.ts (81%) rename src/main/{model/mojang => mojang/model}/auth/Session.ts (100%) rename src/main/mojang/{type => model/internal}/Response.ts (100%) rename src/main/mojang/{type => model/internal}/Status.ts (100%) rename src/main/{ => old}/assetexec.ts (100%) rename src/main/{ => old}/assetguard.ts (99%) rename src/main/{ => old}/authmanager.ts (95%) rename src/main/{ => old}/discordwrapper.ts (100%) rename src/main/{ => old}/distromanager.ts (99%) rename src/main/{ => old}/dropinmodutil.ts (100%) rename src/main/{ => old}/langloader.ts (100%) rename src/main/{ => old}/loggerutil.ts (100%) rename src/main/{ => old}/preloader.ts (97%) rename src/main/{ => old}/processbuilder.ts (99%) rename src/main/{ => old}/processbuilderold.js (100%) rename src/main/{ => old}/serverstatus.ts (100%) rename src/main/{ => util}/isdev.ts (100%) diff --git a/package.json b/package.json index aafa7f63..ee10b00d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "helioslauncher", - "version": "1.7.0", + "version": "2.0.0-alpha.0", "productName": "Helios Launcher", "description": "Modded Minecraft Launcher", "author": "Daniel Scalzi (https://github.com/dscalzi/)", diff --git a/src/main/asset/assetguardnew.ts b/src/main/asset/assetguardnew.ts new file mode 100644 index 00000000..e69de29b diff --git a/src/main/model/mojang/index/LauncherJson.ts b/src/main/asset/model/mojang/LauncherJson.ts similarity index 93% rename from src/main/model/mojang/index/LauncherJson.ts rename to src/main/asset/model/mojang/LauncherJson.ts index 44994087..60041b30 100644 --- a/src/main/model/mojang/index/LauncherJson.ts +++ b/src/main/asset/model/mojang/LauncherJson.ts @@ -1,10 +1,10 @@ -interface LauncherJava { +export interface LauncherJava { sha1: string url: string version: string } -interface LauncherVersions { +export interface LauncherVersions { launcher: { commit: string name: string diff --git a/src/main/model/mojang/index/VersionJson.ts b/src/main/asset/model/mojang/VersionJson.ts similarity index 98% rename from src/main/model/mojang/index/VersionJson.ts rename to src/main/asset/model/mojang/VersionJson.ts index 92904797..ce659642 100644 --- a/src/main/model/mojang/index/VersionJson.ts +++ b/src/main/asset/model/mojang/VersionJson.ts @@ -15,7 +15,7 @@ export interface Natives { windows?: string } -interface BaseArtifact { +export interface BaseArtifact { sha1: string size: number diff --git a/src/main/configmanager.ts b/src/main/config/configmanager.ts similarity index 94% rename from src/main/configmanager.ts rename to src/main/config/configmanager.ts index 08f9e139..9ad2e871 100644 --- a/src/main/configmanager.ts +++ b/src/main/config/configmanager.ts @@ -1,18 +1,19 @@ -import { LoggerUtil } from './loggerutil' import { join } from 'path' -import { pathExistsSync, writeFileSync, ensureDirSync, moveSync, readFileSync } from 'fs-extra' +import { pathExistsSync, writeFileSync, ensureDirSync, readFileSync } from 'fs-extra' import { totalmem } from 'os' -import { SavedAccount } from './model/internal/config/SavedAccount' -import { LauncherConfig } from './model/internal/config/LauncherConfig' -import { ModConfig } from './model/internal/config/ModConfig' -import { NewsCache } from './model/internal/config/NewsCache' +import { SavedAccount } from './model/SavedAccount' +import { LauncherConfig } from './model/LauncherConfig' +import { ModConfig } from './model/ModConfig' +import { NewsCache } from './model/NewsCache' +import { LoggerUtil } from '../logging/loggerutil' + +// TODO final review upon usage in implementation. export class ConfigManager { - private static readonly logger = new LoggerUtil('%c[ConfigManager]', 'color: #a02d2a; font-weight: bold') + private static readonly logger = LoggerUtil.getLogger('ConfigManager') private static readonly sysRoot = process.env.APPDATA || (process.platform == 'darwin' ? process.env.HOME + '/Library/Application Support' : process.env.HOME) - // TODO change - private static readonly dataPath = join(ConfigManager.sysRoot as string, '.westeroscraft') + private static readonly dataPath = join(ConfigManager.sysRoot as string, '.helioslauncher') // Forked processes do not have access to electron, so we have this workaround. private static readonly launcherDir = process.env.CONFIG_DIRECT_PATH || require('electron').remote.app.getPath('userData') @@ -46,8 +47,7 @@ export class ConfigManager { } private static readonly configPath = join(ConfigManager.getLauncherDirectory(), 'config.json') - private static readonly configPathLEGACY = join(ConfigManager.dataPath, 'config.json') // TODO remove, it's been 1 year. - private static readonly firstLaunch = !pathExistsSync(ConfigManager.configPath) && !pathExistsSync(ConfigManager.configPathLEGACY) + private static readonly firstLaunch = !pathExistsSync(ConfigManager.configPath) /** * Three types of values: @@ -135,13 +135,9 @@ export class ConfigManager { if(!pathExistsSync(ConfigManager.configPath)){ // Create all parent directories. ensureDirSync(join(ConfigManager.configPath, '..')) - if(pathExistsSync(ConfigManager.configPathLEGACY)){ - moveSync(ConfigManager.configPathLEGACY, ConfigManager.configPath) - } else { - doLoad = false - ConfigManager.config = ConfigManager.DEFAULT_CONFIG - ConfigManager.save() - } + doLoad = false + ConfigManager.config = ConfigManager.DEFAULT_CONFIG + ConfigManager.save() } if(doLoad){ let doValidate = false @@ -150,8 +146,8 @@ export class ConfigManager { doValidate = true } catch (err){ ConfigManager.logger.error(err) - ConfigManager.logger.log('Configuration file contains malformed JSON or is corrupt.') - ConfigManager.logger.log('Generating a new configuration file.') + ConfigManager.logger.info('Configuration file contains malformed JSON or is corrupt.') + ConfigManager.logger.info('Generating a new configuration file.') ensureDirSync(join(ConfigManager.configPath, '..')) ConfigManager.config = ConfigManager.DEFAULT_CONFIG ConfigManager.save() @@ -161,7 +157,7 @@ export class ConfigManager { ConfigManager.save() } } - ConfigManager.logger.log('Successfully Loaded') + ConfigManager.logger.info('Successfully Loaded') } /** diff --git a/src/main/model/internal/config/LauncherConfig.ts b/src/main/config/model/LauncherConfig.ts similarity index 100% rename from src/main/model/internal/config/LauncherConfig.ts rename to src/main/config/model/LauncherConfig.ts diff --git a/src/main/model/internal/config/ModConfig.ts b/src/main/config/model/ModConfig.ts similarity index 100% rename from src/main/model/internal/config/ModConfig.ts rename to src/main/config/model/ModConfig.ts diff --git a/src/main/model/internal/config/NewsCache.ts b/src/main/config/model/NewsCache.ts similarity index 100% rename from src/main/model/internal/config/NewsCache.ts rename to src/main/config/model/NewsCache.ts diff --git a/src/main/model/internal/config/SavedAccount.ts b/src/main/config/model/SavedAccount.ts similarity index 100% rename from src/main/model/internal/config/SavedAccount.ts rename to src/main/config/model/SavedAccount.ts diff --git a/src/main/index.ts b/src/main/index.ts index d7764bab..3790a686 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -4,7 +4,7 @@ import { join } from "path" import { readdirSync } from "fs-extra" import { format } from "url" import { autoUpdater } from 'electron-updater' -import isdev from "./isdev" +import isdev from "./util/isdev" const installExtensions = async () => { const installer = require('electron-devtools-installer'); diff --git a/src/main/model/mojang/auth/Agent.ts b/src/main/mojang/model/auth/Agent.ts similarity index 100% rename from src/main/model/mojang/auth/Agent.ts rename to src/main/mojang/model/auth/Agent.ts diff --git a/src/main/model/mojang/auth/AuthPayload.ts b/src/main/mojang/model/auth/AuthPayload.ts similarity index 81% rename from src/main/model/mojang/auth/AuthPayload.ts rename to src/main/mojang/model/auth/AuthPayload.ts index 29d9abcf..76b012da 100644 --- a/src/main/model/mojang/auth/AuthPayload.ts +++ b/src/main/mojang/model/auth/AuthPayload.ts @@ -1,4 +1,4 @@ -import { Agent } from "./Agent"; +import { Agent } from './Agent' export interface AuthPayload { diff --git a/src/main/model/mojang/auth/Session.ts b/src/main/mojang/model/auth/Session.ts similarity index 100% rename from src/main/model/mojang/auth/Session.ts rename to src/main/mojang/model/auth/Session.ts diff --git a/src/main/mojang/type/Response.ts b/src/main/mojang/model/internal/Response.ts similarity index 100% rename from src/main/mojang/type/Response.ts rename to src/main/mojang/model/internal/Response.ts diff --git a/src/main/mojang/type/Status.ts b/src/main/mojang/model/internal/Status.ts similarity index 100% rename from src/main/mojang/type/Status.ts rename to src/main/mojang/model/internal/Status.ts diff --git a/src/main/mojang/mojang.ts b/src/main/mojang/mojang.ts index dae8aea5..87c22934 100644 --- a/src/main/mojang/mojang.ts +++ b/src/main/mojang/mojang.ts @@ -1,10 +1,10 @@ import { LoggerUtil } from '../logging/loggerutil' -import { Agent } from '../model/mojang/auth/Agent' -import { Status, StatusColor } from './type/Status' +import { Agent } from './model/auth/Agent' +import { Status, StatusColor } from './model/internal/Status' import axios, { AxiosError } from 'axios' -import { Session } from '../model/mojang/auth/Session' -import { AuthPayload } from '../model/mojang/auth/AuthPayload' -import { MojangResponse, MojangResponseCode, deciperResponseCode, isInternalError } from './type/Response' +import { Session } from './model/auth/Session' +import { AuthPayload } from './model/auth/AuthPayload' +import { MojangResponse, MojangResponseCode, deciperResponseCode, isInternalError } from './model/internal/Response' export class Mojang { diff --git a/src/main/assetexec.ts b/src/main/old/assetexec.ts similarity index 100% rename from src/main/assetexec.ts rename to src/main/old/assetexec.ts diff --git a/src/main/assetguard.ts b/src/main/old/assetguard.ts similarity index 99% rename from src/main/assetguard.ts rename to src/main/old/assetguard.ts index 2c8a659b..4fc1172f 100644 --- a/src/main/assetguard.ts +++ b/src/main/old/assetguard.ts @@ -4,16 +4,16 @@ import { join } from 'path' import { pathExistsSync, pathExists, readdir, exists, readFileSync, createWriteStream, ensureDirSync, readFile, writeFileSync, unlink, createReadStream, readJsonSync } from 'fs-extra' import Registry from 'winreg' import { exec, spawn } from 'child_process' -import { LauncherJson } from './model/mojang/index/LauncherJson' +import { LauncherJson } from '../asset/model/mojang/LauncherJson' import { createHash } from 'crypto' import AdmZip from 'adm-zip' import { forEachOfLimit, eachLimit } from 'async' import { extract } from 'tar-fs' import { createGunzip } from 'zlib' -import { VersionJson, AssetIndex, Rule, Natives, Library } from './model/mojang/index/VersionJson' +import { VersionJson, AssetIndex, Rule, Natives, Library } from '../asset/model/mojang/VersionJson' -import { ConfigManager } from './configmanager' -import isDev from './isdev' +import { ConfigManager } from '../config/configmanager' +import isDev from '../util/isdev' const DistroManager = require('./distromanager') // Constants diff --git a/src/main/authmanager.ts b/src/main/old/authmanager.ts similarity index 95% rename from src/main/authmanager.ts rename to src/main/old/authmanager.ts index d1bb866d..49f6f34d 100644 --- a/src/main/authmanager.ts +++ b/src/main/old/authmanager.ts @@ -1,7 +1,7 @@ import { LoggerUtil } from './loggerutil' -import { ConfigManager } from './configmanager' -import { Mojang } from './mojang/mojang' -import { SavedAccount } from './model/internal/config/SavedAccount' +import { ConfigManager } from '../config/configmanager' +import { Mojang } from '../mojang/mojang' +import { SavedAccount } from '../config/model/SavedAccount' /** * AuthManager diff --git a/src/main/discordwrapper.ts b/src/main/old/discordwrapper.ts similarity index 100% rename from src/main/discordwrapper.ts rename to src/main/old/discordwrapper.ts diff --git a/src/main/distromanager.ts b/src/main/old/distromanager.ts similarity index 99% rename from src/main/distromanager.ts rename to src/main/old/distromanager.ts index 71f8b948..b9022016 100644 --- a/src/main/distromanager.ts +++ b/src/main/old/distromanager.ts @@ -3,7 +3,7 @@ import { Distribution, Module, Type, TypeMetadata, Server } from 'helios-distrib import { readJson, writeJson } from 'fs-extra' import { join } from 'path' import { LoggerUtil } from './loggerutil' -import { ConfigManager } from './configmanager' +import { ConfigManager } from '../config/configmanager' const logger = new LoggerUtil('%c[DistroManager]', 'color: #a02d2a; font-weight: bold') diff --git a/src/main/dropinmodutil.ts b/src/main/old/dropinmodutil.ts similarity index 100% rename from src/main/dropinmodutil.ts rename to src/main/old/dropinmodutil.ts diff --git a/src/main/langloader.ts b/src/main/old/langloader.ts similarity index 100% rename from src/main/langloader.ts rename to src/main/old/langloader.ts diff --git a/src/main/loggerutil.ts b/src/main/old/loggerutil.ts similarity index 100% rename from src/main/loggerutil.ts rename to src/main/old/loggerutil.ts diff --git a/src/main/preloader.ts b/src/main/old/preloader.ts similarity index 97% rename from src/main/preloader.ts rename to src/main/old/preloader.ts index 2c0b4576..096a0d2e 100644 --- a/src/main/preloader.ts +++ b/src/main/old/preloader.ts @@ -1,4 +1,4 @@ -import { ConfigManager } from './configmanager' +import { ConfigManager } from '../config/configmanager' import { DistroManager, DistributionWrapper } from './distromanager' import { join } from 'path' import { remove } from 'fs-extra' diff --git a/src/main/processbuilder.ts b/src/main/old/processbuilder.ts similarity index 99% rename from src/main/processbuilder.ts rename to src/main/old/processbuilder.ts index 70268d4c..0e00e6e3 100644 --- a/src/main/processbuilder.ts +++ b/src/main/old/processbuilder.ts @@ -4,14 +4,14 @@ import { join, basename } from 'path' import { ModuleWrapper, ServerWrapper } from './distromanager' import { Type, Required } from 'helios-distribution-types' import { LoggerUtil } from './loggerutil' -import { ConfigManager } from './configmanager' +import { ConfigManager } from '../config/configmanager' import { spawn } from 'child_process' -import { SavedAccount } from './model/internal/config/SavedAccount' +import { SavedAccount } from '../config/model/SavedAccount' import { tmpdir, release } from 'os' -import { SubModConfig } from './model/internal/config/ModConfig' +import { SubModConfig } from '../config/model/ModConfig' import { pseudoRandomBytes } from 'crypto' import { Util, LibraryInternal } from './assetguard' -import { VersionJson, Rule } from './model/mojang/index/VersionJson' +import { VersionJson, Rule } from '../asset/model/mojang/VersionJson' import { URL } from 'url' const logger = new LoggerUtil('%c[ProcessBuilder]', 'color: #003996; font-weight: bold') diff --git a/src/main/processbuilderold.js b/src/main/old/processbuilderold.js similarity index 100% rename from src/main/processbuilderold.js rename to src/main/old/processbuilderold.js diff --git a/src/main/serverstatus.ts b/src/main/old/serverstatus.ts similarity index 100% rename from src/main/serverstatus.ts rename to src/main/old/serverstatus.ts diff --git a/src/main/isdev.ts b/src/main/util/isdev.ts similarity index 100% rename from src/main/isdev.ts rename to src/main/util/isdev.ts diff --git a/test/mojang/mojangTest.ts b/test/mojang/mojangTest.ts index 244d53ba..0744569f 100644 --- a/test/mojang/mojangTest.ts +++ b/test/mojang/mojangTest.ts @@ -2,8 +2,8 @@ import { Mojang } from "../../src/main/mojang/mojang" import { expect } from 'chai' import nock from 'nock' import { URL } from 'url' -import { Session } from "../../src/main/model/mojang/auth/Session" -import { MojangResponseCode } from "../../src/main/mojang/type/Response" +import { Session } from "../../src/main/mojang/model/auth/Session" +import { MojangResponseCode } from "../../src/main/mojang/model/internal/Response" function expectMojangResponse(res: any, responseCode: MojangResponseCode, negate = false) { expect(res).to.not.be.an('error')