Esempio n. 1
0
Common::SeekableReadStream *BaseFileManager::openFileRaw(const Common::String &filename) {
	Common::SeekableReadStream *ret = NULL;

	if (scumm_strnicmp(filename.c_str(), "savegame:", 9) == 0) {
		if (!BaseEngine::instance().getGameRef()) {
			error("Attempt to load filename: %s without BaseEngine-object, this is unsupported", filename.c_str());
		}
		BaseSaveThumbFile *saveThumbFile = new BaseSaveThumbFile();
		if (DID_SUCCEED(saveThumbFile->open(filename))) {
			ret = saveThumbFile->getMemStream();
		}
		delete saveThumbFile;
		return ret;
	}

	ret = openDiskFile(filename);
	if (ret) {
		return ret;
	}

	ret = openPkgFile(filename);
	if (ret) {
		return ret;
	}

	ret = BaseResources::getFile(filename);
	if (ret) {
		return ret;
	}

	debugC(kWintermuteDebugFileAccess ,"BFileManager::OpenFileRaw - Failed to open %s", filename.c_str());
	return NULL;
}
Esempio n. 2
0
/* removeCommand ()
**
** Remove a file from the BLITZ DISK file.
*/
void removeCommand () {
  Entry * ent, * prev;

  if (commandOptionV) {
    printf ("REMOVING A FILE...\n");
    printf ("  blitzFileName = \'%s\'\n", blitzFileName);
  }

  openDiskFile (1);         /* existing = true */

  /* Set ent to point to the entry to delete;
     set prev to point to the entry before it (or null). */
  ent = firstEntry;
  prev = NULL;
  while (1) {
    if (ent == NULL) {
      fatalError ("This file does not exist on the BLITZ DISK");
    }
    if (strcmp (ent->name, blitzFileName) == 0) {
      break;
    }
    prev = ent;
    ent = ent->next;
  }

  /* Remove the entry */
  if (lastEntry == ent) {
    lastEntry = prev;
  }
  if (firstEntry == ent) {
    firstEntry = ent->next;
  }
  if (prev) {
    prev->next = ent->next;
  }

  /* Adjust the file statistics */
  numberOfFiles--;

  if (commandOptionV) {
    printf ("The file has been removed.\n");
    printf ("  New number of files = %d\n", numberOfFiles);
    printf ("  Total number of sectors used = %d\n", nextFreeSector);
    printf ("  Number of free sectors left = %d\n", numberSectorsOnDisk - nextFreeSector);
    printDirectory ();
  }

  /* Write out the new directory */
  writeDirectory ();
}
Esempio n. 3
0
/* initializeCommand ()
**
** Initialize the BLITZ DISK file by writing out an empty directory.
*/
void initializeCommand () {

  if (commandOptionV) printf ("INITIALIZING THE FILE SYSTEM...\n");

  openDiskFile (0);               /* Existing = false */

  seekTo (4);                     /* Skip past "BLZd" magic number */
  writeInteger (0x73747562);      /* Magic number = "stub" */
  writeInteger (0);               /* Number of file */
  writeInteger (1);               /* Next Free Sector */

  if (commandOptionV) printf ("Number of files on disk = 0\n");
  if (commandOptionV) printf ("Next free sector = 1\n");
  if (commandOptionV) printf ("Number of available sectors = %d\n", numberSectorsOnDisk-1);

  closeFiles ();
}
Esempio n. 4
0
/* extractCommand ()
**
** Copy a file from the BLITZ DISK file into a Unix file.
*/
void extractCommand () {
  Entry * ent;
  int i;
  char * memory;

  if (commandOptionV) {
    printf ("EXTRACTING A FILE FROM THE BLITZ DISK...\n");
    printf ("  blitzFileName = \'%s\'\n", blitzFileName);
    printf ("  unixFileName = \'%s\'\n", unixFileName);
  }

  openDiskFile (1);         /* existing = true */

  ent = findFile (blitzFileName);

  if (ent == NULL) {
    fatalError ("There is no file with this name on the BLITZ DISK");
  }

  if (commandOptionV) {
    printf ("This file starts at sector %d\n", ent->startingSector);
    printf ("Size of this file = %d bytes\n", ent->sizeInBytes);
  }

  // Open the UNIX file for updating...
  errno = 0;
  unixFile = fopen (unixFileName, "wa");
  if (errno) {
    perror ("Error on UNIX file");
    fatalError ("The UNIX file could not be opened for updating");
  }

  if (commandOptionV) printf ("The UNIX file \"%s\" has been opened successfully.\n", unixFileName);

  /* Allocate a chunk of memory big enough to hold all of the file. */
  memory = (char *) calloc (1, ent->sizeInBytes);
  if (memory == 0) {
    fatalError ("Unable to allocate enough memory to hold the entire file");
  }

  /* Reposition the UNIX file to the beginning. */
  errno = 0;
  fseek (unixFile, 0l, SEEK_SET);
  if (errno) {
    perror ("Error on UNIX file");
    fatalError ("The UNIX file could not be repositioned");
  }

  /* Reposition the BLITZ file to the correct sector. */
  seekTo (4 + PAGE_SIZE * ent->startingSector);

  /* Read the BLITZ file entirely into memory. */
  errno = 0;
  i = fread (memory, 1, ent->sizeInBytes, diskFile);
  if (i != ent->sizeInBytes) {
    if (errno) perror ("Error reading from BLITZ DISK file");
    fatalError ("Problems reading from BLITZ DISK file");
  }
  
  /* Write the data to the UNIX file. */
  if (commandOptionV) printf ("Writing to DISK file.\n");
  errno = 0;
  i = fwrite (memory, 1, ent->sizeInBytes, unixFile);
  if (i != ent->sizeInBytes) {
    if (errno) perror ("Error writing to UNIX file");
    fatalError ("Problems writing to UNIX file");
  }

  closeFiles ();

}
Esempio n. 5
0
/* addCommand ()
**
** Copy a UNIX file to the BLITZ DISK file.
*/
void addCommand () {
  long longLength;
  Entry * ent;
  int unixFileSizeInBytes, unixFileSizeInSectors, s, i;
  char * memory;

  if (commandOptionV) {
    printf ("ADD A UNIX FILE TO THE BLITZ DISK...\n");
    printf ("  unixFileName = \'%s\'\n", unixFileName);
    printf ("  blitzFileName = \'%s\'\n", blitzFileName);
  }

  openDiskFile (1);         /* existing = true */

  // Open the UNIX file for reading...
  errno = 0;
  unixFile = fopen (unixFileName, "r");
  if (errno) {
    perror ("Error on UNIX file");
    fatalError ("The UNIX file could not be opened for reading");
  }

  if (commandOptionV) printf ("The UNIX file \"%s\" has been opened successfully.\n", unixFileName);

  /* Get the size of the UNIX file... */
  errno = 0;
  fseek (unixFile, 0l, SEEK_END);
  if (errno) {
    perror ("Error on UNIX file");
    fatalError ("Error during call to fseek");
  }
  longLength = ftell (unixFile);

  /* Check to see if the file is too big... */
  if (longLength > ((long) MAX)) {
    printf ("The maximum integer is %d\n", MAX);
    fatalError ("Error in UNIX File: The UNIX file size exceeds the maximum");
  }

  /* Print the length of the UNIX file */
  unixFileSizeInBytes = (int) longLength;
  unixFileSizeInSectors = (unixFileSizeInBytes + PAGE_SIZE-1) / PAGE_SIZE;
  if (commandOptionV) {
    printf ("The length of the UNIX file = %d bytes.\n", unixFileSizeInBytes);
    printf ("                            = %d sectors.\n", unixFileSizeInSectors);
  }

  ent = findFile (blitzFileName);

  if (ent) {
    if (commandOptionV) printf ("A file with this name already exists; updating it.\n");
    // We have now set "thisFileSizeInBytes" and "thisFileStartingSector"

    /* Make sure this file will fit into the space allocated on BLITZ disk. */
    s = ((ent->sizeInBytes) + PAGE_SIZE-1) / PAGE_SIZE;
    if (commandOptionV) printf ("The size of the BLITZ file = %d sectors.\n", s);
    if (s < unixFileSizeInSectors) {
      fatalError ("The existing file is too small; please delete it and re-add it");
    }

  } else {
    if (commandOptionV) printf ("A file with this name does not already exist; creating new file.\n");

    /* Create a new entry */
    ent = (Entry *) calloc (1, sizeof (Entry));
    ent->startingSector = nextFreeSector;
    ent->sizeInBytes = unixFileSizeInBytes;
    ent->lengthOfName = strlen (blitzFileName);
    ent->name = blitzFileName;

    /* Add it to the list */
    ent->next = 0;
    if (firstEntry) {
      lastEntry->next = ent;
      lastEntry = ent;
    } else {
      firstEntry = ent;
      lastEntry = ent;
    }

    /* Adjust the file statistics */
    nextFreeSector = nextFreeSector + unixFileSizeInSectors;
    numberOfFiles ++;
    sizeOfDirectoryInBytes += 12 + ent->lengthOfName;

    /* Make sure the directory has not grown too large to fit into sector 0. */
    if (sizeOfDirectoryInBytes > PAGE_SIZE) {
      fatalError ("The directory has grown too large to fit into sector 0");
    }

    /* Make sure this file will fit on the disk. */
    if (nextFreeSector > numberSectorsOnDisk) {
      fatalError ("This file will not fit onto the disk");
    }

    if (commandOptionV) {
      printf ("Size of directory info = %d bytes\n", sizeOfDirectoryInBytes);
      printf ("Size of this file = %d sectors\n", unixFileSizeInSectors);
      printf ("New total number of sectors used = %d\n", nextFreeSector);
      printf ("Number of free sectors left = %d\n", numberSectorsOnDisk - nextFreeSector);
      printf ("New number of files = %d\n", numberOfFiles);
      printDirectory ();
    }

    /* Write out the new directory */
    writeDirectory ();
  }

  /* Allocate a chunk of memory big enough to hold all of the source file. */
  memory = (char *) calloc (1, unixFileSizeInBytes);
  if (memory == 0) {
    fatalError ("Unable to allocate enough memory to hold the entire source file");
  }

  /* Reposition the source file to the beginning. */
  errno = 0;
  fseek (unixFile, 0l, SEEK_SET);
  if (errno) {
    perror ("Error on Unix file");
    fatalError ("The Unix file could not be repositioned");
  }

  /* Read the Unix file entirely into memory. */
  errno = 0;
  i = fread (memory, 1, unixFileSizeInBytes, unixFile);
  if (i != unixFileSizeInBytes) {
    if (errno) perror ("Error reading from Unix file");
    fatalError ("Problems reading from Unix file");
  }

  seekTo (4 + PAGE_SIZE * ent->startingSector);
  
  /* Write the data to the DISK file. */
  if (commandOptionV) printf ("Writing to DISK file (sector = %d)\n", ent->startingSector);
  errno = 0;
  i = fwrite (memory, 1, unixFileSizeInBytes, diskFile);
  if (i != unixFileSizeInBytes) {
    if (errno) perror ("Error writing to DISK file");
    fatalError ("Problems writing to DISK file");
  }

  closeFiles ();
}
Esempio n. 6
0
/* createCommand ()
**
** Create a new file on the BLITZ DISK.
*/
void createCommand () {
  Entry * ent;
  int sizeInSectors;
  if (commandOptionV) printf ("CREATING A NEW FILE...\n");
  if (commandOptionV) printf ("  blitzFileName = \'%s\'\n", blitzFileName);
  if (commandOptionV) printf ("  sizeInBytes = %d\n", sizeInBytes);

  openDiskFile (1);         /* existing = true */

  if (findFile (blitzFileName)) {
    fatalError ("A file with this name already exists on the BLITZ DISK");
  }

  /* Create a new entry */
  ent = (Entry *) calloc (1, sizeof (Entry));
  ent->startingSector = nextFreeSector;
  ent->sizeInBytes = sizeInBytes;
  ent->lengthOfName = strlen (blitzFileName);
  ent->name = blitzFileName;

  /* Add it to the list */
  ent->next = 0;
  if (firstEntry) {
    lastEntry->next = ent;
    lastEntry = ent;
  } else {
    firstEntry = ent;
    lastEntry = ent;
  }

  /* Adjust the file statistics */
  sizeInSectors = (sizeInBytes + PAGE_SIZE-1) / PAGE_SIZE;
  nextFreeSector = nextFreeSector + sizeInSectors;
  numberOfFiles ++;
  sizeOfDirectoryInBytes += 12 + ent->lengthOfName;

  /* Make sure the directory has not grown too large to fit into sector 0. */
  if (sizeOfDirectoryInBytes > PAGE_SIZE) {
    fatalError ("The directory has grown too large to fit into sector 0");
  }

  /* Make sure this file will fit on the disk. */
  if (nextFreeSector > numberSectorsOnDisk) {
    fatalError ("This file will not fit onto the disk");
  }

  if (commandOptionV) {
    printf ("Size of directory info = %d bytes\n", sizeOfDirectoryInBytes);
    printf ("Size of this file = %d sectors\n", sizeInSectors);
    printf ("New total number of sectors used = %d\n", nextFreeSector);
    printf ("Number of free sectors left = %d\n", numberSectorsOnDisk - nextFreeSector);
    printf ("New number of files = %d\n", numberOfFiles);

    /* Print the new directory */
    printDirectory ();
  }

  /* Write out the new directory */
  writeDirectory ();

  closeFiles ();
}
Esempio n. 7
0
/* listCommand ()
**
** Print the directory contents.
*/
void listCommand () {
  if (commandOptionV) printf ("LISTING DIRECTORY...\n");
  openDiskFile (1);         /* existing = true */
  printDirectory ();
  closeFiles ();
}