コード例 #1
0
ファイル: m_saves.c プロジェクト: Krazygamr/D-Touch
//
// FromCurr
//
// Copying files from savepathtemp to savepath
//
void FromCurr(void)
{
    DIR *sp2dir = NULL;
    struct dirent *f = NULL;

    if(!(sp2dir = opendir(savepathtemp)))
        I_Error("FromCurr: Couldn't open dir %s", savepathtemp);

    while((f = readdir(sp2dir)))
    {
        byte *filebuffer  = NULL;
        int   filelen     = 0;
        char *srcfilename = NULL;
        char *dstfilename = NULL;

        // haleyjd: skip "." and ".." without assuming they're the
        // first two entries like the original code did.
        if(!strcmp(f->d_name, ".") || !strcmp(f->d_name, ".."))
            continue;

        // haleyjd: use M_SafeFilePath, NOT sprintf.
        srcfilename = M_SafeFilePath(savepathtemp, f->d_name);
        dstfilename = M_SafeFilePath(savepath,     f->d_name);

        filelen = M_ReadFile(srcfilename, &filebuffer);
        M_WriteFile(dstfilename, filebuffer, filelen);

        Z_Free(filebuffer);
        Z_Free(srcfilename);
        Z_Free(dstfilename);
    }

    closedir(sp2dir);
}
コード例 #2
0
//-----------------------------------------------------------------------------
//
// WritePCXfile
//
void
WritePCXfile
( char*		filename,
  byte*		data,
  int		width,
  int		height,
  byte*		palette )
{
  int		i;
  int		length;
  pcx_t*	pcx;
  byte*	pack;

  pcx = Z_Malloc (width*height*2+1000, PU_STATIC, NULL);

  pcx->manufacturer = 0x0a;		// PCX id
  pcx->version = 5;			// 256 colour
  pcx->encoding = 1;			// uncompressed
  pcx->bits_per_pixel = 8;		// 256 colour
  pcx->xmin = 0;
  pcx->ymin = 0;
  i = width - 1;
  pcx->xmax = SHORT(i);
  i = height - 1;
  pcx->ymax = SHORT(i);
  pcx->hres = SHORT(width);
  pcx->vres = SHORT(height);
  memset (pcx->palette,0,sizeof(pcx->palette));
  pcx->color_planes = 1;		// chunky image
  pcx->bytes_per_line = SHORT(width);
  i = 2;				// not a grey scale
  pcx->palette_type = SHORT(i);
  memset (pcx->filler,0,sizeof(pcx->filler));


  // pack the image
  pack = &pcx->data;

  for (i=0 ; i<width*height ; i++)
  {
      if ( (*data & 0xc0) != 0xc0)
	  *pack++ = *data++;
      else
      {
	  *pack++ = 0xc1;
	  *pack++ = *data++;
      }
  }

  // write the palette
  *pack++ = 0x0c;	// palette ID byte
  for (i=0 ; i<768 ; i++)
      *pack++ = *palette++;

  // write output file
  length = pack - (byte *)pcx;
  M_WriteFile (filename, pcx, length);

  Z_Free (pcx);
}
コード例 #3
0
static boolean ConvertMus(byte *musdata, int len, const char *filename)
{
    MEMFILE *instream;
    MEMFILE *outstream;
    void *outbuf;
    size_t outbuf_len;
    int result;

    instream = mem_fopen_read(musdata, len);
    outstream = mem_fopen_write();

    result = mus2mid(instream, outstream);

    if (result == 0)
    {
        mem_get_buf(outstream, &outbuf, &outbuf_len);

        M_WriteFile(filename, outbuf, outbuf_len);
    }

    mem_fclose(instream);
    mem_fclose(outstream);

    return result;
}
コード例 #4
0
//
// FromCurr
//
// Copying files from savepathtemp to savepath
//
void FromCurr(void)
{
    glob_t *glob;

    glob = I_StartGlob(savepathtemp, "*", 0);

    if (glob == NULL)
        I_Error("FromCurr: Couldn't open dir %s", savepathtemp);

    for (;;)
    {
        byte *filebuffer;
        int filelen;
        const char *srcfilename;
        char *dstfilename;

        srcfilename = I_NextGlob(glob);
        if (srcfilename == NULL)
        {
            break;
        }

        dstfilename = M_SafeFilePath(savepath, M_BaseName(srcfilename));

        filelen = M_ReadFile(srcfilename, &filebuffer);
        M_WriteFile(dstfilename, filebuffer, filelen);

        Z_Free(filebuffer);
        Z_Free(dstfilename);
    }

    I_EndGlob(glob);
}
コード例 #5
0
ファイル: m_saves.c プロジェクト: Krazygamr/D-Touch
//
// M_SaveMisObj
//
// Writes the mission objective into the MIS_OBJ file.
//
boolean M_SaveMisObj(const char *path)
{
    boolean result;
    char *destpath = NULL;

    // haleyjd 20110210: use M_SafeFilePath, not sprintf
    destpath = M_SafeFilePath(path, "mis_obj");
    result   = M_WriteFile(destpath, mission_objective, OBJECTIVE_LEN);

    Z_Free(destpath);
    return result;
}
コード例 #6
0
ファイル: ogl_scr.c プロジェクト: carstene1ns/hhexen
void OGL_GrabScreen (void)
{
	int	i, len, temp;
	char	tganame[MAX_OSPATH], *p;
	byte	*buffer;

//
// find a file name to save it to
//
	snprintf (tganame, sizeof(tganame), "%shexen00.tga", basePath);
	p = tganame + strlen(basePath);
	for (i = 0; i <= 99; i++)
	{
		p[5] = i/10 + '0';
		p[6] = i%10 + '0';
		if (access(tganame, F_OK) == -1)
			break;	// file doesn't exist
	}
	if (i == 100)
	{
		P_SetMessage(&players[consoleplayer], "SCREEN SHOT FAILED", false);
		return;
	}

	// NOTE: 18 == sizeof(TargaHeader)
	len = 18 + screenWidth * screenHeight * 3;
	// Z_Malloc would fail here (Z mem is too little)
	buffer = (byte *) malloc (len);
	if (buffer == NULL)
		I_Error ("OGL_GrabScreen: No memory for screenshot");
	memset (buffer, 0, 18);
	buffer[2] = 2;		// uncompressed type
	buffer[12] = screenWidth & 255;
	buffer[13] = screenWidth >> 8;
	buffer[14] = screenHeight & 255;
	buffer[15] = screenHeight >> 8;
	buffer[16] = 24;	// pixel size

	glReadPixels (0, 0, screenWidth, screenHeight, GL_RGB, GL_UNSIGNED_BYTE, buffer + 18);

	// swap rgb to bgr
	for (i = 18; i < len; i += 3)
	{
		temp = buffer[i];
		buffer[i] = buffer[i+2];
		buffer[i+2] = temp;
	}
	M_WriteFile (tganame, buffer, len);

	free (buffer);
	P_SetMessage(&players[consoleplayer], "SCREEN SHOT", false);
}
コード例 #7
0
ファイル: p_saveg.c プロジェクト: twipley/chocolate-doom
void SV_Close(char *fileName)
{
    int length;

    SV_WriteByte(SAVE_GAME_TERMINATOR);
    if (SaveGameType == SVG_RAM)
    {
        length = save_p - savebuffer;
        if (length > SAVEGAMESIZE)
        {
            I_Error("Savegame buffer overrun");
        }
        M_WriteFile(fileName, savebuffer, length);
        Z_Free(savebuffer);
    }
    else
    {                           // SVG_FILE
        fclose(SaveGameFP);
    }
}
コード例 #8
0
ファイル: m_saves.c プロジェクト: Krazygamr/D-Touch
//
// ToCurr
//
// Copying files from savepath to savepathtemp
//
void ToCurr(void)
{
    DIR *spdir = NULL;
    struct dirent *f = NULL;

    ClearTmp();

    // BUG: Rogue copypasta'd this error message, which is why we don't know
    // the real original name of this function.
    if(!(spdir = opendir(savepath)))
        I_Error("ClearSlot: Couldn't open dir %s", savepath);

    while((f = readdir(spdir)))
    {
        byte *filebuffer  = NULL;
        int   filelen     = 0;
        char *srcfilename = NULL;
        char *dstfilename = NULL;

        if(!strcmp(f->d_name, ".") || !strcmp(f->d_name, ".."))
            continue;

        // haleyjd: use M_SafeFilePath, NOT sprintf.
        srcfilename = M_SafeFilePath(savepath,     f->d_name);
        dstfilename = M_SafeFilePath(savepathtemp, f->d_name);

        filelen = M_ReadFile(srcfilename, &filebuffer);
        M_WriteFile(dstfilename, filebuffer, filelen);

        Z_Free(filebuffer);
        Z_Free(srcfilename);
        Z_Free(dstfilename);
    }

    closedir(spdir);
}
コード例 #9
0
//
// ToCurr
//
// Copying files from savepath to savepathtemp
//
void ToCurr(void)
{
    glob_t *glob;

    ClearTmp();

    // BUG: Rogue copypasta'd this error message, which is why we don't know
    // the real original name of this function.
    glob = I_StartGlob(savepath, "*", 0);
    if (glob == NULL)
        I_Error("ClearSlot: Couldn't open dir %s", savepath);

    for (;;)
    {
        byte *filebuffer;
        int filelen;
        const char *srcfilename;
        char *dstfilename;

        srcfilename = I_NextGlob(glob);
        if (srcfilename == NULL)
        {
            break;
        }

        dstfilename = M_SafeFilePath(savepathtemp, M_BaseName(srcfilename));

        filelen = M_ReadFile(srcfilename, &filebuffer);
        M_WriteFile(dstfilename, filebuffer, filelen);

        Z_Free(filebuffer);
        Z_Free(dstfilename);
    }

    I_EndGlob(glob);
}
コード例 #10
0
ファイル: r_demo.c プロジェクト: twinaphex/sdcell
static int G_ReadDemoFooter(const char *filename)
{
#ifndef __CELLOS_LV2__
  int result = false;

  byte *buffer = NULL;
  byte *demoex_p = NULL;
  size_t size;

  M_ChangeDemoExtendedFormat();

  if (!use_demoex_info)
    return result;

  demoex_filename[0] = 0;

  if (demo_demoex_filename && *demo_demoex_filename)
  {
    strncpy(demoex_filename, demo_demoex_filename, PATH_MAX);
  }
  else
  {
    const char* tmp_dir;
    char* tmp_path = NULL;
    const char* template_format = "%sprboom-plus-demoex-XXXXXX";

    tmp_dir = I_GetTempDir();
    if (tmp_dir && *tmp_dir != '\0')
    {
      tmp_path = malloc(strlen(tmp_dir) + 2);
      strcpy(tmp_path, tmp_dir);
      if (!HasTrailingSlash(tmp_dir))
      {
        strcat(tmp_path, "/");
      }

      SNPRINTF(demoex_filename, sizeof(demoex_filename), template_format, tmp_path);
      mktemp(demoex_filename);

      free(tmp_path);
    }
  }

  if (!demoex_filename[0])
  {
    lprintf(LO_ERROR, "G_ReadDemoFooter: failed to create demoex temp file");
  }
  else
  {
    AddDefaultExtension(demoex_filename, ".wad");

    buffer = G_GetDemoFooter(filename, &demoex_p, &size);
    if (buffer)
    {
      //the demo has an additional information itself
      size_t i;
      waddata_t waddata;

      //write an additional info from a demo to demoex.wad
      if (!M_WriteFile(demoex_filename, (void*)demoex_p, size))
      {
        lprintf(LO_ERROR, "G_ReadDemoFooter: failed to create demoex temp file %s", demoex_filename);
      }
      else
      {
        //add demoex.wad to the wads list
        D_AddFile(demoex_filename, source_auto_load);

        //cache demoex.wad for immediately getting its data with W_CacheLumpName
        W_Init();

        WadDataInit(&waddata);

        //enumerate and save all auto-loaded files and demo for future use
        for (i = 0; i < numwadfiles; i++)
        {
          if (
            wadfiles[i].src == source_auto_load ||
            wadfiles[i].src == source_pre ||
            wadfiles[i].src == source_lmp)
          {
            WadDataAddItem(&waddata, wadfiles[i].name, wadfiles[i].src, 0);
          }
        }

        //get needed wads and dehs from demoex.wad
        //restore all critical params like -spechit x
        R_DemoEx_GetParams(buffer, &waddata);

        //replace old wadfiles with the new ones
        if (waddata.numwadfiles)
        {
          for (i = 0; (size_t)i < waddata.numwadfiles; i++)
          {
            if (waddata.wadfiles[i].src == source_iwad)
            {
              W_ReleaseAllWads();
              WadDataToWadFiles(&waddata);
              result = true;
              break;
            }
          }
        }
        WadDataFree(&waddata);
      }
      free(buffer);
    }
    else
    {
      demoex_filename[0] = 0;
    }
  }

  return result;
#else
  return false;
#endif
}
コード例 #11
0
ファイル: cl_download.cpp プロジェクト: JohnnyonFlame/odamex
void IntDownloadComplete(void)
{
    std::string actual_md5 = MD5SUM(download.buf->ptr(), download.buf->maxsize());

	Printf(PRINT_HIGH, "\nDownload complete, got %u bytes\n", download.buf->maxsize());
	Printf(PRINT_HIGH, "%s\n %s\n", download.filename.c_str(), actual_md5.c_str());

	if(download.md5 == "")
	{
		Printf(PRINT_HIGH, "Server gave no checksum, assuming valid\n", (int)download.buf->maxsize());
	}
	else if(actual_md5 != download.md5)
	{
		Printf(PRINT_HIGH, " %s on server\n", download.md5.c_str());
		Printf(PRINT_HIGH, "Download failed: bad checksum\n");

		download.clear();
        CL_QuitNetGame();

        ClearDownloadProgressBar();

        return;
    }

    // got the wad! save it!
    std::vector<std::string> dirs;
    std::string filename;
    size_t i;
#ifdef _WIN32
    const char separator = ';';
#else
    const char separator = ':';
#endif

    // Try to save to the wad paths in this order -- Hyper_Eye
    D_AddSearchDir(dirs, Args.CheckValue("-waddir"), separator);
    D_AddSearchDir(dirs, getenv("DOOMWADDIR"), separator);
    D_AddSearchDir(dirs, getenv("DOOMWADPATH"), separator);
    D_AddSearchDir(dirs, waddirs.cstring(), separator);
    dirs.push_back(startdir);
    dirs.push_back(progdir);

    dirs.erase(std::unique(dirs.begin(), dirs.end()), dirs.end());

    for(i = 0; i < dirs.size(); i++)
    {
        filename.clear();
        filename = dirs[i];
        if(filename[filename.length() - 1] != PATHSEPCHAR)
            filename += PATHSEP;
        filename += download.filename;

        // check for existing file
   	    if(M_FileExists(filename.c_str()))
   	    {
   	        // there is an existing file, so use a new file whose name includes the checksum
   	        filename += ".";
   	        filename += actual_md5;
   	    }

        if (M_WriteFile(filename, download.buf->ptr(), download.buf->maxsize()))
            break;
    }

    // Unable to write
    if(i == dirs.size())
    {
		download.clear();
        CL_QuitNetGame();
        return;
    }

    Printf(PRINT_HIGH, "Saved download as \"%s\"\n", filename.c_str());

	download.clear();
    CL_QuitNetGame();
    CL_Reconnect();

    ClearDownloadProgressBar();
}
コード例 #12
0
static void *I_SDL_RegisterSong(void *data, int len)
{
    char *filename;
    Mix_Music *music;

    if (!music_initialized)
    {
        return NULL;
    }

    // MUS files begin with "MUS"
    // Reject anything which doesnt have this signature

    filename = M_TempFile("doom"); // [crispy] generic filename

    // [crispy] Reverse Choco's logic from "if (MIDI)" to "if (not MUS)"
    // MUS is the only format that requires conversion,
    // let SDL_Mixer figure out the others
/*
    if (IsMid(data, len) && len < MAXMIDLENGTH)
*/
    if (len < 4 || memcmp(data, "MUS\x1a", 4)) // [crispy] MUS_HEADER_MAGIC
    {
        M_WriteFile(filename, data, len);
    }
    else
    {
	// Assume a MUS file and try to convert

        ConvertMus(data, len, filename);
    }

    // Load the MIDI. In an ideal world we'd be using Mix_LoadMUS_RW()
    // by now, but Mix_SetMusicCMD() only works with Mix_LoadMUS(), so
    // we have to generate a temporary file.

#if defined(_WIN32)
    // [AM] If we do not have an external music command defined, play
    //      music with the MIDI server.
    if (midi_server_initialized)
    {
        music = NULL;
        if (!I_MidiPipe_RegisterSong(filename))
        {
            fprintf(stderr, "Error loading midi: %s\n",
                "Could not communicate with midiproc.");
        }
    }
    else
#endif
    {
        music = Mix_LoadMUS(filename);
        if (music == NULL)
        {
            // Failed to load
            fprintf(stderr, "Error loading midi: %s\n", Mix_GetError());
        }

        // Remove the temporary MIDI file; however, when using an external
        // MIDI program we can't delete the file. Otherwise, the program
        // won't find the file to play. This means we leave a mess on
        // disk :(

        if (strlen(snd_musiccmd) == 0)
        {
            remove(filename);
        }
    }

    free(filename);

    return music;
}