summaryrefslogtreecommitdiffhomepage
path: root/proto-ft
diff options
context:
space:
mode:
Diffstat (limited to 'proto-ft')
-rw-r--r--proto-ft/ftnoir_protocol_ft.cpp7
-rw-r--r--proto-ft/ftnoir_protocol_ft.h1
-rw-r--r--proto-ft/mutex.cpp60
-rw-r--r--proto-ft/mutex.hpp16
4 files changed, 78 insertions, 6 deletions
diff --git a/proto-ft/ftnoir_protocol_ft.cpp b/proto-ft/ftnoir_protocol_ft.cpp
index 0c97ffd2..ae8fe5a2 100644
--- a/proto-ft/ftnoir_protocol_ft.cpp
+++ b/proto-ft/ftnoir_protocol_ft.cpp
@@ -1,4 +1,4 @@
-/* Copyright (c) 2013-2018 Stanislaw Halik <sthalik@misaki.pl>
+/* Copyright (c) 2013-2015, 2017 Stanislaw Halik <sthalik@misaki.pl>
* Copyright (c) 2015 Wim Vriend
*
* Permission to use, copy, modify, and/or distribute this software for any
@@ -97,10 +97,7 @@ void freetrack::pose(const double* headpose)
const std::int32_t id = load(ft->GameID);
- data_id++;
- data_id %= 128;
-
- store(data->DataID, 60 * 5 + data_id);
+ store(data->DataID, 60 * 10 + (rand() % 64));
if (intGameID != id)
{
diff --git a/proto-ft/ftnoir_protocol_ft.h b/proto-ft/ftnoir_protocol_ft.h
index 843d1f34..ac82bbd9 100644
--- a/proto-ft/ftnoir_protocol_ft.h
+++ b/proto-ft/ftnoir_protocol_ft.h
@@ -54,7 +54,6 @@ private:
int intGameID = -1;
QString connected_game;
QMutex game_name_mutex;
- unsigned data_id = 0;
void start_dummy();
static float degrees_to_rads(double degrees);
diff --git a/proto-ft/mutex.cpp b/proto-ft/mutex.cpp
new file mode 100644
index 00000000..a012ba90
--- /dev/null
+++ b/proto-ft/mutex.cpp
@@ -0,0 +1,60 @@
+#include "ftnoir_protocol_ft.h"
+#include "mutex.hpp"
+#include <windows.h>
+#include <QDebug>
+
+check_for_first_run::check_for_first_run() : checked_for_first_run(false), is_first_instance(false), enabled(false)
+{
+}
+
+bool check_for_first_run::is_first_run()
+{
+ return checked_for_first_run && is_first_instance;
+}
+
+void check_for_first_run::set_enabled(bool flag)
+{
+ enabled = flag;
+}
+
+void check_for_first_run::try_runonce()
+{
+ constexpr const char* name = "opentrack-freetrack-runonce";
+
+ if (checked_for_first_run)
+ return;
+
+ // just leak it, no issue
+ HANDLE h = CreateMutexA(nullptr, false, name);
+
+ switch (WaitForSingleObject(h, 0))
+ {
+ case WAIT_OBJECT_0:
+ is_first_instance = true;
+ checked_for_first_run = true;
+ break;
+ case WAIT_TIMEOUT:
+ checked_for_first_run = true;
+ break;
+ default:
+ checked_for_first_run = false;
+ break;
+ }
+
+ if (checked_for_first_run && !is_first_instance)
+ CloseHandle(h);
+}
+
+check_for_first_run::~check_for_first_run()
+{
+ try_exit();
+}
+
+void check_for_first_run::try_exit()
+{
+ if (is_first_instance && enabled)
+ {
+ qDebug() << "ft runonce: removing registry keys";
+ freetrack::set_protocols(false, false);
+ }
+}
diff --git a/proto-ft/mutex.hpp b/proto-ft/mutex.hpp
new file mode 100644
index 00000000..f92a14bf
--- /dev/null
+++ b/proto-ft/mutex.hpp
@@ -0,0 +1,16 @@
+#pragma once
+
+class check_for_first_run final
+{
+ bool checked_for_first_run;
+ bool is_first_instance;
+ bool enabled;
+
+ void try_exit();
+public:
+ check_for_first_run();
+ bool is_first_run();
+ void set_enabled(bool flag);
+ void try_runonce();
+ ~check_for_first_run();
+};