Mac: Why can't data be found when it's in a .dmg?

BlitzMax Forums/BlitzMax Programming/Mac: Why can't data be found when it's in a .dmg?

Grey Alien(Posted 2007) [#1]
Hiya. I recently altered my AOTMG game demo so that I've put all the data in the app folder (specifically in Contents/Resources). This means that I can distribute a .dmg with what appears to be a single file in it that users can drag onto their Macs and run. This works fine.

However, if you click the game INSIDE the compressed dmg it does not run because it can't find the data properly (one of my own error messages says it can't load the bitmap at AOTMG.app/Contents/Resources/Data/PortalLogo.jpg) This is weird. I'm not a Mac expert (at all) so does anyone know why it runs on the desktop but not in the DMG. Is it something to do with the DMG being compressed or just tat apps in a dmg can't query their own path? Or maybe I'm doing something wrtong with my code. Thanks!

Test app here:

Intel Mac Only: http://www.greyaliengames.com/aotmg/AOTMG045D.dmg (5Mb ish)

You'll notice that the test app has some other improvements: All dynamic data is written to Users/Shared and also the mouse cursor now moves smoothly in and out of the window in windowed mode. This is compiled with BMax 1.28 so the full-screen/windowed mode changing no longer corrupts the graphics. Also it has a proper Mac icon. It's basically got all the techie stuff I want in a professional Mac game now although I still want to get a minimise icon in windowed mode and work out how to set the desktop wallpaper.


unlikely(Posted 2007) [#2]
I'm not sure exactly what the problem is, as I am able to run the game from the mounted disk image (.dmg) straight away without "copying" to my hard drive.


JazzieB(Posted 2007) [#3]
I've just tested it and it works just fine! I downloaded the file, double-clicked the file to mount it and ran it from the mounted disk. Worked without any problems.

Not really sure what to suggest.


Grey Alien(Posted 2007) [#4]
Oh, well it's supposed to work fine :-) so that's good news. But it doesn't work when I double click it on my Macbook pro inside the mounted disk. How strange!


unlikely(Posted 2007) [#5]
Well, I'm still on Tiger and it looks as if JazzieB is too. I don't know if that has anything to do with it...


Grey Alien(Posted 2007) [#6]
could be a problem on my end due to my ini file. Will look into it. Hey if you go into users/shared/grey alien games/aotmg/aotmg.ini and change PORTAL SPLASH= from 0 to 1, does it still run in the dmg? It doesn't on mine. It's also true that the file it's looking for doesn't exist, however I have code in place to look for a png first and if that fails to look for a jpg so it's weird!...


unlikely(Posted 2007) [#7]
I get the error message where is says that it can't load the bitmap at AOTMG.app/Contents/Resources/Data/portallogo.jpg...

It seems like it's not properly looking for the .png I guess.


Grey Alien(Posted 2007) [#8]
Hmm found out something odd. I'm doing this:

- Using disk utlity I make a 10Mb disk image called AOTMG045D.
- I open it by double clicking it and it mounts a new volume.
- I place my working app in that.
- If I run it in there it runs fine.
- back in disk utility I select the AOTMG045D dmg and make a compressed one with the same name but it won't let me as it says it's in use (even if I eject the disk first). So I have to enter another name like AOTMG045D_2
- When I open the compressed dmg it mounts a volume with the ORIGNAL dmg name i.e. AOTMG045D. This is strange...
- Then when I go into the mounted volume and run the app, it fails to load that PortalLogo.jpg file!
- However, if I drag the app out it's fine.
- What is going on? I'm confused now.

Did some more tests and if I simply make a copy of the first disk image, I can run the app OK in there. So it must be something with the compressed one but crap knows what...


Grey Alien(Posted 2007) [#9]
ChromeFly: Thanks for testing. Yeah it's weird as I know the code that looks for the png works as you can see by dragging the app onto the desktop. All I do is this:

	'try a png and if that doesn't exist, try a jpg.
	If ccFileExists(prefix+"data/portallogo.png") Then
		splash.Init(prefix+""data/portallogo.png")
	Else
		splash.Init(prefix+""data/portallogo.jpg")
	EndIf
[code]

Where ccFileExists is this:

[code]
' -----------------------------------------------------------------------------
' ccFileExists: See if a file exists or not
' -----------------------------------------------------------------------------
Function ccFileExists%(filename$)
	Local file:TStream=OpenFile(filename)
	If file Then
		CloseStream file
		Return 1
	Else
		Return 0
	EndIf
End Function



Brucey(Posted 2007) [#10]
Doesn't FileType(filename) return 0 when a file doesn't exist?

Or is it better to try to open a stream instead?


TMK(Posted 2007) [#11]
Oh yes, I think Brucey is right. I had the same problem, for some reason OpenFile didn't work when I ran it from a mounted DMG, so I had to use FileType to check for existing files instead.


Grey Alien(Posted 2007) [#12]
Aha good tip! in fact GREAT tip. testing now thx!


Dreamora(Posted 2007) [#13]
Did you try to use OpenFile but set Write to false.

Would assume that it fails otherwise as it should not be able to write straight to the DMG. (readfile would be the "straight" solution :) )


Grey Alien(Posted 2007) [#14]
Yep I suddently realised that when it was pointed out as OpenFile must request read/write access by default. Anyway this fix will be in the next framework update.


Grey Alien(Posted 2007) [#15]
Just to confirm this was indeed the problem.


JazzieB(Posted 2007) [#16]
Oh yes, I remember having a similar problem when testing something else (between accounts I think). Suddenly realised that I had one of my functions using OpenFile when all I wanted to do was read the file only.

We probably all tested under an admin account, which might not exhibit the problem you were having if you were testing under a different type of account.


Tricky(Posted 2007) [#17]
You were speaking on a compressed .dmg file right?
I see that you used "OpenFile"....

Both "OpenFile" and "OpenStream" can be allergic to Read-Only environments which compressed .dmg files fall under.

Could you try the same thing in an uncompressed .dmg file and see if it still happens....


Grey Alien(Posted 2007) [#18]
yes it worked in an uncompressed one. It's the readonly thing that failed due to OpenStream.