Exemplo n.º 1
0
static int zfread_alternate(unzFile * f, void *buffer, int length, int inc)
{
    Uint8 *buf = buffer;
    Uint8 tempbuf[4096];
    Uint32 totread, r, i;
    int totlength=length;
    totread = 0;
    

    while (length) {

	r = length;
	if (r > 4096)
	    r = 4096;

	r = unzReadCurrentFile(f, tempbuf, r);
	if (r == 0) {
	    terminate_progress_bar();
	    return totread;
	}
	for (i = 0; i < r; i++) {
	    *buf = tempbuf[i];
	    buf += inc;
	}
	totread += r;
	length -= r;
	update_progress_bar(totread,totlength);
    }

    terminate_progress_bar();
    return totread;
}
Exemplo n.º 2
0
static int zfread(unzFile * f, void *buffer, int length)
{
    Uint8 *buf = (Uint8*)buffer;
    Uint8 *tempbuf;
    Uint32 totread, r, i;
    int totlength=length;
    totread = 0;
    tempbuf=alloca(4097);

    while (length) {

	r = length;
	if (r > 4096)
	    r = 4096;

	r = unzReadCurrentFile(f, tempbuf, r);
	if (r == 0) {
	    terminate_progress_bar();
	    return totread;
	}
	memcpy(buf, tempbuf, r);

	buf += r;
	totread += r;
	length -= r;
	update_progress_bar(totread,totlength);
    }

    terminate_progress_bar();
    return totread;
}
Exemplo n.º 3
0
int soundfile_load_file(char *filename, long lpos, long lsample_count,
                        int status_info)
{
    sf_count_t pos = lpos;
    sf_count_t sample_count = lsample_count;
    int rc = -1;

    if (sf_seek(sndfile, pos, SEEK_SET|SFM_WRITE) == pos) {
        int channels = sfinfo.channels;
        sf_count_t buffer_size = SBW*1000;
        int *buffer = calloc(channels*buffer_size, sizeof(int));

        if (buffer != NULL) {
            SNDFILE *sndfile_new;
            SF_INFO sfinfo_new = sfinfo;

            sfinfo_new.format = 0;
            sndfile_new = sf_open(filename, SFM_READ, &sfinfo_new);
            if (sndfile_new != NULL) {
                sf_count_t processed = 0;
                sf_count_t read_size;

                if (sample_count > sfinfo_new.frames)
                    sample_count = sfinfo_new.frames;

                while (processed < sample_count) {
                    if (buffer_size > sample_count - processed)
                        buffer_size = sample_count - processed;

                    read_size = sf_readf_int(sndfile_new, buffer, buffer_size);
                    if (read_size > 0)
                        sf_writef_int(sndfile, buffer, read_size);

                    processed += buffer_size;
                    if (status_info)
                        update_progress_bar((gfloat)processed/sample_count,
                                          PROGRESS_UPDATE_INTERVAL, FALSE);
                }

                sf_close(sndfile_new);
                rc = 0;
/*                remove(filename); */
            }
            free(buffer);
        }
    }
    return rc;
}
Exemplo n.º 4
0
static void load_previous_server_state(){
	std::ifstream in("server_state.save");
	if(in.is_open()){
		std::vector<std::string> save;
		char data[65536];
		while(in.getline(data, 65536)){
			save.push_back(data);
		}
		const uint_ save_size = save.size();
		for(uint_ i = 0;i < save_size;i++){
			update_class_data(save[i], ~0);
			update_progress_bar(i/save_size, "load_previous_server_state");
		}
	}else{
		printf("There doesn't appear to be a server_save file to use\n");
	}
}
Exemplo n.º 5
0
void
quick_check (void)
{
#ifdef QUICK_CHECK_ENABLED
	static gboolean quick_check_running = FALSE;
	GList *list_pointer;
	gint nb_rom_not_checked;
	gfloat done;
	MameRomEntry *rom;

	GMAMEUI_DEBUG ("Running quick check.");
	if (game_list.num_games == 0)
		return;

	/*prevent user to launch several quick check at the same time */
	if (quick_check_running)
	{
		GMAMEUI_DEBUG ("Quick check already running");
		return;
	}
	quick_check_running = TRUE;
		
	show_progress_bar ();

	nb_rom_not_checked = g_list_length (game_list.not_checked_list);
	g_message (_("Performing quick check, please wait:"));
	/* Disable the callback */
	g_signal_handlers_block_by_func (G_OBJECT (gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (main_gui.scrolled_window_games))),
					 (gpointer)adjustment_scrolled, NULL);

	/* need to use the last or I can find the list anymore*/
	for (list_pointer = game_list.not_checked_list;
	     list_pointer;
	     list_pointer = g_list_next (list_pointer))
	{
		rom = (MameRomEntry *)list_pointer->data;

		/* Check for the existence of the ROM; if the ROM is a clone, the
		   parent set must exist as well */
		if (mame_rom_entry_is_clone (rom))
			if ((check_rom_exists_as_file (mame_rom_entry_get_romname (rom))) &&
			    (check_rom_exists_as_file (mame_rom_entry_get_parent_romname (rom))))
			    g_object_set (rom, "has-roms", UNKNOWN, NULL);
			else
			    g_object_set (rom, "has-roms", NOT_AVAIL, NULL);

		else if (check_rom_exists_as_file (mame_rom_entry_get_romname (rom)))
			g_object_set (rom, "has-roms", UNKNOWN, NULL);
		else
			g_object_set (rom, "has-roms", NOT_AVAIL, NULL);


		/* Looking for samples */
		rom->has_samples = 0;

		if (mame_rom_entry_has_samples (rom))
		{
			/* Check for the existence of the samples; if the samples is a clone, the
			   parent set must exist as well */
			if (strcmp (rom->sampleof, "-")) {
				if ((check_rom_exists_as_file (mame_rom_entry_get_romname (rom))) &&
				    (check_rom_exists_as_file (rom->sampleof)))
					g_object_set (rom, "has-samples", CORRECT, NULL);
			} else if (check_rom_exists_as_file (mame_rom_entry_get_romname (rom)))
				g_object_set (rom, "has-samples", CORRECT, NULL);
		}
		
		list_pointer->data = NULL;
		nb_rom_not_checked--;

		done = (gfloat) (game_list.num_games - nb_rom_not_checked) / (gfloat)game_list.num_games;

#if 0
		if (done >= 0.0 && done <= 1.0)
			update_progress_bar (done);
#endif

		/* if the game is in the list, update it */
		if (rom->is_in_list)
			mame_gamelist_view_update_game_in_list (rom);
	}
	g_list_free(game_list.not_checked_list);
	game_list.not_checked_list = NULL;

	hide_progress_bar ();
	quick_check_running= FALSE;
	
	/* Re-Enable the callback */
	g_signal_handlers_unblock_by_func (G_OBJECT (gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (main_gui.scrolled_window_games))),
					   (gpointer)adjustment_scrolled, NULL);
