2019-09-06 23:43:07 -04:00
|
|
|
#include "mods.h"
|
|
|
|
|
|
|
|
// This file is part of MRCI.
|
|
|
|
|
|
|
|
// MRCI is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// MRCI is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with MRCI under the LICENSE.md file. If not, see
|
|
|
|
// <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
ListMods::ListMods(QObject *parent) : TableViewer(parent)
|
|
|
|
{
|
2019-11-08 22:06:09 -05:00
|
|
|
setParams(TABLE_MODULES, false);
|
|
|
|
addTableColumn(TABLE_MODULES, COLUMN_MOD_MAIN);
|
2019-09-06 23:43:07 -04:00
|
|
|
}
|
|
|
|
|
2019-11-08 22:06:09 -05:00
|
|
|
UploadMod::UploadMod(QObject *parent) : CmdObject(parent) {}
|
|
|
|
DelMod::DelMod(QObject *parent) : CmdObject(parent) {}
|
2019-09-06 23:43:07 -04:00
|
|
|
|
|
|
|
QString ListMods::cmdName() {return "ls_mods";}
|
|
|
|
QString DelMod::cmdName() {return "rm_mod";}
|
|
|
|
QString UploadMod::cmdName() {return "add_mod";}
|
|
|
|
|
2019-11-08 22:06:09 -05:00
|
|
|
bool UploadMod::isExecutable(const QString &path)
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
2019-11-08 22:06:09 -05:00
|
|
|
QFileInfo info(expandEnvVariables(path));
|
2019-09-06 23:43:07 -04:00
|
|
|
|
2019-11-08 22:06:09 -05:00
|
|
|
return info.exists() && info.isExecutable();
|
2019-09-06 23:43:07 -04:00
|
|
|
}
|
|
|
|
|
2019-11-08 22:06:09 -05:00
|
|
|
void UploadMod::procIn(const QByteArray &binIn, quint8 dType)
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
2019-11-08 22:06:09 -05:00
|
|
|
if (dType == TEXT)
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
2019-11-08 22:06:09 -05:00
|
|
|
QStringList args = parseArgs(binIn, 2);
|
|
|
|
QString path = getParam("-mod_path", args);
|
2019-09-06 23:43:07 -04:00
|
|
|
|
2019-11-08 22:06:09 -05:00
|
|
|
if (path.isEmpty())
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
2019-11-08 22:06:09 -05:00
|
|
|
errTxt("err: The path to module executable (-mod_path) argument not found or is empty.\n");
|
2019-09-06 23:43:07 -04:00
|
|
|
}
|
2019-11-08 22:06:09 -05:00
|
|
|
else if (!validModPath(path))
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
2019-11-16 13:08:02 -05:00
|
|
|
errTxt("err: The module path must be less then 512 chars long and cannot contain the following chars: :*?\"<>|\n");
|
2019-09-06 23:43:07 -04:00
|
|
|
}
|
2019-11-08 22:06:09 -05:00
|
|
|
else if (modExists(path))
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
2019-11-08 22:06:09 -05:00
|
|
|
errTxt("err: The module already exists.\n");
|
2019-09-06 23:43:07 -04:00
|
|
|
}
|
2019-11-08 22:06:09 -05:00
|
|
|
else if (!isExecutable(path))
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
2019-11-08 22:06:09 -05:00
|
|
|
errTxt("err: Executable: " + path + " does not exists or does not have execution permissions.\n");
|
2019-09-06 23:43:07 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Query db(this);
|
|
|
|
|
|
|
|
db.setType(Query::PUSH, TABLE_MODULES);
|
2019-11-08 22:06:09 -05:00
|
|
|
db.addColumn(COLUMN_MOD_MAIN, path);
|
2019-09-06 23:43:07 -04:00
|
|
|
db.exec();
|
|
|
|
|
2019-11-08 22:06:09 -05:00
|
|
|
async(ASYNC_ENABLE_MOD, PUB_IPC_WITH_FEEDBACK, toTEXT(path));
|
2019-09-06 23:43:07 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-08 22:06:09 -05:00
|
|
|
void DelMod::procIn(const QByteArray &binIn, quint8 dType)
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
if (dType == TEXT)
|
|
|
|
{
|
|
|
|
QStringList args = parseArgs(binIn, 2);
|
2019-11-08 22:06:09 -05:00
|
|
|
QString path = getParam("-mod_path", args);
|
2019-09-06 23:43:07 -04:00
|
|
|
|
2019-11-08 22:06:09 -05:00
|
|
|
if (path.isEmpty())
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
2019-11-08 22:06:09 -05:00
|
|
|
errTxt("err: The path to module executable (-mod_path) argument not found or is empty.\n");
|
2019-09-06 23:43:07 -04:00
|
|
|
}
|
2019-11-08 22:06:09 -05:00
|
|
|
else if (!validModPath(path))
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
2019-11-16 13:08:02 -05:00
|
|
|
errTxt("err: Invalid module path.\n");
|
2019-09-06 23:43:07 -04:00
|
|
|
}
|
2019-11-08 22:06:09 -05:00
|
|
|
else if (!modExists(path))
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
2019-11-08 22:06:09 -05:00
|
|
|
errTxt("err: No such module found: '" + path + "'\n");
|
2019-09-06 23:43:07 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Query db(this);
|
|
|
|
|
2019-11-08 22:06:09 -05:00
|
|
|
db.setType(Query::DEL, TABLE_MODULES);
|
|
|
|
db.addCondition(COLUMN_MOD_MAIN, path);
|
2019-09-06 23:43:07 -04:00
|
|
|
db.exec();
|
|
|
|
|
2019-11-08 22:06:09 -05:00
|
|
|
async(ASYNC_DISABLE_MOD, PUB_IPC_WITH_FEEDBACK, toTEXT(path));
|
2019-09-06 23:43:07 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|