/** * \brief Retrieves current user directory. */ PUBLIC char *FS_Userdir() { static char *home = NULL; static char W3Dlocaldir[128] = {'\0'}; /* Since the game directory doesn't change in all runtime, it makes sense to only look for it if it wasn't found yet. */ if ( !W3Dlocaldir[0] ){ home = getenv("HOME"); /* Mac OSX doesn't always have the HOME variable defined, so if looking for $HOME fails, try with getpwuid. */ if (!home){ struct passwd* pw; pw = getpwuid( getuid() ); home = pw->pw_dir; } com_snprintf( W3Dlocaldir, 128, "%s%c.local%cshare%cwolf3dredux%c", home, PATH_SEP, PATH_SEP, PATH_SEP, PATH_SEP ); W3Dlocaldir[127] = '\0'; FS_CreateDirectory(W3Dlocaldir); } return W3Dlocaldir; }
/* ----------------------------------------------------------------------------- Function: Parameters: Returns: Notes: ----------------------------------------------------------------------------- */ PRIVATE void R_ScreenShot_f( void ) { W8 *buffer; char picname[ 80 ]; char checkname[ MAX_OSPATH ]; int i; FILE *f; // create the scrnshots directory if it doesn't exist my_snprintf( checkname, sizeof( checkname ), "%s/scrnshot", FS_Gamedir() ); FS_CreateDirectory( checkname ); // // find a file name to save it to // my_strlcpy( picname, "scrn00.tga", sizeof( picname ) ); for( i = 0 ; i <= 99 ; ++i ) { picname[ 4 ] = i / 10 + '0'; picname[ 5 ] = i % 10 + '0'; my_snprintf( checkname, sizeof( checkname ), "%s/scrnshot/%s", FS_Gamedir(), picname ); f = fopen( checkname, "rb" ); if( ! f ) { break; // file doesn't exist } fclose( f ); } if( i == 100 ) { Com_Printf( "R_ScreenShot_f: Couldn't create a file\n" ); return; } buffer = MM_MALLOC( viddef.width * viddef.height * 3 ); pfglReadPixels( 0, 0, viddef.width, viddef.height, GL_RGB, GL_UNSIGNED_BYTE, buffer ); WriteTGA( checkname, 24, viddef.width, viddef.height, buffer, 1, 1 ); MM_FREE( buffer ); Com_Printf( "Wrote %s\n", picname ); }