summaryrefslogtreecommitdiffhomepage
path: root/proto-ft/ftnoir_protocol_ft.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'proto-ft/ftnoir_protocol_ft.cpp')
-rw-r--r--proto-ft/ftnoir_protocol_ft.cpp88
1 files changed, 60 insertions, 28 deletions
diff --git a/proto-ft/ftnoir_protocol_ft.cpp b/proto-ft/ftnoir_protocol_ft.cpp
index c6259593..7f710621 100644
--- a/proto-ft/ftnoir_protocol_ft.cpp
+++ b/proto-ft/ftnoir_protocol_ft.cpp
@@ -10,6 +10,7 @@
#include "ftnoir_protocol_ft.h"
#include "csv/csv.h"
+#include <QDir>
#include <cstddef>
#include <cmath>
@@ -17,7 +18,23 @@
freetrack::~freetrack()
{
- dummyTrackIR.close();
+ //dummyTrackIR.kill(); dummyTrackIR.waitForFinished();
+ if (s.ephemeral_library_location)
+ {
+ QSettings settings_ft("Freetrack", "FreetrackClient");
+ QSettings settings_npclient("NaturalPoint", "NATURALPOINT\\NPClient Location");
+
+ settings_ft.setValue("Path", "");
+ settings_npclient.setValue("Path", "");
+
+ if (dummyTrackIR.state() == dummyTrackIR.Running)
+ {
+ dummyTrackIR.kill();
+ dummyTrackIR.waitForFinished(100);
+ }
+ }
+ else
+ dummyTrackIR.close();
}
static_assert(sizeof(LONG) == sizeof(std::int32_t));
@@ -133,7 +150,7 @@ void freetrack::start_dummy() {
dummyTrackIR.start();
}
-void freetrack::set_protocols(bool ft, bool npclient)
+module_status freetrack::set_protocols()
{
static const QString program_dir = OPENTRACK_BASE_PATH + OPENTRACK_LIBRARY_PATH;
@@ -141,15 +158,46 @@ void freetrack::set_protocols(bool ft, bool npclient)
QSettings settings_ft("Freetrack", "FreetrackClient");
QSettings settings_npclient("NaturalPoint", "NATURALPOINT\\NPClient Location");
- if (ft)
- settings_ft.setValue("Path", program_dir);
- else
- settings_ft.setValue("Path", "");
+ QString location = *s.custom_location_pathname;
+
+ bool use_freetrack = true, use_npclient = true;
+ switch (*s.used_interface)
+ {
+ case settings::enable_npclient: use_freetrack = false; break;
+ case settings::enable_freetrack: use_npclient = false; break;
+ case settings::enable_both: use_freetrack = true; use_npclient = true; break;
+ default:
+ return error(tr("proto/freetrack: wrong interface selection '%1'")
+ .arg(*s.used_interface));
+ }
- if (npclient)
- settings_npclient.setValue("Path", program_dir);
+ if (!s.use_custom_location || s.custom_location_pathname->isEmpty() || !QDir{s.custom_location_pathname}.exists())
+ location = program_dir;
else
- settings_npclient.setValue("Path", "");
+ {
+ bool copy = true;
+
+ if (use_npclient && !QFile{location + "/NPClient.dll"}.exists())
+ copy &= QFile::copy(program_dir + "/NPClient.dll", location + "/NPClient.dll");
+ if (use_npclient && !QFile{location + "/NPClient64.dll"}.exists())
+ copy &= QFile::copy(program_dir + "/NPClient64.dll", location + "/NPClient64.dll");
+ if (use_freetrack && !QFile{location + "/freetrackclient.dll"}.exists())
+ copy &= QFile::copy(program_dir + "/freetrackclient.dll", location + "/freetrackclient.dll");
+ if (use_freetrack && !QFile{location + "/freetrackclient64.dll"}.exists())
+ copy &= QFile::copy(program_dir + "/freetrackclient64.dll", location + "/freetrackclient64.dll");
+
+ if (!copy)
+ return {tr("Can't copy library to selected custom location '%1'").arg(s.custom_location_pathname)};
+ }
+
+ location.replace('\\', '/');
+ if (!location.endsWith('/'))
+ location += '/';
+
+ settings_ft.setValue("Path", use_freetrack ? location : "");
+ settings_npclient.setValue("Path", use_npclient ? location : "");
+
+ return {};
}
module_status freetrack::initialize()
@@ -157,24 +205,8 @@ module_status freetrack::initialize()
if (!shm.success())
return error(tr("Can't load freetrack memory mapping"));
- bool use_ft = false, use_npclient = false;
-
- switch (s.intUsedInterface) {
- case 0:
- use_ft = true;
- use_npclient = true;
- break;
- case 1:
- use_ft = true;
- break;
- case 2:
- use_npclient = true;
- break;
- default:
- break;
- }
-
- set_protocols(use_ft, use_npclient);
+ if (auto ret = set_protocols(); !ret.is_ok())
+ return ret;
pMemData->data.DataID = 1;
pMemData->data.CamWidth = 100;
@@ -195,7 +227,7 @@ module_status freetrack::initialize()
store(pMemData->table_ints[k], 0);
// more games need the dummy executable than previously thought
- if (use_npclient)
+ if (s.used_interface != settings::enable_freetrack)
start_dummy();
return status_ok();