Skip to content
Merged
2 changes: 1 addition & 1 deletion src/components/importing/LocalFileImportModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ export default class LocalFileImportModal extends Vue {
this.$store.commit("error/handleError", R2Error.fromThrownValue(error));
return;
}
const updatedModListResult = await ProfileModList.getModList(profile);
const updatedModListResult = await ProfileModList.getModList(profile.asImmutableProfile());
if (updatedModListResult instanceof R2Error) {
this.$store.commit("error/handleError", updatedModListResult);
return;
Expand Down
2 changes: 1 addition & 1 deletion src/components/profiles-modals/ImportProfileModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ export default class ImportProfileModal extends mixins(ProfilesMixin) {

for (const imported of modList) {
if (imported.getName() == comboMod.getMod().getFullName() && !imported.isEnabled()) {
await ProfileModList.updateMod(installedMod, this.activeProfile, async (modToDisable: ManifestV2) => {
await ProfileModList.updateMod(installedMod, this.activeProfile.asImmutableProfile(), async (modToDisable: ManifestV2) => {
// Need to enable temporarily so the manager doesn't think it's re-disabling a disabled mod.
modToDisable.enable();
await ProfileInstallerProvider.instance.disableMod(modToDisable, this.activeProfile);
Expand Down
12 changes: 6 additions & 6 deletions src/components/views/DownloadModModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ let assignId = 0;
);
}
}
const modList = await ProfileModList.getModList(profile);
const modList = await ProfileModList.getModList(profile.asImmutableProfile());
if (!(modList instanceof R2Error)) {
const err = await ConflictManagementProvider.instance.resolveConflicts(modList, profile);
if (err instanceof R2Error) {
Expand Down Expand Up @@ -250,7 +250,7 @@ let assignId = 0;
}
}

const modListResult = await ProfileModList.getModList(this.profile);
const modListResult = await ProfileModList.getModList(this.profile.asImmutableProfile());
if (!(modListResult instanceof R2Error)) {
const manifestMod = modListResult.find((local: ManifestV2) => local.getName() === this.thunderstoreMod!.getFullName());
if (manifestMod !== undefined) {
Expand Down Expand Up @@ -379,7 +379,7 @@ let assignId = 0;
}
}
this.downloadingMod = false;
const modList = await ProfileModList.getModList(this.profile);
const modList = await ProfileModList.getModList(this.profile.asImmutableProfile());
if (!(modList instanceof R2Error)) {
await this.$store.dispatch('profile/updateModList', modList);
const err = await ConflictManagementProvider.instance.resolveConflicts(modList, this.profile);
Expand All @@ -393,7 +393,7 @@ let assignId = 0;
static async installModAfterDownload(profile: Profile, mod: ThunderstoreMod, version: ThunderstoreVersion): Promise<R2Error | void> {
return new Promise(async (resolve, reject) => {
const manifestMod: ManifestV2 = new ManifestV2().fromThunderstoreMod(mod, version);
const profileModList = await ProfileModList.getModList(profile);
const profileModList = await ProfileModList.getModList(profile.asImmutableProfile());
if (profileModList instanceof R2Error) {
return reject(profileModList);
}
Expand All @@ -413,7 +413,7 @@ let assignId = 0;
}
const installError: R2Error | null = await ProfileInstallerProvider.instance.installMod(manifestMod, profile);
if (!(installError instanceof R2Error)) {
const newModList: ManifestV2[] | R2Error = await ProfileModList.addMod(manifestMod, profile);
const newModList: ManifestV2[] | R2Error = await ProfileModList.addMod(manifestMod, profile.asImmutableProfile());
if (newModList instanceof R2Error) {
return reject(newModList);
}
Expand All @@ -422,7 +422,7 @@ let assignId = 0;
}
if (olderInstallOfMod !== undefined) {
if (!olderInstallOfMod.isEnabled()) {
await ProfileModList.updateMod(manifestMod, profile, async mod => {
await ProfileModList.updateMod(manifestMod, profile.asImmutableProfile(), async mod => {
mod.disable();
});
await ProfileInstallerProvider.instance.disableMod(manifestMod, profile);
Expand Down
6 changes: 3 additions & 3 deletions src/components/views/LocalModList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import Draggable from 'vuedraggable';
import { Component, Vue } from 'vue-property-decorator';
import ManifestV2 from '../../model/ManifestV2';
import R2Error from '../../model/errors/R2Error';
import Profile from '../../model/Profile';
import { ImmutableProfile } from '../../model/Profile';
import AssociatedModsModal from './LocalModList/AssociatedModsModal.vue';
import DisableModModal from './LocalModList/DisableModModal.vue';
import UninstallModModal from './LocalModList/UninstallModModal.vue';
Expand All @@ -46,8 +46,8 @@ import SearchAndSort from './LocalModList/SearchAndSort.vue';
}
})
export default class LocalModList extends Vue {
get profile(): Profile {
return this.$store.getters['profile/activeProfile'];
get profile(): ImmutableProfile {
return this.$store.getters['profile/activeProfile'].asImmutableProfile();
}

get draggableList(): ManifestV2[] {
Expand Down
6 changes: 3 additions & 3 deletions src/pages/Manager.vue
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ import ModalCard from '../components/ModalCard.vue';
this.$store.commit('error/handleError', err);
return;
}
const exportErr = await ProfileModList.exportModListToFile(this.profile);
const exportErr = await ProfileModList.exportModListToFile(this.profile.asImmutableProfile());
if (exportErr instanceof R2Error) {
this.$store.commit('error/handleError', exportErr);
}
Expand All @@ -391,7 +391,7 @@ import ModalCard from '../components/ModalCard.vue';
this.$store.commit('error/handleError', err);
return;
}
const exportErr = await ProfileModList.exportModListAsCode(this.profile, (code: string, err: R2Error | null) => {
const exportErr = await ProfileModList.exportModListAsCode(this.profile.asImmutableProfile(), (code: string, err: R2Error | null) => {
if (err !== null) {
this.$store.commit('error/handleError', err);
} else {
Expand Down Expand Up @@ -630,7 +630,7 @@ import ModalCard from '../components/ModalCard.vue';
}
DownloadModModal.downloadSpecific(this.profile, combo, this.thunderstoreModList, ignoreCache)
.then(async value => {
const modList = await ProfileModList.getModList(this.profile);
const modList = await ProfileModList.getModList(this.profile.asImmutableProfile());
if (!(modList instanceof R2Error)) {
await this.$store.dispatch('profile/updateModList', modList);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/r2mm/downloading/BetterThunderstoreDownloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export default class BetterThunderstoreDownloader extends ThunderstoreDownloader
combo.setVersion(modVersion);
let downloadCount = 0;

const modList = await ProfileModList.getModList(profile);
const modList = await ProfileModList.getModList(profile.asImmutableProfile());
if (modList instanceof R2Error) {
return callback(0, mod.getName(), StatusEnum.FAILURE, modList);
}
Expand Down
4 changes: 2 additions & 2 deletions src/r2mm/installing/LocalModInstaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default class LocalModInstaller extends LocalModInstallerProvider {
callback(false, profileInstallResult);
return Promise.resolve();
}
const modListInstallResult = await ProfileModList.addMod(manifest, profile);
const modListInstallResult = await ProfileModList.addMod(manifest, profile.asImmutableProfile());
if (modListInstallResult instanceof R2Error) {
callback(false, modListInstallResult);
return Promise.resolve();
Expand All @@ -92,7 +92,7 @@ export default class LocalModInstaller extends LocalModInstallerProvider {
callback(false, profileInstallResult);
return Promise.resolve();
}
const modListInstallResult = await ProfileModList.addMod(manifest, profile);
const modListInstallResult = await ProfileModList.addMod(manifest, profile.asImmutableProfile());
if (modListInstallResult instanceof R2Error) {
callback(false, modListInstallResult);
return Promise.resolve();
Expand Down
2 changes: 1 addition & 1 deletion src/r2mm/mods/CacheUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default class CacheUtil {
const activeModSet = new Set<ManifestV2>();
for (const value of profiles) {
const profile = new Profile(value);
const modList = await ProfileModList.getModList(profile);
const modList = await ProfileModList.getModList(profile.asImmutableProfile());
if (modList instanceof R2Error) {
continue;
}
Expand Down
20 changes: 10 additions & 10 deletions src/r2mm/mods/ProfileModList.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as yaml from 'yaml';
import Profile from '../../model/Profile';
import { ImmutableProfile } from '../../model/Profile';

import * as path from 'path';
import FsProvider from '../../providers/generic/file/FsProvider';
Expand Down Expand Up @@ -35,7 +35,7 @@ export default class ProfileModList {
return this.lock.acquire("acquire", fn);
}

public static async getModList(profile: Profile): Promise<ManifestV2[] | R2Error> {
public static async getModList(profile: ImmutableProfile): Promise<ManifestV2[] | R2Error> {
const fs = FsProvider.instance;
await FileUtils.ensureDirectory(profile.getProfilePath());
if (!await fs.exists(profile.joinToProfilePath('mods.yml'))) {
Expand Down Expand Up @@ -84,7 +84,7 @@ export default class ProfileModList {
}
}

public static async saveModList(profile: Profile, modList: ManifestV2[]): Promise<R2Error | null> {
public static async saveModList(profile: ImmutableProfile, modList: ManifestV2[]): Promise<R2Error | null> {
const fs = FsProvider.instance;
try {
const yamlModList: string = yaml.stringify(modList);
Expand Down Expand Up @@ -112,7 +112,7 @@ export default class ProfileModList {
return null;
}

public static async addMod(mod: ManifestV2, profile: Profile): Promise<ManifestV2[] | R2Error> {
public static async addMod(mod: ManifestV2, profile: ImmutableProfile): Promise<ManifestV2[] | R2Error> {
mod.setInstalledAtTime(Number(new Date())); // Set InstalledAt to current epoch millis
let currentModList: ManifestV2[] | R2Error = await this.getModList(profile);
if (currentModList instanceof R2Error) {
Expand All @@ -137,7 +137,7 @@ export default class ProfileModList {
return this.getModList(profile);
}

public static async removeMod(mod: ManifestV2, profile: Profile): Promise<ManifestV2[] | R2Error> {
public static async removeMod(mod: ManifestV2, profile: ImmutableProfile): Promise<ManifestV2[] | R2Error> {
const currentModList: ManifestV2[] | R2Error = await this.getModList(profile);
if (currentModList instanceof R2Error) {
return currentModList;
Expand All @@ -151,7 +151,7 @@ export default class ProfileModList {
return this.getModList(profile);
}

public static async updateMods(mods: ManifestV2[], profile: Profile, apply: (mod: ManifestV2) => void): Promise<ManifestV2[] | R2Error> {
public static async updateMods(mods: ManifestV2[], profile: ImmutableProfile, apply: (mod: ManifestV2) => void): Promise<ManifestV2[] | R2Error> {
const list: ManifestV2[] | R2Error = await this.getModList(profile);
if (list instanceof R2Error) {
return list;
Expand All @@ -169,7 +169,7 @@ export default class ProfileModList {
return this.getModList(profile);
}

public static async updateMod(mod: ManifestV2, profile: Profile, apply: (mod: ManifestV2) => Promise<void>): Promise<ManifestV2[] | R2Error> {
public static async updateMod(mod: ManifestV2, profile: ImmutableProfile, apply: (mod: ManifestV2) => Promise<void>): Promise<ManifestV2[] | R2Error> {
const list: ManifestV2[] | R2Error = await this.getModList(profile);
if (list instanceof R2Error) {
return list;
Expand All @@ -184,7 +184,7 @@ export default class ProfileModList {
return this.getModList(profile);
}

private static async createExport(profile: Profile): Promise<ZipBuilder | R2Error> {
private static async createExport(profile: ImmutableProfile): Promise<ZipBuilder | R2Error> {
const list: ManifestV2[] | R2Error = await this.getModList(profile);
if (list instanceof R2Error) {
return list;
Expand Down Expand Up @@ -219,7 +219,7 @@ export default class ProfileModList {
return builder;
}

public static async exportModListToFile(profile: Profile): Promise<R2Error | string> {
public static async exportModListToFile(profile: ImmutableProfile): Promise<R2Error | string> {
const exportDirectory = path.join(PathResolver.MOD_ROOT, 'exports');
try {
await FileUtils.ensureDirectory(exportDirectory);
Expand All @@ -246,7 +246,7 @@ export default class ProfileModList {
return exportPath;
}

public static async exportModListAsCode(profile: Profile, callback: (code: string, err: R2Error | null) => void): Promise<R2Error | void> {
public static async exportModListAsCode(profile: ImmutableProfile, callback: (code: string, err: R2Error | null) => void): Promise<R2Error | void> {
const fs = FsProvider.instance;
const exportDirectory = path.join(PathResolver.MOD_ROOT, 'exports');
await FileUtils.ensureDirectory(exportDirectory);
Expand Down
14 changes: 7 additions & 7 deletions src/store/modules/ProfileModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ActionTree, GetterTree } from 'vuex';
import { State as RootState } from '../index';
import R2Error from '../../model/errors/R2Error';
import ManifestV2 from '../../model/ManifestV2';
import Profile from "../../model/Profile";
import Profile, { ImmutableProfile } from "../../model/Profile";
import { SortDirection } from '../../model/real_enums/sort/SortDirection';
import { SortLocalDisabledMods } from '../../model/real_enums/sort/SortLocalDisabledMods';
import { SortNaming } from '../../model/real_enums/sort/SortNaming';
Expand Down Expand Up @@ -211,7 +211,7 @@ export default {
}

// Update mod list status to mods.yml.
const updatedList = await ProfileModList.updateMods(mods, profile, (mod) => mod.disable());
const updatedList = await ProfileModList.updateMods(mods, profile.asImmutableProfile(), (mod) => mod.disable());
if (updatedList instanceof R2Error) {
throw updatedList;
} else {
Expand Down Expand Up @@ -266,7 +266,7 @@ export default {
}

// Update mod list status to mods.yml.
const updatedList = await ProfileModList.updateMods(mods, profile, (mod) => mod.enable());
const updatedList = await ProfileModList.updateMods(mods, profile.asImmutableProfile(), (mod) => mod.enable());
if (updatedList instanceof R2Error) {
throw updatedList;
} else {
Expand Down Expand Up @@ -320,7 +320,7 @@ export default {
{dispatch, getters},
params: {
mods: ManifestV2[],
profile: Profile,
profile: ImmutableProfile,
}
) {
const {mods, profile} = params;
Expand Down Expand Up @@ -352,7 +352,7 @@ export default {
return;
}

const modList = await ProfileModList.getModList(state.activeProfile);
const modList = await ProfileModList.getModList(state.activeProfile.asImmutableProfile());

if (!(modList instanceof R2Error)) {
await dispatch('updateModList', modList);
Expand Down Expand Up @@ -394,7 +394,7 @@ export default {
// Update mod list status to mods.yml.
// TODO: can performance be improved by implementing
// a .removeMods(mods, profile) and calling it once outside the loop?
const updatedList = await ProfileModList.removeMod(mod, profile);
const updatedList = await ProfileModList.removeMod(mod, profile.asImmutableProfile());
if (updatedList instanceof R2Error) {
throw updatedList;
} else {
Expand Down Expand Up @@ -433,7 +433,7 @@ export default {
/*** Read profiles mod list from mods.yml in profile directory. */
async updateModListFromFile({dispatch, getters}) {
const profile: Profile = getters['activeProfile'];
const mods = await ProfileModList.getModList(profile);
const mods = await ProfileModList.getModList(profile.asImmutableProfile());

if (mods instanceof R2Error) {
throw mods;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/ProfileUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export async function installModAfterDownload(mod: ThunderstoreMod, version: Thu
throw installError;
}

const newModList: ManifestV2[] | R2Error = await ProfileModList.addMod(manifestMod, profile);
const newModList: ManifestV2[] | R2Error = await ProfileModList.addMod(manifestMod, profile.asImmutableProfile());
if (newModList instanceof R2Error) {
throw newModList;
}
Expand Down
Loading