Пример #1
0
void toolbar_extension::button::read_from_file(t_config_version p_version, const char * p_base, const char * p_name, stream_reader * p_file, unsigned p_size, abort_callback & p_abort)
{
	//t_filesize p_start = p_file->get_position(p_abort);
	t_size read = 0;
	while (read < p_size/* && !p_file->is_eof(p_abort)*/)
	{
		t_identifier_button id;
		p_file->read_lendian_t(id, p_abort);
		unsigned size;
		p_file->read_lendian_t(size, p_abort);
		//if (size > p_file->get_size(p_abort) - p_file->get_position(p_abort))
		//	throw exception_io_data();
		read += sizeof(t_uint32) + sizeof(t_uint32) + size;
		switch (id)
		{
		case I_BUTTON_TYPE:
			p_file->read_lendian_t(m_type, p_abort);
			break;
		case I_BUTTON_FILTER:
			p_file->read_lendian_t(m_filter, p_abort);
			break;
		case I_BUTTON_SHOW:
			p_file->read_lendian_t(m_show, p_abort);
			break;
		case I_BUTTON_GUID:
			p_file->read_lendian_t((GUID&)m_guid, p_abort);
			break;
		case I_BUTTON_SUBCOMMAND:
			p_file->read_lendian_t((GUID&)m_subcommand, p_abort);
			break;
		case I_BUTTON_CUSTOM:
			p_file->read_lendian_t(m_use_custom, p_abort);
			break;
		case I_BUTTON_CUSTOM_HOT:
			p_file->read_lendian_t(m_use_custom_hot, p_abort);
			break;
		case I_BUTTON_CUSTOM_DATA:
			m_custom_image.read_from_file(p_version, p_base, p_name, p_file, size, p_abort);
			break;
		case I_BUTTON_CUSTOM_HOT_DATA:
			m_custom_hot_image.read_from_file(p_version, p_base, p_name, p_file, size, p_abort);
			break;
		case I_BUTTON_USE_CUSTOM_TEXT:
			p_file->read_lendian_t(m_use_custom_text, p_abort);
			break;
		case I_BUTTON_TEXT:
		{
			pfc::array_t<char> name;
			name.set_size(size);
			p_file->read(name.get_ptr(), name.get_size(), p_abort);
			m_text.set_string(name.get_ptr(), name.get_size());
		}
		break;
		default:
			if (p_file->skip(size, p_abort) != size)
				throw exception_io_data_truncation();
			break;
		}
	}
}
Пример #2
0
void toolbar_extension::button::custom_image::read_from_file(t_config_version p_version, const char * p_base, const char * p_name, stream_reader * p_file, unsigned p_size, abort_callback & p_abort) throw (const exception_io &)
{
	//t_filesize p_start = p_file->get_position(p_abort);
	t_filesize read = 0;
	while (/*p_file->get_position(p_abort) - p_start*/ read < p_size /* && !p_file->is_eof(p_abort)*/)
	{
		t_identifier id;
		p_file->read_lendian_t(id, p_abort);
		unsigned size;
		p_file->read_lendian_t(size, p_abort);
		//if (size > p_file->get_size(p_abort) - p_file->get_position(p_abort))
		//	throw exception_io_data();
		pfc::array_t<char> path, maskpath;
		read += 8 + size;
		switch (id)
		{
		case I_BUTTON_MASK_TYPE:
			p_file->read_lendian_t(m_mask_type, p_abort);
			break;
		case I_BUTTON_MASK_COLOUR:
			p_file->read_lendian_t(m_mask_colour, p_abort);
			break;
		case I_CUSTOM_BUTTON_MASK_PATH:
			maskpath.set_size(size);
			p_file->read(maskpath.get_ptr(), maskpath.get_size(), p_abort);
			m_mask_path.set_string(maskpath.get_ptr(), maskpath.get_size());
			break;
		case I_CUSTOM_BUTTON_PATH:
		{
			path.set_size(size);
			p_file->read(path.get_ptr(), path.get_size(), p_abort);
			m_path.set_string(path.get_ptr(), path.get_size());
		}
		break;
		case I_BUTTON_CUSTOM_IMAGE_DATA:
		{
			t_filesize read2 = 0;
			//t_filesize p_start_data = p_file->get_position(p_abort);
			pfc::array_t<char> name;
			pfc::array_t<t_uint8> data;
			while (read2 /*p_file->get_position(p_abort) - p_start_data*/ < size/* && !p_file->is_eof(p_abort)*/)
			{
				DWORD size_data;
				t_identifier id_data;
				p_file->read_lendian_t(id_data, p_abort);
				p_file->read_lendian_t(size_data, p_abort);
				//if (size_data > p_file->get_size(p_abort) - p_file->get_position(p_abort))
				//throw exception_io_data();
				read2 += 8 + size_data;
				switch (id_data)
				{
				case IMAGE_NAME:
					name.set_size(size_data);
					p_file->read(name.get_ptr(), name.get_size(), p_abort);
					break;
				case IMAGE_DATA:
					data.set_size(size_data);
					p_file->read(data.get_ptr(), data.get_size(), p_abort);
					break;
				default:
					if (p_file->skip(size_data, p_abort) != size_data)
						throw exception_io_data_truncation();
					break;
				}
			}
				{
					pfc::string_printf dir1("%s\\images", p_base);
					pfc::string_printf dir2("%s\\images\\%s", p_base, p_name);
					if (!filesystem::g_exists(dir1, p_abort))
						filesystem::g_create_directory(dir1, p_abort);
					if (!filesystem::g_exists(dir2, p_abort))
						filesystem::g_create_directory(dir2, p_abort);

					service_ptr_t<file> p_image;
					pfc::string8 curdir, wname;

					curdir = pfc::string_printf("%s\\images", p_base);

					wname = curdir;
					wname.add_byte('\\');

					wname.add_string(p_name);
					wname.add_byte('\\');

					wname.add_string(name.get_ptr(), name.get_size());
					pfc::string8 name_only = pfc::string_filename(wname);
					pfc::string8 ext = pfc::string_extension(wname);
					unsigned n = 0;

					bool b_write = true;
					{
						bool b_continue = false;
						do
						{
							bool b_exists = filesystem::g_exists(wname, p_abort);
							if (b_exists)
							{
								b_continue = true;
								service_ptr_t<file> p_temp;
								try
								{
									filesystem::g_open(p_temp, wname, filesystem::open_mode_read, p_abort);
									{
										bool b_same = false;
										g_compare_file_with_bytes(p_temp, data, b_same, p_abort);
										if (b_same)
										{
											b_write = false;
											b_continue = false;
										}
									}
								}
								catch (pfc::exception & e)
								{
								}
							}
							else b_continue = false;

							if (b_continue && n<100)
								wname = pfc::string_printf("%s\\%s\\%s %02u.%s", curdir.get_ptr(), p_name, name_only.get_ptr(), n, ext.get_ptr()); n++;

						} while (b_continue && n<100);
					}

					if (b_write)
					{
						filesystem::g_open(p_image, wname, filesystem::open_mode_write_new, p_abort);
						p_image->write(data.get_ptr(), data.get_size(), p_abort);
					}
					m_path = wname;
				}
		}
		break;
		case I_BUTTON_CUSTOM_IMAGE_MASK_DATA:
		{
			t_filesize read2 = 0;
			//t_filesize p_start_data = p_file->get_position(p_abort);
			pfc::array_t<char> name;
			pfc::array_t<t_uint8> data;
			while (read2 /*p_file->get_position(p_abort) - p_start_data*/ < size/* && !p_file->is_eof(p_abort)*/)
			{
				DWORD size_data;
				t_identifier id_data;
				p_file->read_lendian_t(id_data, p_abort);
				p_file->read_lendian_t(size_data, p_abort);
				//if (size_data > p_file->get_size(p_abort) - p_file->get_position(p_abort))
				//	throw exception_io_data();
				read2 += 8 + size_data;
				switch (id_data)
				{
				case IMAGE_NAME:
					name.set_size(size_data);
					p_file->read(name.get_ptr(), name.get_size(), p_abort);
					break;
				case IMAGE_DATA:
					data.set_size(size_data);
					p_file->read(data.get_ptr(), data.get_size(), p_abort);
					break;
				default:
					if (p_file->skip(size_data, p_abort) != size_data)
						throw exception_io_data_truncation();
					break;
				}
			}
				{
					pfc::string_printf dir1("%s\\images", p_base);
					pfc::string_printf dir2("%s\\images\\%s", p_base, p_name);
					if (!filesystem::g_exists(dir1, p_abort))
						filesystem::g_create_directory(dir1, p_abort);
					if (!filesystem::g_exists(dir2, p_abort))
						filesystem::g_create_directory(dir2, p_abort);
					service_ptr_t<file> p_image;
					pfc::string8 curdir, wname;

					curdir = pfc::string_printf("%s\\images", p_base);

					wname = curdir;
					wname.add_byte('\\');

					wname.add_string(p_name);
					wname.add_byte('\\');

					wname.add_string(name.get_ptr(), name.get_size());

					pfc::string8 name_only = pfc::string_filename(wname);
					pfc::string8 ext = pfc::string_extension(wname);
					unsigned n = 0;
					bool b_write = true;
					{
						bool b_continue = false;
						do
						{
							bool b_exists = filesystem::g_exists(wname, p_abort);
							if (b_exists)
							{
								b_continue = true;
								service_ptr_t<file> p_temp;
								try
								{
									filesystem::g_open(p_temp, wname, filesystem::open_mode_read, p_abort);
									{
										bool b_same = false;
										g_compare_file_with_bytes(p_temp, data, b_same, p_abort);
										if (b_same)
										{
											b_write = false;
											b_continue = false;
										}
									}
								}
								catch (pfc::exception & e)
								{
								}
							}
							else b_continue = false;

							if (b_continue && n<100)
								wname = pfc::string_printf("%s\\%s\\%s %02u.%s", curdir.get_ptr(), p_name, name_only.get_ptr(), n, ext.get_ptr()); n++;

						} while (b_continue && n<100);
					}


					if (b_write)
					{
						filesystem::g_open(p_image, wname, filesystem::open_mode_write_new, p_abort);
						p_image->write(data.get_ptr(), data.get_size(), p_abort);
					}
					m_mask_path = wname;
				}
		}
		break;
		default:
			if (p_file->skip(size, p_abort) != size)
				throw exception_io_data_truncation();
			break;
		}
	}
}
Пример #3
0
void file::g_transfer_object(stream_reader * p_src,stream_writer * p_dst,t_filesize p_bytes,abort_callback & p_abort) {
	if (g_transfer(p_src,p_dst,p_bytes,p_abort) != p_bytes)
		throw exception_io_data_truncation();
}
Пример #4
0
void stream_reader::skip_object(t_filesize p_bytes,abort_callback & p_abort) {
	if (skip(p_bytes,p_abort) != p_bytes) throw exception_io_data_truncation();
}
Пример #5
0
void stream_reader::read_object(void * p_buffer,t_size p_bytes,abort_callback & p_abort) {
	if (read(p_buffer,p_bytes,p_abort) != p_bytes) throw exception_io_data_truncation();
}