From 744143e66cf794fa650bc97e968483663f834034 Mon Sep 17 00:00:00 2001 From: Evandro Araujo Date: Tue, 27 Apr 2021 02:00:08 -0300 Subject: [PATCH 1/3] Initial support for auto drive letter --- src/renderer/ProcessHandlerWin.js | 28 +++++++++++++++++-- .../AddEditConnectionWindow/index.vue | 3 +- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/renderer/ProcessHandlerWin.js b/src/renderer/ProcessHandlerWin.js index f577e5a..8deb29a 100644 --- a/src/renderer/ProcessHandlerWin.js +++ b/src/renderer/ProcessHandlerWin.js @@ -9,14 +9,20 @@ class ProcessHandlerWin { } create (conn) { - return new Promise((resolve, reject) => { + return new Promise(async (resolve, reject) => { if (this.settings.sshfsBinary.endsWith('sshfs-win.exe')) { this.settings.sshfsBinary = this.settings.sshfsBinary.replace(/sshfs-win\.exe$/, 'sshfs.exe') } + let mountPoint = conn.mountPoint + + if (mountPoint === 'auto') { + mountPoint = await this.getFirstAvailableDriveLetter() + } + let cmdArgs = [ `${conn.user}@${conn.host}:${conn.folder}`, - conn.mountPoint, + mountPoint, `-p${conn.port}`, `-ovolname=${conn.name.substr(0, 32)}`, '-odebug', @@ -216,6 +222,24 @@ class ProcessHandlerWin { }) }) } + + getFirstAvailableDriveLetter () { + return new Promise((resolve, reject) => { + exec(`wmic logicaldisk get name`, (err, stdout) => { + const driveLetters = 'DEFGHIJKLMNOPQRSTUVWXYZ'.split('') + + if (!err) { + const drivers = stdout.toString().trim().split('\n').slice(1) + .map(i => i.substr(0, 1).toUpperCase()) + const availableDriveLetters = driveLetters.filter(i => !drivers.includes(i)) + + resolve(availableDriveLetters[0] + ':') + } else { + reject(new Error('Process not found')) + } + }) + }) + } } export default ProcessHandlerWin diff --git a/src/renderer/components/AddEditConnectionWindow/index.vue b/src/renderer/components/AddEditConnectionWindow/index.vue index 9c43f3b..5a9b07e 100644 --- a/src/renderer/components/AddEditConnectionWindow/index.vue +++ b/src/renderer/components/AddEditConnectionWindow/index.vue @@ -62,6 +62,7 @@
@@ -167,7 +168,7 @@ export default { password: '', keyFile: process.env.USERPROFILE + '\\.ssh\\id_rsa', key: '', - mountPoint: 'E:', + mountPoint: 'auto', status: 'disconnected', pid: 0, advanced: { From 41e57830acd8c5b5da33735acc541af664f342c1 Mon Sep 17 00:00:00 2001 From: Evandro Araujo Date: Tue, 27 Apr 2021 02:25:15 -0300 Subject: [PATCH 2/3] Use the previously connected letter if possible --- src/renderer/ProcessHandlerWin.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/renderer/ProcessHandlerWin.js b/src/renderer/ProcessHandlerWin.js index 8deb29a..fbd3d0d 100644 --- a/src/renderer/ProcessHandlerWin.js +++ b/src/renderer/ProcessHandlerWin.js @@ -17,7 +17,9 @@ class ProcessHandlerWin { let mountPoint = conn.mountPoint if (mountPoint === 'auto') { - mountPoint = await this.getFirstAvailableDriveLetter() + mountPoint = await this.getFirstAvailableDriveLetter(conn.preferredMountPoint) + + conn.preferredMountPoint = mountPoint } let cmdArgs = [ @@ -223,7 +225,7 @@ class ProcessHandlerWin { }) } - getFirstAvailableDriveLetter () { + getFirstAvailableDriveLetter (preferredMountPoint = null) { return new Promise((resolve, reject) => { exec(`wmic logicaldisk get name`, (err, stdout) => { const driveLetters = 'DEFGHIJKLMNOPQRSTUVWXYZ'.split('') @@ -233,7 +235,11 @@ class ProcessHandlerWin { .map(i => i.substr(0, 1).toUpperCase()) const availableDriveLetters = driveLetters.filter(i => !drivers.includes(i)) - resolve(availableDriveLetters[0] + ':') + if (preferredMountPoint && availableDriveLetters.includes(preferredMountPoint.substr(0, 1))) { + resolve(preferredMountPoint) + } else { + resolve(availableDriveLetters[0] + ':') + } } else { reject(new Error('Process not found')) } From 0244699c6b948220b80ac6b4e5a01bbaab81341d Mon Sep 17 00:00:00 2001 From: Evandro Araujo Date: Tue, 27 Apr 2021 02:57:55 -0300 Subject: [PATCH 3/3] Modifications on UI to support auto drive letter --- .../components/MainWindow/ConnectionItem.vue | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/renderer/components/MainWindow/ConnectionItem.vue b/src/renderer/components/MainWindow/ConnectionItem.vue index 50e0bd5..09f2579 100644 --- a/src/renderer/components/MainWindow/ConnectionItem.vue +++ b/src/renderer/components/MainWindow/ConnectionItem.vue @@ -15,7 +15,7 @@
- {{conn.mountPoint}} + {{mountPointLabel}} @@ -26,7 +26,7 @@
- @@ -101,6 +101,16 @@ export default { showDeleteButton () { return this.mode === 'delete' && !this.isConnected && !this.isConnectingOrDisconnecting + }, + + mountPointLabel () { + if (this.isConnected && this.conn.mountPoint === 'auto') { + return `Auto (${this.conn.preferredMountPoint})` + } else if (this.conn.mountPoint === 'auto') { + return 'Auto' + } else { + return this.conn.mountPoint + } } } }