Mac + FolderItem differences

  1. 5 weeks ago

    Derek D

    Sep 15 Pre-Release Testers Newnan, GA. USA
    Edited 5 weeks ago

    I'm trying to port my project from Windows to Mac (latest Mojave version), latest 2019 1.1 Xojo.

    I have some code here to load some info from a text file:

    #If DebugBuild
      f = GetFolderItem("").Parent.Child("streets.txt")
    #Else
      f = GetFolderItem("streets.txt")
    #EndIf
    
    Dim t As textinputstream = textinputstream.open(f)

    This loads from the text file regardless if its a debug build or the actual compiled product. This fails on a Mac with a IOException 2 error, but works fine with Windows 10. The textinputstream line is the one that fails.

    The text file i'm loading is in the same folder as the Xojo main project file and is in the project itself too. How would I change this to work on a Mac?

    I recommend the FindFile function I use in a lot of MBS examples to find files in the same place as the app:

    Function FindFile(name as string) As FolderItem
    			// Look for file in parent folders from executable on
    			
    			dim parent as FolderItem = app.ExecutableFile.Parent
    			
    			while parent<>Nil
    				
    				dim file as FolderItem = parent.Child(name)
    				
    				if file<>Nil and file.Exists then
    					Return file
    				end if
    				
    				parent = parent.Parent
    			wend
    		End Function
  2. Christian S

    Sep 15 Pre-Release Testers, Xojo Pro, XDC Speakers, Third Party Store Answer Germany

    I recommend the FindFile function I use in a lot of MBS examples to find files in the same place as the app:

    Function FindFile(name as string) As FolderItem
    			// Look for file in parent folders from executable on
    			
    			dim parent as FolderItem = app.ExecutableFile.Parent
    			
    			while parent<>Nil
    				
    				dim file as FolderItem = parent.Child(name)
    				
    				if file<>Nil and file.Exists then
    					Return file
    				end if
    				
    				parent = parent.Parent
    			wend
    		End Function
  3. Derek D

    Sep 15 Pre-Release Testers Newnan, GA. USA

    Ok, thanks. How would I use this find my file 'streets.txt' for example? Would using this solve my issue on Mac?

  4. Dave S

    Sep 15 San Diego, California USA

    It would be better still to NOT store your datafiles "next" to the app, and store them in the folders specifically designated for them

  5. Derek D

    Sep 15 Pre-Release Testers Newnan, GA. USA

    @Dave S It would be better still to NOT store your datafiles "next" to the app, and store them in the folders specifically designated for them

    Fair enough, but how do I make it work either way? It works perfectly in Windows, as I said, so its a Mac file access issue I can assume.

  6. Dave S

    Sep 15 San Diego, California USA

    @DerekDiBenedetto Fair enough, but how do I make it work either way? It

    put them in the correct place "APP Support?" and it works "either" way

  7. Christian S

    Sep 15 Pre-Release Testers, Xojo Pro, XDC Speakers, Third Party Store Germany
      f = FindFile("streets.txt")
    
    Dim t As textinputstream = textinputstream.open(f)

    That was my idea. Independent of platform look for the file next to the app.

    As I don't know what kind of app it is, I wouldn't judge on having files next to the app.

  8. Tim P

    Sep 15 Pre-Release Testers Rochester, NY

    @DerekDiBenedetto Fair enough, but how do I make it work either way? It works perfectly in Windows, as I said, so its a Mac file access issue I can assume.

    What you can do is use a CopyFiles step to copy the streets.txt file into your built application's resources folder. With that, use SpecialFolder.Resources to access the file.

    You can't commercially distribute a Mac app that tries to access files next to the app, Apple's security standards don't make it easy.

  9. Dave S

    Sep 15 San Diego, California USA

    One note about Tims response.... files in SPECIAL.RESOURCES cannot/should not be written to, only read

  10. Dave S

    Sep 15 San Diego, California USA

    @DerekDiBenedetto , End Function.

    leave that out... Xojo adds the method header and footer for you automatically

  11. Derek D

    Sep 15 Pre-Release Testers Newnan, GA. USA

    Dave...yep figured that out after a few. :)

  12. Derek D

    Sep 15 Pre-Release Testers Newnan, GA. USA

    It works! Thanks, Christian!

  13. Sam R

    Sep 15 Pre-Release Testers, Xojo Pro, Third Party Store Hengchun, Pingtung, Taiwan

    @DerekDiBenedetto This loads from the text file regardless if its a debug build or the actual compiled product. This fails on a Mac with a IOException 2 error, but works fine with Windows 10. The textinputstream line is the one that fails.

    The text file i'm loading is in the same folder as the Xojo main project file and is in the project itself too. How would I change this to work on a Mac?

    Don't do this for the Mac. Apple have guidelines on specific locations that executable code and non-executable code can be stored in. While your application will work when breaching these guidelines, Apple's code signing API some times throws hissy fits when files in the wrong place, which prevents you from releasing your application on the internet or via the Mac App Store.

    This causes all kinds of grief as you only find out when you try to release your application; and at that point you realize you need to redesign your app if you want to ship it on the Mac.

    Non-executable files should be stored in the "Resources" folder, and to create confusion, what Apple means in this context is non Mach-O binary files, so even script files should go in the "Resources" folder.

  14. Derek D

    Sep 15 Pre-Release Testers Newnan, GA. USA

    @Sam R Don't do this for the Mac. Apple have guidelines on specific locations that executable code and non-executable code can be stored in...which prevents you from releasing your application on the internet or via the Mac App Store.

    I figured as much. My app won't be on the App Store (it'll be sold elsewhere), so I won't have to worry about this much. But Windows 10 is sort of the same way with non .exe writable files needing to be elsewhere too (AppData usually).

  15. Sam R

    Sep 15 Pre-Release Testers, Xojo Pro, Third Party Store Hengchun, Pingtung, Taiwan

    @DerekDiBenedetto I figured as much. My app won't be on the App Store (it'll be sold elsewhere), so I won't have to worry about this much. But Windows 10 is sort of the same way with non .exe writable files needing to be elsewhere too (AppData usually).

    I apologize if I wasn’t clear; code signing is a process that you must complete in order to publically distribute your app. If you don’t code sign, most people will not be able to open your app. Regardless of where you sell it.

  16. Derek D

    Sep 16 Pre-Release Testers Newnan, GA. USA

    @Sam R I apologize if I wasn’t clear; code signing is a process that you must complete in order to publically distribute your app. If you don’t code sign, most people will not be able to open your app. Regardless of where you sell it.

    Yes, I see that. What exactly are the minimum steps required for this? I did check out Apple's site, but it isn't super clear. Do I need a $99 Dev Account to do this? I don't plan on submitting the app to the App Store.

  17. Beatrix W

    Sep 16 Pre-Release Testers, Third Party Store Europe (Germany)
    Edited 5 weeks ago

    Yes, you need a dev account. You only get the certificates if you have the account. App Store or no App Store you need to pay the 99$/year Apple tax.

    Check out the forum for threads about "my certificates stopped working". Everyone goes through that in some form. The explanations are confusing, convoluted and usually outdated. It's intense fun.

  18. Tim S

    Sep 16 Canterbury, UK

    I can recommend Sam's AppWrapper app, which will code-sign and notarise your app. It did mine the other day and rather to my astonishment the whole process was successful. I was faintly expecting an e-mail back from Apple saying my certs had all been cancelled and self-destruct had been initiated on all my Macs.

or Sign Up to reply!