Skip to content

Commit

Permalink
Fully working
Browse files Browse the repository at this point in the history
  • Loading branch information
psidex committed Jun 10, 2019
1 parent 4e1969c commit acf20c1
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 32 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Ignore generated config.txt
source/config.txt

# Created by https://www.gitignore.io/api/c,clion
# Edit at https://www.gitignore.io/?templates=c,clion
Expand Down
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@

A small Windows app that sits in the tray and allows you to quickly switch between using different [Equalizer APO](https://sourceforge.net/projects/equalizerapo/) configuration files

Due to this being quite a niche app, several things are assumed:
- Equalizer APO is installed in `C:\Program Files\EqualizerAPO`
- This app will be installed in `C:\Program Files\EqualizerAPO\config\E-APO-Config-Switcher`
- You are not manually editing your Equalizer APO config.txt. if you do it *might* cause errors
There are a couple of limitations that come with using this app:
- You cannot manually edit your Equalizer APO configuration. If you do, it will be erased
- This will not work alongside other configuration programs, such as Peace

## Install

- Download the latest `E-APO-Config-Switcher.zip` from releases
- Extract it to `<Equalizer APO install location>\EqualizerAPO\config`
- Run `E_APO_Config_Switcher.exe` (in the same directory as the install script)
- You should now have an icon in your system tray that you can click on
- If you want it to run on system startup, create a shortcut to the exe and move it to the windows startup directory

## Screenshot

![example](example.png)

*This is a temporary screenshot, there is still a lot to be done*

## Credits

- [zserge/tray](https://github.com/zserge/tray) to handle the system tray interaction
Expand Down
Binary file modified example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ project(E_APO_Config_Switcher C)
set(CMAKE_C_STANDARD 99)

include_directories(../tray)
add_executable(E_APO_Config_Switcher main.c helpers.c helpers.h)

# WIN32 = Don't show a console window when running
# This requires using WinMain instead of main - https://stackoverflow.com/a/13871657/6396652
add_executable(E_APO_Config_Switcher WIN32 main.c helpers.c helpers.h)

# Move icon over to binary dir so it is seen by the bin
# configure_file means it will copy if it changes
Expand Down
6 changes: 4 additions & 2 deletions source/helpers.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include <windows.h>
#include "helpers.h"

static const char config_files_glob[] = "E-APO-Config-Files\\*.txt";
static const char config_files_base[] = "E-APO-Config-Files\\";
const char config_files_glob[] = "E-APO-Config-Files\\*.txt";
// config_files_base is relative to the master config.txt
const char config_files_base[] = "E-APO-Config-Switcher\\E-APO-Config-Files\\";

int get_config_file_count() {
int file_count = 0;
Expand Down Expand Up @@ -35,6 +36,7 @@ void populate_e_apo_configs(struct e_apo_config *e_apo_configs) {

strcpy_s(e_apo_configs[current_file_number].file_name, MAX_FILE_NAME, data.cFileName);
strcpy_s(e_apo_configs[current_file_number].include_text, MAX_INCLUDE_TEXT, include_text);
e_apo_configs[current_file_number].checked = 0;

current_file_number++;
} while (FindNextFile(hFind, &data));
Expand Down
3 changes: 2 additions & 1 deletion source/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
#define E_APO_CONFIG_SWITCHER_HELPERS_H

#define MAX_FILE_NAME 255
// Max path len + 9 for the "Include: " chars
// Max path len + 9 for "Include: "
#define MAX_INCLUDE_TEXT 260 + 9

struct e_apo_config {
char file_name[MAX_FILE_NAME];
char include_text[MAX_INCLUDE_TEXT];
int checked;
};

int get_config_file_count();
Expand Down
63 changes: 41 additions & 22 deletions source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,41 @@
#include "helpers.h"

struct tray tray_app;
int config_file_count;
struct e_apo_config *e_apo_configs;

void config_clicked(struct tray_menu *item) {
// When a config file in the tray menu is clicked
item->checked = !item->checked;
// The file that contains includes to config files
const char master_config_path[] = "../config.txt";

void write_current_config() {
// For each checked config, write the include text to the master config file
// TODO: Switch to fopen_s?
FILE *fp = fopen(master_config_path, "w");
for(int i = 0; i < config_file_count; i++) {
if (e_apo_configs[i].checked) {
fputs(e_apo_configs[i].include_text, fp);
fputs("\n", fp); // E-APO doesn't like CR LF, only LF
}
}
fclose(fp);
}

void config_clicked(struct tray_menu *item) {
struct e_apo_config *current_config = item->context;
printf("include_text: %s\n", current_config->include_text);

// Update the tray and the struct
item->checked = !item->checked;
current_config->checked = !current_config->checked;

write_current_config();
tray_update(&tray_app);
}

void quit_app(struct tray_menu *item) {
tray_exit();
}

int main() {
int config_file_count = get_config_file_count();

struct e_apo_config *e_apo_configs = malloc(config_file_count * sizeof(struct e_apo_config));
populate_e_apo_configs(e_apo_configs);

struct tray_menu *tray_menu_items = malloc((config_file_count + 5) * sizeof(struct tray_menu));
void populate_tray_menu(struct tray_menu *tray_menu_items) {
tray_menu_items[0] = (struct tray_menu) {"E-APO-Config-Switcher", 1, 0, NULL, NULL};
tray_menu_items[1] = (struct tray_menu) {"-", 0, 0, NULL, NULL};
tray_menu_items[config_file_count+2] = (struct tray_menu) {"-", 0, 0, NULL, NULL};
Expand All @@ -35,23 +48,29 @@ int main() {
for(int i = 0; i < config_file_count; i++) {
// i + 2 as the first 2 indexes are already used
tray_menu_items[i + 2] = (struct tray_menu) {
e_apo_configs[i].file_name,
0,
0,
config_clicked,
// Pass the e_apo_config struct as context
&e_apo_configs[i]
e_apo_configs[i].file_name,
0,
0,
config_clicked,
// Pass a pointer to the e_apo_config struct as context
&e_apo_configs[i]
};
}
}

// See CMakeLists.txt for WinMain usage reason
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow ) {
config_file_count = get_config_file_count();

e_apo_configs = malloc(config_file_count * sizeof(struct e_apo_config));
struct tray_menu *tray_menu_items = malloc((config_file_count + 5) * sizeof(struct tray_menu));

populate_e_apo_configs(e_apo_configs);
populate_tray_menu(tray_menu_items);

tray_app.icon = "icon.ico";
tray_app.menu = tray_menu_items;

// TODO: Logging to file
for(int i = 0; i < config_file_count; i++) {
printf("Config file loaded: %s\n", e_apo_configs[i].file_name);
}

// Init and start tray app
if (tray_init(&tray_app) < 0) {return 1;}
while (tray_loop(1) == 0) {}
Expand Down

0 comments on commit acf20c1

Please sign in to comment.