Skip to content

Commit

Permalink
adding comparison of patches, installer choices, hashes when isntalli…
Browse files Browse the repository at this point in the history
…ng from collection
  • Loading branch information
IDCs committed Feb 7, 2024
1 parent e461c12 commit 906a26d
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/initweaks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { IExtendedInterfaceProps } from './types/IExtendedInterfaceProps';
import { IINITweak, TweakArray } from './types/IINITweak';
import TweakList from './views/IniTweaks';

import { INI_TWEAKS_PATH, MOD_TYPE, OPTIONAL_TWEAK_PREFIX } from './constants';
import { INI_TWEAKS_PATH, OPTIONAL_TWEAK_PREFIX } from './constants';

const gameSupport = {
skyrim: {
Expand Down
5 changes: 5 additions & 0 deletions src/types/IEntryEx.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { IEntry } from 'turbowalk';

export interface IEntryEx extends IEntry {
fileMD5: string;
}
36 changes: 30 additions & 6 deletions src/util/InstallDriver.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
import * as nexusApi from '@nexusmods/nexus-api';
import * as Promise from 'bluebird';
import * as path from 'path';
Expand All @@ -10,7 +11,11 @@ import { IRevisionEx } from '../types/IRevisionEx';
import { applyPatches } from './binaryPatching';
import { readCollection } from './importCollection';
import InfoCache from './InfoCache';
import { calculateCollectionSize, getUnfulfilledNotificationId, isRelevant, modRuleId } from './util';
import { calculateCollectionSize, getUnfulfilledNotificationId, isRelevant, modRuleId, walkPath } from './util';

import * as _ from 'lodash';
import turbowalk, { IEntry } from 'turbowalk';
import { IFileListItem, IModReference } from 'vortex-api/lib/extensions/mod_management/types/IMod';

export type Step = 'prepare' | 'changelog' | 'query' | 'start' | 'disclaimer' | 'installing' | 'recommendations' | 'review';

Expand All @@ -37,6 +42,9 @@ class InstallDriver {
private get requiredMods() {
return this.mDependentMods.filter(_ => _.type === 'requires');
}
private get recommendedMods() {
return this.mDependentMods.filter(_ => _.type === 'recommends');
}

constructor(api: types.IExtensionApi) {
this.mApi = api;
Expand Down Expand Up @@ -69,8 +77,11 @@ class InstallDriver {
}
applyPatches(api, this.mCollection,
gameId, dependent.reference.description, modId, dependent.extra?.patches);
api.store.dispatch(
actions.setFileOverride(gameId, modId, dependent.extra?.fileOverrides));
util.batchDispatch(api.store, [
actions.setFileOverride(gameId, modId, dependent.extra?.fileOverrides),
actions.setModAttribute(gameId, modId, 'patches', dependent.extra?.patches),
actions.setModAttribute(gameId, modId, 'fileList', dependent.fileList),
]);
}
}
this.triggerUpdate();
Expand Down Expand Up @@ -463,7 +474,7 @@ class InstallDriver {
this.mApi.ext.withSuppressedTests?.(['plugins-changed'], () =>
new Promise(resolve => {
this.mOnStop = () => {
resolve();
resolve(undefined);
this.mOnStop = undefined;
};
}));
Expand Down Expand Up @@ -556,8 +567,21 @@ class InstallDriver {

const required = (collection?.rules ?? [])
.filter(rule => ['requires', 'recommends'].includes(rule.type));
this.mDependentMods = required
.filter(rule => util.findModByRef(rule.reference, mods) === undefined);
const dependencies: types.IModRule[] = required
.reduce((accum, rule) => {
const modRef: any = {
...rule.reference,
patches: { ...rule?.extra?.patches } ?? undefined,
fileList: rule?.fileList,
}
const mod = util.findModByRef(modRef, mods);
if (mod === undefined) {
accum.push(rule);
}
return accum;
}, []);
this.mDependentMods = dependencies;
log('debug', 'dependent mods', JSON.stringify(dependencies));

if (this.requiredMods.length === 0) {
this.mInstallDone = false;
Expand Down
13 changes: 2 additions & 11 deletions src/util/transformCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,17 @@ import * as semver from 'semver';
import { generate as shortid } from 'shortid';
import turbowalk, { IEntry } from 'turbowalk';
import { actions, fs, log, selectors, types, util } from 'vortex-api';
import { fileMD5 } from 'vortexmt';
import { IINITweak } from '../types/IINITweak';

import { fileMD5Async } from './util';

import { importTweaks } from '../initweaks';

interface IResolvedRule {
mod: types.IMod;
rule: types.IModRule;
}

function nop() {
// nop
}

const fileMD5Async = (fileName: string) => new Promise((resolve, reject) => {
fileMD5(fileName,
(err: Error, result: string) => (err !== null) ? reject(err) : resolve(result),
nop);
});

function sanitizeExpression(fileName: string): string {
// drop extension and anything like ".1" or " (1)" at the end which probaby
// indicates duplicate downloads (either in our own format or common browser
Expand Down
28 changes: 28 additions & 0 deletions src/util/util.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
/* eslint-disable */
import * as PromiseBB from 'bluebird';
import { createHash } from 'crypto';
import { types, util } from 'vortex-api';
import { ICollectionModRuleEx } from '../types/ICollection';
import { IEntryEx } from '../types/IEntryEx';
import { IModEx } from '../types/IModEx';
import { fileMD5 } from 'vortexmt';
import turbowalk, { IEntry, IWalkOptions } from 'turbowalk';

export function makeProgressFunction(api: types.IExtensionApi) {
const notificationId = api.sendNotification({
Expand Down Expand Up @@ -124,3 +128,27 @@ export function calculateCollectionSize(mods: { [id: string]: IModWithRule }): n
return prev + size;
}, 0);
}

export async function fileMD5Async(fileName: string): Promise<string> {
return new Promise((resolve, reject) => {
fileMD5(fileName,
(err: Error, result: string) => (err !== null) ? reject(err) : resolve(result),
() => null);
});
}

export async function walkPath(dirPath: string, walkOptions?: IWalkOptions): Promise<IEntryEx[]> {
walkOptions = walkOptions || { skipLinks: true, skipHidden: true, skipInaccessible: true };
const walkResults: IEntryEx[] = [];
return new Promise<IEntryEx[]>(async (resolve, reject) => {
await turbowalk(dirPath, async (entries: IEntry[]) => {
for (const entry of entries) {
const md5 = await fileMD5Async(entry.filePath);
const extendedEntry: IEntryEx = { ...entry, fileMD5: md5 };
walkResults.push(extendedEntry);
}
return Promise.resolve();
}, walkOptions).catch(err => err.code === 'ENOENT' ? Promise.resolve() : Promise.reject(err));
return resolve(walkResults);
});
}
2 changes: 1 addition & 1 deletion src/views/CollectionPageView/CollectionOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ class CollectionOverview extends ComponentEx<ICollectionOverviewProps, { selIdx:
ownSuccess={votedSuccess}
voteAllowed={voteAllowed}
gameVersion={ (this.context.api.getState().persistent?.gameMode as any)?.versions[profile.gameId] ?? '?'}
collectionGameVersion={revision?.gameVersions[0]?.reference ?? '?'}
collectionGameVersion={revision?.gameVersions?.[0]?.reference ?? '?'}
/>
) : null}
</FlexLayout.Fixed>
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1582,8 +1582,8 @@ void-elements@3.1.0:
integrity sha1-YU9/v42AHwu18GYfWy9XhXUOTwk=

vortex-api@Nexus-Mods/vortex-api:
version "1.8.5-r6"
resolved "https://codeload.github.com/Nexus-Mods/vortex-api/tar.gz/de08cb31b344e8b820bb36ffa5a77559a29c85b6"
version "1.8.6"
resolved "https://codeload.github.com/Nexus-Mods/vortex-api/tar.gz/c6fc284558af36317c7d8c664384dbd44abe304c"

warning@^3.0.0:
version "3.0.0"
Expand Down

0 comments on commit 906a26d

Please sign in to comment.