Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ qt5build
deps
dist
setup/Output
.cache
/result
27 changes: 27 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-24.11";
};

outputs = { self, nixpkgs }:
let
forEachSystem = f: nixpkgs.lib.genAttrs [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]
(system: f nixpkgs.legacyPackages.${system});
in {
overlays = (final: prev: {
ssplice-cpp = prev.callPackage ./nix/package.nix { };
});
packages = forEachSystem (pkgs: {
ssplice-cpp = pkgs.callPackage ./nix/package.nix { };
});
devShells = forEachSystem (pkgs: {
default = pkgs.mkShell {
nativeBuildInputs = with pkgs; [
meson
pkg-config
ninja
];
buildInputs = with pkgs; [
kdePackages.qtbase
duktape
curl
libarchive
kdePackages.qtwayland
];
};
});
};
}
4 changes: 2 additions & 2 deletions globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
#include "tools/package.h" // ToolsPackage

// Points to the system-specific designated cache directory
#ifndef TARGET_WINDOWS
#ifndef WIN32
std::filesystem::path CACHE_DIR = (std::filesystem::path(std::getenv("HOME")) / ".cache") / "spplice-cpp";
#else
std::filesystem::path CACHE_DIR = std::filesystem::temp_directory_path() / "spplice-cpp";
#endif
bool CACHE_ENABLE = true;

// Points to the system-specific designated application directory
#ifndef TARGET_WINDOWS
#ifndef WIN32
const std::filesystem::path APP_DIR = (std::filesystem::path(std::getenv("HOME")) / ".config") / "spplice-cpp";
#else
const std::filesystem::path APP_DIR = std::filesystem::path(std::getenv("APPDATA")) / "spplice-cpp";
Expand Down
3 changes: 0 additions & 3 deletions globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@

#include "tools/package.h" // ToolsPackage

// Comment this line to target Linux, uncomment to target Windows
#define TARGET_WINDOWS

extern std::filesystem::path CACHE_DIR;
extern bool CACHE_ENABLE;
extern const std::filesystem::path APP_DIR;
Expand Down
16 changes: 8 additions & 8 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <exception>
#include <functional>
// Platform specific includes
#ifdef TARGET_WINDOWS
#ifdef WIN32
#include <windows.h>
#endif
// Main window dependencies
Expand All @@ -26,8 +26,8 @@
#include <QtConcurrent>
#include <QFutureWatcher>
#include "ui/mainwindow_extend.h"
#include "ui/repositories.h"
#include "ui/settings.h"
#include "ui_Repositories.h"
#include "ui_Settings.h"

// Project globals
#include "globals.h"
Expand Down Expand Up @@ -144,7 +144,7 @@ void signalHandler (int signal) {
crashHandler("Unknown Signal", signal);
}

