File.Open won't open existing file (SOLVED)

Started by Khris, Tue 15/09/2009 17:05:11

Previous topic - Next topic

Khris

For what I'm trying to do I want to read two files off my HD. The first is a PCX image (containing tiles), the second one is a raw file which contains dimensions, then specifics of the tile map. Those are stored using words.

Here's the relevant bit of code:

Code: ags
bool ReadMap(String filename) {
  File*f;
  String fs;
  
  [# SNIP (DynamicSprite is read and displayed fine) SNIP #]
  
  fs = String.Format("tiles/%s#map001.map", filename);
  error = "Map file not found";
  if (!File.Exists(fs)) return false;

  f = File.Open(fs, eFileRead);
  error = "Error opening map file";
  if (f == null) return false;

  int width = f.ReadDoubleword();
  ...


As you can see I've put in several checks. Everything works like it should until I try to open the file for reading.
The manual doesn't mention anything AGS not being able to open raw files, so I assumed those would work fine. However, this doesn't seem to be the case.

I've uploaded the file here (had to remove the hash character from the filename in order to put it on my webspace): RAW FILE

Just to clarify:
1. AGS says the file does exist, so this isn't a problem with the filename.
2. I've double checked that the file isn't open in another program.

SSH

Just a thought: does it work if you rename the file not to have the hash in it?
12

Khris


Gilbert

#3
Hmm. Have you tried changing the slash to a backslash?

Edit:
Also, how does ReadDoubleword() work? It should be okay only if it's using the ReadRaw*() functions to read back data. The other file reading  functions could only be used when the file was written using the "non-raw" Write*() functions.

Khris

#4
The game doesn't even get that far, it displays the error message "Error opening map file", so File.Exists return true, but File.Open returns null.

If I change the slash to a backslash, AGS can't find the file.
If I move the file to the Compiled folder, same thing as before. It exists but can't be opened.

Could any of you try to open the file I uploaded?

Khris

Oh my. It appears that when I first run the program, due to an unrelated error, the file never got closed. So in any subsequent run, opening it failed.

The weird thing is that in between repeated testing, I reexported the files from ProMotion, overwriting the old ones in the process, and also copied the map file to the Compiled directory. None of this seemed to revoke the file's I'm-already-open status.

Only after I opened it with a hex editor and saved it, AGS could open it.

Then I reexported the map and now, my code being corrected and all, everything went fine.

Sorry for the trouble.

SMF spam blocked by CleanTalk