static int copy_file(AL_CONST char *filename, AL_CONST char *dest_path)
{
   char *buffer = NULL;
   char dest_file[1024];
   PACKFILE *f;
   size_t size;
   
   if (!exists(filename))
      return -1;
   buffer = malloc(size = file_size_ex(filename));
   if (!buffer)
      return -1;
   append_filename(dest_file, dest_path, get_filename(filename), 1024);
   f = pack_fopen(filename, F_READ);
   if (!f) {
      free(buffer);
      return -1;
   }
   pack_fread(buffer, size, f);
   pack_fclose(f);
   f = pack_fopen(dest_file, F_WRITE);
   if (!f) {
      free(buffer);
      return -1;
   }
   pack_fwrite(buffer, size, f);
   pack_fclose(f);
   free(buffer);
   
   return 0;
}
Exemple #2
0
int rename_file(char *oldname, char *newname)
{
   PACKFILE *oldfile, *newfile;
   int c;

   oldfile = pack_fopen(oldname, F_READ);
   if (!oldfile)
      return -1;

   newfile = pack_fopen(newname, F_WRITE);
   if (!newfile) {
      pack_fclose(oldfile);
      return -1;
   }

   c = pack_getc(oldfile);

   while (c != EOF) {
      pack_putc(c, newfile);
      c = pack_getc(oldfile);
   } 

   pack_fclose(oldfile);
   pack_fclose(newfile);

   delete_file(oldname); 

   return 0;
}
Exemple #3
0
int save_wav(const char * fn, SAMPLE * sp)
{
	PACKFILE * file;

	eof_log("save_wav() entered", 1);

	if(!fn || !sp)
	{
		return 0;
	}
	/* open file */
	file = pack_fopen(fn, "w");
	if(file == NULL)
	{
		(void) snprintf(eof_log_string, sizeof(eof_log_string) - 1, "\tError saving WAV:  \"%s\"", strerror(errno));	//Get the Operating System's reason for the failure
		eof_log(eof_log_string, 1);
		return 0;
	}

	/* save WAV to the file */
	if(!save_wav_fp(sp, file))
	{
		(void) pack_fclose(file);
		return 0;
	}

	/* close the file */
	(void) pack_fclose(file);

	return 1;
}
Exemple #4
0
/* grab raw binary data */
static DATAFILE *grab_binary(int type, AL_CONST char *filename, DATAFILE_PROPERTY **prop, int depth)
{
   void *mem;
   int64_t sz = file_size_ex(filename);
   PACKFILE *f;

   if (sz <= 0)
      return NULL;

   mem = malloc(sz);

   f = pack_fopen(filename, F_READ);
   if (!f) {
      free(mem);
      return NULL; 
   }

   if (pack_fread(mem, sz, f) < sz) {
      pack_fclose(f);
      free(mem);
      return NULL;
   }

   pack_fclose(f);

   return datedit_construct(type, mem, sz, prop);
}
Exemple #5
0
SOUNDCLIP *my_load_mp3(const char *filname, int voll)
{
  mp3in = pack_fopen(filname, "rb");
  if (mp3in == NULL)
    return NULL;

  char *tmpbuffer = (char *)malloc(MP3CHUNKSIZE);
  if (tmpbuffer == NULL) {
    pack_fclose(mp3in);
    return NULL;
  }
  thistune = new MYMP3();
  thistune->in = mp3in;
  thistune->chunksize = MP3CHUNKSIZE;
  thistune->filesize = mp3in->todo;
  thistune->done = 0;
  thistune->vol = voll;

  if (thistune->chunksize > mp3in->todo)
    thistune->chunksize = mp3in->todo;

  pack_fread(tmpbuffer, thistune->chunksize, mp3in);

  thistune->buffer = (char *)tmpbuffer;
  thistune->stream = almp3_create_mp3stream(tmpbuffer, thistune->chunksize, (mp3in->todo < 1));

  if (thistune->stream == NULL) {
    free(tmpbuffer);
    pack_fclose(mp3in);
    delete thistune;
    return NULL;
  }

  return thistune;
}
Exemple #6
0
void get_stats(void)
{
   PACKFILE *f;

 #ifdef ALLEGRO_UNIX
   if (stat(opt_filename, &stat_stat)) {
      fprintf(stderr, "Error statting %s\n", opt_filename);
      err = 1;
      return;
   }
 #endif

   f = pack_fopen(opt_filename, F_READ);
   if (!f) {
      fprintf(stderr, "Error opening %s\n", opt_filename);
      err = 1;
      return;
   }

   stat_exe_size = f->normal.todo;

   pack_fseek(f, f->normal.todo-8);

   if (pack_mgetl(f) != F_EXE_MAGIC) {
      stat_hasdata = FALSE;
      stat_compressed_size = 0;
      stat_uncompressed_size = 0;
      pack_fclose(f);
      return;
   }

   stat_hasdata = TRUE;
   stat_compressed_size = pack_mgetl(f) - 16;

   pack_fclose(f);
   f = pack_fopen(opt_filename, F_READ);
   if (!f) {
      fprintf(stderr, "Error reading %s\n", opt_filename);
      err = 1;
      return;
   }

   stat_exe_size = f->normal.todo - stat_compressed_size - 16;

   pack_fseek(f, stat_exe_size);

   f = pack_fopen_chunk(f, FALSE);
   if (!f) {
      fprintf(stderr, "Error reading %s\n", opt_filename);
      err = 1;
      return;
   }

   stat_uncompressed_size = f->normal.todo;

   pack_fclose(f);
}
Exemple #7
0
/* This reads the files mysha.pcx and allegro.pcx into a memory block as
 * binary data, and then uses the memory vtable to read the bitmaps out of
 * the memory block.
 */
