Exemple #1
0
NavigationModel::NavigationModel(QObject *parent) :
    QAbstractItemModel(parent),
    d_ptr(new NavigationModelPrivate(this))
{
    Q_D(NavigationModel);

    d->rootItem = new TreeItem();

    d->drivesItem = new TreeItem(d->rootItem, tr("Devices"));
    d->networkItem = new TreeItem(d->rootItem, tr("Network"));
    d->foldersItem = new TreeItem(d->rootItem, tr("Folders"));

    d->driveController = new QDriveController(this);
    connect(d->driveController, SIGNAL(driveMounted(QString)), d, SLOT(onDriveAdded(QString)));
    connect(d->driveController, SIGNAL(driveUnmounted(QString)), d, SLOT(onDriveRemoved(QString)));

    QList<QDriveInfo> drives = QDriveInfo::drives();
    foreach (const QDriveInfo &info, drives) {
        QString name = getDriveName(info);
        QString path = info.rootPath();

        TreeItem *item = 0;
        if (info.type() == QDriveInfo::RemoteDrive)
            item = new TreeItem(d->networkItem, name, path);
        else if (info.type() != QDriveInfo::UnknownDrive)
            item = new TreeItem(d->drivesItem, name, path);

        if (item) {
            item->icon = d->iconProvider.icon(QFileInfo(path));
            d->mapToItem.insert(path, item);
        }
    }
Exemple #2
0
void NavigationModelPrivate::onDriveAdded(const QString &path)
{
    QDriveInfo info(path);
    QString name = getDriveName(info);

    if (info.type() == QDriveInfo::RemoteDrive)
        insertItem(networkItem, name, path);
    else if (info.type() != QDriveInfo::UnknownDrive)
        insertItem(drivesItem, name, path);
}
Exemple #3
0
int main(int argc, char *argv[])
{
	QCoreApplication a(argc, argv);
	IO::IODevicePtr src_device = nullptr;

	if (argc == param_count)
	{
		uint64_t start_offset = 0;
		std::string offset_txt(argv[offset_param]);
		if (offset_txt.compare(offset_str) == 0)
		{
			start_offset = boost::lexical_cast<uint64_t>(argv[offset_value]);
			qInfo() << "offset : " << start_offset <<"(sectors)";
		}


		std::string disk_file_string(argv[disk_file_param]);
		if (disk_file_string.compare(d_str) == 0)
		{
			auto drive_number = boost::lexical_cast<uint32_t>(argv[source_value]);

			auto drive_list = IO::ReadPhysicalDrives();
			auto physical_drive = drive_list.find_by_number(drive_number);
			start_offset *= physical_drive->getBytesPerSector();
			if (physical_drive)
			{
				qInfo() << "You selected";
				qInfo() << "Number : " << drive_number;
				qInfo() << "Name :" << physical_drive->getDriveName().c_str();
				qInfo() << "Serial number : " << physical_drive->getSerialNumber().c_str();
				qInfo() << "Size : " << physical_drive->getSize() << "(bytes)";
			}
			src_device = std::make_shared<IO::DiskDevice>(physical_drive);
		}
		else if (disk_file_string.compare(f_str) == 0)
		{
			std::string src_path = argv[source_value];
			src_device = IO::makeFilePtr(IO::path_string(src_path.begin(), src_path.end()));
			start_offset *= default_sector_size;
		}

		if (!src_device->Open(IO::OpenMode::OpenRead))
		{
			qInfo() << "Error open source device.";
			return -1;
		}

		std::string targer_path = argv[target_value];
		IO::path_string target_folder(targer_path.begin(), targer_path.end());

		if (!src_device)
			return -1;

		//////////////////////////////////////////////////////////////////////////
		QList<JsonFileStruct> listFileStruct;


		QFile file("video.json");
		if (!file.open(QIODevice::ReadOnly))
		{
			qInfo() << "Error to open file. \"" << file.fileName() << "\"";
			return -1;
		}

		auto json_str = file.readAll();
		ReadJsonFIle(json_str, listFileStruct);
		if ( listFileStruct.empty())
		{
			qInfo() << "Error to read" << file.fileName() << "file. Wrong syntax.";
			return -1;
		}

		IO::HeaderBase::Ptr headerBase = std::make_shared<IO::HeaderBase>();
		for (auto theFileStruct : listFileStruct)
			headerBase->addFileFormat(toFileStruct(theFileStruct));

		IO::RawFactoryManager factory_manager;
		initFactoryMananger(factory_manager);

		IO::SignatureFinder signatureFinder(src_device, headerBase);

		//uint64_t start_offset = 0x0;
		uint64_t header_offset = 0;
		uint32_t counter = 0;
		while (start_offset < src_device->Size())
		{
			auto file_struct = signatureFinder.findHeader(start_offset, header_offset);
			if (!file_struct)
			{
				qInfo() << endl << endl << endl << "No more signatures found. Press any key to exit.";
				break;
			}
			qInfo() << "Found signature for [" << file_struct->getName().c_str() << "] file."; 
			qInfo() << "Offset : " << header_offset << "(bytes)";

			start_offset = header_offset;

 			auto raw_factory = factory_manager.Lookup(file_struct->getName());
			IO::RawAlgorithm * raw_algorithm = nullptr;
			if (!raw_factory)
			{
				IO::StandartRaw * standard_raw = new IO::StandartRaw(src_device);
				standard_raw->setMaxFileSize(file_struct->getMaxFileSize());
				standard_raw->setFooter(file_struct->getFooter(), file_struct->getFooterTailEndSize());
				standard_raw->setFooterOffsetSearchBlock(4, 4096);

				raw_algorithm = standard_raw;
				
			}
			else
			{
				raw_algorithm = raw_factory->createRawAlgorithm(src_device);
			}
				
				if (raw_algorithm->Specify(header_offset))
				{
					auto target_file = IO::offsetToPath(target_folder, header_offset, file_struct->getExtension(), 512);
					auto dst_file = IO::makeFilePtr(target_file);
					if (dst_file->Open(IO::OpenMode::Create))
					{
						auto target_size = raw_algorithm->SaveRawFile(*dst_file, header_offset);
						
						if ( target_size == 0)
						{
							qInfo() << "Error to save file. Exit." ;
							//break;

						}
						auto dst_size = dst_file->Size();
						dst_file->Close();
						qInfo() << "Successfully saved " << target_size << "(bytes)" << endl << endl;

						uint64_t jump_size = default_sector_size;

						if ( raw_algorithm->Verify(target_file) )
						{
							target_size /= default_sector_size;
							target_size *= default_sector_size;
							//////////////////////////////////////////////////////////////////////////
							jump_size = target_size;
						}
						else
						{
							// remove file
							IO::path_string new_fileName = target_file + L".bad_file";
							boost::filesystem::rename(target_file, new_fileName);
							//{
							//	qInfo() << "File" << target_file.c_str() << "was removed." << endl;
							//}
							//else
							//	qInfo() << "File" << target_file.c_str() << "Error to delete." << endl;


						}
						//if (jump_size == 0)
							jump_size = default_sector_size;
						start_offset = header_offset + jump_size;

					}
					else
					{
						qInfo() << "Error to create target file." << QString::fromStdWString(target_file);
						qInfo() << "Exit.";
						break;
					}
					
							

				}
				else
				{
					qInfo() << "Not specified for " << QString::fromStdString(file_struct->getName()) << "continue search for other signatures."<<endl;
					start_offset += default_sector_size;
				}
				if ( raw_algorithm)
					delete raw_algorithm;

				

			}



		


	}
	else
		qInfo() << "Wrong params";
	return a.exec();
}