code simplification

This commit is contained in:
Mathias Gumz 2010-09-13 21:59:09 +02:00
parent 24e4e98dbe
commit f6af17aa58

View file

@ -530,37 +530,30 @@ void Fluxbox::ungrab() {
*/ */
void Fluxbox::setupConfigFiles() { 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 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? // is file/dir already there?
if (! stat(dirname.c_str(), &buf)) { const bool create_dir = FbTk::FileUtil::isDirectory(dirname.c_str());
// check if anything with those name exists, if not create new struct CFInfo {
if (stat(init_file.c_str(), &buf)) bool create_file;
create_init = true; const char* default_name;
if (stat(keys_file.c_str(), &buf)) const std::string filename;
create_keys = true; } cfiles[] = {
if (stat(menu_file.c_str(), &buf)) { create_dir, DEFAULT_INITFILE, getDefaultDataFilename(m_RC_INIT_FILE) },
create_menu = true; { create_dir, DEFAULTKEYSFILE, getDefaultDataFilename("keys") },
if (stat(apps_file.c_str(), &buf)) { create_dir, DEFAULTMENU, getDefaultDataFilename("menu") },
create_apps = true; { create_dir, DEFAULT_APPSFILE, getDefaultDataFilename("apps") },
if (stat(overlay_file.c_str(), &buf)) { create_dir, DEFAULT_OVERLAY, getDefaultDataFilename("overlay") },
create_overlay = true; { create_dir, DEFAULT_WINDOWMENU, getDefaultDataFilename("windowmenu") }
if (stat(windowmenu_file.c_str(), &buf)) };
create_windowmenu = true; const size_t nr_of_cfiles = sizeof(cfiles)/sizeof(CFInfo);
} else { 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; fbdbg<<"Creating dir: " << dirname.c_str() << endl;
_FB_USES_NLS; _FB_USES_NLS;
// create directory with perm 700 // create directory with perm 700
@ -572,35 +565,14 @@ void Fluxbox::setupConfigFiles() {
cerr<<endl; cerr<<endl;
return; return;
} }
//mark creation of files
create_init = create_keys = create_menu = create_apps = create_overlay =
create_windowmenu = true;
} }
// copy default files if needed
// copy key configuration for (size_t i = 0; i < nr_of_cfiles; ++i) {
if (create_keys) if (cfiles[i].create_file) {
FbTk::FileUtil::copyFile(DEFAULTKEYSFILE, keys_file.c_str()); FbTk::FileUtil::copyFile(cfiles[i].default_name, cfiles[i].filename.c_str());
}
// copy menu configuration }
if (create_menu)
FbTk::FileUtil::copyFile(DEFAULTMENU, menu_file.c_str());
// copy apps file
if (create_apps)
FbTk::FileUtil::copyFile(DEFAULT_APPSFILE, apps_file.c_str());
// copy overlay file
if (create_overlay)
FbTk::FileUtil::copyFile(DEFAULT_OVERLAY, overlay_file.c_str());
// copy init file
if (create_init)
FbTk::FileUtil::copyFile(DEFAULT_INITFILE, init_file.c_str());
if (create_windowmenu)
FbTk::FileUtil::copyFile(DEFAULT_WINDOWMENU, windowmenu_file.c_str());
#define CONFIG_VERSION 13 #define CONFIG_VERSION 13
FbTk::Resource<int> config_version(m_resourcemanager, 0, FbTk::Resource<int> config_version(m_resourcemanager, 0,
@ -609,7 +581,7 @@ void Fluxbox::setupConfigFiles() {
// configs are out of date, so run fluxbox-update_configs // configs are out of date, so run fluxbox-update_configs
string commandargs = realProgramName("fluxbox-update_configs"); string commandargs = realProgramName("fluxbox-update_configs");
commandargs += " -rc " + init_file; commandargs += " -rc " + cfiles[0].filename;
#ifdef HAVE_GETPID #ifdef HAVE_GETPID
// add the fluxbox pid so fbuc can have us reload rc if necessary // add the fluxbox pid so fbuc can have us reload rc if necessary