Refactor(Replace isKeyA with KeyType)

pull/4/head
wh201906 4 years ago
parent 87dddf4d3d
commit cd122b8959

@ -282,7 +282,7 @@ void Mifare::readAll()
if(result.indexOf("isOk:01") != -1)
{
keyBList->replace(i, tmpKey);
data_syncWithKeyWidget(false, i, false);
data_syncWithKeyWidget(false, i, KEY_B);
}
else
{
@ -407,8 +407,8 @@ void Mifare::readAllC()
}
keyAList->replace(i, dataList->at(cardType.blks[i] + cardType.blk[i] - 1).left(12));
keyBList->replace(i, dataList->at(cardType.blks[i] + cardType.blk[i] - 1).right(12));
data_syncWithKeyWidget(false, i, true);
data_syncWithKeyWidget(false, i, false);
data_syncWithKeyWidget(false, i, KEY_A);
data_syncWithKeyWidget(false, i, KEY_B);
}
}
}
@ -559,8 +559,8 @@ void Mifare::readAllE()
}
keyAList->replace(i, dataList->at(cardType.blks[i] + cardType.blk[i] - 1).left(12));
keyBList->replace(i, dataList->at(cardType.blks[i] + cardType.blk[i] - 1).right(12));
data_syncWithKeyWidget(false, i, true);
data_syncWithKeyWidget(false, i, false);
data_syncWithKeyWidget(false, i, KEY_A);
data_syncWithKeyWidget(false, i, KEY_B);
}
}
@ -626,7 +626,7 @@ void Mifare::data_syncWithDataWidget(bool syncAll, int block)
}
}
void Mifare::data_syncWithKeyWidget(bool syncAll, int sector, bool isKeyA)
void Mifare::data_syncWithKeyWidget(bool syncAll, int sector, KeyType keyType)
{
if(syncAll)
{
@ -638,7 +638,7 @@ void Mifare::data_syncWithKeyWidget(bool syncAll, int sector, bool isKeyA)
}
else
{
if(isKeyA)
if(keyType == KEY_A)
ui->MF_keyWidget->item(sector, 1)->setText(keyAList->at(sector));
else
ui->MF_keyWidget->item(sector, 2)->setText(keyBList->at(sector));
@ -976,9 +976,9 @@ void Mifare::data_setData(int block, const QString &data)
dataList->replace(block, data);
}
void Mifare::data_setKey(int sector, bool isKeyA, const QString &key)
void Mifare::data_setKey(int sector, KeyType keyType, const QString &key)
{
if(isKeyA)
if(keyType == KEY_A)
keyAList->replace(sector, key);
else
keyBList->replace(sector, key);

@ -30,6 +30,12 @@ public:
void dump();
void restore();
enum KeyType
{
KEY_A,
KEY_B,
};
enum DataType
{
DATA_INVALID,
@ -84,7 +90,7 @@ public:
bool data_isKeyValid(const QString &key);
Mifare::DataType data_isDataValid(QString data);
void data_syncWithDataWidget(bool syncAll = true, int block = 0);
void data_syncWithKeyWidget(bool syncAll = true, int sector = 0, bool isKeyA = true);
void data_syncWithKeyWidget(bool syncAll = true, int sector = 0, KeyType keyType = KEY_A);
CardType cardType;
Mifare::CardType getCardType();
@ -104,7 +110,7 @@ public:
void data_data2Key();
void data_setData(int block, const QString &data);
void data_setKey(int sector, bool isKeyA, const QString &key);
void data_setKey(int sector, KeyType keyType, const QString &key);
void lockC();
void writeAllE();
void readAllE();

@ -337,26 +337,26 @@ void MainWindow::on_MF_keyWidget_itemChanged(QTableWidgetItem *item)
QString key = item->text().replace(" ", "").toUpper();
if(key == "" || mifare->data_isKeyValid(key))
{
mifare->data_setKey(item->row(), true, key);
mifare->data_setKey(item->row(), Mifare::KEY_A, key);
}
else
{
QMessageBox::information(this, tr("Info"), tr("Key must consists of 12 Hex symbols(Whitespace is allowed)"));
}
mifare->data_syncWithKeyWidget(false, item->row(), true);
mifare->data_syncWithKeyWidget(false, item->row(), Mifare::KEY_A);
}
else if(item->column() == 2)
{
QString key = item->text().replace(" ", "").toUpper();
if(key == "" || mifare->data_isKeyValid(key))
{
mifare->data_setKey(item->row(), false, key);
mifare->data_setKey(item->row(), Mifare::KEY_B, key);
}
else
{
QMessageBox::information(this, tr("Info"), tr("Key must consists of 12 Hex symbols(Whitespace is allowed)"));
}
mifare->data_syncWithKeyWidget(false, item->row(), false);
mifare->data_syncWithKeyWidget(false, item->row(), Mifare::KEY_B);
}
}

Loading…
Cancel
Save