#ifdef TARGET_WINDOWS
#ifdef WIN32
// Handles low-level exceptions on Windows
LONG WINAPI windowsExceptionHandler (EXCEPTION_POINTERS* info) {
crashHandler("Windows Exception", (uint)(info->ExceptionRecord->ExceptionCode));
Expand Down Expand Up @@ -296,7 +296,7 @@ int main (int argc, char *argv[]) {
QLineEdit *cacheInput = dialogUI.CacheDirInput;

// Write the cache directory to the input field
#ifndef TARGET_WINDOWS
#ifndef WIN32
cacheInput->setText(QString::fromStdString(CACHE_DIR.string()));
#else
cacheInput->setText(QString::fromStdWString(CACHE_DIR.wstring()));
Expand All @@ -305,7 +305,7 @@ int main (int argc, char *argv[]) {
// Connect the cache directory "Apply" button
QObject::connect(dialogUI.CacheDirBtn, &QPushButton::clicked, [cacheInput]() {

#ifndef TARGET_WINDOWS
#ifndef WIN32
const std::filesystem::path newPath(cacheInput->text().toStdString());
#else
const std::filesystem::path newPath(cacheInput->text().toStdWString());
Expand Down Expand Up @@ -418,7 +418,7 @@ int main (int argc, char *argv[]) {

});

#ifndef TARGET_WINDOWS
#ifndef WIN32
// Dynamically set the window icon on Linux
app.setWindowIcon(QIcon(":/resources/icon.ico"));
#endif
Expand Down Expand Up @@ -483,7 +483,7 @@ int main (int argc, char *argv[]) {
std::signal(SIGABRT, signalHandler);
std::signal(SIGINT, signalHandler);

#ifdef TARGET_WINDOWS
#ifdef WIN32
// Register Windows low-level exception handler
SetUnhandledExceptionFilter(windowsExceptionHandler);
#endif
Expand Down
61 changes: 61 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
project('spplice', 'cpp')

if get_option('USE_QT6')
qt = import('qt6')
qt_dep = dependency('qt6', modules: ['Core', 'Widgets', 'Gui', 'Concurrent'])
else
qt = import('qt5')
qt_dep = dependency('qt5', modules: ['Widgets', 'Concurrent'])
endif

duktape = dependency('duktape')
curl = dependency('libcurl')
libarchive = dependency('libarchive')

ui = qt.compile_ui(sources : files([
'ui/MainWindow.ui',
'ui/PackageItem.ui',
'ui/ErrorDialog.ui',
'ui/PackageInfo.ui',
'ui/Repositories.ui',
'ui/Settings.ui',
]))

moc_files = qt.compile_moc(headers : files([
'ui/mainwindow_extend.h',
'tools/package.h',
]))

resources = qt.compile_resources(
sources: [
'resources.qrc'
]
)

executable(
'SppliceCPP',
sources : [
moc_files,
ui,
'ui/mainwindow_extend.cpp',
'main.cpp',
'globals.cpp',
'tools/curl.cpp',
'tools/update.cpp',
'tools/qt.cpp',
'tools/install.cpp',
'tools/package.cpp',
'tools/repo.cpp',
'tools/js.cpp',
'tools/netcon.cpp',
'tools/merge.cpp',
resources,
],
dependencies: [
qt_dep,
duktape,
curl,
libarchive,
],
install: true
)
1 change: 1 addition & 0 deletions meson.options
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
option('USE_QT6', type : 'boolean', value : false, description : 'Build with QT6')
1 change: 1 addition & 0 deletions meson_options.txt
36 changes: 36 additions & 0 deletions nix/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
lib,
stdenv,
meson,
kdePackages,
duktape,
curl,
libarchive,
pkg-config,
ninja,
}:

stdenv.mkDerivation {
pname = "splice-cpp";
version = "0.9.5";

src = lib.cleanSource ../.;

nativeBuildInputs = [
meson
kdePackages.wrapQtAppsHook
pkg-config
ninja
];

buildInputs = [
kdePackages.qtbase
duktape
curl
libarchive
];

mesonFlags = [
(lib.mesonBool "USE_QT6" true)
];
}
6 changes: 1 addition & 5 deletions tools/curl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@
// Definitions for this source file
#include "curl.h"

#ifndef TARGET_WINDOWS
#include "../deps/linux/include/curl/curl.h"
#else
#include "../deps/win32/include/curl/curl.h"
#endif
#include "curl/curl.h"

// Initializes CURL globally
void ToolsCURL::init () {
Expand Down
6 changes: 1 addition & 5 deletions tools/curl.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@

#include <filesystem>

#ifndef TARGET_WINDOWS
#include "../deps/linux/include/curl/curl.h"
#else
#include "../deps/win32/include/curl/curl.h"
#endif
#include "curl/curl.h"

class ToolsCURL {
public:
Expand Down
24 changes: 12 additions & 12 deletions tools/install.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "js.h" // ToolsJS
#include "merge.h" // ToolsMerge

#ifdef TARGET_WINDOWS
#ifdef WIN32
#include "../deps/win32/include/archive.h"
#include "../deps/win32/include/archive_entry.h"

Expand Down Expand Up @@ -100,7 +100,7 @@ bool ToolsInstall::extractLocalFile (const std::filesystem::path path, const std
}

// Retrieves the path to a process executable using its name
#ifndef TARGET_WINDOWS
#ifndef WIN32
std::string ToolsInstall::getProcessPath (const std::string &processName) {

DIR *dir = opendir("/proc");
Expand Down Expand Up @@ -182,7 +182,7 @@ std::wstring ToolsInstall::getProcessPath (const std::string &processName) {
#endif

// Returns true if the Portal 2 process is running
#ifndef TARGET_WINDOWS
#ifndef WIN32
bool ToolsInstall::isGameRunning () {
return ToolsInstall::getProcessPath("portal2_linux") != "" || ToolsInstall::getProcessPath("portal2.exe") != "";
}
Expand All @@ -193,7 +193,7 @@ bool ToolsInstall::isGameRunning () {
#endif

// Finds the Steam binary and uses it to start Portal 2
#ifndef TARGET_WINDOWS
#ifndef WIN32
bool startPortal2 (const std::vector<std::string> extraArgs) {

std::string steamPath = ToolsInstall::getProcessPath("steam");
Expand Down Expand Up @@ -315,7 +315,7 @@ bool startPortal2 (const std::vector<std::string> extraArgs) {
#endif

// Creates a symbolic link for a directory on Linux, and an NTFS junction on Windows
#ifndef TARGET_WINDOWS
#ifndef WIN32
bool linkDirectory (const std::filesystem::path target, const std::filesystem::path linkName) {

if (symlink(target.c_str(), linkName.c_str()) != 0) {
Expand Down Expand Up @@ -409,7 +409,7 @@ bool linkDirectory (const std::filesystem::path target, const std::filesystem::p
#endif

// Creates a symbolic link for a file on Linux and a hard link on Windows
#ifndef TARGET_WINDOWS
#ifndef WIN32
bool linkFile (const std::filesystem::path target, const std::filesystem::path linkName) {

if (symlink(target.c_str(), linkName.c_str()) != 0) {
Expand Down Expand Up @@ -439,7 +439,7 @@ bool linkFile (const std::filesystem::path target, const std::filesystem::path l
#endif

// Removes a symbolic link to a directory on Linux, or an NTFS junction on Windows
#ifndef TARGET_WINDOWS
#ifndef WIN32
bool unlinkDirectory (const std::filesystem::path target) {

if (unlink(target.c_str()) != 0) {
Expand Down Expand Up @@ -471,7 +471,7 @@ bool unlinkDirectory (const std::filesystem::path target) {
}
#endif

#ifndef TARGET_WINDOWS
#ifndef WIN32
bool isDirectoryLink (const std::filesystem::path linkName) {

struct stat path_stat;
Expand Down Expand Up @@ -566,7 +566,7 @@ std::string installPackageDirectory (const std::filesystem::path packageDirector
}

// Find the Portal 2 game files path
#ifndef TARGET_WINDOWS
#ifndef WIN32
std::string gameProcessPath = "";
while (gameProcessPath.length() == 0) {
gameProcessPath = ToolsInstall::getProcessPath("portal2_linux");
Expand Down Expand Up @@ -738,7 +738,7 @@ std::string ToolsInstall::installMergedPackage (std::vector<const ToolsPackage::
if (!extractSuccess) return "Some package files could not be extracted.";

// Store output package directories in a list for use with the merge tool
#ifndef TARGET_WINDOWS
#ifndef WIN32
sourcePaths.push_back(QString::fromStdString(tmpPackageDirectory.string()));
#else
sourcePaths.push_back(QString::fromStdWString(tmpPackageDirectory.wstring()));
Expand All @@ -756,7 +756,7 @@ std::string ToolsInstall::installMergedPackage (std::vector<const ToolsPackage::
}
std::filesystem::create_directories(packageDirectory);

#ifndef TARGET_WINDOWS
#ifndef WIN32
QString packageDirectoryQString = QString::fromStdString(packageDirectory.string());
#else
QString packageDirectoryQString = QString::fromStdWString(packageDirectory.wstring());
Expand All @@ -776,7 +776,7 @@ bool ToolsInstall::killPortal2 () {
if (SPPLICE_INSTALL_STATE == 0) return false;

// Use a platform-specific command string for killing the process
#ifndef TARGET_WINDOWS
#ifndef WIN32
const std::string command = "pkill -e portal2_linux -9; pkill -e portal2.exe -9";
#else
const std::string command = "taskkill /F /T /IM portal2.exe";
Expand Down
Loading