Пример #1
0
/*
================
idCommonLocal::AVIGame

Start AVI recording the current game session
================
*/
void idCommonLocal::AVIGame( const char *demoName ) {
	if ( aviCaptureMode ) {
		EndAVICapture();
		return;
	}

	if ( !mapSpawned ) {
		common->Printf( "No map spawned.\n" );
	}

	if ( !demoName || !demoName[0] ) {
		idStr filename = FindUnusedFileName( "demos/game%03i.game" );
		demoName = filename.c_str();

		// write a one byte stub .game file just so the FindUnusedFileName works,
		fileSystem->WriteFile( demoName, demoName, 1 );
	}

	BeginAVICapture( demoName ) ;
}
Пример #2
0
static int AppendFile(Directory *d)
{ FILE        *f;
  char        pathName[PATHNAMESIZE], newPathName[PATHNAMESIZE], buf[BUFSIZE];
  int         i, j;
  int         oldIndex, newIndex, iFlag;


  if (verbose)
    printf("AppendFile called with directory '%s'\n", d->DirPathName);
  

  if ( (oldIndex=FindExistingFileName(d, pathName)) == -1 )
    {
	printf("AppendFile: failed to get a file to append to\n");
	return -1;
    }
  else if (oldIndex == -2 )
    {
      printf("AppendFile: found a flaw in the filing system\n");
      return 0;
    }

  printf("AppendFile: appending to file '%s'\n", pathName);
 
  /* Having selected a file to append to, we now have FINDUNUSEDFILETRIES */
  /* goes at finding a name that we can rename it to, having appended     */
  /* to it, such that the new name and the file size match (the number    */
  /* of blocks is encoded in the name), and the new size is greater than  */
  /* the old - as it must be, of course, since we're appending.           */
  
  newIndex=-1; iFlag=0;

  for (i=0; i<FINDUNUSEDFILETRIES; i++)
    if ( (newIndex=FindUnusedFileName(d, newPathName)) > oldIndex )
    { iFlag=1; break; }

  if (!iFlag)
  { printf("AppendFile: failed to find a suitable new name for file %s\n",
	   pathName);
    return 1;  /* Don't request a filesystem check, this is tedious. */
  }


  /* Open file in "r+" mode, so we can overwrite the 2nd header word without */
  /* losing the rest of the file's contents.                                 */
  if ( (f=fopen(pathName, "r+")) == NULL )
  { printf("AppendFile: failed to open file '%s'\n", pathName);
    return 0;
  }

  /* Move file pointer to the 2nd word, & change it to correspond to the */
  /* file's new name.                                                    */
  fseek(f, 4, SEEK_SET);

  if ( !fwrite(&newIndex, sizeof(int), 1, f) )
  { printf("AppendFile: failed to modify header byte of file '%s'\n", 
	    pathName);

    free(safetyBlock);
    ReleaseMem();

    if ( fclose(f) == EOF )
      printf("AppendFile: failed to close file '%s'\n", pathName);
    
    if ( unlink(pathName) == -1 )
      printf("AppendFile: couldn't delete file '%s'\n", pathName);

    return 0;
  }

  /* Now move the file pointer to its end and append the new blocks on to */
  /* the end.                                                             */
  fseek(f, 0, SEEK_END);

  for (i=oldIndex; i<newIndex; i++)
  { for (j=0; j<BUFSIZE; j++)
      buf[j]=(unsigned char)i;

    if ( !fwrite(buf, 1, BUFSIZE, f) )
    { printf("AppendFile: failed to append a block to file '%s'\n", 
	     pathName);

      free(safetyBlock);
      ReleaseMem();

      if ( fclose(f) == EOF )
	printf("AppendFile: failed to close file '%s'\n", pathName);

      if ( unlink(pathName) == -1 )
	printf("AppendFile: couldn't delete file '%s'\n", pathName);
    }
  }

  if ( fclose(f) ==EOF )
    {
      printf("AppendFile: couldn't close file %s\n", pathName);

      free(safetyBlock);
      ReleaseMem();

      if ( unlink(pathName) == -1 )
	printf("CreateFile: couldn't delete file %s\n", pathName);

      return 0;
    }

  /* Having appended to the file, give it its new name & check its validity */

#if 0
  if (verbose)
#endif
    printf("AppendFile: renaming file '%s' to '%s'\n", 
	   pathName, newPathName);

  /* There's a bug in the posix 'rename' function, so use one of my own */
  /* devising instead.                                                  */
  if ( !RenRRD(pathName, newPathName) )
  { printf("CreateFile: failed to rename file '%s' as '%s'\n", 
	   pathName, newPathName);
    printf("CreateFile: errno is %d\n", errno);
    return 0;
  }
 
  if ( TestFile(newPathName, d->DirLevel) )
    return 1;
  else
    {
      printf("AppendFile: new file '%s' is corrupt!\n", newPathName);
      return 0;
    }
}
Пример #3
0
	case DS_SOUND:
		soundWorld->ProcessDemoCommand( readDemo );
		break;
	default:
		common->Error( "Bad render demo token" );
	}
}

