*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]