AbsolutePathClassic - bad idea?

One of my apps has been saving folderItem.AbsolutePath in both configuration files and document files for years. No problems.

Since AbsolutePath is now deprecated in 2019r2, I should switch to NativePath, but that would break all previous MacOS versions of my app and create general havoc.

Is there anything wrong with continuing to support the existing file format by providing my own AbsolutePath function? It seems to work OK. Are there any problems I’m not foreseeing?

[code]Function AbsolutePath (extends f as FolderItem) as string

if f=nil then return “”

#if TargetWindows
//in windows absolute and native are same
Return f.NativePath
#Else
//macOS, so walk the folderitem to create the path using “:”
Dim c as FolderItem = f
Dim s as String
Do
s = c.Name + “:” + s
c=c.Parent
Loop until c=nil
Return s
#Endif

End Function[/code]

If you use MBS Xojo Plugins, you can check NewFolderItemFromAbsolutePathMBS function.

see AbsolutePath for Xojo in blog.

It works - for now. It’s deprecated in the macOS API, but still available.
As long as Apple supports the deprecated functions, you’re ok. There may/will be a time in the (distant?) future where you might need to go forward and convert from AbsolutePath to NativePath.

This is how I would do it: use it from Xojo Framework in earlier versions. Use macOS API, otherwise (Windows/Linux) it’s the same as NativePath:

[code]Public Function AbsolutePathClassic(Extends poFolderItem As FolderItem) as String
If (poFolderItem = Nil) Then Return “”

#If (XojoVersion < 2019.02) Then
Return poFolderItem.AbsolutePath

#Else
'Xojo 2019r2 has removed .AbsolutePath
#If TargetMacOS Then

  Declare Function NSClassFromString Lib "Cocoa" (className As CFStringRef) As Ptr
  Declare Function fileURLWithPath Lib "Foundation" selector "fileURLWithPath:" (ptrNSURLClass As Ptr, path As CFStringRef) As Ptr
  Declare Function CFURLCopyFileSystemPath Lib "Foundation" (anURL As Ptr, pathStyle As Int32) As CFStringRef
  
  Const kCFURLPOSIXPathStyle = 0
  Const kCFURLHFSPathStyle = 1
  
  Dim ptrNSURLClass As Ptr = NSClassFromString("NSURL")
  Dim ptrNSURL As Ptr = fileURLWithPath(ptrNSURLClass, poFolderItem.NativePath)
  
  Dim sRes As String = CFURLCopyFileSystemPath(ptrNSURL, kCFURLHFSPathStyle)
  If poFolderItem.Directory And (Right(sRes, 1) <> ":") Then sRes = sRes + ":"
  Return sRes
  
#Else
  Return poFolderItem.NativePath
  
#EndIf

#EndIf
End Function[/code]

And just in case… if Xojo decides to remove the functionality to get a FolderItem from an AbsolutePath, then this would be the way it works using current (deprecated, but still fully functional) macOS API:

[code]Public Function GetFolderItemFromAbsolutePath(psAbsolutePath As String) as FolderItem
Dim sNativePath As String

#If TargetMacOS Then

Declare Function CFURLCopyFileSystemPath Lib "Foundation" (anURL As Ptr, pathStyle As Int32) As CFStringRef
Declare Function CFURLCreateWithFileSystemPath Lib "Foundation" (CFURLCreateWithFileSystemPath As Ptr, filePath As CFStringRef, pathStyle As Int32) As Ptr

Const kCFURLPOSIXPathStyle = 0
Const kCFURLHFSPathStyle = 1

Dim ptrNSURL As Ptr = CFURLCreateWithFileSystemPath(nil, psAbsolutePath, kCFURLHFSPathStyle)
sNativePath = CFURLCopyFileSystemPath(ptrNSURL, kCFURLPOSIXPathStyle)

#Else
'Windows, Linux: NativePath is the same as Xojo’s deprecated AbsolutePath
sNativePath = psAbsolutePath

#EndIf

Return New FolderItem(sNativePath, FolderItem.PathTypeNative)

End Function[/code]

I’ve even tried to play with AbsolutePath’s with macOS Catalina. No issue at all.
I don’t see the reason why Xojo has removed it from their framework.
Anyway - do it yourself (see Declares above), or use a Plugin.
It still works… for now, and most likely for quite some time to come.

Some reading:

http://www.westwind.com/reference/OS-X/paths.html

I believe the colon is going away because at long last, Apple has decided to do away with the old Mac OS notation.

Thanks guys. Good info.