-
Notifications
You must be signed in to change notification settings - Fork 28
/
exutils.cpp
104 lines (91 loc) · 2.91 KB
/
exutils.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include "exutils.h"
#include "ecuseedkeydll.h"
#include <QGuiApplication>
#include <QDebug>
#include <QDir>
#include <QRegularExpression>
ExUTILS::ExUTILS(QObject *parent) : QObject(parent),
p_sett(new QSettings(QStringLiteral("Xplatforms"),QStringLiteral("mbseedkey"),this)),
p_seedkey_dll(Q_NULLPTR)
{
this->loadDllsList();
}
Q_INVOKABLE void ExUTILS::searchFor(QString txt)
{
if(txt.isEmpty())
{
this->dlls_list = this->p_bak_dlls_list;
emit dllsChanged();
return;
}
QStringList srch_list;
foreach(auto el, this->p_bak_dlls_list)
{
if(el.contains(txt, Qt::CaseInsensitive))srch_list.append(el);
}
this->dlls_list = srch_list;
emit dllsChanged();
}
void ExUTILS::loadDllsList(QString search_txt)
{
Q_UNUSED(search_txt)
this->dlls_list.clear();
QDir dir(this->foldername());
QFileInfoList list = dir.entryInfoList(QStringList() << "*.dll", QDir::Files |QDir::NoSymLinks |QDir::NoDotAndDotDot | QDir::Readable, QDir::Name );
for(qint32 x = 0; x < list.count(); x++)
{
this->dlls_list.append(list.at(x).fileName());
/*
auto ecu_test = new ECUSeedKeyDLL(list.at(x).absoluteFilePath());
if(ecu_test->isSeedKeyDll())
{
this->dlls_list.append(ecu_test->DLLName());
qDebug() << "Adding DLL to list: " << ecu_test->DLLName();
}
delete ecu_test;
*/
}
this->p_bak_dlls_list = dlls_list;
emit dllsChanged();
}
void ExUTILS::selectDll(qint32 idx)
{
if(this->dlls_list.isEmpty() || idx >= this->dlls_list.count())return;
auto dllname = this->dlls_list.at(idx);
auto dll_path = QDir::toNativeSeparators(this->foldername()+QDir::toNativeSeparators("/")+dllname);
if(this->p_seedkey_dll != Q_NULLPTR)
{
delete this->p_seedkey_dll;
this->p_seedkey_dll = Q_NULLPTR;
}
this->p_seedkey_dll = new ECUSeedKeyDLL(dll_path);
emit seedkeydllChanged();
}
ECUSeedKeyDLL * ExUTILS::seedkeydll()
{
return this->p_seedkey_dll;
}
QString ExUTILS::foldername()
{
if(this->p_sett->contains(QStringLiteral("current_folder")))
return QDir::toNativeSeparators(this->p_sett->value(QStringLiteral("current_folder")).toString());
else return QDir::toNativeSeparators(qApp->applicationDirPath()+QDir::toNativeSeparators("/dlls"));
}
void ExUTILS::setFoldername(QString fname)
{
if(this->foldername().compare(QDir::toNativeSeparators(fname)) != 0)
{
this->p_sett->setValue(QStringLiteral("current_folder"), fname);
emit foldernameChanged();
this->loadDllsList();
}
}
///TODO: make it better
QString ExUTILS::getInputMaskForSeedLen(qint32 len)
{
QString str = "HH;0";
len--;
for(qint32 i = 0; i < len; i++)str.push_front("HH ");
str.push_front(QChar('>'));
return str;
}