#endif
}
Exemplo n.º 6
0
/* shift all samples from 'first_pos' to begin of file
 * (this removes 'sample_count' samples at end of file)
 */
int soundfile_shift_samples_left(long lfirst_pos, long lsample_count,
                                 int status_info)
{
    /* if 'last_pos' is equal 'end_pos' simply truncate the end
     * else move sample i from 'last_pos' to the 'first_pos' position
     * (for all i between 'last_pos' and end of file)
     * and then truncate 'last_pos - first_pos' samples at the end.
     */
    sf_count_t first_pos = lfirst_pos;
    sf_count_t sample_count = lsample_count;
    sf_count_t end_pos = sf_seek(sndfile, 0, SEEK_END|SFM_READ);
    sf_count_t last_pos = first_pos + sample_count;

    if (sample_count <= 0) {
        puts("soundfile_shift_samples_left: no samples to move");
        return 0;
    }

/*     printf("soundfile_shift_samples_left: " */
/*            "first_pos=%lld, shift=%lld, samples in file=%lld\n", */
/*            first_pos, sample_count, end_pos); */

    if (last_pos < end_pos)
    {
        sf_count_t processed = 0;
        sf_count_t buffer_size;
        int channels = sfinfo.channels;
#define TMPBUFSIZE     (4*SBW*1000)
        int buffer[TMPBUFSIZE];

        /* start position for writing */
        if (sf_seek(sndfile, first_pos, SEEK_SET|SFM_WRITE) < 0)
        {
            perr("soundfile_shift_samples_left: sf_seek write pointer");
            warning("Libsndfile reports write pointer seek error in audio file");
            return -1;
        }

        /* start position for reading */
        if (sf_seek(sndfile, last_pos, SEEK_SET|SFM_READ) < 0)
        {
            perr("soundfile_shift_samples_left: sf_seek read pointer");
            warning("Libsndfile reports read pointer seek error in audio file");
            return -1;
        }

        /* loop to end of file */
        buffer_size = TMPBUFSIZE/channels;

        while ((buffer_size = sf_readf_int(sndfile, buffer, buffer_size)) > 0)
        {
            if (sf_writef_int(sndfile, buffer, buffer_size) != buffer_size) {
                perr("soundfile_shift_samples_left: sf_writef_int");
                warning("Libsndfile reports write error in audio file");
                return -1;
            }

            processed += buffer_size;

            if (status_info)
                update_progress_bar((gfloat)processed/(end_pos-first_pos-sample_count),
                                  PROGRESS_UPDATE_INTERVAL, FALSE);

/*             printf("soundfile_shift_samples_left: processed=%lld (%f.2)\n", */
/*                    processed, (gfloat)processed/(end_pos-first_pos-sample_count)); */
        }
    }

    /* truncate file size for '-sample_count' samples */
    end_pos -= sample_count;

    if (sf_command(sndfile, SFC_FILE_TRUNCATE, &end_pos, sizeof(end_pos)))
    {
        perr("soundfile_shift_samples_left: sf_command");
        warning("Libsndfile reports truncation of audio file failed");
        return -1;
    }

/*     printf("soundfile_shift_samples_left: samples in file=%lld\n", */
/*            sf_seek(sndfile, 0, SEEK_END|SFM_READ)); */

    adjust_all_marker_positions(first_pos, -sample_count);
    return 0;
}
Exemplo n.º 7
0
/* append 'sample_count' samples and shift all samples from 'first_pos'
 * to end of file (this creates 'sample_count' samples at 'first_pos')
 */
int soundfile_shift_samples_right(long lfirst_pos, long lsample_count,
                                  int status_info)
{
    sf_count_t first_pos = lfirst_pos;
    sf_count_t sample_count = lsample_count;
    sf_count_t end_pos = sf_seek(sndfile, 0, SEEK_END|SFM_READ);

    if (sample_count <= 0) {
        puts("soundfile_shift_samples_right: no samples to move");
        return 0;
    }

/*     printf("soundfile_shift_samples_right: " */
/*            "first_pos=%lld, shift=%lld, samples in file=%lld\n", */
/*            first_pos, sample_count, end_pos); */

    if (first_pos < end_pos) {
        sf_count_t processed = 0;
        sf_count_t read_pos, write_pos;
        int channels = sfinfo.channels;
#define TMPBUFSIZE     (4*SBW*1000)
        int buffer[TMPBUFSIZE];
        sf_count_t buffer_size = TMPBUFSIZE/channels;

        /* go to end position and append enough space for the new data */
        if (write_silence(end_pos, sample_count) < 0) {
            return -1;
        }

        /* loop reading-writing from end */
        write_pos = end_pos + sample_count;
        read_pos  = end_pos;

        while (read_pos > first_pos) {
            if (buffer_size > read_pos - first_pos)
                buffer_size = read_pos - first_pos;

            write_pos -= buffer_size;
            read_pos  -= buffer_size;

/*             printf("soundfile_shift_samples_right: " */
/*                    "read_pos=%lld, write_pos=%lld, diff=%lld, buffer_size=%lld\n", */
/*                    read_pos, write_pos, write_pos-read_pos, buffer_size); */

            /* start position for reading */
            if (sf_seek(sndfile, read_pos, SEEK_SET|SFM_READ) < 0) {
                perr("soundfile_shift_samples_right: sf_seek read pointer");
                warning("Libsndfile reports read pointer seek error in audio file");
                return -1;
            }
            if (sf_readf_int(sndfile, buffer, buffer_size) != buffer_size) {
                perr("soundfile_shift_samples_right: sf_readf_int");
                warning("Libsndfile reports read error in audio file");
                return -1;
            }

            /* start position for writing */
            if (sf_seek(sndfile, write_pos, SEEK_SET|SFM_WRITE) < 0) {
                perr("soundfile_shift_samples_right: sf_seek write pointer");
                warning("Libsndfile reports write pointer seek error in audio file");
                return -1;
            }
            if (sf_writef_int(sndfile, buffer, buffer_size) != buffer_size) {
                perr("soundfile_shift_samples_right: sf_writef_int");
                warning("Libsndfile reports write error in audio file");
                return -1;
            }

            processed += buffer_size;
            if (status_info)
                update_progress_bar((gfloat)processed/(end_pos-first_pos),
                                  PROGRESS_UPDATE_INTERVAL, FALSE);

/*             printf("soundfile_shift_samples_right: processed=%lld (%f.2)\n", */
/*                    processed, (gfloat)processed/(end_pos-first_pos)); */
        }
    }

/*     printf("soundfile_shift_samples_right: samples in file=%lld\n", */
/*            sf_seek(sndfile, 0, SEEK_END|SFM_READ)); */

    adjust_all_marker_positions(first_pos, sample_count);
    return 0;
}
Exemplo n.º 8
0
/*--------------------------------------------------------------------------*/
static void
read_remote_file_callback( GnomeVFSAsyncHandle *handle,
			   GnomeVFSResult result,
			   gpointer buffer,
			   GnomeVFSFileSize bytes_requested,
			   GnomeVFSFileSize bytes_read,
			   gpointer callback_data )
{
	DownloadCallbackData *data = (DownloadCallbackData *)callback_data;
	GnomeVFSFileSize      bytes_written;

	gb_debug (DEBUG_UPDATE, "START");

	if ( update_cancel_flag ) {
		gnome_vfs_async_close( handle, close_remote_file_callback, data );
		gb_debug (DEBUG_UPDATE, "END -- CANCEL");
		return;
	}

	switch (result) {

	case GNOME_VFS_OK:
		if ( bytes_read > 0 ) {
			data->total_bytes_read += bytes_read;
			data->file_bytes_read += bytes_read;

			update_progress_bar (GTK_PROGRESS_BAR(file_progress),
					     data->file_bytes_read,
					     data->file_bytes);
			update_progress_bar (GTK_PROGRESS_BAR(total_progress),
					     data->total_bytes_read,
					     data->total_bytes);

			gnome_vfs_write( data->local_handle,
					 buffer, bytes_read, &bytes_written );
			if ( bytes_written != bytes_read ) {
				g_warning( "Write failed: %d bytes written != %d bytes read",
					   (gint)bytes_written, (gint)bytes_read );
			}
			gnome_vfs_async_read( handle, data->buffer, data->buffer_length,
					      read_remote_file_callback, data );
		}
		else {
			gnome_vfs_async_close( handle, close_remote_file_callback, data );
			gb_debug (DEBUG_UPDATE, "0 length read");
		}
		break;

	case GNOME_VFS_ERROR_EOF:
		gb_debug (DEBUG_UPDATE, "EOF -- %" GNOME_VFS_OFFSET_FORMAT_STR,
			  bytes_read);
		gnome_vfs_async_close( handle, close_remote_file_callback, data );
		break;

	default:
		g_warning( "Read failed: %s", gnome_vfs_result_to_string(result) );
		break;

	}

	gb_debug (DEBUG_UPDATE, "END");
}
Exemplo n.º 9
0
/*--------------------------------------------------------------------------*/
static void open_remote_file_callback( GnomeVFSAsyncHandle *handle,
				       GnomeVFSResult result,
				       gpointer callback_data )
{
	DownloadCallbackData *data = (DownloadCallbackData *)callback_data;
	GnomeVFSFileInfo     *info = (GnomeVFSFileInfo *)data->p->data;
	gchar                *local_path, *local_text_uri, *local_name;
	GnomeVFSHandle       *local_handle;
	gchar                *status_string;
	GnomeVFSResult        ret;

	gb_debug (DEBUG_UPDATE, "START");

	if ( update_cancel_flag ) {
		gnome_vfs_async_close( handle, close_remote_file_callback, data );
		gb_debug (DEBUG_UPDATE, "END -- CANCEL");
		return;
	}

	switch (result) {

	case GNOME_VFS_OK:
		data->file_bytes_read = 0;
		data->file_bytes      = info->size;

		status_string = g_strdup_printf( _("File: \"%s\" (%d of %d)"),
						 info->name, (data->i+1), data->n );
		gtk_label_set_text( GTK_LABEL(file_label), status_string );
		g_free( status_string );

		update_progress_bar (GTK_PROGRESS_BAR(file_progress),
				     0,
				     data->file_bytes);
		update_progress_bar (GTK_PROGRESS_BAR(total_progress),
				     data->total_bytes_read,
				     data->total_bytes);
    
		local_name = hash_filename( info->name );
		local_path = g_build_filename (gb_util_get_home_data_dir(),
					       local_name,
					       NULL);
		local_text_uri = gnome_vfs_get_uri_from_local_path( local_path );
		ret = gnome_vfs_create( &local_handle, local_text_uri,
					GNOME_VFS_OPEN_WRITE, FALSE, 0664 );
		if ( ret != GNOME_VFS_OK ) {
			g_warning( "error opening local file %s, %s\n", local_path,
				   gnome_vfs_result_to_string(ret) );
		}
		else {
			data->local_handle = local_handle;
			gnome_vfs_async_read( handle, data->buffer, data->buffer_length,
					      read_remote_file_callback, data );
		}
		g_free( local_name );
		g_free( local_path );
		g_free( local_text_uri );
		break;

	default:
		g_warning( "Open failed: %s.\n", gnome_vfs_result_to_string(result) );
		break;

	}

	gb_debug (DEBUG_UPDATE, "END");
}
Exemplo n.º 10
0
static void end_operation(void)
{
    pop_status_text();
    update_progress_bar(0.0, PROGRESS_UPDATE_INTERVAL, TRUE);
}
Exemplo n.º 11
0
static void begin_operation(char *status_text)
{
    push_status_text(status_text);
    update_progress_bar(0.0, PROGRESS_UPDATE_INTERVAL, TRUE) ;
}
Exemplo n.º 12
0
SDL_bool dr_load_game(DRIVER *dr,char *name) {
    unzFile *gz;
    int i;
    LIST *l;
    char *zip=get_zip_name(name);
    gz = unzOpen(zip);
    free(zip);
    if (gz==NULL) {
	return SDL_FALSE;
    }
    if (dr->special_bios) {
	memory.bios=malloc(dr->bios.size);
	memory.bios_size=dr->bios.size;
	if (!dr_load_section(gz,dr->bios,memory.bios)) return SDL_FALSE;
    }
    for (i=0;i<SEC_MAX;i++) {
	int s=dr->section[i].size;
	Uint8 *current_buf=NULL;
	//if (dr->section[i].item==NULL) continue;
	if (s==0) continue;
	//      printf("%p %d \n",dr->section[i].item,i);
	switch (i) {
	case SEC_CPU:
	    memory.cpu = malloc(s);
	    current_buf = memory.cpu;
	    memory.cpu_size = s;
	    break;
	case SEC_SFIX:
	    memory.sfix_game = malloc(s);
	    memory.fix_game_usage = malloc(s >> 5);
	    current_buf = memory.sfix_game;
	    memory.sfix_size = s;
	    break;
	case SEC_SM1:
	    memory.sm1 = malloc(s);
	    current_buf = memory.sm1;
	    memory.sm1_size = s;
	    break;
	case SEC_SOUND1:
	    memory.sound1 = malloc(s);
	    memory.sound1_size = s;
	    current_buf = memory.sound1;
	    break;
	case SEC_SOUND2:
	    memory.sound2 = malloc(s);
	    memory.sound2_size = s;
	    current_buf = memory.sound2;
	    break;
	case SEC_GFX:
	    memory.gfx = malloc(s);
	    //printf("Alloc %x for GFX: %p\n",s,memory.gfx);
	    memory.gfx_size = s;
	    current_buf = memory.gfx;
	    memory.pen_usage = malloc((s >> 7) * sizeof(int));
	    memset(memory.pen_usage, 0, (s >> 7) * sizeof(int));
	    memory.nb_of_tiles = s >> 7;
	    break;
	    /* TODO: Crypted rom */
	default:
	    break;
	}
	if (!dr_load_section(gz,dr->section[i],current_buf)) return SDL_FALSE;
    }
    unzClose(gz);

    /* TODO: Use directly the driver value insteed of recopying them */
    conf.game=dr->name;
    conf.rom_type=dr->rom_type;
    conf.special_bios=dr->special_bios;
    conf.extra_xor=dr->xor;
    set_bankswitchers(dr->banksw_type);
    for(i=0;i<6;i++)
	memory.bksw_unscramble[i]=dr->banksw_unscramble[i];
    for(i=0;i<64;i++)
	memory.bksw_offset[i]=dr->banksw_off[i];


    if (conf.rom_type == MGD2) {
	create_progress_bar("Convert MGD2");
	convert_mgd2_tiles(memory.gfx, memory.gfx_size);
	convert_mgd2_tiles(memory.gfx, memory.gfx_size);
	terminate_progress_bar();
    }
    if (conf.rom_type == MVS_CMC42) {
	create_progress_bar("Decrypt GFX ");
	kof99_neogeo_gfx_decrypt(conf.extra_xor);
	terminate_progress_bar();
    }
    if (conf.rom_type == MVS_CMC50) {
	create_progress_bar("Decrypt GFX ");
	kof2000_neogeo_gfx_decrypt(conf.extra_xor);
	terminate_progress_bar();
    }

    convert_all_char(memory.sfix_game, memory.sfix_size,
		     memory.fix_game_usage);


    if (CF_BOOL(cf_get_item_by_name("convtile"))) {
	create_progress_bar("Convert tile");
	for (i = 0; i < memory.nb_of_tiles; i++) {
	    convert_tile(i);
	    if (i%100==0) update_progress_bar(i,memory.nb_of_tiles);
	}
	terminate_progress_bar();
    }

    if (memory.sound2 == NULL) {
	memory.sound2 = memory.sound1;
	memory.sound2_size = memory.sound1_size;
    }
    //backup neogeo game vectors
    memcpy(memory.game_vector,memory.cpu,0x80);
    printf("                                                                             \r");

    return SDL_TRUE;
}
Exemplo n.º 13
0
void Dialog::beginProgramming()
{
  int numTries = 0;
  char buf[1024];
  int rc;
  QMessageBox msgbox;
#ifdef _WIN32
    Sleep(3000);
#else
    usleep(3000000);
#endif
  rc = Mobot_dongleGetTTY(buf, 1024);
  if(rc) {
    msgbox.setText("No connected robots detected.");
    msgbox.exec();
    return;
  }
  while(1) {
    qDebug() << "Connecting to: " << buf;
    stk_ = new CStkComms();
    rc = stk_->connectWithTTY(buf);
    qDebug() << "Connection finish with code: " << rc;
    if(rc) { 
      if(numTries > 20) {
        msgbox.setText("Detected robot not running valid bootloader. Please make "
            "sure that the \"Program Firmware\" button is being clicked after "
            "the red LED flashes but before the solid blue LED is showing. 1");
        msgbox.exec();
        return; 
      } else {
#ifdef _WIN32
        Sleep(100);
#else
        usleep(100000);
#endif
        numTries++;
      }
    } else {
      break;
    }
    numTries = 0;
#if 0
    qDebug() << "Attempting handshake...";
    rc = stk_->handshake();
    qDebug() << "Handshake finished with code " << rc;
    if(rc) { 
      if(numTries > 5) {
        msgbox.setText("Detected robot not running valid bootloader. Please make "
            "sure that the \"Program Firmware\" button is being clicked after "
            "the red LED flashes but before the solid blue LED is showing. 2");
        msgbox.exec();
        return; 
      } else {
#ifdef _WIN32
        Sleep(500);
#else
        usleep(500000);
#endif
        numTries++;
      }
    }
#endif
  }
  qDebug() << "Attempting to begin programming...";
  stk_->programAllAsync(g_hexfilename.c_str());
  ui->progressBar->setEnabled(true);
  /* Start a timer to update the progress bar */
  timer_ = new QTimer(this);
  QObject::connect(timer_, SIGNAL(timeout()), this, SLOT(update_progress_bar()));
  timer_->start(1000);
}