Skip to content

Commit 660fd49

Browse files
committed
refactor: new installer & cleanup
- bump version to 1.0.4 - removed Microsoft Installer Project and replaced it with an Inno Setup script - installer now contains "Run after installation" option
1 parent 826855d commit 660fd49

File tree

8 files changed

+107
-1195
lines changed

8 files changed

+107
-1195
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,5 +399,9 @@ FodyWeavers.xsd
399399
# Notepad++ auto-generated backup files
400400
*.bak
401401

402+
# Created setup files
403+
Installers/
404+
402405
# Extra
403406
enc_temp_folder/
407+

ThreeFingerDrag/Resource.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//{{NO_DEPENDENCIES}}
22
// Microsoft Visual C++ generated include file.
3-
// Used by ThreeFingerDrag.rc
3+
// Used by Gestures.rc
44

55
#define IDS_APP_TITLE 103
66

ThreeFingerDrag/ThreeFingerDrag.cpp

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "ThreeFingerDrag.h"
22

3-
using namespace ThreeFingerDrag;
3+
using namespace Gestures;
44
using namespace WinToastLib;
55

66
// Constants
@@ -26,7 +26,7 @@ NOTIFYICONDATA tray_icon_data;
2626
GestureProcessor gesture_processor;
2727
std::thread update_settings_thread;
2828
std::thread touch_activity_thread;
29-
BOOL run_loops = true;
29+
BOOL application_running = true;
3030

3131
// Forward declarations
3232

@@ -38,8 +38,7 @@ void CreateTrayMenu(HWND hWnd);
3838
void RemoveStartupRegistryKey();
3939
void AddStartupRegistryKey();
4040
void ReadPrecisionTouchPadInfo();
41-
void StartUpdateThread();
42-
void StartActivityThread();
41+
void StartPeriodicUpdateThreads();
4342
void HandleUncaughtExceptions();
4443

4544

@@ -78,10 +77,10 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
7877
}
7978

8079
// Start threads
81-
StartUpdateThread();
82-
StartActivityThread();
80+
StartPeriodicUpdateThreads();
8381

84-
if (IsInitialStartup()) {
82+
// First time running application
83+
if (Application::IsInitialStartup()) {
8584
bool result = Popups::DisplayPrompt("Would you like run ThreeFingerDrag on startup of Windows?", "ThreeFingerDrag");
8685
if (result)
8786
AddStartupRegistryKey();
@@ -101,7 +100,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
101100
Shell_NotifyIcon(NIM_DELETE, &tray_icon_data);
102101

103102
// Join threads
104-
run_loops = false;
103+
application_running = false;
105104
update_settings_thread.join();
106105
touch_activity_thread.join();
107106

@@ -141,13 +140,14 @@ BOOL InitInstance(const HINSTANCE hInstance, int nCmdShow)
141140
return FALSE;
142141
}
143142

143+
// Initialize WinToast notifications
144144

145145
auto appName = L"ThreeFingerDrag";
146146

147147
WinToast::WinToastError error;
148148
WinToast::instance()->setAppName(appName);
149149

150-
auto str = GetVersionString();
150+
auto str = Application::GetVersionString();
151151
const std::wstring w_version(str.begin(), str.end());
152152
const auto aumi = WinToast::configureAUMI(L"Austin Nixholm", appName, L"Tool", L"Current");
153153

@@ -175,6 +175,7 @@ BOOL InitInstance(const HINSTANCE hInstance, int nCmdShow)
175175
}
176176

177177
// Initialize tray icon data
178+
178179
tray_icon_data.cbSize = sizeof(NOTIFYICONDATA);
179180
tray_icon_data.hWnd = tool_window_handle;
180181
tray_icon_data.uID = 1;
@@ -183,7 +184,7 @@ BOOL InitInstance(const HINSTANCE hInstance, int nCmdShow)
183184
tray_icon_data.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_THREEFINGERDRAG));
184185

185186
std::string title = "Three Finger Drag ";
186-
title.append(GetVersionString());
187+
title.append(Application::GetVersionString());
187188
const std::wstring w_title(title.begin(), title.end());
188189
lstrcpy(tray_icon_data.szTip, w_title.c_str());
189190

@@ -251,26 +252,22 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
251252
/**
252253
* \brief Starts a thread that periodically updates setting info.
253254
*/
254-
void StartUpdateThread()
255+
void StartPeriodicUpdateThreads()
255256
{
257+
// Check for any updates to the user's precision touchpad settings every few seconds
256258
update_settings_thread = std::thread([&]
257259
{
258-
while (run_loops)
260+
while (application_running)
259261
{
260262
std::this_thread::sleep_for(UPDATE_SETTINGS_PERIOD_MS);
261263
ReadPrecisionTouchPadInfo();
262264
}
263265
});
264-
}
265266

266-
/**
267-
* \brief Starts a thread that periodically checks
268-
*/
269-
void StartActivityThread()
270-
{
267+
// Check if the dragging action needs to be completed
271268
touch_activity_thread = std::thread([&]
272269
{
273-
while (run_loops)
270+
while (application_running)
274271
{
275272
std::this_thread::sleep_for(TOUCH_ACTIVITY_PERIOD_MS);
276273
if (!gesture_processor.IsDragging())

ThreeFingerDrag/ThreeFingerDrag.h

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,53 @@
1212
#include "popups.h"
1313

1414

15-
constexpr int VERSION_MAJOR = 1;
16-
constexpr int VERSION_MINOR = 0;
17-
constexpr int VERSION_PATCH = 3;
15+
namespace Application {
1816

19-
constexpr char kVersionFileName[] = "version.txt";
17+
constexpr int VERSION_MAJOR = 1;
18+
constexpr int VERSION_MINOR = 0;
19+
constexpr int VERSION_PATCH = 4;
2020

21-
inline std::string GetVersionString() {
22-
return std::to_string(VERSION_MAJOR) + "." + std::to_string(VERSION_MINOR) + "." + std::to_string(VERSION_PATCH);
23-
}
21+
constexpr char VERSION_FILE_NAME[] = "version.txt";
22+
23+
std::string GetVersionString() {
24+
return std::to_string(VERSION_MAJOR) + "." + std::to_string(VERSION_MINOR) + "." + std::to_string(VERSION_PATCH);
25+
}
2426

25-
inline bool IsInitialStartup() {
27+
/**
28+
* @brief Checks if a version.txt file exists in application data and updates it.
29+
* @return True if no version file was found
30+
*/
31+
bool IsInitialStartup() {
32+
size_t len;
33+
char* env_path;
34+
const errno_t err = _dupenv_s(&env_path, &len, "LOCALAPPDATA");
2635

27-
size_t len;
28-
char* env_path;
29-
const errno_t err = _dupenv_s(&env_path, &len, "LOCALAPPDATA");
36+
if (err == 0 && env_path != nullptr) {
37+
std::string version_file_path_ = std::string(env_path);
38+
version_file_path_ += "\\";
39+
version_file_path_ += "ThreeFingerDrag";
3040

31-
if (err == 0 && env_path != nullptr) {
32-
std::string log_file_path_ = std::string(env_path);
33-
log_file_path_ += "\\";
34-
log_file_path_ += "ThreeFingerDrag";
35-
log_file_path_ += "\\";
36-
log_file_path_ += kVersionFileName;
41+
// Create the application data directory if necessary
42+
if (!std::filesystem::exists(version_file_path_))
43+
std::filesystem::create_directory(version_file_path_);
3744

38-
if (std::filesystem::exists(log_file_path_))
39-
return false;
45+
version_file_path_ += "\\";
46+
version_file_path_ += VERSION_FILE_NAME;
4047

41-
std::ofstream versionFile(log_file_path_);
42-
if (!versionFile)
43-
return false;
48+
// File contents do not need to update after initial creation
49+
if (std::filesystem::exists(version_file_path_))
50+
return false;
4451

45-
versionFile << GetVersionString();
46-
versionFile.close();
52+
// Create the file if it has not been created yet, and write the current version to it
53+
std::ofstream versionFile(version_file_path_);
54+
if (!versionFile)
55+
return false;
56+
57+
versionFile << GetVersionString();
58+
versionFile.close();
59+
}
60+
61+
return true;
4762
}
63+
}
4864

49-
return true;
50-
}

ThreeFingerDrag/touch_gestures.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace
1818
constexpr auto USAGE_DIGITIZER_Y_COORDINATE = 0x31;
1919
}
2020

21-
namespace ThreeFingerDrag
21+
namespace Gestures
2222
{
2323
void GestureProcessor::ParseRawTouchData(const LPARAM lParam)
2424
{

ThreeFingerDrag/touch_gestures.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <vector>
55
#include <chrono>
66

7-
namespace ThreeFingerDrag
7+
namespace Gestures
88
{
99
struct TouchPoint
1010
{

0 commit comments

Comments
 (0)