fileName = "pkg:/xml/data.xml" - or "pkg:/xml/test.png"
LocalFileBrowser = CreateObject("roFileSystem")
print (LocalFileBrowser.exists(fileName))
contents = ReadAsciiFile(fileName)
print "Type: "+type(contents )
<DefenderBitmapSet>
<ExtraInfo cellsize="40"/>
<Bitmap name="Background" filespec="pkg:/snake_assets/snake.map_w-dirt.png" />
<Bitmap name="game-over" filespec="pkg:/snake_assets/snake.gameover.png" />
<Bitmap name="title-screen" filespec="pkg:/snake_assets/snake.title.3.png" />
<Bitmap name="snake" filespec="pkg:/snake_assets/snake.body_sprite.png">
<Region name="butt-North" x="00" y="00" w="40" h="40" />
<Region name="butt-East" x="40" y="00" w="40" h="40" />
<Region name="butt-South" x="80" y="00" w="40" h="40" />
<Region name="butt-West" x="120" y="00" w="40" h="40" />
</Bitmap>
<Bitmap name="water_strip" filespec="pkg:/snake_assets/snake.water_sprite.png">
<Region name="a" x="0" y="0" w="40" h="40" t="400" />
</Bitmap>
<Bitmap name="empty" shape="rect" color="0" w="40" h="40" t="680" />
<Animation name="water">
<frame use="water_strip.a" />
</Animation>
<Animation name="tongue-North">
<frame use="snake.tongue-North" />
<frame use="empty" />
</Animation>
<Animation name="tongue-East">
<frame use="snake.tongue-East" />
<frame use="empty" />
</Animation>
<Animation name="tongue-South">
<frame use="snake.tongue-South" />
<frame use="empty" />
</Animation>
<Animation name="tongue-West">
<frame use="snake.tongue-West" />
<frame use="empty" />
</Animation>
</DefenderBitmapSet>
"AlexHolsgrove" wrote:
If I perform the checking on say an image file, it works fine (exists = true / type is PNG etc). When I replace the filename with my XML it just fails....
contents = ReadAsciiFile(fileName)
print "Type: "+type(contents )
"belltown" wrote:
Try reading the file into an roByteArray and examine the first few bytes to see if there's anything there other than a non-null ASCII character, i.e. check that each byte is between 1 and 127 inclusive. If you encounter anything else (like 0, or 254 or 255) then it's not an ASCII file. It might, for example, be UTF-8 encoded with a byte order mark, or some other non-ASCII encoding.
"EnTerr" wrote:
Checking with roByteArray is good idea!
To clarify though, there is nothing wrong with reading utf-8 file with readAsciiFile(). The naming ASCII is a misnomer, just like with the function ASC(). I checked the behavior and file gets read with some caveats:
- all file contents (text/binary/what-have-you) will be returned, until first \0. CHR(0) is end of the line, think C ASCIIZ char array.
- utf-8 in the file will be decoded to proper Unicodes on fw5 - while on fw3 it will remain as sequence of bytes
- the optional 3-byte BOM at file beginning - if present - is not processed/removed; that is, on fw5 string will start with chr(65279), on fw3 it will be chr(&hEF)+chr(&hBB)+chr(&hBF)
"EnTerr" wrote:"AlexHolsgrove" wrote:
If I perform the checking on say an image file, it works fine (exists = true / type is PNG etc). When I replace the filename with my XML it just fails....
contents = ReadAsciiFile(fileName)
print "Type: "+type(contents )
There is no way the code you show returned type "PNG". It will always be saying String, no matter if read failed (len(contents) = 0) or not. Which makes me think you need to look more closely at what you were doing.
fileName = "pkg:/images/Logo_Overhang_HD.png"
xml = ReadAsciiFile(fileName)
print "Type: "+type(xml)
print xml
print xml.Len()
print "Done"
fileName = "pkg:/xml/sprite.small.map.xml"
LocalFileBrowser = CreateObject("roFileSystem")
print "Exists: "
print LocalFileBrowser.exists(fileName)
Exists:
false
"AlexHolsgrove" wrote:
The PNG was actually the raw output. This is the actual code I was running - just as a test: [...] The length was only 7 but I expected that to fail anyway.
Before even getting as far as reading in the file, I should be able to use roFileSystem to check if the XML file exists. I am certain I have the correct filename / path (the code returns true when I test for any of the image assets) [...]
"AlexHolsgrove" wrote:
That's exactly the problem - Eclipse wasn't including the directories with my XML (and other assets: viewtopic.php?f=34&t=44784)
The one thing that bugs me, is if I go to File->Export and then select the directories that I need - Eclipse doesn't remember them next time. It means that I can use the toolbar button to do a silent deployment (Ctrl+Alt+E). Is there a way to fix this?