Windows/Mac - "file does not exist" - trying to build - BUG?- please help *RESOLVED*

*resolution* This was an ID10T error on my part - I had the files on the PC but not the mac. I did not understand that system.ResourcesDirectory was the place where main.lua resides. Sorry.


Hello:

I discovered a difference in behavior from the PC to the MAC. The code below is designed to see if there is a database on the system.DocumentsDirectory folder. If not, it will move it there along with the background music that I will later call with media.playsound. If these files don’t exist on the PC … no problem. It moves them there and the game starts up perfectly. However, on the MAC I get the error below. One more important piece of info: in the assets folder there are three sub-folders: graphics, sounds, and “database” where I stuck the db. I have tried with and without that third folder. I have also moved the DB to the root assets folder. It runs fine on the MAC when the files are in the sandbox. It is also worth mentioning that I read this: http://developer.anscamobile.com/forum/2010/12/27/auto-populate-documents-directory-build-time and am still not sure what I am doing wrong.

Any help would be greatly appreciated.

[lua]local function copyFile( srcName, srcPath, dstName, dstPath, overwrite )

local results = true – assume no errors

– Copy the source file to the destination file

local rfilePath = system.pathForFile( srcName, srcPath )
local wfilePath = system.pathForFile( dstName, dstPath )

local rfh = io.open( rfilePath, “rb” )
local wfh = io.open( wfilePath, “wb” )

if not wfh then
print( “writeFileName open error!” )
results = false – error
else
– Read the file from the Resource directory and write it to the destination directory
local data = rfh:read( “*a” )

if not data then
print( “read error!” )
results = false – error
else
if not wfh:write( data ) then
print( “write error!” )
results = false – error
end
end
end

– Clean up our file handles
rfh:close()
wfh:close()

return results
end
–check to see if the database is there by reading a row - if not put it there
local path = system.pathForFile( “data.db”, system.DocumentsDirectory )

– io.open opens a file at path. returns nil if no file found
local fh, reason = io.open( path, “r” )
if fh then
– read all contents of file into a string
local contents = fh:read( “*a” )
print( "Contents of " … path … “\n” … contents )
else
print(“database not detected - will move it there now”)
– Copy file from assets dir to /Documents dir
copyFile( “overkill.mp3”, system.ResourceDirectory, “overkill.mp3”, system.DocumentsDirectory )
copyFile( “data.db”, system.ResourceDirectory, “data.db”, system.DocumentsDirectory )

end
–[/lua]

Now here is the error message that I get on the MAC:

[html]
The file sandbox for this project is located at the following folder:
(/Users/jayme_fishman/Library/Application Support/Corona Simulator/100211_2-7ADFD60AA4BB7E707C31E577D8139FE6)
WARNING: Cannot create path for resource file ‘overkill.mp3’. File does not exist.

Runtime error
/Users/jayme_fishman/Desktop/100211_2/main.lua:34: bad argument #1 to ‘open’ (string expected, got nil)
stack traceback:
[C]: ?
[C]: in function ‘open’
/Users/jayme_fishman/Desktop/100211_2/main.lua:34: in function ‘copyFile’
/Users/jayme_fishman/Desktop/100211_2/main.lua:72: in main chunk
Runtime error: /Users/jayme_fishman/Desktop/100211_2/main.lua:34: bad argument #1 to ‘open’ (string expected, got nil)
stack traceback:
[C]: ?
[C]: in function ‘open’
/Users/jayme_fishman/Desktop/100211_2/main.lua:34: in function ‘copyFile’
/Users/jayme_fishman/Desktop/100211_2/main.lua:72: in main chunk
[/html]

I am trying to test an iPhone build today so any help would be awesome. [import]uid: 81347 topic_id: 15887 reply_id: 315887[/import]

Also, I tried another set of code that works on the PC but not the mac … any ideas?:

[lua]-- See if Database File Already Exists in Documents Directory
path = system.pathForFile( “data.db”, system.DocumentsDirectory )
file = io.open( path, “r” )

if( file == nil )then
print(“database not detected - will move it there now”)
– Doesn’t Already Exist, So Copy it In From Resource Directory

pathSource = system.pathForFile( “data.db”, system.ResourceDirectory )
fileSource = io.open( pathSource, “r” )
contentsSource = fileSource:read( “*a” )

– Write Destination File in Documents Directory

pathDest = system.pathForFile( “data.db”, system.DocumentsDirectory )
fileDest = io.open( pathDest, “w” )
fileDest:write( contentsSource )

– Done

io.close( fileSource )
io.close( fileDest )

end

path = system.pathForFile( “overkill.mp3”, system.DocumentsDirectory )
file = io.open( path, “r” )

if( file == nil )then
print(“overkill music not detected - will move it there now”)
– Doesn’t Already Exist, So Copy it In From Resource Directory

pathSource = system.pathForFile( “overkill.mp3”, system.ResourceDirectory )
fileSource = io.open( pathSource, “r” )
contentsSource = fileSource:read( “*a” )

– Write Destination File in Documents Directory

pathDest = system.pathForFile( “overkill.mp3”, system.DocumentsDirectory )
fileDest = io.open( pathDest, “w” )
fileDest:write( contentsSource )

– Done

io.close( fileSource )
io.close( fileDest )

end[/lua] [import]uid: 81347 topic_id: 15887 reply_id: 58756[/import]

Okay - I got it working but sure would like an explanation as to why I had to do what I had to do …

On the PC I can stuff the files that will be moved to system.DocumentsDirectory in the assets folder. The code reads system.ResourceDirectory to include those files. However, I discovered on the mac this is not the case. To get it to work I had to place those files in the same directory as main.lua. That appears to be the only place the mac looks for system.ResourceDirectory. Can somebody help me reconcile this difference?

Thanks,
Jfish [import]uid: 81347 topic_id: 15887 reply_id: 58760[/import]