示例#1
0
PFC_NORETURN void foobar2000_io::exception_io_from_win32(DWORD p_code) {
	//pfc::string_fixed_t<32> debugMsg; debugMsg << "Win32 I/O error #" << (t_uint32)p_code;
	//TRACK_CALL_TEXT(debugMsg);
	switch(p_code) {
	case ERROR_ALREADY_EXISTS:
	case ERROR_FILE_EXISTS:
		throw exception_io_already_exists();
	case ERROR_NETWORK_ACCESS_DENIED:
	case ERROR_ACCESS_DENIED:
		throw exception_io_denied();
	case ERROR_WRITE_PROTECT:
		throw exception_io_write_protected();
	case ERROR_BUSY:
	case ERROR_PATH_BUSY:
	case ERROR_SHARING_VIOLATION:
	case ERROR_LOCK_VIOLATION:
		throw exception_io_sharing_violation();
	case ERROR_HANDLE_DISK_FULL:
	case ERROR_DISK_FULL:
		throw exception_io_device_full();
	case ERROR_FILE_NOT_FOUND:
	case ERROR_PATH_NOT_FOUND:
		throw exception_io_not_found();
	case ERROR_BROKEN_PIPE:
	case ERROR_NO_DATA:
		throw exception_io_no_data();
	case ERROR_NETWORK_UNREACHABLE:
	case ERROR_NETNAME_DELETED:
		throw exception_io_network_not_reachable();
	case ERROR_NOT_READY:
		throw exception_io_device_not_ready();
	case ERROR_INVALID_DRIVE:
		throw exception_io_invalid_drive();
	case ERROR_CRC:
	case ERROR_FILE_CORRUPT:
	case ERROR_DISK_CORRUPT:
		throw exception_io_file_corrupted();
	case ERROR_BUFFER_OVERFLOW:
		throw exception_io_buffer_overflow();
	case ERROR_DISK_CHANGE:
		throw exception_io_disk_change();
	case ERROR_DIR_NOT_EMPTY:
		throw exception_io_directory_not_empty();
	case ERROR_INVALID_NAME:
		throw exception_io_invalid_path_syntax();
	default:
		throw exception_io_win32_ex(p_code);
	}
}
示例#2
0
void toolbar_extension::button::custom_image::write_to_file(stream_writer &p_file, bool b_paths, abort_callback & p_abort) throw (const exception_io &)
{
	p_file.write_lendian_t(I_BUTTON_MASK_TYPE, p_abort);
	p_file.write_lendian_t(sizeof(m_mask_type), p_abort);
	p_file.write_lendian_t(m_mask_type, p_abort);

	if (b_paths)
	{
		p_file.write_lendian_t(I_CUSTOM_BUTTON_PATH, p_abort);
		p_file.write_lendian_t(m_path.length(), p_abort);
		p_file.write(m_path.get_ptr(), m_path.length(), p_abort);
	}
	else
	{
		pfc::string8 realPath, canPath;
		try{
			p_file.write_lendian_t(I_BUTTON_CUSTOM_IMAGE_DATA, p_abort);

			{
				service_ptr_t<file> p_image;
				get_path(realPath);
				filesystem::g_get_canonical_path(realPath, canPath);
				filesystem::g_open(p_image, canPath, filesystem::open_mode_read, p_abort);

				pfc::string_filename_ext name(m_path);

				t_filesize imagesize = p_image->get_size(p_abort);

				if (imagesize >= MAXLONG)
					throw exception_io_device_full();

				unsigned size = (unsigned)imagesize + name.length() + 4 * sizeof(t_uint32);
				p_file.write_lendian_t(size, p_abort);

				p_file.write_lendian_t(IMAGE_NAME, p_abort);
				p_file.write_lendian_t(name.length(), p_abort);
				p_file.write(name.get_ptr(), name.length(), p_abort);

				p_file.write_lendian_t(IMAGE_DATA, p_abort);
				p_file.write_lendian_t((unsigned)imagesize, p_abort);
				pfc::array_t<t_uint8> temp;
				temp.set_size((unsigned)imagesize);
				p_image->read(temp.get_ptr(), temp.get_size(), p_abort);
				p_file.write(temp.get_ptr(), temp.get_size(), p_abort);
			}
		}
		catch (const pfc::exception & err)
		{
			throw pfc::exception(pfc::string_formatter() << "Error reading file \"" << realPath << "\" : " << err.what());
		}
	}
	if (m_mask_type == uie::MASK_BITMAP)
	{
		if (b_paths)
		{
			p_file.write_lendian_t(I_CUSTOM_BUTTON_MASK_PATH, p_abort);
			p_file.write_lendian_t(m_mask_path.length(), p_abort);
			p_file.write(m_mask_path.get_ptr(), m_mask_path.length(), p_abort);
		}
		else
		{
			try {
				p_file.write_lendian_t(I_BUTTON_CUSTOM_IMAGE_MASK_DATA, p_abort);

				service_ptr_t<file> p_image;
				filesystem::g_open(p_image, m_mask_path, filesystem::open_mode_read, p_abort);

				pfc::string_filename_ext name(m_mask_path);

				t_filesize imagesize = p_image->get_size(p_abort);

				if (imagesize >= MAXLONG)
					throw exception_io_device_full();

				unsigned size = (unsigned)imagesize + name.length() + sizeof(IMAGE_NAME) + sizeof(IMAGE_DATA);
				p_file.write_lendian_t(size, p_abort);

				p_file.write_lendian_t(IMAGE_NAME, p_abort);
				p_file.write_lendian_t(name.length(), p_abort);
				p_file.write(name.get_ptr(), name.length(), p_abort);

				p_file.write_lendian_t(IMAGE_DATA, p_abort);
				p_file.write_lendian_t((unsigned)imagesize, p_abort);
				pfc::array_t<t_uint8> temp;
				temp.set_size((unsigned)imagesize);
				p_image->read(temp.get_ptr(), temp.get_size(), p_abort);
				p_file.write(temp.get_ptr(), temp.get_size(), p_abort);
			}
			catch (const pfc::exception & err)
			{
				throw pfc::exception(pfc::string_formatter() << "Error reading file \"" << m_mask_path << "\" : " << err.what());
			}
		}
	}

	if (m_mask_type == uie::MASK_COLOUR)
	{
		p_file.write_lendian_t(I_BUTTON_MASK_COLOUR, p_abort);
		p_file.write_lendian_t(sizeof(m_mask_colour), p_abort);
		p_file.write_lendian_t(m_mask_colour, p_abort);
	}
}