mirror of
https://github.com/InoriRus/Kyty.git
synced 2026-08-28 05:06:40 +00:00
add Linux support
This commit is contained in:
@@ -28,8 +28,10 @@ add_executable(launcher WIN32
|
||||
|
||||
|
||||
target_link_libraries(launcher Qt5::Widgets)
|
||||
if(MSVC OR MINGW)
|
||||
target_link_libraries(launcher psapi)
|
||||
target_link_libraries(launcher setupapi)
|
||||
endif()
|
||||
if (CLANG AND NOT MSVC)
|
||||
target_link_libraries(launcher pthread)
|
||||
endif()
|
||||
@@ -45,9 +47,11 @@ endif()
|
||||
|
||||
add_dependencies(launcher KytyGitVersion)
|
||||
|
||||
find_program(QT_WINDEPLOYQT NAMES windeployqt PATHS "${Qt5_DIR}/../../../bin")
|
||||
if(NOT QT_WINDEPLOYQT)
|
||||
message(FATAL_ERROR "Could not find windeployqt")
|
||||
if(NOT LINUX)
|
||||
find_program(QT_WINDEPLOYQT NAMES windeployqt PATHS "${Qt5_DIR}/../../../bin")
|
||||
if(NOT QT_WINDEPLOYQT)
|
||||
message(FATAL_ERROR "Could not find windeployqt")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(launcher_name "launcher")
|
||||
@@ -56,17 +60,19 @@ set_target_properties(launcher PROPERTIES OUTPUT_NAME ${launcher_name})
|
||||
|
||||
install(TARGETS launcher DESTINATION .)
|
||||
|
||||
install(CODE "
|
||||
execute_process(
|
||||
COMMAND ${QT_WINDEPLOYQT} \"\${CMAKE_INSTALL_PREFIX}/${launcher_name}.exe\"
|
||||
if(NOT LINUX)
|
||||
install(CODE "
|
||||
execute_process(
|
||||
COMMAND ${QT_WINDEPLOYQT} \"\${CMAKE_INSTALL_PREFIX}/${launcher_name}.exe\"
|
||||
--no-svg
|
||||
--no-angle
|
||||
--no-opengl
|
||||
--no-opengl-sw
|
||||
--no-system-d3d-compiler
|
||||
--no-translations
|
||||
)
|
||||
")
|
||||
--no-translations
|
||||
)
|
||||
")
|
||||
endif()
|
||||
|
||||
|
||||
qt5_create_translation(QM_FILES ${launcher_src} ${launcher_forms} ${launcher_ts} OPTIONS -I ${CMAKE_SOURCE_DIR}/launcher/include)
|
||||
@@ -79,10 +85,13 @@ get_property(inc_headers TARGET launcher PROPERTY INCLUDE_DIRECTORIES)
|
||||
list(APPEND inc_headers
|
||||
${CMAKE_SOURCE_DIR}/launcher
|
||||
${CMAKE_BINARY_DIR}/launcher/launcher_autogen/include
|
||||
${Qt5_DIR}/../../../include
|
||||
${Qt5_DIR}/../../../include/QtWidgets
|
||||
${Qt5_DIR}/../../../include/QtCore
|
||||
${Qt5_DIR}/../../../include/QtGui
|
||||
${Qt5Widgets_INCLUDE_DIRS}
|
||||
${Qt5Core_INCLUDE_DIRS}
|
||||
${Qt5Gui_INCLUDE_DIRS}
|
||||
#${Qt5_DIR}/../../../include
|
||||
#${Qt5_DIR}/../../../include/QtWidgets
|
||||
#${Qt5_DIR}/../../../include/QtCore
|
||||
#${Qt5_DIR}/../../../include/QtGui
|
||||
)
|
||||
|
||||
include_what_you_use_with_mappings(launcher "${inc_headers}" "${iwyu_maps}")
|
||||
|
||||
@@ -30,7 +30,7 @@ public:
|
||||
explicit MainDialog(QWidget* parent = nullptr);
|
||||
~MainDialog() override = default;
|
||||
|
||||
void RunInterpreter(QProcess* process, Kyty::Configuration* info, bool con_emu);
|
||||
void RunInterpreter(QProcess* process, Kyty::Configuration* info, [[maybe_unused]] bool con_emu);
|
||||
|
||||
static void WriteSettings(QSettings* s);
|
||||
static void ReadSettings(QSettings* s);
|
||||
|
||||
@@ -64,7 +64,11 @@ void ConfigurationListWidget::WriteSettings()
|
||||
s = new QSettings(CONF_FILE_NAME, QSettings::IniFormat);
|
||||
} else
|
||||
{
|
||||
#ifdef __linux__
|
||||
s = new QSettings(QSettings::IniFormat, QSettings::UserScope, CONF_ORG_NAME, CONF_APP_NAME);
|
||||
#else
|
||||
s = new QSettings(QSettings::IniFormat, QSettings::SystemScope, CONF_ORG_NAME, CONF_APP_NAME);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (s != nullptr)
|
||||
@@ -95,7 +99,11 @@ void ConfigurationListWidget::ReadSettings()
|
||||
s = new QSettings(CONF_FILE_NAME, QSettings::IniFormat);
|
||||
} else
|
||||
{
|
||||
#ifdef __linux__
|
||||
s = new QSettings(QSettings::IniFormat, QSettings::UserScope, CONF_ORG_NAME, CONF_APP_NAME);
|
||||
#else
|
||||
s = new QSettings(QSettings::IniFormat, QSettings::SystemScope, CONF_ORG_NAME, CONF_APP_NAME);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (s != nullptr)
|
||||
|
||||
@@ -27,7 +27,9 @@
|
||||
|
||||
#include "ui_main_dialog.h"
|
||||
|
||||
#ifndef __linux__
|
||||
#include <windows.h> // IWYU pragma: keep
|
||||
#endif
|
||||
|
||||
// IWYU pragma: no_include <minwindef.h>
|
||||
// IWYU pragma: no_include <processthreadsapi.h>
|
||||
@@ -35,24 +37,39 @@
|
||||
|
||||
class QWidget;
|
||||
|
||||
constexpr char SCRIPT_EXE[] = "fc_script.exe";
|
||||
constexpr char CMD_EXE[] = "cmd.exe";
|
||||
constexpr char CONEMU_EXE[] = "C:/Program Files/ConEmu/ConEmu64.exe";
|
||||
#ifdef __linux__
|
||||
constexpr char SCRIPT_EXE[] = "fc_script";
|
||||
#else
|
||||
constexpr char SCRIPT_EXE[] = "fc_script.exe";
|
||||
#endif
|
||||
|
||||
#ifndef __linux__
|
||||
constexpr char CMD_EXE[] = "cmd.exe";
|
||||
constexpr char CONEMU_EXE[] = "C:/Program Files/ConEmu/ConEmu64.exe";
|
||||
#else
|
||||
constexpr char GNOME[] = "gnome-terminal";
|
||||
constexpr char XTERM[] = "xterm";
|
||||
constexpr char KYTY_BASH_FILE[] = "kyty_run.sh";
|
||||
#endif
|
||||
constexpr char KYTY_MOUNT[] = "kyty_mount";
|
||||
constexpr char KYTY_EXECUTE[] = "kyty_execute";
|
||||
constexpr char KYTY_LOAD_ELF[] = "kyty_load_elf";
|
||||
// constexpr char KYTY_LOAD_SYMBOLS[] = "kyty_load_symbols";
|
||||
constexpr char KYTY_LOAD_SYMBOLS_ALL[] = "kyty_load_symbols_all";
|
||||
constexpr char KYTY_LOAD_PARAM_SFO[] = "kyty_load_param_sfo";
|
||||
constexpr char KYTY_INIT[] = "kyty_init";
|
||||
constexpr char KYTY_LUA_FILE[] = "kyty_run.lua";
|
||||
constexpr DWORD CMD_X_CHARS = 175;
|
||||
constexpr DWORD CMD_Y_CHARS = 1000;
|
||||
constexpr char SETTINGS_MAIN_DIALOG[] = "MainDialog";
|
||||
constexpr char SETTINGS_MAIN_LAST_GEOMETRY[] = "geometry";
|
||||
constexpr char KYTY_LOAD_SYMBOLS_ALL[] = "kyty_load_symbols_all";
|
||||
constexpr char KYTY_LOAD_PARAM_SFO[] = "kyty_load_param_sfo";
|
||||
constexpr char KYTY_INIT[] = "kyty_init";
|
||||
constexpr char KYTY_LUA_FILE[] = "kyty_run.lua";
|
||||
#ifndef __linux__
|
||||
constexpr DWORD CMD_X_CHARS = 175;
|
||||
constexpr DWORD CMD_Y_CHARS = 1000;
|
||||
#endif
|
||||
constexpr char SETTINGS_MAIN_DIALOG[] = "MainDialog";
|
||||
constexpr char SETTINGS_MAIN_LAST_GEOMETRY[] = "geometry";
|
||||
|
||||
class DetachableProcess: public QProcess
|
||||
{
|
||||
Q_OBJECT;
|
||||
|
||||
public:
|
||||
explicit DetachableProcess(QObject* parent = nullptr): QProcess(parent) {}
|
||||
void Detach()
|
||||
@@ -87,10 +104,12 @@ public:
|
||||
private:
|
||||
static QByteArray g_last_geometry;
|
||||
|
||||
Ui::MainDialog* m_ui = {nullptr};
|
||||
MainDialog* m_main_dialog = nullptr;
|
||||
QString m_interpreter;
|
||||
DetachableProcess m_process;
|
||||
Ui::MainDialog* m_ui = {nullptr};
|
||||
MainDialog* m_main_dialog = nullptr;
|
||||
QString m_interpreter;
|
||||
|
||||
/*DetachableProcess*/ QProcess m_process;
|
||||
|
||||
ConfigurationItem* m_running_item = nullptr;
|
||||
};
|
||||
|
||||
@@ -135,7 +154,7 @@ void MainDialogPrivate::Setup(MainDialog* main_dialog)
|
||||
Update();
|
||||
});
|
||||
|
||||
connect(main_dialog, &MainDialog::Quit, [=]() { m_process.Detach(); });
|
||||
// connect(main_dialog, &MainDialog::Quit, [=]() { m_process.Detach(); });
|
||||
|
||||
m_ui->label_settings_file->setText(tr("Settings file: ") + m_ui->widget->GetSettingsFile());
|
||||
|
||||
@@ -196,14 +215,23 @@ void MainDialogPrivate::FindInterpreter()
|
||||
return;
|
||||
}
|
||||
|
||||
#ifndef __linux__
|
||||
QFile console(CONEMU_EXE);
|
||||
bool con_emu = console.exists();
|
||||
#else
|
||||
bool con_emu = true;
|
||||
#endif
|
||||
|
||||
m_ui->radioButton_Cmd->setEnabled(true);
|
||||
m_ui->radioButton_Cmd->setChecked(true);
|
||||
m_ui->radioButton_ConEmu->setEnabled(con_emu);
|
||||
m_ui->radioButton_ConEmu->setChecked(false);
|
||||
|
||||
#ifdef __linux__
|
||||
m_ui->radioButton_Cmd->setText(QCoreApplication::translate("MainDialog", "gnome-terminal", nullptr));
|
||||
m_ui->radioButton_ConEmu->setText(QCoreApplication::translate("MainDialog", "xterm", nullptr));
|
||||
#endif
|
||||
|
||||
Update();
|
||||
}
|
||||
|
||||
@@ -265,7 +293,28 @@ static bool CreateLuaScript(Kyty::Configuration* info, const QString& file_name)
|
||||
return false;
|
||||
}
|
||||
|
||||
void MainDialog::RunInterpreter(QProcess* process, Kyty::Configuration* info, bool con_emu)
|
||||
#ifdef __linux__
|
||||
static bool CreateBashScript(const QString& interpreter, const QString& lua_file_name, const QString& file_name)
|
||||
{
|
||||
QFile file(file_name);
|
||||
if (file.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||
{
|
||||
QTextStream s(&file);
|
||||
|
||||
s << "#!/bin/bash\n";
|
||||
s << interpreter << " " << lua_file_name << "\n";
|
||||
s << "echo Press any key...\n";
|
||||
s << "read -n1\n";
|
||||
|
||||
file.close();
|
||||
|
||||
return file.setPermissions(file.permissions() | QFile::ExeUser | QFile::ExeOwner | QFile::ExeGroup);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
void MainDialog::RunInterpreter(QProcess* process, Kyty::Configuration* info, [[maybe_unused]] bool con_emu)
|
||||
{
|
||||
const auto& interpreter = m_p->GetInterpreter();
|
||||
|
||||
@@ -273,7 +322,6 @@ void MainDialog::RunInterpreter(QProcess* process, Kyty::Configuration* info, bo
|
||||
auto dir = f.absoluteDir();
|
||||
|
||||
auto lua_file_name = dir.filePath(KYTY_LUA_FILE);
|
||||
|
||||
if (!CreateLuaScript(info, lua_file_name))
|
||||
{
|
||||
QMessageBox::critical(this, tr("Error"), tr("Can't create file:\n") + lua_file_name);
|
||||
@@ -281,6 +329,25 @@ void MainDialog::RunInterpreter(QProcess* process, Kyty::Configuration* info, bo
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
auto bash_file_name = dir.filePath(KYTY_BASH_FILE);
|
||||
if (!CreateBashScript(interpreter, lua_file_name, bash_file_name))
|
||||
{
|
||||
QMessageBox::critical(this, tr("Error"), tr("Can't create file:\n") + bash_file_name);
|
||||
QApplication::quit();
|
||||
return;
|
||||
}
|
||||
|
||||
if (con_emu)
|
||||
{
|
||||
process->setProgram(XTERM);
|
||||
process->setArguments({"-e", "bash", "-c", bash_file_name});
|
||||
} else
|
||||
{
|
||||
process->setProgram(GNOME);
|
||||
process->setArguments({"--", "bash", "-c", bash_file_name});
|
||||
}
|
||||
#else
|
||||
if (con_emu)
|
||||
{
|
||||
process->setProgram(CONEMU_EXE);
|
||||
@@ -290,7 +357,9 @@ void MainDialog::RunInterpreter(QProcess* process, Kyty::Configuration* info, bo
|
||||
process->setProgram(CMD_EXE);
|
||||
process->setArguments({"/K", interpreter, lua_file_name});
|
||||
}
|
||||
#endif
|
||||
process->setWorkingDirectory(dir.path());
|
||||
#ifndef __linux__
|
||||
process->setCreateProcessArgumentsModifier(
|
||||
[](QProcess::CreateProcessArguments* args)
|
||||
{
|
||||
@@ -303,6 +372,7 @@ void MainDialog::RunInterpreter(QProcess* process, Kyty::Configuration* info, bo
|
||||
// args->startupInfo->dwFillAttribute =
|
||||
// static_cast<DWORD>(BACKGROUND_BLUE) | static_cast<DWORD>(FOREGROUND_RED) | static_cast<DWORD>(FOREGROUND_INTENSITY);
|
||||
});
|
||||
#endif
|
||||
process->start();
|
||||
process->waitForFinished(100);
|
||||
}
|
||||
|
||||
@@ -258,42 +258,42 @@
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/ConfigurationListWidget.cpp" line="128"/>
|
||||
<location filename="../src/ConfigurationListWidget.cpp" line="136"/>
|
||||
<source>New configuration</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/ConfigurationListWidget.cpp" line="142"/>
|
||||
<location filename="../src/ConfigurationListWidget.cpp" line="150"/>
|
||||
<source>Edit configuration</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/ConfigurationListWidget.cpp" line="153"/>
|
||||
<location filename="../src/ConfigurationListWidget.cpp" line="161"/>
|
||||
<source>Delete configuration</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/ConfigurationListWidget.cpp" line="153"/>
|
||||
<location filename="../src/ConfigurationListWidget.cpp" line="161"/>
|
||||
<source>Do you want to delete configuration?</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/ConfigurationListWidget.cpp" line="189"/>
|
||||
<location filename="../src/ConfigurationListWidget.cpp" line="197"/>
|
||||
<source>Run</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/ConfigurationListWidget.cpp" line="191"/>
|
||||
<location filename="../src/ConfigurationListWidget.cpp" line="199"/>
|
||||
<source>New...</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/ConfigurationListWidget.cpp" line="192"/>
|
||||
<location filename="../src/ConfigurationListWidget.cpp" line="200"/>
|
||||
<source>Edit...</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/ConfigurationListWidget.cpp" line="193"/>
|
||||
<location filename="../src/ConfigurationListWidget.cpp" line="201"/>
|
||||
<source>Delete</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
@@ -328,12 +328,24 @@
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/MainDialog.cpp" line="279"/>
|
||||
<location filename="../src/MainDialog.cpp" line="231"/>
|
||||
<source>gnome-terminal</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/MainDialog.cpp" line="232"/>
|
||||
<source>xterm</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/MainDialog.cpp" line="327"/>
|
||||
<location filename="../src/MainDialog.cpp" line="336"/>
|
||||
<source>Error</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/MainDialog.cpp" line="279"/>
|
||||
<location filename="../src/MainDialog.cpp" line="327"/>
|
||||
<location filename="../src/MainDialog.cpp" line="336"/>
|
||||
<source>Can't create file:
|
||||
</source>
|
||||
<translation type="unfinished"></translation>
|
||||
@@ -342,27 +354,27 @@
|
||||
<context>
|
||||
<name>MainDialogPrivate</name>
|
||||
<message>
|
||||
<location filename="../src/MainDialog.cpp" line="140"/>
|
||||
<location filename="../src/MainDialog.cpp" line="159"/>
|
||||
<source>Settings file: </source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/MainDialog.cpp" line="166"/>
|
||||
<location filename="../src/MainDialog.cpp" line="185"/>
|
||||
<source>Emulator: </source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/MainDialog.cpp" line="178"/>
|
||||
<location filename="../src/MainDialog.cpp" line="197"/>
|
||||
<source>Version: </source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/MainDialog.cpp" line="194"/>
|
||||
<location filename="../src/MainDialog.cpp" line="213"/>
|
||||
<source>Error</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/MainDialog.cpp" line="194"/>
|
||||
<location filename="../src/MainDialog.cpp" line="213"/>
|
||||
<source>Can't find emulator</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
|
||||
Reference in New Issue
Block a user