/*
================
Common_DemoShot_f
================
*/
CONSOLE_COMMAND( demoShot, "writes a screenshot as a demo", NULL ) {
	if ( args.Argc() != 2 ) {
		idStr filename = FindUnusedFileName( "demos/shot%03i.demo" );
		commonLocal.DemoShot( filename );
	} else {
		commonLocal.DemoShot( va( "demos/shot_%s.demo", args.Argv(1) ) );
	}
}

/*
================
Common_RecordDemo_f
================
*/
CONSOLE_COMMAND( recordDemo, "records a demo", NULL ) {
	if ( args.Argc() != 2 ) {
		idStr filename = FindUnusedFileName( "demos/demo%03i.demo" );
		commonLocal.StartRecordingRenderDemo( filename );
Пример #4
0
static int CreateFile(Directory *d)
{
  int         fileNum, i, j;
  char        pathName[PATHNAMESIZE], buf[BUFSIZE];
  FILE        *f;

  if (verbose)
    printf("CreateFile called on directory '%s'\n", d->DirPathName);

  if ( (fileNum=FindUnusedFileName(d, pathName)) == -1 )
  { if (verbose)
      printf("CreateFile: FindUnusedFileName failed\n");
    return 0;
  }

  printf("Creating file %s\n", pathName);

  if ( (f=fopen(pathName, "wb")) == NULL)
  { printf("CreateFile: failed to open file %s\n", pathName);

    free(safetyBlock);
    ReleaseMem();

    return 0;
  }
  
  if ( !fwrite(&(d->DirLevel), sizeof(int), 1, f) ||
       !fwrite(&fileNum, sizeof(int), 1, f) )
  { printf("CreateFile: error writing header of file %s\n", pathName);

    free(safetyBlock);
    ReleaseMem();

    if ( fclose(f) == EOF)
      printf("CreateFile: couldn't close file %s\n", pathName);

    if ( unlink(pathName) == -1)
      printf("CreateFile: couldn't delete file %s\n", pathName);

    return 0;
  }

  for (i=0; i<fileNum; i++)
  { for (j=0; j<BUFSIZE; j++)
      buf[j]=(unsigned char)i;

    if ( fwrite(buf, 1, BUFSIZE, f) == 0 )
    { printf("CreateFile: error in writing contents of file %s\n", 
	     pathName);

      free(safetyBlock);
      ReleaseMem();
      
      if ( fclose(f) == EOF )
	printf("CreateFile: couldn't close file %s\n", pathName);
      
      if ( unlink(pathName) == -1)
	printf("CreateFile: couldn't delete file %s\n", pathName);
      
      return 0;
    }
  }

#ifndef DEBUG
  if (verbose)
#endif
    printf("CreateFile: created file %s\n", pathName);

  if ( fclose(f) ==EOF )
  { printf("CreateFile: couldn't close file %s\n", pathName);

    free(safetyBlock);
    ReleaseMem();

    if ( unlink(pathName) == -1)
      printf("CreateFile: couldn't delete file %s\n", pathName);

    return 0;
  }
 
  if ( TestFile(pathName, d->DirLevel) )
    return 1;
  else
  { printf("CreateFile: new file '%s' is corrupt!\n", pathName);
    return 0;
  }
}