changed attachment data type to QByteArray

git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@28 b624d157-de02-0410-bad0-e51aec6abb33
master
tariq 19 years ago
parent 5f8095706e
commit 9d2b50b9c3
  1. 7
      src/Database.cpp
  2. 3
      src/Database.h
  3. 31
      src/PwManager.cpp
  4. 36
      src/dialogs/EditEntryDlg.cpp

@ -28,8 +28,7 @@ Creation=QDateTime::currentDateTime();
LastMod=QDateTime::currentDateTime();
LastAccess=QDateTime::currentDateTime();
Expire=QDateTime(QDate(2999,12,28),QTime(23,59,59)); //Never
BinaryDataLength=0;
pBinaryData=NULL;
BinaryData=QByteArray();
}
bool CGroup::UI_ExpandByDefault=true;
@ -59,9 +58,5 @@ CGroup::~CGroup(){
}
CEntry::~CEntry(){
if(pBinaryData) {
delete [] pBinaryData;
}
pBinaryData=NULL;
}

@ -43,8 +43,7 @@ QDateTime Creation;
QDateTime LastMod;
QDateTime LastAccess;
QDateTime Expire;
Q_UINT8 *pBinaryData;
Q_UINT32 BinaryDataLength;
QByteArray BinaryData;
/*Q_UINT32 PasswordLength;*/
bool ReadEntryField(Q_UINT16 FieldType, Q_UINT32 FieldSize, Q_UINT8 *pData);
bool operator==(const CEntry&) const;

@ -408,7 +408,7 @@ Entries.removeAt(Entries.indexOf(*entry));
bool PwDatabase::IsMetaStream(CEntry& p){
if(p.pBinaryData == NULL) return false;
if(p.BinaryData.isNull()) return false;
if(p.Additional == "") return false;
if(p.BinaryDesc == "") return false;
if(p.BinaryDesc != "bin-stream") return false;
@ -546,18 +546,11 @@ switch(FieldType)
break;
case 0x000E:
if(FieldSize != 0)
{
///@TODO: im Destruktor löschen
///@TODO: im Konstruktor auf Null
pBinaryData = new Q_UINT8[FieldSize];
memcpy(pBinaryData, pData, FieldSize);
BinaryDataLength = FieldSize;
}
BinaryData=QByteArray((char*)pData,FieldSize);
else
{pBinaryData=0;}
BinaryData=QByteArray(); //=NULL
break;
case 0xFFFF:
///@TODO: Alle Elemente geladen - Status setzen oder so was
break;
default:
return false; // Field unsupported
@ -609,7 +602,7 @@ for(int i = 0; i < Entries.size(); i++){
+Entries[i].Password.length()+1
+Entries[i].Additional.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
FileSize = (FileSize + 16) - (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;
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;
memcpyToLEnd32(buffer+pos, &FieldSize); pos += 4;
if((Entries[i].pBinaryData != NULL) && (FieldSize != 0))
memcpy(buffer+pos, Entries[i].pBinaryData, FieldSize);
if((!Entries[i].BinaryData.isNull()) && (FieldSize != 0))
memcpy(buffer+pos, Entries[i].BinaryData.data(), FieldSize);
pos += FieldSize;
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());
size += sizeof(left->Expire);
kp_assert(results, left->BinaryDataLength == right->BinaryDataLength);
kp_assert(results, (left->pBinaryData == NULL && right->pBinaryData == NULL) ||
memcmp(left->pBinaryData, right->pBinaryData, left->BinaryDataLength) == 0);
size += sizeof(left->pBinaryData);
size += sizeof(left->BinaryDataLength);
kp_assert(results, left->BinaryData.length() == right->BinaryData.length());
kp_assert(results, (left->BinaryData.isNull() && right->BinaryData.isNull()) ||
memcmp(left->BinaryData.data(), right->BinaryData.data(), left->BinaryData.length()) == 0);
size += left->BinaryData.length();
size += sizeof(left->BinaryData.length());
kp_assert(results, size == sizeof(CEntry));
}

@ -69,7 +69,7 @@ ButtonOpenAttachment->setIcon(*Icon_FileOpen);
ButtonDeleteAttachment->setIcon(*Icon_EditDelete);
ButtonSaveAttachment->setIcon(*Icon_FileSave);
if(entry->pBinaryData==NULL){
if(entry->BinaryData.isNull()){
ButtonSaveAttachment->setDisabled(true);
ButtonDeleteAttachment->setDisabled(true);}
setCaption(entry->Title);
@ -92,17 +92,17 @@ Edit_Attachment->setText(entry->BinaryDesc);
Edit_Comment->setText(entry->Additional);
InitGroupComboBox();
InitIconComboBox();
if(entry->BinaryDataLength==0)
if(entry->BinaryData.length()==0)
Label_AttachmentSize->setText("");
else{
QString unit;
int faktor;
int prec;
if(entry->BinaryDataLength<1000){unit=" Byte";faktor=1;prec=0;}
else {if(entry->BinaryDataLength<1000000){unit=" kB";faktor=1000;prec=1;}
if(entry->BinaryData.length()<1000){unit=" Byte";faktor=1;prec=0;}
else {if(entry->BinaryData.length()<1000000){unit=" kB";faktor=1000;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){
DateTime_Expire->setDisabled(true);
@ -260,16 +260,7 @@ QMessageBox::warning(NULL,trUtf8("Fehler"),trUtf8("Datei konnte nicht geöffnet
return;
}
ModFlag=true;
if(entry->pBinaryData)delete [] entry->pBinaryData;
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());
entry->BinaryData=file.readAll();
file.close();
QFileInfo info(filename);
entry->BinaryDesc=info.fileName();
@ -278,11 +269,11 @@ Edit_Attachment->setText(entry->BinaryDesc);
QString unit;
int faktor;
int prec;
if(entry->BinaryDataLength<1000){unit=" Byte";faktor=1;prec=0;}
else {if(entry->BinaryDataLength<1000000){unit=" kB";faktor=1000;prec=1;}
if(entry->BinaryData.length()<1000){unit=" Byte";faktor=1;prec=0;}
else {if(entry->BinaryData.length()<1000000){unit=" kB";faktor=1000;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);
ButtonSaveAttachment->setEnabled(true);
ButtonDeleteAttachment->setEnabled(true);
@ -305,13 +296,13 @@ QMessageBox::critical(NULL,"Fehler",QString::fromUtf8("Datei konnte nicht erstel
return;
}
int r=file.writeBlock((char*)entry->pBinaryData,entry->BinaryDataLength);
int r=file.write(entry->BinaryData);
if(r==-1){
file.close();
QMessageBox::critical(NULL,"Fehler",QString::fromUtf8("Beim schreiben in der Datei ist ein Fehler aufgetreten."),"OK");
return;
}
if(r!=entry->BinaryDataLength){
if(r!=entry->BinaryData.length()){
file.close();
QMessageBox::critical(NULL,"Fehler",QString::fromUtf8("Die Datei konnte nicht vollständig geschrieben werden."),"OK");
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);
if(r==0){
ModFlag=true;
delete[]entry->pBinaryData;
entry->pBinaryData=NULL;
entry->BinaryDataLength=0;
entry->BinaryData.clear();
entry->BinaryData=QByteArray();
entry->BinaryDesc="";
Edit_Attachment->setText("");
Label_AttachmentSize->setText("");