mirror of
https://gitlab.com/Syping/luaengineapp.git
synced 2024-11-05 05:26:55 +01:00
add linkFile
This commit is contained in:
parent
98f65a669f
commit
97ed09b3f9
2 changed files with 47 additions and 1 deletions
|
@ -20,7 +20,14 @@
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QDebug>
|
#include <QString>
|
||||||
|
#include <QFile>
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
#include "windows.h"
|
||||||
|
#include <iostream>
|
||||||
|
#else
|
||||||
|
#include "unistd.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
LuaEngineOS::LuaEngineOS(QObject *parent, bool loadBaseLibraries) : LuaEngine(parent, loadBaseLibraries)
|
LuaEngineOS::LuaEngineOS(QObject *parent, bool loadBaseLibraries) : LuaEngine(parent, loadBaseLibraries)
|
||||||
{
|
{
|
||||||
|
@ -33,6 +40,11 @@ void LuaEngineOS::pushClass(lua_State *L_p)
|
||||||
// Directory
|
// Directory
|
||||||
pushFunction(L_p, "directoryListFiles", directoryListFiles);
|
pushFunction(L_p, "directoryListFiles", directoryListFiles);
|
||||||
|
|
||||||
|
// File
|
||||||
|
pushFunction(L_p, "linkFile", linkFile);
|
||||||
|
pushVariant(L_p, "Symlink", (int)0);
|
||||||
|
pushVariant(L_p, "Hardlink", (int)1);
|
||||||
|
|
||||||
// Process
|
// Process
|
||||||
pushFunction(L_p, "executeProcess", executeProcess);
|
pushFunction(L_p, "executeProcess", executeProcess);
|
||||||
}
|
}
|
||||||
|
@ -61,6 +73,39 @@ int LuaEngineOS::directoryListFiles(lua_State *L_p)
|
||||||
return 0;
|
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
|
||||||
|
}
|
||||||
|
getVariant(L_p, linkSucceeded);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
getVariant(L_p, false);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int LuaEngineOS::executeProcess(lua_State *L_p)
|
int LuaEngineOS::executeProcess(lua_State *L_p)
|
||||||
{
|
{
|
||||||
if (getArgumentCount(L_p) >= 1) {
|
if (getArgumentCount(L_p) >= 1) {
|
||||||
|
|
|
@ -31,6 +31,7 @@ public:
|
||||||
static void pushClass(lua_State *L_p);
|
static void pushClass(lua_State *L_p);
|
||||||
static void pushClass(LuaEngine *luaEngine);
|
static void pushClass(LuaEngine *luaEngine);
|
||||||
static int directoryListFiles(lua_State *L_p);
|
static int directoryListFiles(lua_State *L_p);
|
||||||
|
static int linkFile(lua_State *L_p);
|
||||||
static int executeProcess(lua_State *L_p);
|
static int executeProcess(lua_State *L_p);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in a new issue