Exemplo n.º 1
0
bool savegame::save_game_interactive(CVideo& video, const std::string& message,
									 gui::DIALOG_TYPE dialog_type)
{
	show_confirmation_ = true;
	create_filename();

	int res = gui2::twindow::OK;
	bool exit = true;

	do{
		try{
			res = show_save_dialog(video, message, dialog_type);
			exit = true;

			if (res == gui2::twindow::OK){
				exit = check_overwrite(video);
			}
		}
		catch (illegal_filename_exception){
			exit = false;
		}
	}
	while (!exit);

	if (res == 2) //Quit game
		throw end_level_exception(QUIT);

	if (res != gui2::twindow::OK)
		return false;

	return save_game(&video);
}
Exemplo n.º 2
0
static void
vfs_file_task_do_move ( VFSFileTask* task,
                        const char* src_file,
                        const char* dest_file )
{
    gchar* new_dest_file = NULL;
    gboolean dest_exists;
    struct stat file_stat;
    int result;

    if ( should_abort( task ) )
        return ;
    /* g_debug( "move \"%s\" to \"%s\"\n", src_file, dest_file ); */
    if ( lstat( src_file, &file_stat ) == -1 )
    {
        task->error = errno;    /* Error occurred */
        call_state_callback( task, VFS_FILE_TASK_ERROR );
        if ( should_abort( task ) )
            return ;
    }

    task->current_file = src_file;
    task->current_dest = dest_file;

    if ( should_abort( task ) )
        return ;

    call_progress_callback( task );

    if ( ! check_overwrite( task, dest_file,
           &dest_exists, &new_dest_file ) )
        return ;

    if ( new_dest_file )
        task->current_dest = dest_file = new_dest_file;

    result = rename( src_file, dest_file );

    if ( result != 0 )
    {
        task->error = errno;
        call_state_callback( task, VFS_FILE_TASK_ERROR );
        if ( should_abort( task ) )
        {
            g_free( new_dest_file );
            return ;
        }
    }
    else
        chmod( dest_file, file_stat.st_mode );

    task->progress += file_stat.st_size;
    call_progress_callback( task );

    g_free( new_dest_file );
}
Exemplo n.º 3
0
bool savegame::save_game_automatic(CVideo& video, bool ask_for_overwrite, const std::string& filename)
{
	if (filename == "")
		create_filename();
	else
		filename_ = filename;

	if (ask_for_overwrite){
		if (!check_overwrite(video)) {
			return save_game_interactive(video, "", gui::OK_CANCEL);
		}
	}

	return save_game(&video);
}
Exemplo n.º 4
0
bool savegame::save_game_interactive(CVideo& video, const std::string& message,
									 gui::DIALOG_TYPE dialog_type)
{
	show_confirmation_ = true;
	create_filename();

	const int res = show_save_dialog(video, message, dialog_type);

	if (res == 2) { 
		throw_quit_game_exception(); //Quit game
	}

	if (res == gui2::twindow::OK && check_overwrite(video)) {
		return save_game(&video);
	}

	return false;
}
Exemplo n.º 5
0
bool savegame::save_game_automatic(CVideo& video, bool ask_for_overwrite, const std::string& filename)
{
	bool overwrite = true;

	if (filename == "")
		create_filename();
	else
		filename_ = filename;

	if (ask_for_overwrite){
		overwrite = check_overwrite(video);

		if (!overwrite)
			return save_game_interactive(video, "", true);
	}

	return save_game(&video);
}
Exemplo n.º 6
0
int main(int argc, char *argv[]) {
    FILE    *fd,
            *fdo;
    u8      *fin,
            *fout;

    fputs("QuakeLive PK3 decrypter "VER"\n"
        "by Luigi Auriemma\n"
        "e-mail: [email protected]\n"
        "web:    aluigi.org\n"
        "\n", stdout);

    if(argc < 3) {
        printf("\n"
            "Usage:\n"
            "  %s <infile> <outfile>\n"
            "\n"
            "Example:\n"
            "  %s encrypted/quakelive-map.pk3 decrypted/some-map.pk3\n"
            "\n", argv[0], argv[0]);
        exit(1);
    }
    fin  = argv[1];
    fout = argv[2];

    printf("- open %s\n", fin);
    fd = fopen(fin, "rb");
    if(!fd) std_err();

    printf("- create %s\n", fout);
    if(check_overwrite(fout) < 0) exit(1);
    fdo = fopen(fout, "wb");
    if(!fdo) std_err();

    quakelive_decrypt(fd, fdo);

    fclose(fd);
    fclose(fdo);
    printf("- done\n");
    return(0);
}
Exemplo n.º 7
0
static int
FileSelectionDialog(GtkWidget *parent, int type, char *stock)
{
  struct nGetOpenFileData *data;
  GtkWidget *dlg, *rc;
  GtkFileFilter *filter;
  char *fname;

  data = &FileSelection;

  data->parent = (parent) ? parent : TopLevel;
  dlg = gtk_file_chooser_dialog_new(data->title,
				    GTK_WINDOW(data->parent),
				    type,
				    _("_Cancel"), GTK_RESPONSE_CANCEL,
				    stock, GTK_RESPONSE_ACCEPT,
				    NULL);
  gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(dlg), TRUE);
  rc = gtk_check_button_new_with_mnemonic(_("_Change current directory"));
  gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dlg))), rc, FALSE, FALSE, 5);
  data->chdir_cb = rc;
  gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dlg), data->multi);
  data->widget = dlg;

  if (data->ext) {
    char *filter_str, *filter_name, *ext_name;

    filter_str = g_strdup_printf("*.%s", data->ext);
    ext_name = g_ascii_strup(data->ext, -1);
    filter_name = g_strdup_printf(_("%s file (*.%s)"), ext_name, data->ext);
    g_free(ext_name);

    filter = gtk_file_filter_new();
    gtk_file_filter_add_pattern(filter, filter_str);
    gtk_file_filter_set_name(filter, filter_name);
    gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dlg), filter);
    g_free(filter_str);
    g_free(filter_name);

    filter = gtk_file_filter_new();
    gtk_file_filter_add_pattern(filter, "*");
    gtk_file_filter_set_name(filter, _("All"));
    gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dlg), filter);
  }

  if (data->init_dir && *(data->init_dir)) {
    gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dlg), *(data->init_dir));
  }
  gtk_widget_show_all(dlg);

  if (data->changedir && data->init_dir) {
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data->chdir_cb), data->chdir);
  } else {
    gtk_widget_hide(data->chdir_cb);
  }

  fname = get_filename_with_ext(data->init_file, data->ext);
  if (fname) {
    if (type == GTK_FILE_CHOOSER_ACTION_SAVE) {
#ifdef WINDOWS
      char *tmp;
      tmp = g_locale_from_utf8(fname, -1, NULL, NULL, NULL);
      if (tmp) {
	file_dialog_set_current_neme(dlg, tmp);
	g_free(tmp);
      }
#else  /* WINDOWS */
      file_dialog_set_current_neme(dlg, fname);
#endif	/* WINDOWS */
    } else {
      gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dlg), fname);
    }
    g_free(fname);
  }

  data->ret = IDCANCEL;

  while (1) {
    if (ndialog_run(dlg) != GTK_RESPONSE_ACCEPT)
      break;

    fsok(dlg);
    if (data->ret == IDOK && type == GTK_FILE_CHOOSER_ACTION_SAVE) {
      file_dialog_set_current_neme(dlg, FileSelection.file[0]);
      if (! data->overwrite && check_overwrite(dlg, FileSelection.file[0])) {
	data->ret = IDCANCEL;
	continue;
      }
    }
    break;
  }

  gtk_widget_destroy(dlg);
  reset_event();
  data->widget = NULL;

  return data->ret;
}
Exemplo n.º 8
0
static void
vfs_file_task_do_copy( VFSFileTask* task,
                       const char* src_file,
                       const char* dest_file )
{
    GDir * dir;
    const gchar* file_name;
    gchar* sub_src_file;
    gchar* sub_dest_file;
    struct stat file_stat;
    char buffer[ 4096 ];
    int rfd;
    int wfd;
    ssize_t rsize;
    char* new_dest_file = NULL;
    gboolean dest_exists;
    int result;

    if ( should_abort( task ) )
        return ;
    if ( lstat( src_file, &file_stat ) == -1 )
    {
        /* Error occurred */
        call_state_callback( task, VFS_FILE_TASK_ERROR );
        if ( should_abort( task ) )
            return ;
    }

    task->current_file = src_file;
    task->current_dest = dest_file;
    call_progress_callback( task );

    result = 0;
    if ( S_ISDIR( file_stat.st_mode ) )
    {
        if ( ! check_overwrite( task, dest_file,
                                &dest_exists, &new_dest_file ) )
            goto _return_;

        if ( new_dest_file )
            task->current_dest = dest_file = new_dest_file;

        if ( ! dest_exists )
            result = mkdir( dest_file, file_stat.st_mode | 0700 );

        if ( result == 0 )
        {
            struct utimbuf times;
            task->progress += file_stat.st_size;
            call_progress_callback( task );

            dir = g_dir_open( src_file, 0, NULL );
            while ( (file_name = g_dir_read_name( dir )) )
            {
                if ( should_abort( task ) )
                    break;
                sub_src_file = g_build_filename( src_file, file_name, NULL );
                sub_dest_file = g_build_filename( dest_file, file_name, NULL );
                vfs_file_task_do_copy( task, sub_src_file, sub_dest_file );
                g_free( sub_dest_file );
                g_free( sub_src_file );
            }
            g_dir_close( dir );
            chmod( dest_file, file_stat.st_mode );
            times.actime = file_stat.st_atime;
            times.modtime = file_stat.st_mtime;
            utime( dest_file, &times );
            /* Move files to different device: Need to delete source files */
            if ( ( task->type == VFS_FILE_TASK_MOVE
                 || task->type == VFS_FILE_TASK_TRASH )
                 && !should_abort( task ) )
            {
                if ( (result = rmdir( src_file )) )
                {
                    task->error = errno;
                    call_state_callback( task, VFS_FILE_TASK_ERROR );
                    if ( should_abort( task ) )
                        goto _return_;
                }
            }
        }
        else
        {  /* result != 0, error occurred */
            task->error = errno;
            call_state_callback( task, VFS_FILE_TASK_ERROR );
        }
    }
    else if ( S_ISLNK( file_stat.st_mode ) )
    {
        if ( ( rfd = readlink( src_file, buffer, sizeof( buffer ) ) ) > 0 )
        {
            if ( ! check_overwrite( task, dest_file,
                                    &dest_exists, &new_dest_file ) )
                goto _return_;

            if ( new_dest_file )
                task->current_dest = dest_file = new_dest_file;

            if ( ( wfd = symlink( buffer, dest_file ) ) == 0 )
            {
                chmod( dest_file, file_stat.st_mode );
                /* Move files to different device: Need to delete source files */
                if( task->type == VFS_FILE_TASK_MOVE || task->type == VFS_FILE_TASK_TRASH )
                {
                    result = unlink( src_file );
                    if ( result )
                    {
                        task->error = errno;
                        call_state_callback( task, VFS_FILE_TASK_ERROR );
                    }
                }
                task->progress += file_stat.st_size;
                call_progress_callback( task );
            }
            else
            {
                task->error = errno;
                call_state_callback( task, VFS_FILE_TASK_ERROR );
            }
        }
        else
        {
            task->error = errno;
            call_state_callback( task, VFS_FILE_TASK_ERROR );
        }
    }
    else
    {
        if ( ( rfd = open( src_file, O_RDONLY ) ) >= 0 )
        {
            if ( ! check_overwrite( task, dest_file,
                                    &dest_exists, &new_dest_file ) )
                goto _return_;

            if ( new_dest_file )
                task->current_dest = dest_file = new_dest_file;

            if ( ( wfd = creat( dest_file,
                                file_stat.st_mode | S_IWUSR ) ) >= 0 )
            {
                struct utimbuf times;
                while ( ( rsize = read( rfd, buffer, sizeof( buffer ) ) ) > 0 )
                {
                    if ( should_abort( task ) )
                        break;

                    if ( write( wfd, buffer, rsize ) > 0 )
                        task->progress += rsize;
                    else
                    {
                        task->error = errno;
                        call_state_callback( task, VFS_FILE_TASK_ERROR );
                        close( wfd );
                    }
                    call_progress_callback( task );
                }
                close( wfd );
                chmod( dest_file, file_stat.st_mode );
                times.actime = file_stat.st_atime;
                times.modtime = file_stat.st_mtime;
                utime( dest_file, &times );

                /* Move files to different device: Need to delete source files */
                if ( (task->type == VFS_FILE_TASK_MOVE || task->type == VFS_FILE_TASK_TRASH)
                     && !should_abort( task ) )
                {
                    result = unlink( src_file );
                    if ( result )
                    {
                        task->error = errno;
                        call_state_callback( task, VFS_FILE_TASK_ERROR );
                    }
                }
            }
            else
            {
                task->error = errno;
                call_state_callback( task, VFS_FILE_TASK_ERROR );
            }
            close( rfd );
        }
        else
        {
            task->error = errno;
            call_state_callback( task, VFS_FILE_TASK_ERROR );
        }
    }
_return_:
    g_free( new_dest_file );
}