static void memread_test(void)
{
   PACKFILE *f;
   MEMREAD_INFO memread_info;
   BITMAP *bmp, *bmp2;
   unsigned char *block;
   int64_t l1, l2;
   PACKFILE *f1, *f2;

   l1 = file_size_ex("allegro.pcx");
   l2 = file_size_ex("mysha.pcx");

   block = malloc(l1 + l2);

   /* Read mysha.pcx into the memory block. */
   f1 = pack_fopen("allegro.pcx", "rb");
   CHECK(f1, "opening allegro.pcx");
   pack_fread(block, l1, f1);
   pack_fclose(f1);

   /* Read allegro.pcx into the memory block. */
   f2 = pack_fopen("mysha.pcx", "rb");
   CHECK(f2, "opening mysha.pcx");
   pack_fread(block + l1, l2, f2);
   pack_fclose(f2);

   /* Open the memory block as PACKFILE, using our memory vtable. */
   memread_info.block = block;
   memread_info.length = l1 + l2;
   memread_info.offset = 0;
   f = pack_fopen_vtable(&memread_vtable, &memread_info);
   CHECK(f, "reading from memory block");

   /* Read the bitmaps out of the memory block. */
   bmp = load_pcx_pf(f, NULL);
   CHECK(bmp, "load_pcx_pf");
   bmp2 = load_pcx_pf(f, NULL);
   CHECK(bmp2, "load_pcx_pf");

   blit(bmp, screen, 0, 0, 0, 0, bmp->w, bmp->h);
   textprintf_ex(screen, font, bmp->w + 8, 8, -1, -1,
      "\"allegro.pcx\"");
   textprintf_ex(screen, font, bmp->w + 8, 8 + 20, -1, -1,
      "read out of a memory file");

   blit(bmp2, screen, 0, 0, 0, bmp->h + 8, bmp2->w, bmp2->h);
   textprintf_ex(screen, font, bmp2->w + 8, bmp->h + 8, -1, -1,
      "\"mysha.pcx\"");
   textprintf_ex(screen, font, bmp2->w + 8, bmp->h + 8 + 20, -1, -1,
      "read out of a memory file");

   destroy_bitmap(bmp);
   destroy_bitmap(bmp2);
   pack_fclose(f);

   next();
}
Exemple #8
0
int eof_copy_file(const char * src, const char * dest)
{
	PACKFILE * src_fp = NULL;
	PACKFILE * dest_fp = NULL;
	void *ptr = NULL;	//Used to buffer memory
	unsigned long src_size = 0;
	unsigned long i;

 	eof_log("eof_copy_file() entered", 1);

	if((src == NULL) || (dest == NULL))
		return 0;
	if(!ustricmp(src,dest))		//Special case:  The input and output file are the same
		return 0;				//Return success without copying any files

	src_size = (unsigned long)file_size_ex(src);
	if(src_size > LONG_MAX)
		return 0;	//Unable to validate I/O due to Allegro's usage of signed values
	src_fp = pack_fopen(src, "r");
	if(!src_fp)
	{
		return 0;
	}
	dest_fp = pack_fopen(dest, "w");
	if(!dest_fp)
	{
		(void) pack_fclose(src_fp);
		return 0;
	}
//Attempt to buffer the input file into memory for faster read and write
	ptr = malloc((size_t)src_size);
	if(ptr != NULL)
	{	//If a buffer large enough to store the input file was created
		long long_src_size = src_size;
		if((pack_fread(ptr, long_src_size, src_fp) != long_src_size) || (pack_fwrite(ptr, long_src_size, dest_fp) != long_src_size))
		{	//If there was an error reading from file or writing from memory
			free(ptr);	//Release buffer
			return 0;	//Return error
		}
		free(ptr);	//Release buffer
	}
	else
	{	//Otherwise copy the slow way (one byte at a time)
		for(i = 0; i < src_size; i++)
		{
			(void) pack_putc(pack_getc(src_fp), dest_fp);
		}
	}
	(void) pack_fclose(src_fp);
	(void) pack_fclose(dest_fp);
	return 1;
}
Exemple #9
0
int eof_file_compare(char *file1, char *file2)
{
	uint64_t filesize,ctr;
	int data1,data2;
	PACKFILE *fp1 = NULL,*fp2 = NULL;
	char result = 0;	//The result is assumed to "files identical" until found otherwise

 	eof_log("eof_file_compare() entered", 1);

	if((file1 == NULL) || (file2 == NULL))
	{
		return 2;	//Return error
	}

	filesize = file_size_ex(file1);	//Get length of file1
	if(filesize != file_size_ex(file2))
	{	//If file1 and file2 are different lengths
		return 1;	//Return files don't match
	}

	fp1 = pack_fopen(file1, "r");
	if(fp1 == NULL)
	{
		return 2;	//Return error
	}
	fp2 = pack_fopen(file2, "r");
	if(fp2 == NULL)
	{
		(void) pack_fclose(fp1);
		return 2;	//Return error
	}

	for(ctr = 0;ctr < filesize; ctr++)
	{	//For each byte in the files
		data1 = pack_getc(fp1);	//Read one byte from each
		data2 = pack_getc(fp2);
		if((data1 == EOF) || (data2 == EOF))
		{	//If EOF was reached unexpectedly
			break;	//Exit loop
		}
		if(data1 != data2)
		{
			result = 1;	//Store a "non identical" result
			break;		//Exit loop
		}
	}
	(void) pack_fclose(fp1);
	(void) pack_fclose(fp2);

	return result;
}
Exemple #10
0
void extract_data(void)
{
   PACKFILE *f, *df;
   int c;

   get_stats();

   if (!err) {
      if (!stat_hasdata) {
	 fprintf(stderr, "%s has no appended data: cannot extract it\n", opt_filename);
	 err = 1;
	 return;
      }

      f = pack_fopen(opt_filename, F_READ);
      if (!f) {
	 fprintf(stderr, "Error reading %s\n", opt_filename);
	 err = 1;
	 return;
      }

      pack_fseek(f, stat_exe_size);
      f = pack_fopen_chunk(f, FALSE);
      if (!f) {
	 fprintf(stderr, "Error reading %s\n", opt_filename);
	 err = 1;
	 return;
      }

      if (opt_allegro)
	 df = pack_fopen(opt_dataname, (opt_compress ? F_WRITE_PACKED : F_WRITE_NOPACK));
      else
	 df = pack_fopen(opt_dataname, F_WRITE);

      if (!df) {
	 pack_fclose(f);
	 fprintf(stderr, "Error writing %s\n", opt_dataname);
	 err = 1;
	 return;
      }

      while ((c = pack_getc(f)) != EOF)
	 pack_putc(c, df);

      printf("%d bytes extracted from %s into %s\n", stat_uncompressed_size, opt_filename, opt_dataname);

      pack_fclose(f);
      pack_fclose(df);
   }
}
Exemple #11
0
int save_midi(char *filename, MIDI *midi)
{
    int c;
    long len;
    PACKFILE *fp;
    int num_tracks = 0;
    
    if(!midi)
        return 1;
        
    fp = pack_fopen_password(filename, F_WRITE,"");                       /* open the file */
    
    if(!fp)
        return 2;
        
    for(c=0; c<MIDI_TRACKS; c++)
        if(midi->track[c].len > 0)
            num_tracks++;
            
    pack_fwrite((void *) "MThd", 4, fp);                      /* write midi header */
    
    pack_mputl(6, fp);                                        /* header chunk length = 6 */
    
    pack_mputw((num_tracks==1) ? 0 : 1, fp);                  /* MIDI file type */
    
    pack_mputw(num_tracks, fp);                               /* number of tracks */
    
    pack_mputw(midi->divisions, fp);                          /* beat divisions (negatives?) */
    
    for(c=0; c<num_tracks; c++)                               /* write each track */
    {
        pack_fwrite((void *) "MTrk", 4, fp);                    /* write track header */
        
        len = midi->track[c].len;
        pack_mputl(len, fp);                                    /* length of track chunk */
        
        if(pack_fwrite(midi->track[c].data, len, fp) != len)
            goto err;
    }
    
    pack_fclose(fp);
    return 0;
    
    /* oh dear... */
err:
    pack_fclose(fp);
    delete_file(filename);
    return 3;
}
Exemple #12
0
int eof_undo_load_state(const char * fn)
{
	EOF_SONG * sp = NULL;
	PACKFILE * fp = NULL, * rfp = NULL;
	char rheader[16] = {0};
	int old_eof_silence_loaded = eof_silence_loaded;	//Retain this value, since it is destroyed by eof_destroy_song()
	char eof_recover_path[50];

 	eof_log("eof_undo_load_state() entered", 1);

	if(fn == NULL)
	{
		return 0;
	}
	fp = pack_fopen(fn, "r");
	if(!fp)
	{
		return 0;
	}
	if(pack_fread(rheader, 16, fp) != 16)
	{
		return 0;	//Return error if 16 bytes cannot be read
	}
	sp = eof_create_song();		//Initialize an empty chart
	if(sp == NULL)
	{
		return 0;
	}
	sp->tags->accurate_ts = 0;	//For existing projects, this setting must be manually enabled in order to prevent unwanted alteration to beat timings
	(void) snprintf(eof_recover_path, sizeof(eof_recover_path) - 1, "%seof.recover", eof_temp_path);
	rfp = pack_fopen(eof_recover_path, "r");	//Open the recovery file to prevent eof_destroy_song() from deleting it
	if(!eof_load_song_pf(sp, fp))
	{	//If loading the undo state fails
		allegro_message("Failed to perform undo");
		(void) pack_fclose(rfp);	//Close this recovery file handle so that it will be deleted by the following call to eof_destroy_song()
		eof_destroy_song(sp);
		return 0;	//Return failure
	}
	if(eof_song)
	{
		eof_destroy_song(eof_song);	//Destroy the chart that is open
	}
	(void) pack_fclose(rfp);
	eof_song = sp;	//Replacing it with the loaded undo state
	eof_silence_loaded = old_eof_silence_loaded;	//Restore the status of whether chart audio is loaded

	(void) pack_fclose(fp);
	return 1;
}
Exemple #13
0
SOUNDCLIP *my_load_static_ogg(const char *filname, int voll, bool loop)
{

  // first, read the mp3 into memory
  PACKFILE *mp3in = pack_fopen(filname, "rb");
  if (mp3in == NULL)
    return NULL;

  long muslen = mp3in->todo;

  char *mp3buffer = (char *)malloc(muslen);
  if (mp3buffer == NULL)
    return NULL;

  pack_fread(mp3buffer, muslen, mp3in);
  pack_fclose(mp3in);

  // now, create an OGG structure for it
  thissogg = new MYSTATICOGG();
  thissogg->vol = voll;
  thissogg->repeat = loop;
  thissogg->done = 0;
  thissogg->mp3buffer = mp3buffer;
  thissogg->mp3buffersize = muslen;

  thissogg->tune = alogg_create_ogg_from_buffer(mp3buffer, muslen);
  if (thissogg->tune == NULL) {
    thissogg->destroy();
    delete thissogg;
    return NULL;
  }

  return thissogg;
}
Exemple #14
0
/* This demonstrates seeking. It opens expackf.c, and reads some characters
 * from it.
 */
