diff options
Diffstat (limited to 'src/config/ConfigManager.cpp')
| -rw-r--r-- | src/config/ConfigManager.cpp | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 4eb617b9..39e9409e 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -40,6 +40,8 @@ CConfigManager::CConfigManager() { configValues["input:kb_options"].strValue = ""; configValues["input:kb_rules"].strValue = ""; configValues["input:kb_model"].strValue = ""; + + configValues["autogenerated"].intValue = 0; } void CConfigManager::init() { @@ -289,14 +291,27 @@ void CConfigManager::loadConfigLoadVars() { const std::string CONFIGPATH = ENVHOME + (ISDEBUG ? (std::string) "/.config/hypr/hyprlandd.conf" : (std::string) "/.config/hypr/hyprland.conf"); std::ifstream ifs; - ifs.open(CONFIGPATH.c_str()); + ifs.open(CONFIGPATH); if (!ifs.good()) { - Debug::log(WARN, "Config reading error. (No file?)"); - parseError = "The config could not be read. (No file?)"; + Debug::log(WARN, "Config reading error. (No file? Attempting to generate, backing up old one if exists)"); + try { + std::filesystem::rename(CONFIGPATH, CONFIGPATH + ".backup"); + } catch(...) { /* Probably doesn't exist */} - ifs.close(); - return; + std::ofstream ofs; + ofs.open(CONFIGPATH, std::ios::trunc); + + ofs << AUTOCONFIG; + + ofs.close(); + + ifs.open(CONFIGPATH); + + if (!ifs.good()) { + parseError = "Broken config file! (Could not open)"; + return; + } } std::string line = ""; @@ -335,6 +350,8 @@ void CConfigManager::loadConfigLoadVars() { // parseError will be displayed next frame if (parseError != "") g_pHyprError->queueCreate(parseError + "\nHyprland may not work correctly.", CColor(255, 50, 50, 255)); + else if (configValues["autogenerated"].intValue == 1) + g_pHyprError->queueCreate("Warning: You're using an autogenerated config! (config file: " + CONFIGPATH + " )\nSUPER+Enter -> kitty\nSUPER+T -> Alacritty\nSUPER+M -> exit Hyprland", CColor(255, 255, 70, 255)); else g_pHyprError->destroy(); } @@ -344,6 +361,11 @@ void CConfigManager::tick() { const std::string CONFIGPATH = ENVHOME + (ISDEBUG ? (std::string) "/.config/hypr/hyprlandd.conf" : (std::string) "/.config/hypr/hyprland.conf"); + if (!std::filesystem::exists(CONFIGPATH)) { + loadConfigLoadVars(); + return; + } + struct stat fileStat; int err = stat(CONFIGPATH.c_str(), &fileStat); if (err != 0) { |
