void receivedClipboardDataLoad(wimp_message * wmessage) {
/* we got a dataload message, so grab the <Wimp$Scrap> file, then delete it
 * and return a dataloadack to the sender
 */
bits load_addr, exec_addr, file_type;
fileswitch_attr attr;
fileswitch_object_type obj_type;
int length;
	/* find the file size */
	xosfile_read_stamped_no_path(&(wmessage->data.data_xfer.file_name[0]),
		&obj_type, &load_addr, &exec_addr, &length, &attr, &file_type);
	/* if the obj_type is not-found, clear the buffer and return */
	if(obj_type == fileswitch_NOT_FOUND) {
		allocClipboard(1);
		return;
	}
	/* make sure we have enough buffer space for it
	 * fail if not */
	if(!allocClipboard(length+1))
		return;
	/* now load the file */
	xosfile_load_stamped_no_path(&(wmessage->data.data_xfer.file_name[0]),		(byte*)clipboardBuffer, &obj_type,
		&load_addr, &exec_addr, &length, &attr);
	/* delete the file */
	xosfscontrol_wipe(&(wmessage->data.data_xfer.file_name[0]), osfscontrol_WIPE_FORCE, 0,0,0,0);
	/* We modify the received block and return it to sender */
	wmessage->action = message_DATA_LOAD_ACK;
	wmessage->your_ref = wmessage->my_ref;
	xwimp_send_message(wimp_USER_MESSAGE, wmessage, wmessage->sender);
}
Ejemplo n.º 2
0
bool ro_gui_load_theme(char *path) {
  	os_error *error;
	struct theme_file_header *file_header;
	char *workspace;
	int workspace_size, file_size, output_left;
	fileswitch_object_type obj_type;
	squash_output_status status;
	os_fw file_handle;
	char *raw_data;
	char *compressed;
	char *decompressed;

	/*	Get memory for the header
	*/
	file_header = (struct theme_file_header *)calloc(1, 
				sizeof (struct theme_file_header));
	if (!file_header) {
	 	LOG(("No memory for calloc()"));
	 	warn_user("NoMemory", 0);
	}
	
	/*	Load the header
	*/
	error = xosfind_openinw(osfind_NO_PATH, path, 0, &file_handle);
	if (error) {
		free(file_header);
		LOG(("xosfind_openinw: 0x%x: %s",
				error->errnum, error->errmess));
		warn_user("FileError", error->errmess);
		return false;
	}
	if (file_handle == 0) {
		free(file_header);
		LOG(("File not present"));
		warn_user("FileError", error->errmess);
		return false;
	}
	error = xosgbpb_read_atw(file_handle, (char *)file_header,
			sizeof (struct theme_file_header),
			0, &output_left);
	xosfind_closew(file_handle);
	if (error) {
		free(file_header);
		LOG(("xosbgpb_read_atw: 0x%x: %s",
				error->errnum, error->errmess));
		warn_user("FileError", error->errmess);
		return false;
	}
	if (output_left > 0) {
		free(file_header);
		LOG(("Insufficient data"));
		warn_user("FileError", error->errmess);
		return false;
	}
	
	/*	Check the header is OK
	*/
	if ((file_header->magic_value != 0x4d54534e) ||
		(file_header->parser_version > 2)) return false;

	/*	Try to load the sprite file
	*/
	if (file_header->decompressed_sprite_size > 0) {
		error = xosfile_read_stamped_no_path(path,
				&obj_type, 0, 0, &file_size, 0, 0);
		if (error) {
			free(file_header);
			LOG(("xosfile_read_stamped_no_path: 0x%x: %s",
					error->errnum, error->errmess));
			warn_user("FileError", error->errmess);
			return false;
		}
		if (obj_type != fileswitch_IS_FILE) {
			free(file_header);
			return false;
		}
		raw_data = malloc(file_size);
		if (!raw_data) {
			free(file_header);
			LOG(("No memory for malloc()"));
			warn_user("NoMemory", 0);
			return false;
		}
		error = xosfile_load_stamped_no_path(path, (byte *)raw_data,
				0, 0, 0, 0, 0);
		if (error) {
			free(raw_data);
			free(file_header);
			LOG(("xosfile_load_stamped_no_path: 0x%x: %s",
					error->errnum, error->errmess));
			warn_user("FileError", error->errmess);
			return false;
		}
		
		/*	Decompress the data
		*/
		decompressed = malloc(file_header->decompressed_sprite_size);
		if (!decompressed) {
			free(raw_data);
			free(file_header);
			LOG(("No memory for malloc()"));
			warn_user("NoMemory", 0);
		}
		error = xsquash_decompress_return_sizes(-1, &workspace_size, 0);
		if (error) {
			free(decompressed);
			free(raw_data);
		  	free(file_header);
			LOG(("xsquash_decompress_return_sizes: 0x%x: %s",
					error->errnum, error->errmess));
			warn_user("MiscError", error->errmess);
			return false;
		}
		workspace = malloc(workspace_size);
		if (!workspace) {
			free(decompressed);
			free(raw_data);
		  	free(file_header);
			LOG(("No memory for malloc()"));
			warn_user("NoMemory", 0);
			return false;
		}
		compressed = raw_data + sizeof(struct theme_file_header);
		error = xsquash_decompress(0, /*squash_INPUT_ALL_PRESENT,*/
				workspace,
				(byte *)compressed, file_header->compressed_sprite_size,
				(byte *)decompressed, file_header->decompressed_sprite_size,
				&status, 0, 0, 0, 0);
		free(workspace);
		free(raw_data);
		if (error) {
			free(decompressed);
			LOG(("xsquash_decompress: 0x%x: %s",
					error->errnum, error->errmess));
			warn_user("MiscError", error->errmess);
			return false;
		}
		if (status != 0) {
		  	free(decompressed);
			return false;
		}
		if (theme_sprites) free(theme_sprites);
		theme_sprites = (osspriteop_area *)decompressed;		
	} else {
		if (theme_sprites) free(theme_sprites);
		theme_sprites = NULL;
	}
	
	/*	Set out values
	*/
	ro_gui_set_icon_string(dialog_main, ICON_MAIN_NAME, file_header->name);
	ro_gui_set_icon_string(dialog_main, ICON_MAIN_AUTHOR, file_header->author);
	ro_gui_set_icon_background_colour(dialog_main, ICON_MAIN_BROWSER_COLOUR,
			file_header->browser_bg);
	ro_gui_set_icon_background_colour(dialog_main, ICON_MAIN_HOTLIST_COLOUR,
			file_header->hotlist_bg);
	ro_gui_set_icon_background_colour(dialog_main, ICON_MAIN_STATUSBG_COLOUR,
			file_header->status_bg);
	ro_gui_set_icon_background_colour(dialog_main, ICON_MAIN_STATUSFG_COLOUR,
			file_header->status_fg);
	if (file_header->parser_version >= 2) {
		ro_gui_set_icon_selected_state(dialog_main, ICON_MAIN_THROBBER_LEFT,
				file_header->theme_flags & (1 << 0));
		ro_gui_set_icon_selected_state(dialog_main, ICON_MAIN_THROBBER_REDRAW,
				file_header->theme_flags & (1 << 1));
	} else {
		ro_gui_set_icon_selected_state(dialog_main, ICON_MAIN_THROBBER_LEFT,
				file_header->theme_flags);
		ro_gui_set_icon_selected_state(dialog_main, ICON_MAIN_THROBBER_REDRAW,
				true);
	}

	/*	Remember the filename for saving later on
	*/
	if (theme_filename) free(theme_filename);
	theme_filename = malloc(strlen(path) + 1);
	sprintf(theme_filename, "%s", path);
	if (sprite_filename) free(sprite_filename);
	sprite_filename = NULL;
	
	/*	Exit cleanly
	*/
	free(file_header);
	return true;
}