static void stdio_seek_test(void)
{
   FILE *fp;
   PACKFILE *f;
   char str[8];

   fp = fopen("expackf.c", "rb");
   if (!fp) {
      /* Handle the case where the user is running from a build directory
       * directly under the Allegro root directory.
       */
      fp = fopen("../../examples/expackf.c", "rb");
   }
   CHECK(fp, "opening expackf.c");
   f = pack_fopen_vtable(&stdio_vtable, fp);
   CHECK(f, "reading with stdio");

   pack_fseek(f, 33);
   pack_fread(str, 7, f);
   str[7] = '\0';

   textprintf_ex(screen, font, 0, 0, -1, -1, "Reading from \"expackf.c\" with stdio.");
   textprintf_ex(screen, font, 0, 20, -1, -1, "Seeking to byte 33, reading 7 bytes:");
   textprintf_ex(screen, font, 0, 40, -1, -1, "\"%s\"", str);
   textprintf_ex(screen, font, 0, 60, -1, -1, "(Should be \"Allegro\")");

   pack_fclose(f);

   next();
}
Exemple #15
0
/* close_fli:
 *  Shuts down the FLI player at the end of the file.
 */
void close_fli(void)
{
   remove_int(fli_timer_callback);

   if (fli_file) {
      pack_fclose(fli_file);
      fli_file = NULL;
   }

   if (fli_filename) {
      _AL_FREE(fli_filename);
      fli_filename = NULL;
   }

   if (fli_bitmap) {
      destroy_bitmap(fli_bitmap);
      fli_bitmap = NULL;
   }

   fli_mem_data = NULL;
   fli_mem_pos = 0;

   reset_fli_variables();

   fli_status = FLI_NOT_OPEN;
}
Exemple #16
0
void close_ogg_file(OGGFILE *ogg) {
  if (ogg) {
    pack_fclose(ogg->f);
    alogg_destroy_oggstream(ogg->s);
    free(ogg);
  }
}
Exemple #17
0
OGGFILE *open_ogg_file(char *filename) {
  OGGFILE *p = NULL;
  PACKFILE *f = NULL;
  ALOGG_OGGSTREAM *s = NULL;
  char data[DATASZ];
  int len;

  if (!(p = (OGGFILE *)malloc(sizeof(OGGFILE))))
    goto error;
  if (!(f = pack_fopen(filename, F_READ)))
    goto error;
  if ((len = pack_fread(data, DATASZ, f)) <= 0)
    goto error;
  if (len < DATASZ) {
    if (!(s = alogg_create_oggstream(data, len, TRUE)))
      goto error;
  }
  else {
    if (!(s = alogg_create_oggstream(data, DATASZ, FALSE)))
      goto error;
  }
  p->f = f;
  p->s = s;
  return p;

  error:
  pack_fclose(f);
  free(p);
  return NULL;
}
Exemple #18
0
SOUNDCLIP *my_load_wave(const char *filename, int voll, int loop)
{
#ifdef MAC_VERSION
    SAMPLE *new_sample = NULL;
    PACKFILE* wavin = pack_fopen(filename, "rb");
    if (wavin != NULL) {
      new_sample = load_wav_pf(wavin);
      pack_fclose(wavin);
    }
#else
    // Load via soundcache.
    long dummy;
    SAMPLE *new_sample = (SAMPLE*)get_cached_sound(filename, true, &dummy);
#endif

    if (new_sample == NULL)
        return NULL;

    thiswave = new MYWAVE();
    thiswave->wave = new_sample;
    thiswave->vol = voll;
    thiswave->firstTime = 1;
    thiswave->repeat = loop;

    return thiswave;
}
Exemple #19
0
int	detect_it(char *f) {
    int	sig;
    PACKFILE *fn = pack_fopen(f, "rb");

    if (fn == NULL)
        return FALSE;

    sig	= pack_mgetl(fn);
    if (sig	!= AL_ID('I','M','P','M')) {
        pack_fclose(fn);
        return FALSE;
    }
    pack_fclose(fn);

    return TRUE;
}
Exemple #20
0
void * eof_buffer_file(const char * fn, char appendnull)
{
// 	eof_log("eof_buffer_file() entered");

	void * data = NULL;
	PACKFILE * fp = NULL;
	size_t filesize, buffersize;

	if(fn == NULL)
		return NULL;
	fp = pack_fopen(fn, "r");
	if(fp == NULL)
	{
		return NULL;
	}
	filesize = buffersize = file_size_ex(fn);
	if(appendnull)
	{	//If adding an extra NULL byte of padding to the end of the buffer
		buffersize++;	//Allocate an extra byte for the padding
	}
	data = (char *)malloc(buffersize);
	if(data == NULL)
		return NULL;

	(void) pack_fread(data, (long)filesize, fp);
	if(appendnull)
	{	//If adding an extra NULL byte of padding to the end of the buffer
		((char *)data)[buffersize - 1] = 0;	//Write a 0 byte at the end of the buffer
	}
	(void) pack_fclose(fp);
	return data;
}
Exemple #21
0
/*! \brief Save the current map
 *
 * Another even more useful than the original function
 */
