Is there a way to detect when user opens file from a network share vs. a local drive?
At least I could warn them that it might cause an issue with their files.
Is there a way to detect when user opens file from a network share vs. a local drive?
At least I could warn them that it might cause an issue with their files.
On Windows, you can call the API function GetDriveType using the drive from the file path. The return value will tell you whether the drive type is remote, removable, etc. I don’t know whether there is an equivalent API call on OSX and on Linux, but I would assume so.
Mac? Win? Linux?
Mac or Windows. Not offering Linux app.
I have GetDriveType in my plugins:
GetDriveTypeMBS(path as string) as integer
So something like
if GetDriveTypeMBS(file.nativePath) = 4 then
msgbox "network drive"
end if
for Mac OS X:
[code] dim f as FolderItem = GetFolderItem("/Volumes/Ablage1", FolderItem.PathTypeNative)
dim n as NSURLMBS = NSURLMBS.URLWithItem(f)
dim value as Variant
dim error as NSErrorMBS
dim Local as Boolean
// network volumes are not local
if n.getResourceValue(value, n.NSURLVolumeIsLocalKey, error) then
MsgBox "Local: "+value.StringValue
Local = value.BooleanValue
else
MsgBox error.LocalizedDescription
end if
// network volumes have an URL
if n.getResourceValue(value, n.NSURLVolumeURLForRemountingKey, error) then
MsgBox "URLForRemounting: "+value.StringValue
else
MsgBox error.LocalizedDescription
end if[/code]
As Louis pointed out, here’s the code for windows if you haven’t picked up Christian’s excellent MBS Win Plugin yet:
https://msdn.microsoft.com/en-gb/library/windows/desktop/aa364939(v=vs.85).aspx
Public Function GetDriveType(path As String) as Integer
Declare Function GetDriveType Lib "Kernel32.dll" Alias "GetDriveTypeW" (lpRootPathName As WString) As UInt32
Return GetDriveType(path) 'Supply path with or without trailing \\ i.e. C:\\ or C:
End Function
I used this and on Windows opened a file from a SharedDocs on another windows computer on my network.
It did not flag it as from a “network drive”. Does a “network drive” have to be a mapped drive?
This file I opened is accessed via network → the computer name → SharedDocs folder
Interesting, when you navigate to this SharedDocs folder, what address do you see at the top of the explorer window and what does it change to when you click into it?
I see this… where powerhorse08 is the name of the other computer.
NETWORK > POWERHORSE08 > SHAREDDOCS
If I click on it then it changes to:
\\POWERHORSE08\SharedDocs
Ahh, you do need the trailing \ on the end. If I run my code above and send
system.DebugLog(str(GetDriveType("\\backup\backup"))) it returns 1
but if I send
system.DebugLog(str(GetDriveType("\\backup\backup"))) it reutrns 4
This might be the problem you’re getting.
Christian might want to update his doc there, I did wonder at the time as the MSDN poted above says it needed the trailing \
I’m using his builtin MBS function code:
if GetDriveTypeMBS(file.nativePath) = 4 then
msgbox "network drive"
end if
So do I manually add a trailing “/” to nativepath?
if GetDriveTypeMBS(file.nativePath + "\") = 4 then
msgbox "network drive"
end if
If there isnt one, then yes
One problem with this… I had a guy running our app in parallels and the path
then is
//Mac/then the long path
Thus my “check” for network gets triggered even though he is not on a network.
I guess I have to check for //Mac and exclude those cases.
Good to know. All windows UNC’s use backslash, not forward slash, if it contains a forward slash then burn it with fire daintily work around it.
Sorry I just typed it in wrong. Thanks.
Ah ok. You might want to make sure that MAC isn’t a user customisable name.
YOu are right. Didn’t think of that. But then it would be hard to tell when to not show the warning… as how would I tell they are running in Parallels? I will search the boards to see if anyone has a way to do that.