From dae6a98f826f78bda7511ba6de4c8b813353501e Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 21 Aug 2021 14:15:43 +0200 Subject: proto/freetrack: implement more dll location controls --- proto-ft/ftnoir_ftcontrols.ui | 183 +++++++++++++++++++++++---------- proto-ft/ftnoir_protocol_ft.cpp | 73 ++++++++----- proto-ft/ftnoir_protocol_ft.h | 16 +-- proto-ft/ftnoir_protocol_ft_dialog.cpp | 26 ++++- proto-ft/lang/nl_NL.ts | 36 ++++++- proto-ft/lang/ru_RU.ts | 36 ++++++- proto-ft/lang/stub.ts | 36 ++++++- proto-ft/lang/zh_CN.ts | 36 ++++++- 8 files changed, 333 insertions(+), 109 deletions(-) (limited to 'proto-ft') diff --git a/proto-ft/ftnoir_ftcontrols.ui b/proto-ft/ftnoir_ftcontrols.ui index 0d142d09..90c9db46 100644 --- a/proto-ft/ftnoir_ftcontrols.ui +++ b/proto-ft/ftnoir_ftcontrols.ui @@ -12,22 +12,10 @@ 0 0 - 508 - 232 + 533 + 326 - - - 0 - 0 - - - - - 0 - 0 - - freetrack protocol settings @@ -42,6 +30,13 @@ false + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + @@ -95,64 +90,138 @@ - + - - - 0 - 0 - - - Repair NPClient location + Library location Qt::AlignJustify|Qt::AlignTop - - false - - - - 9 - - - - - Locate DLL - - - - - - - - 0 - 0 - - - - Replace the registry entry if you want to use other software with the NPClient protocol and it doesn't work automatically. + + + + + + 0 + + + 0 + + + + + Locate DLL + + + + + + + + 0 + 0 + + + + Replace the registry entry if you want to use other software with the NPClient protocol and it doesn't work automatically. Starting tracking will again overwrite the DLL locations. - - - true - + + + true + + + + + + + + + + + 6 + + + 0 + + + 0 + + + + + Useful for titles like Elite: Dangerous that require the library to reside in a specified location. Use this to avoid relocating your opentrack installation. + + + Custom location + + + + + + + + 0 + 0 + + + + + + + + + 0 + 0 + + + + Browse... + + + + + + + + + + + 0 + + + 0 + + + 0 + + + + + This is useful when you're only evaluating opentrack, and haven't yet decided to use it all the time. + + + Clear location when tracking is stopped + + + + - - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - + + cbxSelectInterface + bntLocateNPClient + enable_custom_location + custom_location + set_custom_location + ephemeral_registry_entry + diff --git a/proto-ft/ftnoir_protocol_ft.cpp b/proto-ft/ftnoir_protocol_ft.cpp index c6259593..9613f4a8 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 #include #include @@ -17,7 +18,15 @@ 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", ""); + } } static_assert(sizeof(LONG) == sizeof(std::int32_t)); @@ -133,7 +142,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 +150,39 @@ 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; + const auto selection = *s.used_interface; + + bool use_freetrack = ~selection & settings::enable_freetrack, + use_npclient = ~selection & settings::enable_npclient; - 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)}; + } + + if (!location.endsWith('/')) + location += '/'; + location.replace('\\', '/'); + + settings_ft.setValue("Path", use_freetrack ? location : ""); + settings_npclient.setValue("Path", use_npclient ? location : ""); + + return {}; } module_status freetrack::initialize() @@ -157,24 +190,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 +212,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_npclient) start_dummy(); return status_ok(); diff --git a/proto-ft/ftnoir_protocol_ft.h b/proto-ft/ftnoir_protocol_ft.h index a59796dd..4b7ab89e 100644 --- a/proto-ft/ftnoir_protocol_ft.h +++ b/proto-ft/ftnoir_protocol_ft.h @@ -27,11 +27,12 @@ using namespace options; struct settings : opts { - value intUsedInterface; - settings() : - opts("proto-freetrack"), - intUsedInterface(b, "used-interfaces", 0) - {} + enum enable_status { enable_both, enable_freetrack, enable_npclient, }; + value used_interface{b, "used-interfaces", (int)enable_both}; + value ephemeral_library_location{b, "ephemeral-library-location", false}; + value use_custom_location{b, "use-custom-location", false}; + value custom_location_pathname{b, "custom-library-location", {}}; + settings() : opts("proto-freetrack") {} }; class freetrack : TR, public IProtocol @@ -58,7 +59,9 @@ private: void start_dummy(); public: - static void set_protocols(bool ft, bool npclient); + enum class status { starting, stopping }; + [[nodiscard]] module_status set_protocols(); + void clear_protocols(); }; class FTControls: public IProtocolDialog @@ -75,6 +78,7 @@ private slots: void selectDLL(); void doOK(); void doCancel(); + void set_custom_location(); }; class freetrackDll : public Metadata diff --git a/proto-ft/ftnoir_protocol_ft_dialog.cpp b/proto-ft/ftnoir_protocol_ft_dialog.cpp index 58077b87..9686ee92 100644 --- a/proto-ft/ftnoir_protocol_ft_dialog.cpp +++ b/proto-ft/ftnoir_protocol_ft_dialog.cpp @@ -22,7 +22,17 @@ FTControls::FTControls() connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(doCancel())); connect(ui.bntLocateNPClient, SIGNAL(clicked()), this, SLOT(selectDLL())); - tie_setting(s.intUsedInterface, ui.cbxSelectInterface); + const settings::enable_status cbx[] = { + settings::enable_both, + settings::enable_freetrack, + settings::enable_npclient, + }; + tie_setting(s.used_interface, ui.cbxSelectInterface); + tie_setting(s.ephemeral_library_location, ui.ephemeral_registry_entry); + tie_setting(s.custom_location_pathname, ui.custom_location); + tie_setting(s.use_custom_location, ui.enable_custom_location); + + connect(ui.set_custom_location, &QAbstractButton::clicked, this, &FTControls::set_custom_location); } void FTControls::doOK() @@ -50,4 +60,16 @@ void FTControls::selectDLL() node.setValue("Path", dllname.dir().path()); } } - +void FTControls::set_custom_location() +{ + static const auto program_directory = OPENTRACK_BASE_PATH + OPENTRACK_LIBRARY_PATH; + auto previous_location = *s.custom_location_pathname; + if (!s.use_custom_location || previous_location.isEmpty() || !QDir{previous_location}.exists()) + previous_location = program_directory; + auto dir = QFileDialog::getExistingDirectory(this, tr("Select library location"), previous_location); + if (dir.isEmpty() || !QDir{dir}.exists()) + dir = QString{}; + else + ui.enable_custom_location->setEnabled(true); + ui.custom_location->setText(dir); +} diff --git a/proto-ft/lang/nl_NL.ts b/proto-ft/lang/nl_NL.ts index ec4f58da..f8408198 100644 --- a/proto-ft/lang/nl_NL.ts +++ b/proto-ft/lang/nl_NL.ts @@ -11,6 +11,10 @@ Dll file (*.dll);;All Files (*) + + Select library location + + UICFTControls @@ -26,10 +30,6 @@ Disable one of the protocols if game is confused by presence of both at the same time. - - Repair NPClient location - - Locate DLL @@ -52,6 +52,30 @@ Starting tracking will again overwrite the DLL locations. Use TrackIR, disable freetrack + + Library location + + + + Custom location + + + + Browse... + + + + This is useful when you're only evaluating opentrack, and haven't yet decided to use it all the time. + + + + Clear location when tracking is stopped + + + + Useful for titles like Elite: Dangerous that require the library to reside in a specified location. Use this to avoid relocating your opentrack installation. + + freetrack @@ -63,6 +87,10 @@ Starting tracking will again overwrite the DLL locations. Can't load freetrack memory mapping + + Can't copy library to selected custom location '%1' + + freetrackDll diff --git a/proto-ft/lang/ru_RU.ts b/proto-ft/lang/ru_RU.ts index c793ae6b..c934e0f7 100644 --- a/proto-ft/lang/ru_RU.ts +++ b/proto-ft/lang/ru_RU.ts @@ -11,6 +11,10 @@ Dll file (*.dll);;All Files (*) + + Select library location + + UICFTControls @@ -26,10 +30,6 @@ Disable one of the protocols if game is confused by presence of both at the same time. Отключите один из протоколов в случае, если при включении обоих интерфейсов игра не корректно определяет их. - - Repair NPClient location - Решение проблем с расположением NPClient'а - Locate DLL Укажите DLL @@ -54,6 +54,30 @@ Starting tracking will again overwrite the DLL locations. Use TrackIR, disable freetrack + + Library location + + + + Custom location + + + + Browse... + + + + This is useful when you're only evaluating opentrack, and haven't yet decided to use it all the time. + + + + Clear location when tracking is stopped + + + + Useful for titles like Elite: Dangerous that require the library to reside in a specified location. Use this to avoid relocating your opentrack installation. + + freetrack @@ -65,6 +89,10 @@ Starting tracking will again overwrite the DLL locations. Can't load freetrack memory mapping + + Can't copy library to selected custom location '%1' + + freetrackDll diff --git a/proto-ft/lang/stub.ts b/proto-ft/lang/stub.ts index 635844a5..e15244b9 100644 --- a/proto-ft/lang/stub.ts +++ b/proto-ft/lang/stub.ts @@ -11,6 +11,10 @@ Dll file (*.dll);;All Files (*) + + Select library location + + UICFTControls @@ -26,10 +30,6 @@ Disable one of the protocols if game is confused by presence of both at the same time. - - Repair NPClient location - - Locate DLL @@ -52,6 +52,30 @@ Starting tracking will again overwrite the DLL locations. Use TrackIR, disable freetrack + + Library location + + + + Custom location + + + + Browse... + + + + This is useful when you're only evaluating opentrack, and haven't yet decided to use it all the time. + + + + Clear location when tracking is stopped + + + + Useful for titles like Elite: Dangerous that require the library to reside in a specified location. Use this to avoid relocating your opentrack installation. + + freetrack @@ -63,6 +87,10 @@ Starting tracking will again overwrite the DLL locations. Can't load freetrack memory mapping + + Can't copy library to selected custom location '%1' + + freetrackDll diff --git a/proto-ft/lang/zh_CN.ts b/proto-ft/lang/zh_CN.ts index 442a1aa1..2425f48b 100644 --- a/proto-ft/lang/zh_CN.ts +++ b/proto-ft/lang/zh_CN.ts @@ -11,6 +11,10 @@ Dll file (*.dll);;All Files (*) + + Select library location + + UICFTControls @@ -18,10 +22,6 @@ freetrack protocol settings - - Repair NPClient location - - Locate DLL @@ -52,6 +52,30 @@ Starting tracking will again overwrite the DLL locations. Use TrackIR, disable freetrack + + Library location + + + + Custom location + + + + Browse... + + + + This is useful when you're only evaluating opentrack, and haven't yet decided to use it all the time. + + + + Clear location when tracking is stopped + + + + Useful for titles like Elite: Dangerous that require the library to reside in a specified location. Use this to avoid relocating your opentrack installation. + + freetrack @@ -63,6 +87,10 @@ Starting tracking will again overwrite the DLL locations. Can't load freetrack memory mapping + + Can't copy library to selected custom location '%1' + + freetrackDll -- cgit v1.2.3