void do_save_map (const char *filename)
{
   int p, q;
   PACKFILE *pf;

   pf = pack_fopen (filename, F_WRITE_PACKED);
   save_s_map (&gmap, pf);

   for (q = 0; q < 50; ++q) {
      save_s_entity (&gent[q], pf);
   }
   for (q = 0; q < gmap.ysize; ++q) {
      for (p = 0; p < gmap.xsize; ++p) {
         pack_iputw (map[q * gmap.xsize + p], pf);
      }
   }
   for (q = 0; q < gmap.ysize; ++q) {
      for (p = 0; p < gmap.xsize; ++p) {
         pack_iputw (b_map[q * gmap.xsize + p], pf);
      }
   }
   for (q = 0; q < gmap.ysize; ++q) {
      for (p = 0; p < gmap.xsize; ++p) {
         pack_iputw (f_map[q * gmap.xsize + p], pf);
      }
   }

   pack_fwrite (z_map, (gmap.xsize * gmap.ysize), pf);
   pack_fwrite (sh_map, (gmap.xsize * gmap.ysize), pf);
   pack_fwrite (o_map, (gmap.xsize * gmap.ysize), pf);
   pack_fclose (pf);
}                               /* save_map () */
Exemple #22
0
AnimationSet::AnimationSet(const char* filename) throw (std::bad_alloc, ReadError) :
	currAnim(0)
{
	PACKFILE* f = pack_fopen(filename, "rp");
	if (!f)
		throw new ReadError();

	int nameLen = igetl(f);
	name = (char*)malloc(nameLen+1);
	if (!name) {
		pack_fclose(f);
		throw new std::bad_alloc();
	}

	anims = 0;

	try {
		for (int i = 0; i < nameLen; i++)
			name[i] = my_pack_getc(f);
		name[nameLen] = 0;
		numAnims = igetl(f);
		anims = new Animation*[numAnims];
		for (int i = 0; i < numAnims; i++)
			anims[i] = 0;
		for (int i = 0; i < numAnims; i++) {
			anims[i] = new Animation();
			anims[i]->load(f);
		}
	}
	catch (...) {
		free(name);
		if (anims) {
			for (int i = 0;  i < numAnims; i++) {
				if (anims[i])
					delete anims[i];
			}
			delete[] anims;
		}
		throw new ReadError();
	}

	pack_fclose(f);

	debug_message("Animation set %s loaded\n", filename);
}
Exemple #23
0
int save_scenario(int kind) {
	int i;

	for (i=0; save_dialog[i].proc; i++) {
      save_dialog[i].fg = colors[black];
      save_dialog[i].bg = colors[gray];
   }
	save_dialog[SAVE_LISTBOX].bg = colors[white];
	save_dialog[SAVE_EDIT].bg = colors[white];
	
	if (kind) strcpy(ext, "*.sce"); else strcpy(ext, "*.sav");

	file_index = for_each_file(ext, FA_ARCH, foo, 0);
	files = (files_t *)malloc(sizeof(files_t)*file_index);
	file_index=0;
	for_each_file(ext, FA_ARCH, add_file, 0);
	
	filename[0]='\0';
	
	if (kind==SL_SCENARIO) {
		save_dialog[SAVE_FRAME].dp = "Save Scenario";
		strcpy(ext, ".sce");
	} else {
		save_dialog[SAVE_FRAME].dp = "Save Game";
		strcpy(ext, ".sav");
	}
	
	i=1;
	if (do_dialog(save_dialog, -1)==SAVE_OKAY) {
		PACKFILE *file;
		unsigned short magic = MAGIC;
		
		if (filename[0]=='\0') {
			file = pack_fopen(files[save_dialog[SAVE_LISTBOX].d1].name, "wb");
		} else {
			char fn[16];
			sprintf(fn, "%s%s", filename, ext);
			file = pack_fopen(fn, "wb");
		}	
		
		if (file) {
			pack_fwrite(&game, sizeof(game_t), file);
			pack_fwrite(matrix, sizeof(tile_t)*game.tiles, file);
			pack_fwrite(players, sizeof(players_t)*8, file);
			pack_fwrite(&magic, sizeof(unsigned short), file);
			pack_fclose(file);

			printf("Game saved.\n");
			i=0;
		}
		if (i==1) alert("!ERROR", "Could not save the scenario", NULL, "OK", NULL, 'o', 0);
	}

	free(files);
	return i;
}
int TiledMap::loadMap(const char* mapName)
{
	char tempstr[256] = "";
	usprintf(tempstr, "%s", mapName);

	PACKFILE *file = pack_fopen(tempstr, F_READ_PACKED);
	this->loadFrom(file, tileRepository);
	pack_fclose(file);
	return 0;
}
Exemple #25
0
void Animation::load(char *filename) throw (std::bad_alloc, ReadError)
{
	PACKFILE *f = pack_fopen(filename, "rp");
	if (!f)
		throw new ReadError();
	
	load(f);

	pack_fclose(f);
}
/* exports a bitmap into an external file */
static int export_jpeg(AL_CONST DATAFILE *dat, AL_CONST char *filename)
{
	PACKFILE *f = pack_fopen(filename, F_WRITE);

	if (f) {
		pack_fwrite(dat->dat, dat->size, f);
		pack_fclose(f);
	}

	return (errno == 0);
}
Exemple #27
0
  void destroy()
  {
    if (!done)
      alogg_stop_oggstream(stream);

    alogg_destroy_oggstream(stream);
    stream = NULL;
    if (buffer != NULL)
      free(buffer);
    buffer = NULL;
    pack_fclose(in);
  }
Exemple #28
0
SOUNDCLIP *my_load_ogg(const char *filname, int voll)
{

  mp3in = pack_fopen(filname, "rb");
  if (mp3in == NULL)
    return NULL;

  char *tmpbuffer = (char *)malloc(MP3CHUNKSIZE);
  if (tmpbuffer == NULL) {
    pack_fclose(mp3in);
    return NULL;
  }

  thisogg = new MYOGG();
  thisogg->in = mp3in;
  thisogg->vol = voll;
  thisogg->chunksize = MP3CHUNKSIZE;
  thisogg->done = 0;
  thisogg->last_but_one = 0;
  thisogg->last_ms_offs = 0;
  thisogg->last_but_one_but_one = 0;

  if (thisogg->chunksize > mp3in->todo)
    thisogg->chunksize = mp3in->todo;

  pack_fread(tmpbuffer, thisogg->chunksize, mp3in);

  thisogg->buffer = (char *)tmpbuffer;
  thisogg->stream = alogg_create_oggstream(tmpbuffer, thisogg->chunksize, (mp3in->todo < 1));

  if (thisogg->stream == NULL) {
    free(tmpbuffer);
    pack_fclose(mp3in);
    delete thisogg;
    return NULL;
  }

  return thisogg;
}
Exemple #29
0
/* fli_rewind:
 *  Helper function to rewind to the beginning of the FLI file data.
 *  Pass offset from the beginning of the data in bytes.
 */
