Skip to content

Commit

Permalink
Merge branch 'develop' into code-export-file-busy
Browse files Browse the repository at this point in the history
  • Loading branch information
MythicManiac authored Mar 5, 2024
2 parents b155286 + 24f760e commit 6c98fca
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
4 changes: 0 additions & 4 deletions src/pages/Manager.vue
Original file line number Diff line number Diff line change
Expand Up @@ -638,10 +638,6 @@ import CategoryFilterModal from '../components/modals/CategoryFilterModal.vue';
// accesses visibleModList from Vuex store.
await this.$store.dispatch('profile/loadOrderingSettings');
// Reset the mod list to prevent the previous profile's list
// flashing on the screen while a new profile's list is loaded.
await this.$store.dispatch('profile/updateModList', []);
// Used by OnlineModView, called here for consistency.
this.$store.commit('modFilters/reset');
}
Expand Down
4 changes: 4 additions & 0 deletions src/pages/Profiles.vue
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,10 @@ export default class Profiles extends Vue {
}
async setProfileAndContinue() {
// Reset the mod list to prevent the previous profile's list
// flashing on the screen while a new profile's list is loaded.
await this.$store.dispatch('profile/updateModList', []);
await settings.setProfile(Profile.getActiveProfile().getProfileName());
await this.$router.push({name: 'manager.installed'});
}
Expand Down
15 changes: 15 additions & 0 deletions src/r2mm/mods/ProfileModList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { ProfileApiClient } from '../profiles/ProfilesClient';
export default class ProfileModList {

public static SUPPORTED_CONFIG_FILE_EXTENSIONS = [".cfg", ".txt", ".json", ".yml", ".yaml", ".ini"];
public static readonly MAX_EXPORT_AS_CODE_SIZE = 20000000; // 20MB

private static lock = new AsyncLock();

Expand Down Expand Up @@ -257,6 +258,20 @@ export default class ProfileModList {
return R2Error.fromThrownValue(e);
}

const zipStats = await fs.lstat(exportPath);
if (zipStats.size > this.MAX_EXPORT_AS_CODE_SIZE) {
const zipSize = FileUtils.humanReadableSize(zipStats.size);
const maxSize = FileUtils.humanReadableSize(this.MAX_EXPORT_AS_CODE_SIZE);
const fileTypes = this.SUPPORTED_CONFIG_FILE_EXTENSIONS.join(', ');
const configFolder = path.join(profile.getPathOfProfile(), 'BepInEx', 'config');
return new R2Error(
'The profile is too large to be exported as a code',
`Exported profile size is ${zipSize} while the maximum supported size is ${maxSize}.
Exported profile includes ${fileTypes} files and all the contents of ${configFolder}`,
'You can still try exporting the profile as a file from the settings view.'
);
}

const profileBuffer = '#r2modman\n' + (await fs.base64FromZip(exportPath));
try {
const storageResponse = await ProfileApiClient.createProfile(profileBuffer);
Expand Down
16 changes: 16 additions & 0 deletions src/utils/FileUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,20 @@ export default class FileUtils {
return Promise.resolve();
}

public static humanReadableSize(bytes: number) {
// NumberFormat renders GBs as BBs ("billion bytes") when using "byte" unit type.
if (bytes > 999999999 && bytes < 1000000000000) {
return `${(bytes / 1000000000).toLocaleString(undefined, {
minimumFractionDigits: 1,
maximumFractionDigits: 1,
})} GB`;
}

return Intl.NumberFormat("en", {
notation: "compact",
style: "unit",
unit: "byte",
unitDisplay: "narrow",
}).format(bytes);
};
}

0 comments on commit 6c98fca

Please sign in to comment.