diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2021-08-21 14:15:43 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2021-08-21 14:15:43 +0200 |
commit | dae6a98f826f78bda7511ba6de4c8b813353501e (patch) | |
tree | 7c531774f9d4b5865393190e8ae1527b86e63bd6 | |
parent | b615cc6d60beede9cb76b143007a7a1720846c5c (diff) |
proto/freetrack: implement more dll location controls
-rw-r--r-- | proto-ft/ftnoir_ftcontrols.ui | 183 | ||||
-rw-r--r-- | proto-ft/ftnoir_protocol_ft.cpp | 73 | ||||
-rw-r--r-- | proto-ft/ftnoir_protocol_ft.h | 16 | ||||
-rw-r--r-- | proto-ft/ftnoir_protocol_ft_dialog.cpp | 26 | ||||
-rw-r--r-- | proto-ft/lang/nl_NL.ts | 36 | ||||
-rw-r--r-- | proto-ft/lang/ru_RU.ts | 36 | ||||
-rw-r--r-- | proto-ft/lang/stub.ts | 36 | ||||
-rw-r--r-- | proto-ft/lang/zh_CN.ts | 36 |
8 files changed, 333 insertions, 109 deletions
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 @@ <rect> <x>0</x> <y>0</y> - <width>508</width> - <height>232</height> + <width>533</width> + <height>326</height> </rect> </property> - <property name="sizePolicy"> - <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="minimumSize"> - <size> - <width>0</width> - <height>0</height> - </size> - </property> <property name="windowTitle"> <string>freetrack protocol settings</string> </property> @@ -42,6 +30,13 @@ <bool>false</bool> </property> <layout class="QGridLayout" name="gridLayout_2"> + <item row="5" column="0"> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="standardButtons"> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + </property> + </widget> + </item> <item row="0" column="0"> <widget class="QGroupBox" name="groupBox_3"> <property name="sizePolicy"> @@ -95,64 +90,138 @@ </layout> </widget> </item> - <item row="1" column="0"> + <item row="1" column="0" rowspan="2"> <widget class="QGroupBox" name="groupBox_4"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> <property name="title"> - <string>Repair NPClient location</string> + <string>Library location</string> </property> <property name="alignment"> <set>Qt::AlignJustify|Qt::AlignTop</set> </property> - <property name="flat"> - <bool>false</bool> - </property> - <layout class="QHBoxLayout" name="horizontalLayout_2"> - <property name="spacing"> - <number>9</number> - </property> - <item> - <widget class="QPushButton" name="bntLocateNPClient"> - <property name="text"> - <string>Locate DLL</string> - </property> - </widget> - </item> - <item> - <widget class="QLabel" name="label_10"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Minimum"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="text"> - <string>Replace the registry entry if you want to use other software with the NPClient protocol and it doesn't work automatically. + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0"> + <widget class="QWidget" name="widget" native="true"> + <layout class="QHBoxLayout" name="horizontalLayout"> + <property name="topMargin"> + <number>0</number> + </property> + <property name="bottomMargin"> + <number>0</number> + </property> + <item> + <widget class="QPushButton" name="bntLocateNPClient"> + <property name="text"> + <string>Locate DLL</string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="label_10"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Maximum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>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.</string> - </property> - <property name="wordWrap"> - <bool>true</bool> - </property> + </property> + <property name="wordWrap"> + <bool>true</bool> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item row="1" column="0"> + <widget class="QWidget" name="widget" native="true"> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <property name="spacing"> + <number>6</number> + </property> + <property name="topMargin"> + <number>0</number> + </property> + <property name="bottomMargin"> + <number>0</number> + </property> + <item> + <widget class="QCheckBox" name="enable_custom_location"> + <property name="toolTip"> + <string>Useful for titles like Elite: Dangerous that require the library to reside in a specified location. Use this to avoid relocating your opentrack installation.</string> + </property> + <property name="text"> + <string>Custom location</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="custom_location"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Maximum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="set_custom_location"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Maximum" vsizetype="Maximum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Browse...</string> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item row="2" column="0"> + <widget class="QWidget" name="widget_2" native="true"> + <layout class="QHBoxLayout" name="horizontalLayout_4"> + <property name="spacing"> + <number>0</number> + </property> + <property name="topMargin"> + <number>0</number> + </property> + <property name="bottomMargin"> + <number>0</number> + </property> + <item> + <widget class="QCheckBox" name="ephemeral_registry_entry"> + <property name="toolTip"> + <string>This is useful when you're only evaluating opentrack, and haven't yet decided to use it all the time.</string> + </property> + <property name="text"> + <string>Clear location when tracking is stopped</string> + </property> + </widget> + </item> + </layout> </widget> </item> </layout> </widget> </item> - <item row="2" column="0"> - <widget class="QDialogButtonBox" name="buttonBox"> - <property name="standardButtons"> - <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> - </property> - </widget> - </item> </layout> </widget> + <tabstops> + <tabstop>cbxSelectInterface</tabstop> + <tabstop>bntLocateNPClient</tabstop> + <tabstop>enable_custom_location</tabstop> + <tabstop>custom_location</tabstop> + <tabstop>set_custom_location</tabstop> + <tabstop>ephemeral_registry_entry</tabstop> + </tabstops> <resources> <include location="ft-protocol.qrc"/> <include location="ft-protocol.qrc"/> 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 <QDir> #include <cstddef> #include <cmath> @@ -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<int> intUsedInterface; - settings() : - opts("proto-freetrack"), - intUsedInterface(b, "used-interfaces", 0) - {} + enum enable_status { enable_both, enable_freetrack, enable_npclient, }; + value<int> used_interface{b, "used-interfaces", (int)enable_both}; + value<bool> ephemeral_library_location{b, "ephemeral-library-location", false}; + value<bool> use_custom_location{b, "use-custom-location", false}; + value<QString> 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 @@ <source>Dll file (*.dll);;All Files (*)</source> <translation type="unfinished"></translation> </message> + <message> + <source>Select library location</source> + <translation type="unfinished"></translation> + </message> </context> <context> <name>UICFTControls</name> @@ -27,10 +31,6 @@ <translation type="unfinished"></translation> </message> <message> - <source>Repair NPClient location</source> - <translation type="unfinished"></translation> - </message> - <message> <source>Locate DLL</source> <translation type="unfinished"></translation> </message> @@ -52,6 +52,30 @@ Starting tracking will again overwrite the DLL locations.</source> <source>Use TrackIR, disable freetrack</source> <translation type="unfinished"></translation> </message> + <message> + <source>Library location</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Custom location</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Browse...</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>This is useful when you're only evaluating opentrack, and haven't yet decided to use it all the time.</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Clear location when tracking is stopped</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Useful for titles like Elite: Dangerous that require the library to reside in a specified location. Use this to avoid relocating your opentrack installation.</source> + <translation type="unfinished"></translation> + </message> </context> <context> <name>freetrack</name> @@ -63,6 +87,10 @@ Starting tracking will again overwrite the DLL locations.</source> <source>Can't load freetrack memory mapping</source> <translation type="unfinished"></translation> </message> + <message> + <source>Can't copy library to selected custom location '%1'</source> + <translation type="unfinished"></translation> + </message> </context> <context> <name>freetrackDll</name> 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 @@ <source>Dll file (*.dll);;All Files (*)</source> <translation></translation> </message> + <message> + <source>Select library location</source> + <translation type="unfinished"></translation> + </message> </context> <context> <name>UICFTControls</name> @@ -27,10 +31,6 @@ <translation>Отключите один из протоколов в случае, если при включении обоих интерфейсов игра не корректно определяет их.</translation> </message> <message> - <source>Repair NPClient location</source> - <translation>Решение проблем с расположением NPClient'а </translation> - </message> - <message> <source>Locate DLL</source> <translation>Укажите DLL</translation> </message> @@ -54,6 +54,30 @@ Starting tracking will again overwrite the DLL locations.</source> <source>Use TrackIR, disable freetrack</source> <translation type="unfinished"></translation> </message> + <message> + <source>Library location</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Custom location</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Browse...</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>This is useful when you're only evaluating opentrack, and haven't yet decided to use it all the time.</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Clear location when tracking is stopped</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Useful for titles like Elite: Dangerous that require the library to reside in a specified location. Use this to avoid relocating your opentrack installation.</source> + <translation type="unfinished"></translation> + </message> </context> <context> <name>freetrack</name> @@ -65,6 +89,10 @@ Starting tracking will again overwrite the DLL locations.</source> <source>Can't load freetrack memory mapping</source> <translation type="unfinished"></translation> </message> + <message> + <source>Can't copy library to selected custom location '%1'</source> + <translation type="unfinished"></translation> + </message> </context> <context> <name>freetrackDll</name> 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 @@ <source>Dll file (*.dll);;All Files (*)</source> <translation type="unfinished"></translation> </message> + <message> + <source>Select library location</source> + <translation type="unfinished"></translation> + </message> </context> <context> <name>UICFTControls</name> @@ -27,10 +31,6 @@ <translation type="unfinished"></translation> </message> <message> - <source>Repair NPClient location</source> - <translation type="unfinished"></translation> - </message> - <message> <source>Locate DLL</source> <translation type="unfinished"></translation> </message> @@ -52,6 +52,30 @@ Starting tracking will again overwrite the DLL locations.</source> <source>Use TrackIR, disable freetrack</source> <translation type="unfinished"></translation> </message> + <message> + <source>Library location</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Custom location</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Browse...</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>This is useful when you're only evaluating opentrack, and haven't yet decided to use it all the time.</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Clear location when tracking is stopped</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Useful for titles like Elite: Dangerous that require the library to reside in a specified location. Use this to avoid relocating your opentrack installation.</source> + <translation type="unfinished"></translation> + </message> </context> <context> <name>freetrack</name> @@ -63,6 +87,10 @@ Starting tracking will again overwrite the DLL locations.</source> <source>Can't load freetrack memory mapping</source> <translation type="unfinished"></translation> </message> + <message> + <source>Can't copy library to selected custom location '%1'</source> + <translation type="unfinished"></translation> + </message> </context> <context> <name>freetrackDll</name> 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 @@ <source>Dll file (*.dll);;All Files (*)</source> <translation type="unfinished"></translation> </message> + <message> + <source>Select library location</source> + <translation type="unfinished"></translation> + </message> </context> <context> <name>UICFTControls</name> @@ -19,10 +23,6 @@ <translation type="unfinished"></translation> </message> <message> - <source>Repair NPClient location</source> - <translation type="unfinished"></translation> - </message> - <message> <source>Locate DLL</source> <translation type="unfinished"></translation> </message> @@ -52,6 +52,30 @@ Starting tracking will again overwrite the DLL locations.</source> <source>Use TrackIR, disable freetrack</source> <translation type="unfinished"></translation> </message> + <message> + <source>Library location</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Custom location</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Browse...</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>This is useful when you're only evaluating opentrack, and haven't yet decided to use it all the time.</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Clear location when tracking is stopped</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Useful for titles like Elite: Dangerous that require the library to reside in a specified location. Use this to avoid relocating your opentrack installation.</source> + <translation type="unfinished"></translation> + </message> </context> <context> <name>freetrack</name> @@ -63,6 +87,10 @@ Starting tracking will again overwrite the DLL locations.</source> <source>Can't load freetrack memory mapping</source> <translation type="unfinished"></translation> </message> + <message> + <source>Can't copy library to selected custom location '%1'</source> + <translation type="unfinished"></translation> + </message> </context> <context> <name>freetrackDll</name> |