static void fli_rewind(int offset)
{
   if (fli_mem_data) {
      fli_mem_pos = offset;
   }
   else {
      pack_fclose(fli_file);
      fli_file = pack_fopen(fli_filename, F_READ);
      if (fli_file)
	 pack_fseek(fli_file, offset);
      else
	 fli_status = FLI_ERROR;
   }
}
Exemple #30
0
/* initialize buffer, call once before first getbits or showbits */
void _apeg_initialize_buffer(APEG_LAYER *layer)
{
	layer->Incnt = 0;
	layer->got_last = FALSE;

	switch(layer->buffer_type)
	{
		case DISK_BUFFER:
			// (Re)open the file
			if(layer->pf)
				pack_fclose(layer->pf);

			layer->pf = pack_fopen(layer->fname, F_READ);
			if(!layer->pf)
			{
				sprintf(apeg_error, "Couldn't open %s", layer->fname);
				apeg_error_jump(NULL);
			}
			break;

		case MEMORY_BUFFER:
			layer->mem_data.buf -= layer->buffer_size -
			                       layer->mem_data.bytes_left;
			layer->mem_data.bytes_left = layer->buffer_size;
			break;

		case USER_BUFFER:
			if(!layer->ext_data.request || !layer->ext_data.skip ||
			   !layer->ext_data.init)
				apeg_error_jump("Unable to request data");

			layer->buffer_size = layer->ext_data.init(layer->ext_data.ptr);
			if(layer->buffer_size <= 0)
				apeg_error_jump("Data init failed");
			layer->buffer_size = (layer->buffer_size+3) & (~3);
			break;

		default:
			sprintf(apeg_error, "Unknown buffer type: %d", layer->buffer_type);
			apeg_error_jump(NULL);
	}

	layer->Bfr = 0;
	layer->Incnt = 0;
	layer->Rdmax = 0;
	if(layer->system_stream_flag != MPEG_SYSTEM)
		layer->Rdmax = ~0u;
	if(layer->system_stream_flag != OGG_SYSTEM)
		apeg_flush_bits(layer, 0); /* fills valid data into Bfr */
}