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
Problem porting from PC to Mac
Re: Problem porting from PC to Mac
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
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: Problem porting from PC to Mac
I did and it looks greatmk-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.
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
Code: Select all
#!/bin/bash
cp -rf Contents $1
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.
-
- Addict
- Posts: 1309
- Joined: Fri Aug 28, 2015 6:10 pm
- Location: Portugal
Re: Problem porting from PC to Mac
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.
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:-
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.
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.
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.
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
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:-
Notice that there is no Resources folder.Display Image (01).app
├── Contents
│ ├── Info.plist
│ ├── MacOS
│ ├── DisplayImage(01) - - - - This is your executable
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.
6. Step back to your main folder and double click the Display Image (01a).app to run the application and the image is displayed.Display Image (01a).app
├── Contents
│ ├── Info.plist
│ ├── MacOS
│ ├── DisplayImage(01) - - - - This is your executable
│ ├── Resources
│ ├─── 550.jpg
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"
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.
Re: Problem porting from PC to Mac
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
Small Path Helper
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
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
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive