diff --git a/electron.js b/electron.js index 00f26a2..fb93e0f 100644 --- a/electron.js +++ b/electron.js @@ -261,6 +261,29 @@ ipcMain.on(Constants.IPC_Check_Installed, (event, data) => { }); }); +ipcMain.on(Constants.IPC_Check_Mount_Location, (event, data) => { + let response = { + Success: true, + Error: '' + }; + + try { + if (fs.existsSync(data.Location) && fs.statSync(data.Location).isDirectory()) { + if (fs.readdirSync(data.Location).length !== 0) { + response.Success = false; + response.Error = 'Directory not empty: ' + data.Location; + } + } else { + response.Success = false; + response.Error = 'Directory not found: ' + data.Location; + } + } catch (e) { + response.Success = false; + response.Error = e.toString(); + } + event.returnValue = response; +}); + ipcMain.on(Constants.IPC_Delete_File, (event, data) => { try { if (fs.existsSync(data.FilePath)) { diff --git a/src/App.js b/src/App.js index 02ce71c..1bd8781 100644 --- a/src/App.js +++ b/src/App.js @@ -656,7 +656,7 @@ class App extends Component { dependencies={this.state.MissingDependencies} onDownload={this.handleDependencyDownload}/> - ) + ); } let downloadDisplay = null; @@ -665,7 +665,8 @@ class App extends Component { - ); + + ); } let upgradeDisplay = null; diff --git a/src/constants.js b/src/constants.js index 8f86720..4d0a498 100644 --- a/src/constants.js +++ b/src/constants.js @@ -27,6 +27,8 @@ exports.IPC_Check_Dependency_Installed_Reply = 'check_dependency_installed'; exports.IPC_Check_Installed = 'check_installed'; exports.IPC_Check_Installed_Reply = 'check_installed_reply'; +exports.IPC_Check_Mount_Location = 'check_mount_location'; + exports.IPC_Delete_File = 'delete_file'; exports.IPC_Detect_Mounts = 'detect_mounts'; diff --git a/src/containers/MountItems/MountItems.js b/src/containers/MountItems/MountItems.js index 7756370..7ba698f 100644 --- a/src/containers/MountItems/MountItems.js +++ b/src/containers/MountItems/MountItems.js @@ -58,34 +58,51 @@ class MountItems extends Component { }; handleMountUnMount = (storageType, mount, location) => { - if (ipcRenderer) { - const state = { - ...this.state[storageType], - AllowMount: false, - }; - - this.props.mountsBusy(true); - - this.setState({ - [storageType]: state, - }, ()=> { - if (mount) { - ipcRenderer.send(Constants.IPC_Mount_Drive, { - Directory: this.props.directory, + if (!location || (location.trim().length === 0)) { + this.props.errorHandler('Mount location is not set'); + } else { + if (ipcRenderer) { + let allowAction = true; + if (mount && (this.props.platform !== 'win32')) { + const result = ipcRenderer.sendSync(Constants.IPC_Check_Mount_Location, { Location: location, - NoConsoleSupported: this.props.noConsoleSupported, - StorageType: storageType, - Version: this.props.version, }); - } else { - ipcRenderer.send(Constants.IPC_Unmount_Drive, { - Directory: this.props.directory, - Location: location, - StorageType: storageType, - Version: this.props.version, + if (!result.Success) { + allowAction = false; + this.props.errorHandler(result.Error.toString()); + } + } + + if (allowAction) { + const state = { + ...this.state[storageType], + AllowMount: false, + }; + + this.props.mountsBusy(true); + + this.setState({ + [storageType]: state, + }, () => { + if (mount) { + ipcRenderer.send(Constants.IPC_Mount_Drive, { + Directory: this.props.directory, + Location: location, + NoConsoleSupported: this.props.noConsoleSupported, + StorageType: storageType, + Version: this.props.version, + }); + } else { + ipcRenderer.send(Constants.IPC_Unmount_Drive, { + Directory: this.props.directory, + Location: location, + StorageType: storageType, + Version: this.props.version, + }); + } }); } - }); + } } };