summaryrefslogtreecommitdiff
path: root/src/inspircd.cpp
diff options
context:
space:
mode:
authorPeter Powell <petpow@saberuk.com>2019-12-08 22:26:33 +0000
committerPeter Powell <petpow@saberuk.com>2019-12-08 22:26:33 +0000
commit98561bddd06d118e5043094bc884593049f37315 (patch)
treec2e1db8492c8816e7082b578a580d7322f19a418 /src/inspircd.cpp
parent23a122cb63aae9d5ef5ec80208e79563c88c2660 (diff)
Extract config file finding code to a function.
Diffstat (limited to 'src/inspircd.cpp')
-rw-r--r--src/inspircd.cpp40
1 files changed, 23 insertions, 17 deletions
diff --git a/src/inspircd.cpp b/src/inspircd.cpp
index c88235ce6..3c11cc82e 100644
--- a/src/inspircd.cpp
+++ b/src/inspircd.cpp
@@ -165,6 +165,25 @@ namespace
#endif
}
+ // Locates a config file on the file system.
+ bool FindConfigFile(std::string& path)
+ {
+ if (FileSystem::FileExists(path))
+ return true;
+
+#ifdef _WIN32
+ // Windows hides file extensions by default so try appending .txt to the path
+ // to help users who have that feature enabled and can't create .conf files.
+ const std::string txtpath = path + ".txt";
+ if (FileSystem::FileExists(txtpath))
+ {
+ path.assign(txtpath);
+ return true;
+ }
+#endif
+ return false;
+ }
+
// Attempts to fork into the background.
bool ForkIntoBackground()
{
@@ -441,24 +460,11 @@ InspIRCd::InspIRCd(int argc, char** argv)
Logs->AddLogTypes("*", fls, true);
}
- if (!FileSystem::FileExists(ConfigFileName))
+ if (!FindConfigFile(ConfigFileName))
{
-#ifdef _WIN32
- /* Windows can (and defaults to) hide file extensions, so let's play a bit nice for windows users. */
- std::string txtconf = this->ConfigFileName;
- txtconf.append(".txt");
-
- if (FileSystem::FileExists(txtconf))
- {
- ConfigFileName = txtconf;
- }
- else
-#endif
- {
- std::cout << "ERROR: Cannot open config file: " << ConfigFileName << std::endl << "Exiting..." << std::endl;
- this->Logs->Log("STARTUP", LOG_DEFAULT, "Unable to open config file %s", ConfigFileName.c_str());
- Exit(EXIT_STATUS_CONFIG);
- }
+ this->Logs->Log("STARTUP", LOG_DEFAULT, "Unable to open config file %s", ConfigFileName.c_str());
+ std::cout << "ERROR: Cannot open config file: " << ConfigFileName << std::endl << "Exiting..." << std::endl;
+ Exit(EXIT_STATUS_CONFIG);
}
std::cout << con_green << "InspIRCd - Internet Relay Chat Daemon" << con_reset << std::endl;