void QtCurveShadowConfiguration::save(KConfig *cfg)
{
    KConfigGroup               group(cfg, CFG_GROUP);
    QtCurveShadowConfiguration def(m_colorGroup);

    WRITE_ENTRY("Size", m_size);
    WRITE_ENTRY("HOffset", m_hOffset);
    WRITE_ENTRY("VOffset", m_vOffset);
    WRITE_ENTRY("ColorType", m_colorType);
    WRITE_ENTRY("ShadowType", m_shadowType);

    if (m_colorType != CT_CUSTOM) {
        group.deleteEntry("Color");
    } else {
        WRITE_ENTRY("Color", m_color);
    }
}
Example #2
0
//////////////////////////////////////////////////////////////////////////
// Entries
//////////////////////////////////////////////////////////////////////////
void SaveLoad::writeEntry(SavegameType type, EntityIndex entity, uint32 value) {
#define WRITE_ENTRY(name, func, val) { \
	uint32 _prevPosition = (uint32)_savegame->pos(); \
	func; \
	uint32 _count = (uint32)_savegame->pos() - _prevPosition; \
	debugC(kLastExpressDebugSavegame, "Savegame: Writing " #name ": %d bytes", _count); \
	if (_count != val)\
		error("SaveLoad::writeEntry: Number of bytes written (%d) differ from expected count (%d)", _count, val); \
}

	if (!_savegame)
		error("SaveLoad::writeEntry: savegame stream is invalid");

	SavegameEntryHeader header;

	header.type = type;
	header.time = (uint32)getState()->time;
	header.chapter = getProgress().chapter;
	header.value = value;

	// Save position
	uint32 originalPosition = (uint32)_savegame->pos();

	// Write header
	Common::Serializer ser(NULL, _savegame);
	header.saveLoadWithSerializer(ser);

	// Write game data
	WRITE_ENTRY("entity index", ser.syncAsUint32LE(entity), 4);
	WRITE_ENTRY("state", getState()->saveLoadWithSerializer(ser), 4 + 4 + 4 + 4 + 1 + 4 + 4);
	WRITE_ENTRY("selected item", getInventory()->saveSelectedItem(ser), 4);
	WRITE_ENTRY("positions", getEntities()->savePositions(ser), 4 * 1000);
	WRITE_ENTRY("compartments", getEntities()->saveCompartments(ser), 4 * 16 * 2);
	WRITE_ENTRY("progress", getProgress().saveLoadWithSerializer(ser), 4 * 128);
	WRITE_ENTRY("events", getState()->syncEvents(ser), 512);
	WRITE_ENTRY("inventory", getInventory()->saveLoadWithSerializer(ser), 7 * 32);
	WRITE_ENTRY("objects", getObjects()->saveLoadWithSerializer(ser), 5 * 128);
	WRITE_ENTRY("entities", getEntities()->saveLoadWithSerializer(ser), 1262 * 40);
	WRITE_ENTRY("sound", getSound()->saveLoadWithSerializer(ser), 3 * 4 + getSound()->count() * 64);
	WRITE_ENTRY("savepoints", getSavePoints()->saveLoadWithSerializer(ser), 128 * 16 + 4 + getSavePoints()->count() * 16);

	header.offset = (uint32)_savegame->pos() - (originalPosition + 32);

	// Add padding if necessary
	while (header.offset & 0xF) {
		_savegame->writeByte(0);
		header.offset++;
	}

	// Save end position
	uint32 endPosition = (uint32)_savegame->pos();

	// Validate entry header
	if (!header.isValid())
		error("SaveLoad::writeEntry: entry header is invalid");

	// Save the header with the updated info
	_savegame->seek(originalPosition);
	header.saveLoadWithSerializer(ser);

	// Move back to the end of the entry
	_savegame->seek(endPosition);
}
Example #3
0
static TestEntry write_seek__nonwords[] = {
 {"AAX",""}, {"AaX",""}, {"AbX",""}, {"AcX",""}, {"AdX",""}, {"AeX",""},
 {"AfX",""}, {"AgX",""}, {"AzX",""},
};

static struct {
  const char *name;
  unsigned n_entries;
  TestEntry *entries;
  unsigned n_neg_entries;
  TestEntry *neg_entries;
} test_seek_datasets[] =
{
#define WRITE_ENTRY(name, pos, neg) \
  { name, DSK_N_ELEMENTS(pos), pos, DSK_N_ELEMENTS(neg), neg }
  WRITE_ENTRY ("odd/even", write_seek__odd_letters_to_cap, write_seek__even_letters_to_cap),
  WRITE_ENTRY ("even/odd", write_seek__even_letters_to_cap, write_seek__odd_letters_to_cap),
  WRITE_ENTRY ("dict list 1", write_seek__dict_head_to_dict_tail, write_seek__nonwords),
#undef WRITE_ENTRY
};


static void
test_simple_write_seek (void)
{
  unsigned i;
  for (i = 0; i < DSK_N_ELEMENTS (test_seek_datasets); i++)
    test_various_write_seek_1 (test_seek_datasets[i].name,
                               test_seek_datasets[i].n_entries,
                               test_seek_datasets[i].entries,
                               test_seek_datasets[i].n_neg_entries,
Example #4
0
File: decomp.c Project: wareya/gzrt
/* Show extractor window */
void gzrt_wdecomp_show ( MAINWIN * c )
{
	FILE          * h;
	GtkWidget     * window;
	GtkWidget     * pbar;
	GtkWidget     * dialog;
	int		        result;
	unsigned char * buffer;
	unsigned char * ftable;
	
	/* Does the parent exist? */
	if( g_list_find( parents, c ) )
		
		/* Yep... */
		return;
		
	/* Check filesize */
	if( c->c->filesize >= 40 * 1024 * 1024 )
	{
		gzrt_notice( "Error", "This ROM is already decompressed!" );
		return;
	}
		
	/* Add parent */
	parents = g_list_append( parents, c );
		
	/* Create file saving dialog */
	dialog = gtk_file_chooser_dialog_new
	( 
		"Choose a destination", NULL,
		GTK_FILE_CHOOSER_ACTION_SAVE, 
		GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
		GTK_STOCK_OPEN,   GTK_RESPONSE_ACCEPT, 
		NULL
	);
	gtk_widget_show_all( dialog );
	
	/* Run the dialog and fetch the result */
	while( (result = gtk_dialog_run( GTK_DIALOG(dialog) )) )
	switch( result )
	{
		/* A file has been chosen */
		case GTK_RESPONSE_ACCEPT:
		{
			char * n = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(dialog) );
			
			/* Check that file doesn't exist */
			if( (h = fopen(n, "rb")) )
			{
				gzrt_notice("Error", "File already exists.");
				fclose( h );
				continue;
			}
				
			/* Check that we can write to it */
			if( !(h = fopen(n, "wb")) )
			{
				gzrt_notice("Error", "Can't write to that file!");
				continue;
			}
			
			/* Destroy window */
			gtk_widget_destroy( dialog );
			
			/* Looks good, gogogo */
			goto decompress_rom;
		}
		break;
		
		/* Cancel */
		case GTK_RESPONSE_REJECT:
		 gtk_widget_destroy(dialog);
		 parents = g_list_remove( parents, c );
		 goto skiploop;
		break;
		
		/* Default */
		default:
		 parents = g_list_remove( parents, c );
		 gtk_widget_destroy(dialog);
		 goto skiploop;
	}
	
	/* Out of loop */
skiploop: ;
	return;
	
	/* Decompress a ROM */
decompress_rom: ;
	FILE * out = h;
	int    i;
	
	/* Create window */
	window = gtk_window_new( GTK_WINDOW_POPUP );
    gtk_widget_set_size_request( window, 400, 30 );
	gtk_window_set_title( GTK_WINDOW(window), " " );
	gtk_window_set_position( GTK_WINDOW(window), GTK_WIN_POS_CENTER_ALWAYS );
	gtk_window_set_keep_above( GTK_WINDOW(window), TRUE );
	gtk_window_set_modal( GTK_WINDOW(window), TRUE );
	
	/* Create progress bar */
	pbar = gtk_progress_bar_new();
	gtk_container_add( GTK_CONTAINER(window), pbar );
	gtk_widget_show_all( window );
	pbarset( pbar, 0.0, "%.2f%%", 0.0 );
	
	/* Create scratch buffer */
	buffer = gzrt_malloc( 8 * 1024 * 1024 );
	
	/* Create a new FS table */
	ftable = gzrt_malloc(ZFSEnd(c->z->fs) - ZFSStart(c->z->fs));
	
	/* Begin decompression */
	for( i = 0; i < z64fs_entries(c->z->fs); i++ )
	{
		/* Does this file exist? */
		if( !ZFileExists(c->z->fs, i) )
		{
			WRITE_ENTRY( ftable, i, 0, ZFileVirtStart(c->z->fs, i) );
			WRITE_ENTRY( ftable, i, 1, ZFileVirtEnd(c->z->fs, i)   );
			WRITE_ENTRY( ftable, i, 2, 0xFFFFFFFF 			   );
			WRITE_ENTRY( ftable, i, 3, 0xFFFFFFFF 			   );
			continue;
		}
		
		/* Read the file */
		z64fs_read_file( c->z, i, buffer );
		
		/* Write it */
		fwrite( buffer, ZFileVirtSize(c->z->fs, i), 1, out );
		
		/* Update new file table */
		WRITE_ENTRY( ftable, i, 0, ZFileVirtStart(c->z->fs, i) );
		WRITE_ENTRY( ftable, i, 1, ZFileVirtEnd(c->z->fs, i)   );
		WRITE_ENTRY( ftable, i, 2, ZFileVirtStart(c->z->fs, i) );
		WRITE_ENTRY( ftable, i, 3, 0 					   );
		
		/* Update progress bar */
		if( !((i + 1) % (z64fs_entries(c->z->fs) / 32)) )
			pbarset( pbar, (double)i / z64fs_entries(c->z->fs), "%.2f%%", (double)i / z64fs_entries(c->z->fs) * 100.0 );
	}
	
	/* Write new file table */
	int tmp = ftell(out);
	fseek( out, ZFSStart(c->z->fs), SEEK_SET );
	fwrite( ftable, 1, ZFSEnd(c->z->fs) - ZFSStart(c->z->fs), out );
	fseek( out, tmp, SEEK_SET );
	
	/* Set 100% */
	pbarset( pbar, 1.0, "Padding file..." );
	
	/* Write padding */
	for( i = ftell( out ); i < 64 * 1024 * 1024; i++ )
		fputc( 0x00, out );
	
	/* Fix CRCs */
	pbarset( pbar, 1.0, "Fixing CRCs..." );
	/* n64rom_crc_quick( out ); */
	
	/* Finished */
	gtk_widget_destroy( window );
	fclose( out );
	gzrt_free( buffer );
	gzrt_free( ftable );
	
	/* Remove it from parents list */
	parents = g_list_remove( parents, c );
	
	/* Show message */
	gzrt_notice( "Notice", "ROM decompression complete." );
}