diff --git a/README.md b/README.md index 9c119cb..ce29c8c 100644 --- a/README.md +++ b/README.md @@ -22,14 +22,14 @@ Inspired by [Peace](https://sourceforge.net/projects/peace-equalizer-apo-extensi ## Install -- Download the latest `E-APO-Config-Switcher.zip` from [releases](https://github.com/psidex/EACS/releases/latest) +- Download the latest `EACS.zip` from [releases](https://github.com/psidex/EACS/releases/latest) - Extract it to `\EqualizerAPO\config` -- Run `E_APO_Config_Switcher.exe` that is now inside `config\E-APO-Config-Switcher` +- Run `EACS.exe` that is now inside `config\EACS` - You should now have the icon in your system tray, you can now left/right click on it to switch configurations - If you want it to run on system startup, create a shortcut to the exe and move it to the Windows startup directory ## Edit / Add / Remove Configurations -The folder that contains all the configuration files will be located at `EqualizerAPO\config\E-APO-Config-Switcher\config-files` +The folder that contains all the configuration files will be located at `EqualizerAPO\config\EACS\config-files` See [the user guide](./GUIDE.md) for more detailed information diff --git a/config/config.go b/config/config.go index 010f3eb..8e20c8b 100644 --- a/config/config.go +++ b/config/config.go @@ -1,81 +1,58 @@ package config import ( + "fmt" "github.com/getlantern/systray" "io/ioutil" "os" - "strings" "tawesoft.co.uk/go/dialog" ) const configFileDir = "./config-files/" const configFileMaster = "../config.txt" +const includeText = "Include: EACS\\config-files\\%s" type EApoConfig struct { - Name string - Data []byte + FileName string MenuItem *systray.MenuItem } -// Takes a FileInfo interface. Assuming that file is in configFileDir, load the contents of that file into an -// EApoConfig struct and return it. -func configStructFromFile(file os.FileInfo) (EApoConfig, error) { - fileName := file.Name() - - dat, err := ioutil.ReadFile(configFileDir + fileName) - if err != nil { - return EApoConfig{}, err - } - - configName := strings.Replace(fileName, ".txt", "", 1) - - return EApoConfig{ - Name: configName, - Data: dat, - }, nil -} - -// Creates a slice of EApoConfigs which contain the data for all config files in configFileDir. func CreateConfigSlice() []*EApoConfig { var configSlice []*EApoConfig files, err := ioutil.ReadDir(configFileDir) if err != nil { - dialog.Alert("EACS Config Error", "Cannot read config file directory: "+configFileDir) - // Can't do anything else. + errMsg := fmt.Sprintf("Cannot read config file directory: %s", configFileDir) + dialog.Alert("EACS Config Error", errMsg) os.Exit(1) } for _, file := range files { if !file.IsDir() { - configStruct, err := configStructFromFile(file) - // Ignore files that cause err. - if err == nil { - configSlice = append(configSlice, &configStruct) - } + configStruct := EApoConfig{FileName: file.Name()} + configSlice = append(configSlice, &configStruct) } } return configSlice } -// Write all items in configSlice to configFileMaster if their associated menu item is checked. func WriteConfigToMaster(configSlice []*EApoConfig) { var completeData []byte newline := []byte("\n") for _, config := range configSlice { if config.MenuItem.Checked() { - // "..." -> https://stackoverflow.com/a/16248257/6396652 + includeStatement := fmt.Sprintf(includeText, config.FileName) + completeData = append(completeData, []byte(includeStatement)...) completeData = append(completeData, newline...) - completeData = append(completeData, config.Data...) } } err := ioutil.WriteFile(configFileMaster, completeData, 0644) if err != nil { - dialog.Alert("EACS Config Error", "Cannot write to master config file: "+configFileMaster) + errMsg := fmt.Sprintf("Cannot write to master config file: %s", configFileMaster) + dialog.Alert("EACS Config Error", errMsg) os.Exit(1) - return } } diff --git a/main.go b/main.go index ba19751..ca88851 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,7 @@ import ( "github.com/getlantern/systray" "github.com/psidex/EACS/config" "github.com/psidex/EACS/icon" + "strings" ) func main() { @@ -18,7 +19,8 @@ func onReady() { configSlice := config.CreateConfigSlice() for _, configStruct := range configSlice { - btn := systray.AddMenuItem(configStruct.Name, "Activate / Deactivate this config") + configName := strings.Replace(configStruct.FileName, ".txt", "", 1) + btn := systray.AddMenuItem(configName, "Activate / Deactivate this config") configStruct.MenuItem = btn go func() {