Problem porting from PC to Mac

Mac OSX specific forum
User avatar
mk-soft
Always Here
Always Here
Posts: 5313
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Problem porting from PC to Mac

Post by mk-soft »

I have long solved the problem with the folders and the APP resources with a mini tool. Probably no one has read it.

Link: viewtopic.php?f=19&t=76872#p566758
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
deseven
Enthusiast
Enthusiast
Posts: 362
Joined: Wed Jan 12, 2011 3:48 pm
Location: Serbia
Contact:

Re: Problem porting from PC to Mac

Post by deseven »

mk-soft wrote:I have long solved the problem with the folders and the APP resources with a mini tool. Probably no one has read it.
I did and it looks great :)
But i found it a bit too complicated. My typical project setup looks like that:

Code: Select all

.
├── Contents
│   ├── Info.plist
│   └── Resources
│       ├── image1.png
│       ├── image2.png
│       └── image3.png
├── app.pb
└── inject.sh
Where inject.sh is simply:

Code: Select all

#!/bin/bash

cp -rf Contents $1
Two tools must be set up like this:
Image
One for "After Compile/Run" and another for "After Create Executable".
Oh, and "Create temporary executable in the source directory" must be checked in compiler options.

That's it.
collectordave
Addict
Addict
Posts: 1309
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: Problem porting from PC to Mac

Post by collectordave »

I have also read it and it helped enormously.

The problem is in understanding the differences between a Windows executable and a MAC executable.

To explain the differences here is a practical example.

1. Create a folder 'Display Image' wherever you like to keep you PB programmes.

2. Create a sub folder in the display images folder called 'Resources'

3. Copy a jpg image of your choice to the Display Image/Resources folder. I used 550.jpg.

4. Start a new file with PB and copy the code below into the file.

Code: Select all

UseJPEGImageDecoder()

Global frmDisplayImage

Global imgDisplay

Global ImageFileName.s,ImageToDisplay.i

frmDisplayImage = OpenWindow(#PB_Any, 0, 0, 310, 330, "Display An Image", #PB_Window_SystemMenu)
imgDisplay = ImageGadget(#PB_Any, 20, 10, 270, 290, 0)

ImageFileName = "Resources/550.jpg"

ImageToDisplay = LoadImage(#PB_Any,ImageFileName)

SetGadgetState(imgDisplay,ImageID(ImageToDisplay))

Repeat
    Event = WaitWindowEvent()
    
  Until Event = #PB_Event_CloseWindow
5. Save the file as 'Display Image (01).pb

6. Change the ImageFileName in the code to the image you copied to the Resources folder.

7. Run the programme and your image will be displayed.

8. Compile the programme twice, the first time use Display Image(01).app, the second time use Display Image(01a).app.

This will leave you with two applications exactly the same just named differently.

Run each application and no image will be displayed!

Now to understand why no image?

Use Finder and right click on Image Display(01).app, select Show Package Contents and you should see the following:-
Display Image (01).app
├── Contents
│ ├── Info.plist
│ ├── MacOS
│ ├── DisplayImage(01) - - - - This is your executable
Notice that there is no Resources folder.

Again using Finder right click on Display Image (01a).app and you will see the same folder tree.

Now follow these steps:

1. Double click the 'Contents' folder it opens the folder.

2. Using finder create a new folder called 'Resources' in the contents folder.

3. Double click the new Resources folder.

4. Copy your image to this new resources folder

5. Step back to the Show package content display and it should look similar to this.
Display Image (01a).app
├── Contents
│ ├── Info.plist
│ ├── MacOS
│ ├── DisplayImage(01) - - - - This is your executable
│ ├── Resources
│ ├─── 550.jpg
6. Step back to your main folder and double click the Display Image (01a).app to run the application and the image is displayed.

The reason using ImageFileName = "Resources/550.jpg" fails when compiled in Display Image(01).app is that it looks for the Resources folder INSIDE the application which does not exist until you create it.

PB does provide another way to include images with an executable using a data section.

Create a new file with PB and copy the code below to this file as Display Image (02).pb, change the file name in the DataSection portion to your file name then run the application and the image is displayed.

Code: Select all

UseJPEGImageDecoder()

Global frmDisplayImage

Global imgDisplay

Global ImageFileName.s,ImageToDisplay.i

frmDisplayImage = OpenWindow(#PB_Any, 0, 0, 310, 330, "Display An Image", #PB_Window_SystemMenu)
imgDisplay = ImageGadget(#PB_Any, 20, 10, 270, 290, 0)

ImageToDisplay =CatchImage(#PB_Any, ?StartEnabled)

SetGadgetState(imgDisplay,ImageID(ImageToDisplay))

Repeat
    Event = WaitWindowEvent()
    
Until Event = #PB_Event_CloseWindow

DataSection
  StartEnabled:
    IncludeBinary "Resources/550.jpg"
Compile this application and then run and the image is displayed without adding a resources folder.

Now a few considerations if like me your application displays many images, currently I have nearly 12Gb of images to display, including these in the application would bloat the application to 12Gb plus. This makes no sense as it would take forever to load and run.

Include just the images for your application, such as button images or small images used for icons etc. in the application. The images which are data can be placed elsewhere, such as in the users Documents folder and accessed easily from there.
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
User avatar
mk-soft
Always Here
Always Here
Posts: 5313
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Problem porting from PC to Mac

Post by mk-soft »

Only files to be read belong in the programme folder.
Depending on the OS, there are separate folders for settings and user files belong in Documents (or where the user wants to store them).

You can make it difficult for yourself under macOS or do it the way deseven and I do. Have the required files copied onfy, via PB tools, into the APP folder.

My project structure

Code: Select all

./project_path
  -- Main.pb
  -- MyAppData
  -- -- Resources
  -- -- -- Images.png
  -- -- Library
  -- -- -- libxyz.dylib
Small Path Helper

Code: Select all

;- TOP

; Comment: Get Path Helper v1.02 by mk-soft

; Change names
#CompanyName = "mk-soft"
#ApplicationName = "MyApp"

Macro GetParentPath(Path)
  GetPathPart(RTrim(Path, #PS$))
EndMacro

Procedure.s GetProgramPath()
  Protected r1.s
  r1 = GetPathPart(ProgramFilename())
  CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
    r1 = GetParentPath(r1)
    r1 = GetParentPath(r1)
  CompilerEndIf
  ProcedureReturn r1
EndProcedure

Procedure.s GetResourcesPath()
  Protected r1.s
  r1 = GetPathPart(ProgramFilename())
  CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
    r1 = GetParentPath(r1)
  CompilerEndIf
  r1 + "Resources" + #PS$
  ProcedureReturn r1
EndProcedure

Procedure.s GetLibraryPath()
  Protected r1.s
  r1 = GetPathPart(ProgramFilename())
  CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
    r1 = GetParentPath(r1)
  CompilerEndIf
  r1 + "Library" + #PS$
  ProcedureReturn r1
EndProcedure

Procedure.s GetProgramDataPath()
  Protected basepath.s, subpath.s, datapath.s
  
  CompilerIf #PB_Compiler_OS = #PB_OS_Linux
    basepath = GetHomeDirectory()
    subpath = basepath + "." + #CompanyName + #PS$
  CompilerElse
    basepath = GetUserDirectory(#PB_Directory_ProgramData)
    subpath = basepath + #CompanyName + #PS$
  CompilerEndIf
  datapath = subpath  + #ApplicationName + #PS$
  If FileSize(datapath) <> -2
    If FileSize(subpath) <> -2
      CreateDirectory(subpath)
    EndIf
    If FileSize(datapath) <> -2
      CreateDirectory(datapath)
    EndIf
  EndIf
  ProcedureReturn datapath
EndProcedure

CompilerIf #PB_Compiler_IsMainFile
  Debug "Program Path: " + GetProgramPath()
  Debug "Program Resources Path: " + GetResourcesPath()
  Debug "Program Library Path: " + GetLibraryPath()
  Debug "Program Data Path: " + GetProgramDataPath()
CompilerEndIf
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply