예제 #1
0
//---------------------------------------------------------------------------
int32_t PacketFile::readPackedPacket(int32_t packet, puint8_t buffer)
{
	int32_t result = 0;
	if((packet == -1) || (packet == currentPacket) || (seekPacket(packet) == NO_ERROR))
	{
		if((getStorageType() == STORAGE_TYPE_RAW) || (getStorageType() == STORAGE_TYPE_FWF))
		{
			seek(packetBase);
			result = read(buffer, packetSize);
		}
		else
		{
			switch(getStorageType())
			{
				case STORAGE_TYPE_LZD:
				{
					seek(packetBase + sizeof(int32_t));
					read(buffer, packetSize);
				}
				break;
				case STORAGE_TYPE_ZLIB:
				{
					seek(packetBase + sizeof(int32_t));
					read(buffer, packetSize);
				}
				break;
			}
		}
	}
	return result;
}
예제 #2
0
//---------------------------------------------------------------------------
long PacketFile::readPackedPacket (long packet, unsigned char *buffer)
{
	long result = 0;

	if ((packet==-1) || (packet == currentPacket) || (seekPacket(packet) == NO_ERR))
	{
		if ((getStorageType() == STORAGE_TYPE_RAW) || (getStorageType() == STORAGE_TYPE_FWF))
		{
			seek(packetBase);
			result = read(buffer, packetSize);
		}
		else
		{
			switch (getStorageType())
			{
				case STORAGE_TYPE_LZD:
				{
					seek(packetBase+sizeof(long));
					read(buffer,packetSize);
				}
				break;

				case STORAGE_TYPE_ZLIB:
				{
					seek(packetBase+sizeof(long));
					read(buffer,packetSize);
				}
				break;

			}
		}
	}

	return result;
}
예제 #3
0
void NewProjectDialog::on_storagePathPushButton_clicked() {
  QString path;
  if (getStorageType() == "json") {
    path = QFileDialog::getSaveFileName(this, tr("Select Storage File"), ".",
                                        tr("Json File (*.json)"));
    if (!path.isEmpty() && !path.endsWith(".json")) path = path + ".json";
  } else if (getStorageType() == "xml")
    QMessageBox::warning(this, "Warning", "Not implemented yet");
  // path = QFileDialog::getExistingDirectory(this,tr("Select ImageSet
  // Path"),".");
  if (!path.isEmpty()) ui->storagePathLineEdit->setText(path);
}
예제 #4
0
std::string LogType::getStorageTypeAsString() const
{
    switch(getStorageType())
    {
    case LOG_STORAGETYPE_TIMEFOLDER:
        return "TimeFolder";
    default:
        return "Unknown";
    }
}
예제 #5
0
//---------------------------------------------------------------------------
long PacketFile::seekPacket (long packet)
{
	long offset, next;

	if (packet < 0)
	{
		return(PACKET_OUT_OF_RANGE);
	}
	
	offset = readPacketOffset(packet, &packetType);

	currentPacket = packet++;

	if (packet == numPackets)
		next = getLength();
	else
		next = readPacketOffset(packet);

	packetSize = next-offset;

	packetBase = offset;  // seek to beginning of packet
	seek(packetBase);
	
	switch (getStorageType())
	{
		case STORAGE_TYPE_LZD:
			// the first DWORD of a compressed packet is the unpacked length
			packetUnpackedSize = readLong();
			break;

		case STORAGE_TYPE_ZLIB:
			// the first DWORD of a compressed packet is the unpacked length
			packetUnpackedSize = readLong();
			break;

		case STORAGE_TYPE_RAW:
			packetUnpackedSize = packetSize;
		break;

		case STORAGE_TYPE_NUL:
			packetUnpackedSize = 0;
		break;	
			
		default:
			return(BAD_PACKET_VERSION);
	}

	if (offset > 0)
		return(NO_ERR);
		
	return (PACKET_OUT_OF_RANGE);
}
예제 #6
0
bool LogType::parseStorageType()
{
    setStorageType( iniGetValue( ini::SECTION,
        ini::VAR_SWA_STORAGETYPE, ini::settings::storageType ));

    if (iniGetError())
    {
        writeError( "Can't get 'Storage Type'" );
        return false;
    }

    if ((getStorageType() == LOG_STORAGETYPE_UNKNOWN)
        || (getStorageType() > LOG_STORAGETYPE_LAST))
    {
        writeError( "'Storage Type' invalid" );
        return false;
    }

    writeInfo ( "Storage Type = %d (%s)", getStorageType(), getStorageTypeAsString().c_str());

    return true;
}
예제 #7
0
void NewProjectDialog::on_buttonBox_accepted() {
  QString name = ui->projectNameLineEdit->text();
  QString imageSetType = getImageSetType();
  QString imageSetPath = ui->imageSetPathLineEdit->text();
  QString storageType = getStorageType();
  QString storagePath = ui->storagePathLineEdit->text();
  try {
    project = AnnotatorLib::Project::create(
        name.toStdString(), imageSetType.toStdString(),
        imageSetPath.toStdString(), storageType.toStdString(),
        storagePath.toStdString());
    project->setPath(ui->projectFileLineEdit->text().toStdString());
    project->loadSession();
    this->accept();
  } catch (std::exception &e) {
    QMessageBox::warning(this, "Error", QString::fromStdString(e.what()));
  }
}
예제 #8
0
//---------------------------------------------------------------------------
int32_t PacketFile::insertPacket(int32_t packet, puint8_t buffer, int32_t nbytes, uint8_t pType)
{
	//--------------------------------------------------------
	// This function writes the packet to the current end
	// of file and stores the packet address in the seek
	// table.  Originally, replace was a NONO.  No, we check
	// for the size and, if it is different, insert the new
	// packet into a new file and basically spend many timeparts doing it.
	// Necessary for the teditor.
	// I Love it.
	int32_t result = 0;
	if(packet < 0)
	{
		return result;
	}
	//---------------------------------------------------------------
	// Only used here, so OK if regular WINDOWS(tm) malloc!
	puint8_t workBuffer = (puint8_t)malloc(DEFAULT_MAX_PACKET);
	//-------------------------------------------------------------
	// All new code here.  Basically, open a new packet file,
	// write each of the old packets and this new one.  Close all
	// and copy the new one over the old one.  Open the new one and
	// set pointers accordingly.
	PacketFile tmpFile;
	result = tmpFile.create("AF3456AF.788");
	if(packet >= numPackets)
	{
		numPackets++;
	}
	tmpFile.reserve(numPackets);
	for(size_t i = 0; i < numPackets; i++)
	{
		if(i == packet)
		{
			if(nbytes >= DEFAULT_MAX_PACKET)
			{
				//----------------------------------------------------
				// Not sure what to do here.  We'll try reallocating
				::free(workBuffer);
				workBuffer = (puint8_t)malloc(packetSize);
			}
			tmpFile.writePacket(i, buffer, nbytes, pType);
		}
		else
		{
			seekPacket(i);
			int32_t storageType = getStorageType();
			int32_t packetSize = getPacketSize();
			if(packetSize >= DEFAULT_MAX_PACKET)
			{
				//----------------------------------------------------
				// Not sure what to do here.  We'll try reallocating
				::free(workBuffer);
				workBuffer = (puint8_t)malloc(packetSize);
			}
			readPacket(i, workBuffer);
			tmpFile.writePacket(i, workBuffer, packetSize, storageType);
		}
	}
	//------------------------------------
	// Now close and reassign everything.
	char ourFileName[250];
	int32_t ourFileMode = 0;
	strcpy(ourFileName, fileName);
	ourFileMode = fileMode;
	tmpFile.close();
	close();
	remove(ourFileName);
	rename("AF3456AF.788", ourFileName);
	remove("AF3456AF.788");
	open(ourFileName, (FileMode)ourFileMode);
	seekPacket(packet);
	return result;
}
예제 #9
0
//---------------------------------------------------------------------------
int32_t PacketFile::readPacket(int32_t packet, puint8_t buffer)
{
	int32_t result = 0;
	if((packet == -1) || (packet == currentPacket) || (seekPacket(packet) == NO_ERROR))
	{
		if((getStorageType() == STORAGE_TYPE_RAW) || (getStorageType() == STORAGE_TYPE_FWF))
		{
			seek(packetBase);
			result = read(buffer, packetSize);
		}
		else
		{
			switch(getStorageType())
			{
				case STORAGE_TYPE_LZD:
				{
					seek(packetBase + sizeof(int32_t));
					if(!LZPacketBuffer)
					{
						LZPacketBuffer = (puint8_t)malloc(LZPacketBufferSize);
						gosASSERT(LZPacketBuffer);
					}
					if((int32_t)LZPacketBufferSize < packetSize)
					{
						LZPacketBufferSize = packetSize;
						free(LZPacketBuffer);
						LZPacketBuffer = (puint8_t)malloc(LZPacketBufferSize);
						gosASSERT(LZPacketBuffer);
					}
					if(LZPacketBuffer)
					{
						read(LZPacketBuffer, (packetSize - sizeof(int32_t)));
						int32_t decompLength = LZDecomp(buffer, LZPacketBuffer, packetSize - sizeof(int32_t));
						if(decompLength != packetUnpackedSize)
							result = 0;
						else
							result = decompLength;
					}
				}
				break;
				case STORAGE_TYPE_ZLIB:
				{
					seek(packetBase + sizeof(int32_t));
					if(!LZPacketBuffer)
					{
						LZPacketBuffer = (puint8_t)malloc(LZPacketBufferSize);
						gosASSERT(LZPacketBuffer);
					}
					if((int32_t)LZPacketBufferSize < packetSize)
					{
						LZPacketBufferSize = packetSize;
						free(LZPacketBuffer);
						LZPacketBuffer = (puint8_t)malloc(LZPacketBufferSize);
						gosASSERT(LZPacketBuffer);
					}
					if(LZPacketBuffer)
					{
						read(LZPacketBuffer, (packetSize - sizeof(int32_t)));
						uint32_t decompLength = LZPacketBufferSize;
						int32_t decompResult = uncompress(buffer, &decompLength, LZPacketBuffer, packetSize - sizeof(int32_t));
						if((decompResult != Z_OK) || ((int32_t)decompLength != packetUnpackedSize))
							result = 0;
						else
							result = decompLength;
					}
				}
				break;
				case STORAGE_TYPE_HF:
					STOP(("Tried to read a Huffman Compressed Packet.  No Longer Supported!!"));
					break;
			}
		}
	}
	return result;
}