mirror of
https://github.com/rizinorg/cutter.git
synced 2025-02-21 14:16:08 +00:00
runtime crash fix (#799)
* folders mess fix * improvements * remove dot and dotdot from search list * array bound check
This commit is contained in:
parent
92505d042a
commit
8bf4058499
@ -26,17 +26,6 @@ static const QStringList cutterSpecificOptions = {
|
|||||||
|
|
||||||
ColorSchemeFileSaver::ColorSchemeFileSaver(QObject *parent) : QObject (parent)
|
ColorSchemeFileSaver::ColorSchemeFileSaver(QObject *parent) : QObject (parent)
|
||||||
{
|
{
|
||||||
QDir currDir;
|
|
||||||
QStringList dirs = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
|
|
||||||
dirs.removeOne(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation));
|
|
||||||
|
|
||||||
currDir = QDir(dirs.at(0)).filePath("radare2");
|
|
||||||
// currDir.entryList(QDir::Dirs, QDir::Name) returns { current dir, upper dir, dirs ... }
|
|
||||||
// so it takes first (and only) dir using .at(2)
|
|
||||||
currDir = currDir.filePath(currDir.entryList(QDir::Dirs,
|
|
||||||
QDir::Name).at(2) + QDir::separator() + "cons");
|
|
||||||
standardR2ThemesLocationPath = currDir.absolutePath();
|
|
||||||
|
|
||||||
customR2ThemesLocationPath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) +
|
customR2ThemesLocationPath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) +
|
||||||
QDir::separator() +
|
QDir::separator() +
|
||||||
"radare2" + QDir::separator() +
|
"radare2" + QDir::separator() +
|
||||||
@ -44,6 +33,40 @@ ColorSchemeFileSaver::ColorSchemeFileSaver(QObject *parent) : QObject (parent)
|
|||||||
if (!QDir(customR2ThemesLocationPath).exists()) {
|
if (!QDir(customR2ThemesLocationPath).exists()) {
|
||||||
QDir().mkpath(customR2ThemesLocationPath);
|
QDir().mkpath(customR2ThemesLocationPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QDir currDir;
|
||||||
|
QStringList dirs = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
|
||||||
|
dirs.removeOne(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation));
|
||||||
|
standardR2ThemesLocationPath = "";
|
||||||
|
|
||||||
|
for (auto &it : dirs) {
|
||||||
|
currDir = QDir(it).filePath("radare2");
|
||||||
|
if (currDir.exists()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
currDir.setPath("");
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList entry = currDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name);
|
||||||
|
standardR2ThemesLocationPath = currDir.absolutePath();
|
||||||
|
currDir.setPath("");
|
||||||
|
for (auto it : entry) {
|
||||||
|
it = standardR2ThemesLocationPath + QDir::separator() + it + QDir::separator() + "cons";
|
||||||
|
if (QDir(it).exists()) {
|
||||||
|
currDir = it;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
standardR2ThemesLocationPath = currDir.absolutePath();
|
||||||
|
if (standardR2ThemesLocationPath == "") {
|
||||||
|
QMessageBox mb;
|
||||||
|
mb.setIcon(QMessageBox::Critical);
|
||||||
|
mb.setStandardButtons(QMessageBox::Ok);
|
||||||
|
mb.setWindowTitle(tr("Standard themes not found!"));
|
||||||
|
mb.setText(tr("The radare2 standard themes could not be found! This probably means radare2 is not properly installed. If you think it is open an issue please."));
|
||||||
|
mb.exec();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QFile::FileError ColorSchemeFileSaver::copy(const QString &srcThemeName,
|
QFile::FileError ColorSchemeFileSaver::copy(const QString &srcThemeName,
|
||||||
@ -77,6 +100,9 @@ QFile::FileError ColorSchemeFileSaver::copy(const QString &srcThemeName,
|
|||||||
_obj[standardBackgroundOptionName] = QJsonArray({back.red(), back.green(), back.blue()});
|
_obj[standardBackgroundOptionName] = QJsonArray({back.red(), back.green(), back.blue()});
|
||||||
for (auto &it : _obj.keys()) {
|
for (auto &it : _obj.keys()) {
|
||||||
QJsonArray rgb = _obj[it].toArray();
|
QJsonArray rgb = _obj[it].toArray();
|
||||||
|
if (rgb.size() != 3) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
src.push_back("ec " + it + " " +
|
src.push_back("ec " + it + " " +
|
||||||
QColor(rgb[0].toInt(), rgb[1].toInt(), rgb[2].toInt()).name().replace("#", "rgb:"));
|
QColor(rgb[0].toInt(), rgb[1].toInt(), rgb[2].toInt()).name().replace("#", "rgb:"));
|
||||||
}
|
}
|
||||||
@ -84,16 +110,18 @@ QFile::FileError ColorSchemeFileSaver::copy(const QString &srcThemeName,
|
|||||||
src = QString(fIn.readAll()).split('\n');
|
src = QString(fIn.readAll()).split('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringList tmp;
|
||||||
for (auto &it : src) {
|
for (auto &it : src) {
|
||||||
if (it.isEmpty()) {
|
if (it.isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
fOut.write(it.toUtf8() + '\n');
|
fOut.write(it.toUtf8() + '\n');
|
||||||
|
|
||||||
|
tmp = it.split(' ');
|
||||||
if (it.length() > 2 && it.left(2) == "#~") {
|
if (it.length() > 2 && it.left(2) == "#~") {
|
||||||
options.removeOne(it.split(' ')[0].remove("#~").toUtf8());
|
options.removeOne(tmp[0].remove("#~").toUtf8());
|
||||||
} else {
|
} else if (tmp.size() > 1) {
|
||||||
options.removeOne(it.split(' ').at(1));
|
options.removeOne(tmp.at(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,7 +177,9 @@ QMap<QString, QColor> ColorSchemeFileSaver::getCutterSpecific() const
|
|||||||
for (auto &it : data) {
|
for (auto &it : data) {
|
||||||
if (it.length() > 2 && it.left(2) == "#~") {
|
if (it.length() > 2 && it.left(2) == "#~") {
|
||||||
QStringList currLine = it.split(' ');
|
QStringList currLine = it.split(' ');
|
||||||
ret.insert(currLine[0].remove("#~"), currLine[1].replace("rgb:", "#"));
|
if (currLine.size() > 1) {
|
||||||
|
ret.insert(currLine[0].remove("#~"), currLine[1].replace("rgb:", "#"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,9 +190,7 @@ QMap<QString, QColor> ColorSchemeFileSaver::getCutterSpecific() const
|
|||||||
QStringList ColorSchemeFileSaver::getCustomSchemes() const
|
QStringList ColorSchemeFileSaver::getCustomSchemes() const
|
||||||
{
|
{
|
||||||
QStringList sl;
|
QStringList sl;
|
||||||
sl = QDir(customR2ThemesLocationPath).entryList(QDir::Files, QDir::Name);
|
sl = QDir(customR2ThemesLocationPath).entryList(QDir::Files | QDir::NoDotAndDotDot, QDir::Name);
|
||||||
sl.removeOne(".");
|
|
||||||
sl.removeOne("..");
|
|
||||||
return sl;
|
return sl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,6 +271,9 @@ void Configuration::setColorTheme(QString theme)
|
|||||||
QJsonObject::iterator it;
|
QJsonObject::iterator it;
|
||||||
for (it = colorsObject.begin(); it != colorsObject.end(); it++) {
|
for (it = colorsObject.begin(); it != colorsObject.end(); it++) {
|
||||||
QJsonArray rgb = it.value().toArray();
|
QJsonArray rgb = it.value().toArray();
|
||||||
|
if (rgb.size() != 3) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
s.setValue("colors." + it.key(), QColor(rgb[0].toInt(), rgb[1].toInt(), rgb[2].toInt()));
|
s.setValue("colors." + it.key(), QColor(rgb[0].toInt(), rgb[1].toInt(), rgb[2].toInt()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user