Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding ability to import and install archives via cmdline #17002

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/app/Application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1098,16 +1098,20 @@ class Application {
}

private applyArguments(args: IParameters) {
if (args.download || args.install) {
if (args.download || args.install || args.installArchive) {
const prom: Promise<void> = (this.mMainWindow === undefined)
// give the main instance a moment to fully start up
? Promise.delay(2000)
: Promise.resolve(undefined);

prom.then(() => {
if (this.mMainWindow !== undefined) {
this.mMainWindow.sendExternalURL(args.download || args.install,
args.install !== undefined);
if (args.download || args.install) {
this.mMainWindow.sendExternalURL(args.download || args.install, args.install !== undefined);
}
if (args.installArchive) {
this.mMainWindow.installModFromArchive(args.installArchive);
}
} else {
// TODO: this instructions aren't very correct because we know Vortex doesn't have
// a UI and needs to be shut down from the task manager
Expand Down
10 changes: 10 additions & 0 deletions src/app/MainWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,16 @@ class MainWindow {
}
}

public installModFromArchive(archivePath: string) {
if (this.mWindow != null) {
try {
this.mWindow.webContents.send('install-archive', archivePath);
} catch (err) {
log('error', 'failed to send install-archive', { archivePath, error: err.message });
}
}
}

public getHandle(): Electron.BrowserWindow {
return this.mWindow;
}
Expand Down
10 changes: 9 additions & 1 deletion src/extensions/download_management/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -811,10 +811,18 @@ function processCommandline(api: IExtensionApi) {
const { commandLine } = state.session.base;

const cliUrl = commandLine.download ?? commandLine.install;

if (cliUrl) {
api.events.emit('start-download-url', cliUrl, undefined, commandLine.install !== undefined);
}

const arcPath = commandLine.installArchive;
if (typeof arcPath === 'string' && path.isAbsolute(arcPath)) {
api.events.emit('import-downloads', [arcPath], (dlIds: string[]) => {
dlIds.forEach(dlId => {
api.events.emit('start-install-download', dlId);
});
});
}
}

function init(context: IExtensionContextExt): boolean {
Expand Down
25 changes: 21 additions & 4 deletions src/renderer.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/**
* entry point for the renderer process(es)
*/
/* eslint-disable */

if (process.env.DEBUG_REACT_RENDERS === 'true') {
// eslint-disable-next-line @typescript-eslint/no-var-requires
Expand Down Expand Up @@ -518,9 +516,22 @@ function init() {

const startupPromise = new Promise(resolve => (startupFinished = resolve));

const api = extensions.getApi();
// tslint:disable-next-line:no-unused-variable
const globalNotifications = new GlobalNotifications(extensions.getApi());
const globalNotifications = new GlobalNotifications(api);

function startinstallFromArchive(filePath: string) {
startupPromise.then(() => {
if (typeof filePath !== 'string' || !path.isAbsolute(filePath)) {
return;
}
api.events.emit('import-downloads', [filePath], (dlIds: string[]) => {
dlIds.forEach(dlId => {
api.events.emit('start-install-download', dlId);
});
});
});
}
function startDownloadFromURL(url: string, fileName?: string, install?: boolean) {
startupPromise.then(() => {
if (typeof url !== 'string') {
Expand Down Expand Up @@ -558,6 +569,12 @@ function init() {
},
);

ipcRenderer.on(
'install-archive',
(event, filePath: string) => {
startinstallFromArchive(filePath);
});

ipcRenderer.on('relay-event', (sender, event, ...args) => {
eventEmitter.emit(event, ...args);
});
Expand Down
4 changes: 4 additions & 0 deletions src/util/commandLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import startupSettings from './startupSettings';
export interface IParameters {
download?: string;
install?: string;
installArchive?: string;
installExtension?: string;
report?: string;
restore?: string;
Expand Down Expand Up @@ -50,6 +51,7 @@ const ARG_COUNTS = {
'-s': 1,
'--download': 1,
'--install': 1,
'--install-archive': 1,
'--install-extension': 1,
'--start-minimized': 1,
'--game': 1,
Expand Down Expand Up @@ -168,6 +170,7 @@ function parseCommandline(argv: string[], electronIsShitHack: boolean): IParamet
+ '(any supported protocol like nxm:, https:, ...).')
.option('-i, --install <url>', 'Start downloadling & installing the specified url '
+ '(any supported protocol like nxm:, https:, ...).')
.option('--install-archive <path>', 'Start installing the specified archive. Use absolute path.')
.option('--install-extension <id>', 'Start downloadling & installing the specified '
+ 'vortex extension. id can be "modId:<number>".')
.option('-g, --get <path>', 'Print the state variable at the specified path and quit. '
Expand Down Expand Up @@ -222,6 +225,7 @@ const SKIP_ARGS = {
'--game': 1,
'--profile': 1,
'--install': 1,
'--install-archive': 1,
'--install-extension': 1,
'--restore': 1,
'--merge': 1,
Expand Down