mirror of
https://gitlab.com/Syping/luaengineapp.git
synced 2025-09-15 21:21:41 +02:00
make I/O library
This commit is contained in:
parent
9321c1b9fb
commit
769d291f35
12 changed files with 247 additions and 72 deletions
|
@ -21,7 +21,6 @@
|
|||
#include <QProcess>
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QDebug>
|
||||
#include <QFile>
|
||||
#ifdef Q_OS_WIN
|
||||
#include "windows.h"
|
||||
|
@ -38,14 +37,6 @@ LuaEngineOS::LuaEngineOS(QObject *parent, bool loadBaseLibraries) : LuaEngine(pa
|
|||
|
||||
void LuaEngineOS::pushClass(lua_State *L_p)
|
||||
{
|
||||
// Directory
|
||||
pushFunction(L_p, "directoryListFiles", directoryListFiles);
|
||||
|
||||
// File
|
||||
pushFunction(L_p, "linkFile", linkFile);
|
||||
pushVariant(L_p, "Symlink", (int)0);
|
||||
pushVariant(L_p, "Hardlink", (int)1);
|
||||
|
||||
// Process
|
||||
pushFunction(L_p, "executeProcess", executeProcess);
|
||||
}
|
||||
|
@ -55,58 +46,6 @@ void LuaEngineOS::pushClass(LuaEngine *luaEngine)
|
|||
pushClass(luaEngine->luaState());
|
||||
}
|
||||
|
||||
int LuaEngineOS::directoryListFiles(lua_State *L_p)
|
||||
{
|
||||
if (getArgumentCount(L_p) >= 1) {
|
||||
QStringList directories;
|
||||
QStringList nameFilters;
|
||||
QString directory = getVariant(L_p, 1).toString();
|
||||
if (getArgumentCount(L_p) >= 2) {
|
||||
nameFilters << getVariant(L_p, 2).toString();
|
||||
}
|
||||
QDirIterator dirIterator(directory, nameFilters, QDir::Files | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
|
||||
while (dirIterator.hasNext()) {
|
||||
directories << dirIterator.next();
|
||||
}
|
||||
pushVariant(L_p, directories);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LuaEngineOS::linkFile(lua_State *L_p)
|
||||
{
|
||||
if (getArgumentCount(L_p) >= 2) {
|
||||
bool symlinkMode = true;
|
||||
if (getArgumentCount(L_p) >= 3 && getVariant(L_p, 3).toInt() == 1) {
|
||||
symlinkMode = false;
|
||||
}
|
||||
bool linkSucceeded = false;
|
||||
if (symlinkMode) {
|
||||
#ifdef Q_OS_WIN
|
||||
QString targetFile = getVariant(L_p, 2).toString();
|
||||
if (targetFile.right(4) != ".lnk") {
|
||||
targetFile += ".lnk";
|
||||
}
|
||||
linkSucceeded = QFile::link(getVariant(L_p, 1).toString(), targetFile);
|
||||
#else
|
||||
linkSucceeded = QFile::link(getVariant(L_p, 1).toString(), getVariant(L_p, 2).toString());
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
#ifdef Q_OS_WIN
|
||||
linkSucceeded = CreateHardLinkW(getVariant(L_p, 2).toString().toStdWString().c_str(), getVariant(L_p, 1).toString().toStdWString().c_str(), NULL);
|
||||
#else
|
||||
linkSucceeded = link(getVariant(L_p, 1).toString().toUtf8().data(), getVariant(L_p, 2).toString().toUtf8().data());
|
||||
#endif
|
||||
}
|
||||
pushVariant(L_p, linkSucceeded);
|
||||
return 1;
|
||||
}
|
||||
getVariant(L_p, false);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int LuaEngineOS::executeProcess(lua_State *L_p)
|
||||
{
|
||||
if (getArgumentCount(L_p) >= 1) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue