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

Newly select data directories can be reselected at a later date #1026

Merged
merged 1 commit into from
May 20, 2023
Merged
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
16 changes: 12 additions & 4 deletions src/pages/Manager.vue
Original file line number Diff line number Diff line change
Expand Up @@ -535,13 +535,21 @@ import CategoryFilterModal from '../components/modals/CategoryFilterModal.vue';
buttonLabel: 'Select Data Folder'
}).then(async files => {
if (files.length === 1) {
const dataDirectoryOverrideFile = ".ddir.mm";
const filesInDirectory = await fs.readdir(files[0]);
if (filesInDirectory.length > 0 && files[0] !== PathResolver.APPDATA_DIR) {
this.showError(new R2Error("Selected directory is not empty", `Directory is not empty: ${files[0]}. Contains ${filesInDirectory.length} files.`, "Select an empty directory or create a new one."));
return;
} else {

const hasOverrideFile = filesInDirectory.find(value => value.toLowerCase() === dataDirectoryOverrideFile) != undefined;
const directoryHasContents = filesInDirectory.length > 0;
const isDefaultDataDirectory = files[0] === PathResolver.APPDATA_DIR;

if (hasOverrideFile || !directoryHasContents || isDefaultDataDirectory) {
await this.settings.setDataDirectory(files[0]);
// Write dataDirectoryOverrideFile to allow re-selection of directory if changed at a later point.
await fs.writeFile(path.join(files[0], dataDirectoryOverrideFile), "");
InteractionProvider.instance.restartApp();
} else {
this.showError(new R2Error("Selected directory is not empty", `Directory is not empty: ${files[0]}. Contains ${filesInDirectory.length} files.`, "Select an empty directory or create a new one."));
return;
}
}
});
Expand Down