From f6af17aa58701cdb579cca52ac83edf289e118e7 Mon Sep 17 00:00:00 2001 From: Mathias Gumz Date: Mon, 13 Sep 2010 21:59:09 +0200 Subject: code simplification --- src/fluxbox.cc | 84 ++++++++++++++++++++-------------------------------------- 1 file changed, 28 insertions(+), 56 deletions(-) diff --git a/src/fluxbox.cc b/src/fluxbox.cc index fbffc92..aabdb04 100644 --- a/src/fluxbox.cc +++ b/src/fluxbox.cc @@ -530,37 +530,30 @@ void Fluxbox::ungrab() { */ void Fluxbox::setupConfigFiles() { - bool create_init = false, create_keys = false, create_menu = false, - create_apps = false, create_overlay = false, create_windowmenu = false; - string dirname = getDefaultDataFilename(""); - string init_file = getDefaultDataFilename(m_RC_INIT_FILE); - string keys_file = getDefaultDataFilename("keys"); - string menu_file = getDefaultDataFilename("menu"); - string apps_file = getDefaultDataFilename("apps"); - string overlay_file = getDefaultDataFilename("overlay"); - string windowmenu_file = getDefaultDataFilename("windowmenu"); - - struct stat buf; // is file/dir already there? - if (! stat(dirname.c_str(), &buf)) { - - // check if anything with those name exists, if not create new - if (stat(init_file.c_str(), &buf)) - create_init = true; - if (stat(keys_file.c_str(), &buf)) - create_keys = true; - if (stat(menu_file.c_str(), &buf)) - create_menu = true; - if (stat(apps_file.c_str(), &buf)) - create_apps = true; - if (stat(overlay_file.c_str(), &buf)) - create_overlay = true; - if (stat(windowmenu_file.c_str(), &buf)) - create_windowmenu = true; - - } else { + const bool create_dir = FbTk::FileUtil::isDirectory(dirname.c_str()); + + struct CFInfo { + bool create_file; + const char* default_name; + const std::string filename; + } cfiles[] = { + { create_dir, DEFAULT_INITFILE, getDefaultDataFilename(m_RC_INIT_FILE) }, + { create_dir, DEFAULTKEYSFILE, getDefaultDataFilename("keys") }, + { create_dir, DEFAULTMENU, getDefaultDataFilename("menu") }, + { create_dir, DEFAULT_APPSFILE, getDefaultDataFilename("apps") }, + { create_dir, DEFAULT_OVERLAY, getDefaultDataFilename("overlay") }, + { create_dir, DEFAULT_WINDOWMENU, getDefaultDataFilename("windowmenu") } + }; + const size_t nr_of_cfiles = sizeof(cfiles)/sizeof(CFInfo); + + if (create_dir) { // check if anything with those name exists, if not create new + for (size_t i = 0; i < nr_of_cfiles; ++i) { + cfiles[i].create_file = access(cfiles[i].filename.c_str(), F_OK); + } + } else{ fbdbg<<"Creating dir: " << dirname.c_str() << endl; _FB_USES_NLS; // create directory with perm 700 @@ -572,35 +565,14 @@ void Fluxbox::setupConfigFiles() { cerr< config_version(m_resourcemanager, 0, @@ -609,7 +581,7 @@ void Fluxbox::setupConfigFiles() { // configs are out of date, so run fluxbox-update_configs string commandargs = realProgramName("fluxbox-update_configs"); - commandargs += " -rc " + init_file; + commandargs += " -rc " + cfiles[0].filename; #ifdef HAVE_GETPID // add the fluxbox pid so fbuc can have us reload rc if necessary -- cgit v0.11.2