hide resources

Archives Forums/MacOS X Discussion/hide resources

FantomKite(Posted 2009) [#1]
How to hide resources (sounds, images, and others) in the app-file, and so that app then could get these files?


Brucey(Posted 2009) [#2]
You can create a folder in the application bundle called Resources (if it isn't there already), and put your media in there.

In your application, you can access the folder using a line like this :
ExtractDir(AppFile) + "/../Resources"



Brucey(Posted 2009) [#3]
If you want to copy files into your app bundle as part of the build process, the default BlitzMax cannot do this.

You could create a command-line script, perhaps.
Or an AppleScript.
Or use a third-party enhancement to BlitzMax's build system which does support post build scripting as part of a normal build process.


Nigel Brown(Posted 2009) [#4]
This is probably a lot more than you are asking for but have been meaning to put this up for a while, for storage as much as anything else. I usually start a project by making it fully releasable from the start.

Here is a script that I created to build a releasable project you will need to do a little work to decipher what's going on. A little hint 'ProjectFolder' should be the name of the folder that your project resides in, and 'ProjectName' should be the released name of the project.

version.txt is a plain text file with 0.00.00 in it for the first build. the source to increment the version number is below, it is incremented when I build the PC version and the MacAutobuilder just reads it. Thank Brucey for the auto-incrementing version number code :-) Use code in main.bmx to extract the version number from the embedded file...

MacAutobuilder.sh
echo Getting the serial number
export VER=`cat /Volumes/ProjectFolder/media/version.txt`
echo $VER

echo Building Intel Source
'/Applications/BlitzMax/bin/bmk' makeapp -b bah.appstub -r -a -t gui '/Volumes/ProjectFolder/ProjectName.bmx'

echo Making Universal Binary
lipo -create /Volumes/ProjectFolder/ProjectName.app/Contents/MacOS/ProjectName /Volumes/ProjectFolder/ProjectName.app/Contents/MacOS/ProjectName-ppc -output /Volumes/ProjectFolder/ProjectName.app/Contents/MacOS/ProjectName-uni

echo Removing Intel and PPC executables.
rm -v -f /Volumes/ProjectFolder/ProjectName.app/Contents/MacOS/ProjectName
rm -v -f /Volumes/ProjectFolder/ProjectName.app/Contents/MacOS/ProjectName-ppc
mv -v /Volumes/ProjectFolder/ProjectName.app/Contents/MacOS/ProjectName-uni /Volumes/ProjectFolder/ProjectName.app/Contents/MacOS/ProjectName

echo Restoring icons
cp '/Volumes/ProjectFolder/ProjectName.icns' '/Volumes/ProjectFolder/ProjectName.app/Contents/Resources/ProjectName.icns'

echo Making package
'/Developer/Applications/Utilities/PackageMaker.app/Contents/MacOS/PackageMaker' --doc '/Volumes/ProjectFolder/ProjectName.pmdoc' --out '/Users/nbrown/Desktop/ProjectName.pkg'

echo Making a disk image...
hdiutil create '/Users/nbrown/Desktop/ProjectName-scratch.dmg' -volname ProjectName-$VER -type UDIF -megabytes 50 -fs HFS+

echo Mounting the disk image...
MYDEV=`hdiutil attach '/Users/nbrown/Desktop/ProjectName-scratch.dmg' | tail -n 1 | awk '{print $1'}`
echo Device is $MYDEV

echo Copying ProjectName package to the disk image...
ditto -X '/Users/nbrown/Desktop/ProjectName.pkg' /Volumes/ProjectName-$VER/ProjectName.pkg

echo Unmounting the disk image...
hdiutil detach $MYDEV

echo Compressing the disk image...
hdiutil convert '/Users/nbrown/Desktop/ProjectName-scratch.dmg' -format UDZO -o /Users/nbrown/Desktop/nsm0-$VER-mac

echo removing scratch file.
rm -f '/Users/nbrown/Desktop/ProjectName-scratch.dmg'

echo COMPLETE


UpdateVersion.bmx
SuperStrict

Framework BRL.Stream
Import BaH.Format
Import brl.retro

DebugLog CommandLine()

Local filename:String = CommandLine() '"../media/version.txt"
Local formatter:TFormatter = TFormatter.Create("%d.%02d.%02d")

Local s:String = LoadString(filename)
Local digits:String[] = s.Split(".")
Local major:Int = digits[0].ToInt()
Local minor:Int = digits[1].ToInt()
Local micro:Int = digits[2].ToInt()

micro:+ 1
If micro > 99 Then
	micro = 0
	minor:+ 1
	
	If minor > 99 Then
		minor = 0
		major:+ 1
	End If
End If

formatter.IntArg(major).IntArg(minor).IntArg(micro)
' update text

SaveString(formatter.Format(), filename)

End

Function CommandLine$()
	Local CmdLine:String
	
	For Local e:String = EachIn AppArgs[1..] 'start from the second element of the appargs array
		CmdLine:+ e +" " 'add each element to the CmdLine string
	Next
	Return CmdLine
End Function


main.bmx
Incbin "media/version.txt"
Global version:String ' = "0.00.00"

Local p:Byte Ptr = IncbinPtr("media/version.txt")
Local bytes:Int = IncbinLen("media/version.txt")
version = String.FromBytes(p,bytes)
DebugLog "String.FromBytes(p,bytes="+version



coffeedotbean(Posted 2009) [#5]
Sorry.. loads of useful stuff above but wouldn't

incbin

work?

I am not a MAC person so app-file might mean a whole other thing on a mac.

Incbin "test.png"
Incbin "test.ogg"


Global image:Timage = LoadImage("incbin::test.png")
Global sound:tsound = LoadSound("incbin::test.ogg")



Brucey(Posted 2009) [#6]
Incbin is fine, but if you want a Universal app, your incbin'd files will be included twice - once in the PPC part of the binary, the other in the x86 part of the binary.


coffeedotbean(Posted 2009) [#7]
ah I c


Brucey(Posted 2009) [#8]
Or use a third-party enhancement to BlitzMax's build system which does support post build scripting as part of a normal build process.


While we're all throwing examples around, this is an example of a post-build script I have for a project, that is auto-magically run when I build my app (because I have my custom BMK (NG) installed) :

# post build script
#
@define copydll
	local ext
	local pre

	if bmk.Platform() == "macos" then
		ext = "dylib"
		pre = ""
	end

	local path = utils.ModulePath("bah.bass") .. "/lib/" .. bmk.Platform() .. "/"
	local file = pre .. arg1 .. "." .. ext

	sys.CopyFile(path .. file, %exepath% .. "/" .. file)
@end

@define copyfiles
	
	local path = %buildpath% .. "/gamedata"

	# copy audio
	sys.CopyDir(path .. "/audio", %exepath% .. "/../Resources/audio")
	
	# copy grahics
	sys.CopyDir(path .. "/graphics", %exepath% .. "/../Resources/graphics")

	# copy icons
	sys.CopyFile(%buildpath% .. "/AppIcons.icns", %exepath% .. "/../Resources/" .. %outfile% .. ".icns")

	
@end


# do the copy
copydll libbass
copyfiles

This build system uses Lua, so the code between the @define and @end blocks is essentially your basic Lua. However it also acts like a template, where anything between %% is replaced with an appropriate value at runtime.

This example is actually copying the BASS library, and all the audio and graphics files into the application bundle, as well as overriding the default icons file with a custom one.

Anyhoo... there are many ways to do this, and this is just another of them.


xlsior(Posted 2009) [#9]
...IncBin?


Brucey(Posted 2009) [#10]
...IncBin?

Hello ?


xlsior(Posted 2009) [#11]
Nevermind, when I typed my message to suggest 'Incbin', the previous posts mentioning it weren't visible yet (That'll show me to pre-load a bunch of threads in different tabs and then read/reply to them)

I guess my message didn't make much sense at the place in the discussion where it finally appeared. :-?


Brucey(Posted 2009) [#12]
That'll show me to pre-load a bunch of threads in different tabs and then read/reply to them

Let that be a lesson to you :-)


FantomKite(Posted 2009) [#13]
I solved this problem as follows:

Created app with the final name of the game or program. Then when you declare the resource (music, pictures, etc.), I pointed the way NameGame.app / Contents / Data. And in the Data folder to store all resources. Only in this way is 1 minus:
1 You can not rename a file app.

sample code:

Global LoadingFon:TImage = LoadImage("NameGame.app/Contents/Data/Art/GameInterface/MainMenu/Loading/MainMenuFon.jpg") 
DrawImage(LoadingFon,10,10)
flip




Brucey(Posted 2009) [#14]
Or you can do it like that.