changed attachment data type to QByteArray
git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@28 b624d157-de02-0410-bad0-e51aec6abb33
This commit is contained in:
		
							parent
							
								
									5f8095706e
								
							
						
					
					
						commit
						9d2b50b9c3
					
				| 
						 | 
					@ -28,8 +28,7 @@ Creation=QDateTime::currentDateTime();
 | 
				
			||||||
LastMod=QDateTime::currentDateTime();
 | 
					LastMod=QDateTime::currentDateTime();
 | 
				
			||||||
LastAccess=QDateTime::currentDateTime();
 | 
					LastAccess=QDateTime::currentDateTime();
 | 
				
			||||||
Expire=QDateTime(QDate(2999,12,28),QTime(23,59,59)); //Never
 | 
					Expire=QDateTime(QDate(2999,12,28),QTime(23,59,59)); //Never
 | 
				
			||||||
BinaryDataLength=0;
 | 
					BinaryData=QByteArray();
 | 
				
			||||||
pBinaryData=NULL;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool CGroup::UI_ExpandByDefault=true;
 | 
					bool CGroup::UI_ExpandByDefault=true;
 | 
				
			||||||
| 
						 | 
					@ -59,9 +58,5 @@ CGroup::~CGroup(){
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
CEntry::~CEntry(){
 | 
					CEntry::~CEntry(){
 | 
				
			||||||
if(pBinaryData) {
 | 
					 | 
				
			||||||
delete [] pBinaryData;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
pBinaryData=NULL;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -43,8 +43,7 @@ QDateTime Creation;
 | 
				
			||||||
QDateTime LastMod;
 | 
					QDateTime LastMod;
 | 
				
			||||||
QDateTime LastAccess;
 | 
					QDateTime LastAccess;
 | 
				
			||||||
QDateTime Expire;
 | 
					QDateTime Expire;
 | 
				
			||||||
Q_UINT8 *pBinaryData;
 | 
					QByteArray BinaryData;
 | 
				
			||||||
Q_UINT32 BinaryDataLength;
 | 
					 | 
				
			||||||
/*Q_UINT32 PasswordLength;*/
 | 
					/*Q_UINT32 PasswordLength;*/
 | 
				
			||||||
bool ReadEntryField(Q_UINT16 FieldType, Q_UINT32 FieldSize, Q_UINT8 *pData);
 | 
					bool ReadEntryField(Q_UINT16 FieldType, Q_UINT32 FieldSize, Q_UINT8 *pData);
 | 
				
			||||||
bool operator==(const CEntry&) const;
 | 
					bool operator==(const CEntry&) const;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -408,7 +408,7 @@ Entries.removeAt(Entries.indexOf(*entry));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool PwDatabase::IsMetaStream(CEntry& p){
 | 
					bool PwDatabase::IsMetaStream(CEntry& p){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if(p.pBinaryData == NULL) return false;
 | 
					if(p.BinaryData.isNull()) return false;
 | 
				
			||||||
if(p.Additional == "") return false;
 | 
					if(p.Additional == "") return false;
 | 
				
			||||||
if(p.BinaryDesc == "") return false;
 | 
					if(p.BinaryDesc == "") return false;
 | 
				
			||||||
if(p.BinaryDesc != "bin-stream") return false;
 | 
					if(p.BinaryDesc != "bin-stream") return false;
 | 
				
			||||||
| 
						 | 
					@ -546,18 +546,11 @@ switch(FieldType)
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
	case 0x000E:
 | 
						case 0x000E:
 | 
				
			||||||
		if(FieldSize != 0)
 | 
							if(FieldSize != 0)
 | 
				
			||||||
		{
 | 
								BinaryData=QByteArray((char*)pData,FieldSize);
 | 
				
			||||||
			///@TODO: im Destruktor löschen
 | 
					 | 
				
			||||||
			///@TODO: im Konstruktor auf Null
 | 
					 | 
				
			||||||
			pBinaryData = new Q_UINT8[FieldSize];
 | 
					 | 
				
			||||||
			memcpy(pBinaryData, pData, FieldSize);
 | 
					 | 
				
			||||||
			BinaryDataLength = FieldSize;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		else
 | 
							else
 | 
				
			||||||
		{pBinaryData=0;}
 | 
								BinaryData=QByteArray(); //=NULL
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
	case 0xFFFF:
 | 
						case 0xFFFF:
 | 
				
			||||||
		///@TODO: Alle Elemente geladen - Status setzen oder so was
 | 
					 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
		return false; // Field unsupported
 | 
							return false; // Field unsupported
 | 
				
			||||||
| 
						 | 
					@ -609,7 +602,7 @@ for(int i = 0; i < Entries.size(); i++){
 | 
				
			||||||
	   +Entries[i].Password.length()+1
 | 
						   +Entries[i].Password.length()+1
 | 
				
			||||||
	   +Entries[i].Additional.utf8().length()+1
 | 
						   +Entries[i].Additional.utf8().length()+1
 | 
				
			||||||
	   +Entries[i].BinaryDesc.utf8().length()+1
 | 
						   +Entries[i].BinaryDesc.utf8().length()+1
 | 
				
			||||||
	   +Entries[i].BinaryDataLength;}
 | 
						   +Entries[i].BinaryData.length();}
 | 
				
			||||||
// Round up filesize to 16-byte boundary for Rijndael/Twofish
 | 
					// Round up filesize to 16-byte boundary for Rijndael/Twofish
 | 
				
			||||||
FileSize = (FileSize + 16) - (FileSize % 16);
 | 
					FileSize = (FileSize + 16) - (FileSize % 16);
 | 
				
			||||||
char* buffer=new char[FileSize+16];
 | 
					char* buffer=new char[FileSize+16];
 | 
				
			||||||
| 
						 | 
					@ -758,11 +751,11 @@ for(int i = 0; i < Entries.size(); i++){
 | 
				
			||||||
		memcpyToLEnd32(buffer+pos, &FieldSize); pos += 4;
 | 
							memcpyToLEnd32(buffer+pos, &FieldSize); pos += 4;
 | 
				
			||||||
		memcpy(buffer+pos, Entries[i].BinaryDesc.utf8(),FieldSize);  pos += FieldSize;
 | 
							memcpy(buffer+pos, Entries[i].BinaryDesc.utf8(),FieldSize);  pos += FieldSize;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		FieldType = 0x000E; FieldSize = Entries[i].BinaryDataLength;
 | 
							FieldType = 0x000E; FieldSize = Entries[i].BinaryData.length();
 | 
				
			||||||
		memcpyToLEnd16(buffer+pos, &FieldType); pos += 2;
 | 
							memcpyToLEnd16(buffer+pos, &FieldType); pos += 2;
 | 
				
			||||||
		memcpyToLEnd32(buffer+pos, &FieldSize); pos += 4;
 | 
							memcpyToLEnd32(buffer+pos, &FieldSize); pos += 4;
 | 
				
			||||||
		if((Entries[i].pBinaryData != NULL) && (FieldSize != 0))
 | 
							if((!Entries[i].BinaryData.isNull()) && (FieldSize != 0))
 | 
				
			||||||
			memcpy(buffer+pos, Entries[i].pBinaryData, FieldSize);
 | 
								memcpy(buffer+pos, Entries[i].BinaryData.data(), FieldSize);
 | 
				
			||||||
		pos += FieldSize;
 | 
							pos += FieldSize;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		FieldType = 0xFFFF; FieldSize = 0;
 | 
							FieldType = 0xFFFF; FieldSize = 0;
 | 
				
			||||||
| 
						 | 
					@ -1245,11 +1238,11 @@ void assertEntriesEq(KPTestResults& results, CEntry* left, CEntry* right){
 | 
				
			||||||
	kp_assert(results, left->Expire.toTime_t() == right->Expire.toTime_t());
 | 
						kp_assert(results, left->Expire.toTime_t() == right->Expire.toTime_t());
 | 
				
			||||||
	size += sizeof(left->Expire);
 | 
						size += sizeof(left->Expire);
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	kp_assert(results, left->BinaryDataLength == right->BinaryDataLength);
 | 
						kp_assert(results, left->BinaryData.length() == right->BinaryData.length());
 | 
				
			||||||
	kp_assert(results, (left->pBinaryData == NULL && right->pBinaryData == NULL) ||
 | 
						kp_assert(results, (left->BinaryData.isNull() && right->BinaryData.isNull()) ||
 | 
				
			||||||
		memcmp(left->pBinaryData, right->pBinaryData, left->BinaryDataLength) == 0);
 | 
							memcmp(left->BinaryData.data(), right->BinaryData.data(), left->BinaryData.length()) == 0);
 | 
				
			||||||
	size += sizeof(left->pBinaryData);
 | 
						size += left->BinaryData.length();
 | 
				
			||||||
	size += sizeof(left->BinaryDataLength);
 | 
						size += sizeof(left->BinaryData.length());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	kp_assert(results, size == sizeof(CEntry));
 | 
						kp_assert(results, size == sizeof(CEntry));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -69,7 +69,7 @@ ButtonOpenAttachment->setIcon(*Icon_FileOpen);
 | 
				
			||||||
ButtonDeleteAttachment->setIcon(*Icon_EditDelete);
 | 
					ButtonDeleteAttachment->setIcon(*Icon_EditDelete);
 | 
				
			||||||
ButtonSaveAttachment->setIcon(*Icon_FileSave);
 | 
					ButtonSaveAttachment->setIcon(*Icon_FileSave);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if(entry->pBinaryData==NULL){
 | 
					if(entry->BinaryData.isNull()){
 | 
				
			||||||
  ButtonSaveAttachment->setDisabled(true);
 | 
					  ButtonSaveAttachment->setDisabled(true);
 | 
				
			||||||
  ButtonDeleteAttachment->setDisabled(true);}
 | 
					  ButtonDeleteAttachment->setDisabled(true);}
 | 
				
			||||||
setCaption(entry->Title);
 | 
					setCaption(entry->Title);
 | 
				
			||||||
| 
						 | 
					@ -92,17 +92,17 @@ Edit_Attachment->setText(entry->BinaryDesc);
 | 
				
			||||||
Edit_Comment->setText(entry->Additional);
 | 
					Edit_Comment->setText(entry->Additional);
 | 
				
			||||||
InitGroupComboBox();
 | 
					InitGroupComboBox();
 | 
				
			||||||
InitIconComboBox();
 | 
					InitIconComboBox();
 | 
				
			||||||
if(entry->BinaryDataLength==0)
 | 
					if(entry->BinaryData.length()==0)
 | 
				
			||||||
  Label_AttachmentSize->setText("");
 | 
					  Label_AttachmentSize->setText("");
 | 
				
			||||||
else{
 | 
					else{
 | 
				
			||||||
  QString unit;
 | 
					  QString unit;
 | 
				
			||||||
  int faktor;
 | 
					  int faktor;
 | 
				
			||||||
  int prec;
 | 
					  int prec;
 | 
				
			||||||
  if(entry->BinaryDataLength<1000){unit=" Byte";faktor=1;prec=0;}
 | 
					  if(entry->BinaryData.length()<1000){unit=" Byte";faktor=1;prec=0;}
 | 
				
			||||||
  else {if(entry->BinaryDataLength<1000000){unit=" kB";faktor=1000;prec=1;}
 | 
					  else {if(entry->BinaryData.length()<1000000){unit=" kB";faktor=1000;prec=1;}
 | 
				
			||||||
  	else{unit=" MB";faktor=1000000;prec=1;}
 | 
					  	else{unit=" MB";faktor=1000000;prec=1;}
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  Label_AttachmentSize->setText(QString::number((float)entry->BinaryDataLength/(float)faktor,'f',prec)+unit);
 | 
					  Label_AttachmentSize->setText(QString::number((float)entry->BinaryData.length()/(float)faktor,'f',prec)+unit);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
if(entry->Expire==Date_Never){
 | 
					if(entry->Expire==Date_Never){
 | 
				
			||||||
  DateTime_Expire->setDisabled(true);
 | 
					  DateTime_Expire->setDisabled(true);
 | 
				
			||||||
| 
						 | 
					@ -260,16 +260,7 @@ QMessageBox::warning(NULL,trUtf8("Fehler"),trUtf8("Datei konnte nicht geöffnet
 | 
				
			||||||
return;
 | 
					return;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
ModFlag=true;
 | 
					ModFlag=true;
 | 
				
			||||||
if(entry->pBinaryData)delete [] entry->pBinaryData;
 | 
					entry->BinaryData=file.readAll();
 | 
				
			||||||
entry->pBinaryData = new Q_UINT8 [file.size()];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
if(entry->pBinaryData==NULL){
 | 
					 | 
				
			||||||
file.close();
 | 
					 | 
				
			||||||
QMessageBox::critical(NULL,"Fehler",QString::fromUtf8("Es ist nicht genügend Arbeitsspeicher für diesen Vorgang vorhanden."),"OK");
 | 
					 | 
				
			||||||
return;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
entry->BinaryDataLength=file.size();
 | 
					 | 
				
			||||||
file.readBlock((char*)entry->pBinaryData,file.size());
 | 
					 | 
				
			||||||
file.close();
 | 
					file.close();
 | 
				
			||||||
QFileInfo info(filename);
 | 
					QFileInfo info(filename);
 | 
				
			||||||
entry->BinaryDesc=info.fileName();
 | 
					entry->BinaryDesc=info.fileName();
 | 
				
			||||||
| 
						 | 
					@ -278,11 +269,11 @@ Edit_Attachment->setText(entry->BinaryDesc);
 | 
				
			||||||
QString unit;
 | 
					QString unit;
 | 
				
			||||||
int faktor;
 | 
					int faktor;
 | 
				
			||||||
int prec;
 | 
					int prec;
 | 
				
			||||||
  if(entry->BinaryDataLength<1000){unit=" Byte";faktor=1;prec=0;}
 | 
					  if(entry->BinaryData.length()<1000){unit=" Byte";faktor=1;prec=0;}
 | 
				
			||||||
  else {if(entry->BinaryDataLength<1000000){unit=" kB";faktor=1000;prec=1;}
 | 
					  else {if(entry->BinaryData.length()<1000000){unit=" kB";faktor=1000;prec=1;}
 | 
				
			||||||
  	else{unit=" MB";faktor=1000000;prec=1;}
 | 
					  	else{unit=" MB";faktor=1000000;prec=1;}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
Label_AttachmentSize->setText(QString::number((float)entry->BinaryDataLength/(float)faktor,'f',prec)+unit);
 | 
					Label_AttachmentSize->setText(QString::number((float)entry->BinaryData.length()/(float)faktor,'f',prec)+unit);
 | 
				
			||||||
ButtonOpenAttachment->setEnabled(true);
 | 
					ButtonOpenAttachment->setEnabled(true);
 | 
				
			||||||
ButtonSaveAttachment->setEnabled(true);
 | 
					ButtonSaveAttachment->setEnabled(true);
 | 
				
			||||||
ButtonDeleteAttachment->setEnabled(true);
 | 
					ButtonDeleteAttachment->setEnabled(true);
 | 
				
			||||||
| 
						 | 
					@ -305,13 +296,13 @@ QMessageBox::critical(NULL,"Fehler",QString::fromUtf8("Datei konnte nicht erstel
 | 
				
			||||||
return;
 | 
					return;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int r=file.writeBlock((char*)entry->pBinaryData,entry->BinaryDataLength);
 | 
					int r=file.write(entry->BinaryData);
 | 
				
			||||||
if(r==-1){
 | 
					if(r==-1){
 | 
				
			||||||
file.close();
 | 
					file.close();
 | 
				
			||||||
QMessageBox::critical(NULL,"Fehler",QString::fromUtf8("Beim schreiben in der Datei ist ein Fehler aufgetreten."),"OK");
 | 
					QMessageBox::critical(NULL,"Fehler",QString::fromUtf8("Beim schreiben in der Datei ist ein Fehler aufgetreten."),"OK");
 | 
				
			||||||
return;
 | 
					return;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
if(r!=entry->BinaryDataLength){
 | 
					if(r!=entry->BinaryData.length()){
 | 
				
			||||||
file.close();
 | 
					file.close();
 | 
				
			||||||
QMessageBox::critical(NULL,"Fehler",QString::fromUtf8("Die Datei konnte nicht vollständig geschrieben werden."),"OK");
 | 
					QMessageBox::critical(NULL,"Fehler",QString::fromUtf8("Die Datei konnte nicht vollständig geschrieben werden."),"OK");
 | 
				
			||||||
return;
 | 
					return;
 | 
				
			||||||
| 
						 | 
					@ -324,9 +315,8 @@ void CEditEntryDlg::OnDeleteAttachment()
 | 
				
			||||||
int r=QMessageBox::warning(this,trUtf8("Anhang löschen?"),trUtf8("Sie sind dabei den Anhang zu löschen.\nSind Sie sicher, dass Sie dies tun wollen?"),trUtf8("Ja"),trUtf8("Nein"),NULL,1,1);
 | 
					int r=QMessageBox::warning(this,trUtf8("Anhang löschen?"),trUtf8("Sie sind dabei den Anhang zu löschen.\nSind Sie sicher, dass Sie dies tun wollen?"),trUtf8("Ja"),trUtf8("Nein"),NULL,1,1);
 | 
				
			||||||
if(r==0){
 | 
					if(r==0){
 | 
				
			||||||
ModFlag=true;
 | 
					ModFlag=true;
 | 
				
			||||||
delete[]entry->pBinaryData;
 | 
					entry->BinaryData.clear();
 | 
				
			||||||
entry->pBinaryData=NULL;
 | 
					entry->BinaryData=QByteArray();
 | 
				
			||||||
entry->BinaryDataLength=0;
 | 
					 | 
				
			||||||
entry->BinaryDesc="";
 | 
					entry->BinaryDesc="";
 | 
				
			||||||
Edit_Attachment->setText("");
 | 
					Edit_Attachment->setText("");
 | 
				
			||||||
Label_AttachmentSize->setText("");
 | 
					Label_AttachmentSize->setText("");
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue