Strange File Path

OK, I understand that the image file should not be beside the application. However, the problem is not only with the image file path, but already in
app_path=GetFolderItem("")

app_path does contain following values:

AbsolutePath:

NativePath:

ShellPath:

URLPath:

Does this mean that my app is banned and that I need to use native path ?

Stop using AbsolutePath.

What the other paths tell you is that effectively, your app is translocated. That is the reason why you did not find your files.

https://duckduckgo.com/?q=what+is+apple+macos+translocation&ia=web

[quote=389431:@Lukas Paul Truninger]OK, I understand that the image file should not be beside the application. However, the problem is not only with the image file path, but already in
app_path=GetFolderItem("")
[/quote]
Basically, you need to design as if GetFolderItem("") isn’t a thing.

OK, I have now following code. If I run on older Mac, then “PathTypeNative” does return NIL, so I made a backwards compatibility using PathTypeAbsolute. This works so far. But when using Native Path, I do get an IOExeption in " read_stream=BinaryStream.Open(LoaderFile1,false)"

I think this is because tle LoaderFile shall not be next to the application?? Thus I did try to put it in a folder. However, following line of code does not work:
LoaderFile1=app_path.Child(“fw_update”).Child(LoaderFilePath1)

?? How do I need to create the file path?
If I write only
LoaderFile1=app_path.Child(LoaderFilePath1)
the child is added to the file path. But as soon as I write
LoaderFile1=app_path.Child(…).Child(…)
childs are not added at all to filepath …

[code] app_path=GetFolderItem("", FolderItem.PathTypeNative)
if app_path = Nil then
app_path=GetFolderItem("", FolderItem.PathTypeAbsolute) // backward compatibility
if app_path = Nil then
MsgBox(“Filepath not found. Please contact Prostage”)
return False
else
//MsgBox("Absolut Path: " + app_path.AbsolutePath )
end if
else
//MsgBox("Native Path: " + app_path.NativePath )
end if

LoaderFile1=app_path.Child("fw_update").Child(LoaderFilePath1)

if LoaderFile1.exists then
  read_stream=BinaryStream.Open(LoaderFile1,false)
else
  MsgBox("Loader file is missing: " + LoaderFile1.NativePath )
end if[/code]

… I did also try using
app_path=SpecialFolder.CurrentWorkingDirectory
as decribed on
https://documentation.xojo.com/index.php/SpecialFolder
But this path does only contain “MacintoshHD:” which is definitely not the folder of Current Working Directory…

Sigh.

[quote]You need to package your app the correct way.
Resources should be internal, not next to the app[/quote]

I assume you have a good reason for ignoring this.
Would you like to tell us what the reason is?

Also, try adding this to the app Open event:

//fix for quarantine in osx10.12 Dim Terminal as new shell Terminal.Mode=1 Terminal.Execute("xattr -dr com.apple.quarantine "+app.ExecutableFile.Parent.Parent.Parent.ShellPath) do app.doEvents(5) loop until not terminal.IsRunning

This is exactly what I’m trying to do, but so far no one told me how to do and it’s hard to find some useful instructions online. Also, Xojo online documentation is soooo dodgy …

Sigh… please re-read about “app translocation”. This has nothing to do with Xojo but is a macOS issue. You need to sign your app and the dmg file. Then you need to check if you have “applications” in the path to getfolderitem(""). You also have to put your internal files INTO the app and not next to it.

How to do this?

How to do this? Is this part of DropDMG.app?

On app signing: either see https://successfulsoftware.net/2012/08/30/how-to-sign-your-mac-os-x-app-for-gatekeeper/ or use AppWrapper. This is very very painful process. It gives odd errors and sometimes it fails without errors.

On putting files into your app: either you drag them directly into your Xojo project. I think they then end up in the resources folder. Or you use a CopyFile script step. There you have more control over where your files and up and you can set if the copying is to be done for build or debug.

They do.

I have a function which returns a folderitem for this folder:

[code]function SpecialFolderResources() as folderitem
dim f as folderitem
#if targetMacOS
f =app.ExecutableFile.Parent.Parent.Child(“Resources”)
#else
#if debugBuild
f =app.executableFile.parent.child(“DebugMyApp Resources”)
#else
f =app.ExecutableFile.Parent.Child(“MyApp Resources”)
#endif
#endif

if f = nil or f.exists = false then
f = GetFolderItem(“”) //or NIL… take your pick…
end if
return f
end function
[/code]

so using that as a guide, you can copy files which it contains to specialfolder.temporary and use the copy

If what you drag is a text file, you can use the name (no file extension) as a read-only string
If what you drag is a picture, you can use it as a read-only picture

Anything else, you probably need to either save out using a binarystream, or use the resources folder.child and perform an actual file copy to applicationdata

Tim J. above, thank you very much for the suggestions. :slight_smile:

Thanx for the tips about drag and drop the files. I did test this, and so far I understand that:

  • drag and drop does not copy the file into my xojo project, but only make an alias
  • on build, the file is included with the app. But I’m still not sure if this will copy the file into the app, or into a special resource folder somewhere on harddisk? If 2nd applies, then I will need an installer to distribute the application, right?
  • Also, I did not figure out so far how to access the files once they are in resource folder?
  1. Yes, the files aren’t copied into the project, only the app.

  2. Ahem, how much experience to do have with macOS? Select a random app and do a “show contents” in the content menu. You can put all types of stuff into an app. And no, no installer needed.

  3. Code was given before:

[code]function SpecialFolderResources() as folderitem
dim f as folderitem
#if targetMacOS
f =app.ExecutableFile.Parent.Parent.Child(“Resources”)
#else
#if debugBuild
f =app.executableFile.parent.child(“DebugMyApp Resources”)
#else
f =app.ExecutableFile.Parent.Child(“MyApp Resources”)
#endif
#endif

if f = nil or f.exists = false then
f = GetFolderItem("") //or NIL… take your pick…
end if
return f
end function[/code]

[quote=389674:@Lukas Paul Truninger]Thanx for the tips about drag and drop the files. I did test this, and so far I understand that:

  • drag and drop does not copy the file into my xojo project, but only make an alias
  • on build, the file is included with the app. But I’m still not sure if this will copy the file into the app, or into a special resource folder somewhere on harddisk? If 2nd applies, then I will need an installer to distribute the application, right?
  • Also, I did not figure out so far how to access the files once they are in resource folder?[/quote]

It looks like an “alias” because the IDE shows the name in italics.

It gets put into the “Resources” folder in your app bundle. As Beatrix says, you can view this folder by selecting your compiled app in the Finder, right-clicking, and selecting “Show Package Contents”.

You just access the file by its name. Say you drag something called MyPic.png into the IDE. You can then use it, for example, like this:

Canvas1.backdrop = MyPic

Autocomplete should work as you type.

Please use the TPSF module for that. It uses declares to get the folder the correct way on macOS (thanks, Sam!)
It also features the other CopyFiles step locations, and takes the maintenance portion off of you :slight_smile:

Not this again! :smiley: