mirror of
https://github.com/hyprwm/hyprpaper.git
synced 2024-11-16 22:25:59 +01:00
Merge pull request #14 from vinhig/main
Fixing config manager that doesn't error out on bad keyword.
This commit is contained in:
commit
6fa4ea8a68
1 changed files with 15 additions and 10 deletions
|
@ -2,14 +2,15 @@
|
|||
#include "../Hyprpaper.hpp"
|
||||
|
||||
CConfigManager::CConfigManager() {
|
||||
// init the entire thing
|
||||
// Initialize the configuration
|
||||
// Read file from default location
|
||||
// or from an explicit location given by user
|
||||
|
||||
std::string configPath;
|
||||
if (g_pHyprpaper->m_szExplicitConfigPath.empty()) {
|
||||
const char *const ENVHOME = getenv("HOME");
|
||||
configPath = ENVHOME + (std::string) "/.config/hypr/hyprpaper.conf";
|
||||
}
|
||||
else {
|
||||
const char* const ENVHOME = getenv("HOME");
|
||||
configPath = ENVHOME + std::string("/.config/hypr/hyprpaper.conf");
|
||||
} else {
|
||||
configPath = g_pHyprpaper->m_szExplicitConfigPath;
|
||||
}
|
||||
|
||||
|
@ -17,7 +18,11 @@ CConfigManager::CConfigManager() {
|
|||
ifs.open(configPath);
|
||||
|
||||
if (!ifs.good()) {
|
||||
Debug::log(CRIT, "Hyprpaper was not provided a config!");
|
||||
if (g_pHyprpaper->m_szExplicitConfigPath.empty()) {
|
||||
Debug::log(CRIT, "No config file provided. Default config file `~/.config/hypr/hyprpaper.conf` couldn't be opened.");
|
||||
} else {
|
||||
Debug::log(CRIT, "No config file provided. Specified file `%s` couldn't be opened.", configPath);
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
@ -25,7 +30,7 @@ CConfigManager::CConfigManager() {
|
|||
int linenum = 1;
|
||||
if (ifs.is_open()) {
|
||||
while (std::getline(ifs, line)) {
|
||||
// Read line by line.
|
||||
// Read line by line
|
||||
try {
|
||||
parseLine(line);
|
||||
} catch (...) {
|
||||
|
@ -35,8 +40,9 @@ CConfigManager::CConfigManager() {
|
|||
parseError += "Config error at line " + std::to_string(linenum) + ": Line parsing error.";
|
||||
}
|
||||
|
||||
if (!parseError.empty() && parseError.find("Config error at line") != 0) {
|
||||
if (!parseError.empty()) {
|
||||
parseError = "Config error at line " + std::to_string(linenum) + ": " + parseError;
|
||||
break;
|
||||
}
|
||||
|
||||
++linenum;
|
||||
|
@ -74,7 +80,7 @@ void CConfigManager::parseLine(std::string& line) {
|
|||
if (COMMENTSTART != std::string::npos)
|
||||
line = line.substr(0, COMMENTSTART);
|
||||
|
||||
// remove shit at the beginning
|
||||
// Strip line
|
||||
while (line[0] == ' ' || line[0] == '\t') {
|
||||
line = line.substr(1);
|
||||
}
|
||||
|
@ -88,7 +94,6 @@ void CConfigManager::parseLine(std::string& line) {
|
|||
|
||||
const auto COMMAND = removeBeginEndSpacesTabs(line.substr(0, EQUALSPLACE));
|
||||
const auto VALUE = removeBeginEndSpacesTabs(line.substr(EQUALSPLACE + 1));
|
||||
//
|
||||
|
||||
parseKeyword(COMMAND, VALUE);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue