Commit 5b301a30 authored by Gregor Longariva's avatar Gregor Longariva 💬
Browse files

Merge branch '18-networksharemounter-mountpfad' into 'dev'

Resolve "networkShareMounter Mountpfad"

Closes #18

See merge request faumac/networkShareMounter!23
parents becbf217 397b7eaf
......@@ -11,7 +11,7 @@
<key>de.fau.rrze.NetworkShareMounter</key>
<string>Network Share Mounter</string>
<key>de.fau.rrze.NetworkShareMounter-LaunchAtLoginHelper</key>
<string>de.fau.rrze.NetworkShareMounter-LaunchAtLoginHelpe</string>
<string>de.fau.rrze.NetworkShareMounter-LaunchAtLoginHelper</string>
</dict>
<key>signingCertificate</key>
<string>Developer ID Application</string>
......
......@@ -10,6 +10,10 @@
<true/>
<key>helpURL</key>
<string></string>
<key>location</key>
<string></string>
<key>cleanupLocationDirectory</key>
<false/>
<key>customNetworkShares</key>
<array/>
</dict>
......
......@@ -40,9 +40,10 @@ typealias MountCallbackHandler = (Int32, URL?, [String]?) -> Void;
class Mounter {
var localizedFolder: String
var localizedFolder = Settings.translation[Locale.current.languageCode!] ?? Settings.translation["en"]!
var mountpath: String
let fm = FileManager.default
let userDefaults = UserDefaults.standard
//let url: URL
fileprivate var asyncRequestId: AsyncRequestID?
......@@ -50,10 +51,15 @@ class Mounter {
init() {
// create subfolder in home to mount shares in
self.localizedFolder = Settings.translation[Locale.current.languageCode!] ?? Settings.translation["en"]!
self.mountpath = NSString(string: "~/\(localizedFolder)").expandingTildeInPath
if let userDefaultsLocation = userDefaults.string(forKey: "location") {
self.mountpath = NSString(string: userDefaults.string(forKey: "location")!).expandingTildeInPath
} else {
self.mountpath = NSString(string: "~/\(self.localizedFolder)").expandingTildeInPath
}
do {
//
// try to create (if not exists) the directory where the network shares will be mounted
if !fm.fileExists(atPath: mountpath) {
try fm.createDirectory(atPath: mountpath, withIntermediateDirectories: false, attributes: nil)
NSLog("\(mountpath): created")
......@@ -126,32 +132,37 @@ extension Mounter {
// if directory is a regular directory go on
if !isDirectoryFilesystemMount(atPath: path.appendingPathComponent(filePath)) {
//
// if the function has a parameter we want ot hanlde files
if let unwrappedFilename = filename {
if !isDirectoryFilesystemMount(atPath: path.appendingPathComponent(filePath)) {
let deleteFile = path.appendingPathComponent(filePath).appendingPathComponent(unwrappedFilename)
if fm.fileExists(atPath: deleteFile) {
NSLog("Deleting obstructing file \(deleteFile)")
try fm.removeItem(atPath: deleteFile)
// Clean up directories only if defined in userdefaults
if userDefaults.bool(forKey: "cleanupLocationDirectory") == true {
//
// if the function has a parameter we want ot handle files
if let unwrappedFilename = filename {
if !isDirectoryFilesystemMount(atPath: path.appendingPathComponent(filePath)) {
let deleteFile = path.appendingPathComponent(filePath).appendingPathComponent(unwrappedFilename)
if fm.fileExists(atPath: deleteFile) {
NSLog("Deleting obstructing file \(deleteFile)")
try fm.removeItem(atPath: deleteFile)
}
}
} else {
//
// else we have a directory to remove
// delete directories only if the direcotry/location of the mountpoints
let deleteFile = path.appendingPathComponent(filePath)
let task = Process()
task.launchPath = "/bin/rmdir"
task.arguments = ["\(deleteFile)"]
let pipe = Pipe()
task.standardOutput = pipe
//
// Launch the task
task.launch()
//
// Get the data
let data = pipe.fileHandleForReading.readDataToEndOfFile()
let output = NSString(data: data, encoding: String.Encoding.utf8.rawValue)
NSLog("Deleting obstructing directory \(deleteFile): \(output ?? "done")")
}
} else {
//
// else we have a directory to remove
let deleteFile = path.appendingPathComponent(filePath)
let task = Process()
task.launchPath = "/bin/rmdir"
task.arguments = ["\(deleteFile)"]
let pipe = Pipe()
task.standardOutput = pipe
//
// Launch the task
task.launch()
//
// Get the data
let data = pipe.fileHandleForReading.readDataToEndOfFile()
let output = NSString(data: data, encoding: String.Encoding.utf8.rawValue)
NSLog("Deleting obstructing directory \(deleteFile): \(output ?? "done")")
}
} else {
//
......@@ -173,7 +184,7 @@ extension Mounter {
//
// rudimentary check for XXX-1, XXX-2, ... mountdirs
// sure, this could be done better (e.g. regex mathcing), but I don't think it's worth thinking about
for count in 1...10 {
for count in 1...20 {
if filePath.contains(shareMountDir + "-\(count)") {
NSLog("Duplicatre mount of \(share): it is already mounted as \(path.appendingPathComponent(filePath)). Trying to unmount...")
unmountShare(atPath: path.appendingPathComponent(filePath))
......
......@@ -29,8 +29,13 @@ For an easier configuration of all the preference keys without creating or modif
| `canQuit` | Boolean | if set, the user can quit the app | true | v2 | optional ||
| `canChangeAutostart` | Boolean | if set to false, the user can not change the Autostart option | true | v2 | optional ||
| `unmountOnExit` | Boolean | if set to false the shares will be mounted after quitting the app | true | v2 | optional ||
| `location` | String | This is the path under which the shares will be mounte | - | v2 | optional | `/Volumes` |
| `cleanupLocationDirectory` | Boolean | if set to true the mount location will be cleaned up from obstructing files and directories. Use with caution! | false | v2 | - | `false` |
| `helpURL` | String | configure a help URL to help users interact with the application | - | v2 | optional |https://www.anleitungen.rrze.fau.de/betriebssysteme/apple-macos-und-ios/macos/#networksharemounter|
If `location` is left empty (or is not defined), a directory is created in a subdirectory of the user's home where the network drives will be mounted. Since this directory always contains only mounted network shares, there is a routine that cleans up this directory and deletes unnecessary files and directories.
If another directory is used to mount the network drives (like `location` set to, for example, `/Volumes`) **it is strongly recommended** to disable the cleanup routine by setting `cleanupLocationDirectory` to `false`.
### Screenshots
Screenshots of our Network Share Mounter app. On the left the menu bar icon with the mount, unmount and quit options. On the right the configuration window with the custom network share list:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment