From 1e92ae25a912aeef01b9b71f200424f928c73ede Mon Sep 17 00:00:00 2001
From: 1280px <71165491+1280px@users.noreply.github.com>
Date: Fri, 26 Jan 2024 01:59:57 +0700
Subject: [PATCH] Config file locating hotfix
---
README.md | 9 +++++----
main.c | 6 +++++-
2 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/README.md b/README.md
index 50390db..691079d 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,5 @@
# CapsWitch 🧙♀️⬆️
-A simple, lightweight (13/76 KB) and configurable program that switches keyboard layout with CapsLock key — just put it in Startup folder and enjoy!
+A simple, lightweight (13/78 KB) and configurable program that switches keyboard layout with CapsLock key — just put it in Startup folder and enjoy!
> **Note**: For keyboard layout switching to work in programs running with elevated privileges, CapsWitch should be ran **as administrator**. This can be done, for example, [using Task Scheduler](https://youtu.be/jt1Eb-NaBeg).
It runs fine **without privileges escalation** as well, however it will only work in non-elevated programs.
@@ -7,8 +7,8 @@ A simple, lightweight (13/76 KB) and configurable program that switches keyboard
## Install it!
Download an archive with the preferred version:
-+ [Windows 7–11 (x64)](https://github.com/1280px/CapsWitch/releases/download/m2.1/CapsWitch-64.zip) (shortlink: https://t.ly/ZrzXY)
-+ [Windows XP + (x86)](https://github.com/1280px/CapsWitch/releases/download/m2.1/CapsWitch-XP.zip) (shortlink: https://t.ly/M83hf)
++ [Windows 7–11 (x64)](https://github.com/1280px/CapsWitch/releases/download/m2.1.1/CapsWitch-64.zip) (shortlink: https://t.ly/v_fmo)
++ [Windows XP + (x86)](https://github.com/1280px/CapsWitch/releases/download/m2.1.1/CapsWitch-XP.zip) (shortlink: https://t.ly/9zlcG)
Then, upzip it wherever you want (e.g. in ```shell:startup``` or ```shell:common startup```, which are Startup folder locations for current user and all users respectively), double-click the .exe and you're done!
@@ -36,6 +36,7 @@ CapsWitch works by emulating a layout switch keystroke *(Alt+Shift by default)*
## Configure it!
-CapsWitch allows some customization using .ini settings file. By default, it looks for ```CapsWitch.ini``` file in its working directory, however you can pass custom file path using agruments (i.e. ```.\CapsWitch.exe "C:\test.ini"```). The program can also work without .ini file, using built-in default values.
+CapsWitch allows some customization using .ini settings file. By default, it looks for ```.ini``` file in the same directory, however you can pass custom configs file path using agruments (i.e. ```.\CapsWitch.exe "C:\test.ini"```).
+
The program can also work without .ini file, using built-in values (same as default).
*You can see more information about each option [in default .ini file](https://github.com/1280px/CapsWitch/blob/master/CapsWitch.ini).*
diff --git a/main.c b/main.c
index b07e267..842e137 100644
--- a/main.c
+++ b/main.c
@@ -62,7 +62,11 @@ int importSettingsFromFile(char* settingsFilePath, struct Settings* Settings)
// use default path if arguments didn't provide any
if (settingsFilePath == NULL) {
char defaultFilePath[MAX_PATH];
- GetFullPathName("CapsWitch.ini", MAX_PATH, defaultFilePath, NULL);
+ GetModuleFileName(NULL, defaultFilePath, MAX_PATH);
+ // replace 3 last characters (.exe -> .ini)
+ defaultFilePath[strlen(defaultFilePath)-3] = 'i';
+ defaultFilePath[strlen(defaultFilePath)-2] = 'n';
+ defaultFilePath[strlen(defaultFilePath)-1] = 'i';
settingsFilePath = defaultFilePath;
}
// if it is provided, throw error if the file doesn't exist