Commits

Morel Bérenger committed c792c82

General configuration refactoring

Moved platform specific code in a separate function
Removed boost::filesystem dependencies from AppConfig
Add a TextFile::OpenFile method without boost parameters

  • Participants
  • Parent commits 424cf78

Comments (0)

Files changed (8)

File src/gui/appconfig.cpp

 
 #include <utils/textfile.h>
 
-#ifdef WIN32
-#define HOME "HOMEPATH" ///\todo check that it should not be %APPDATA% instead of %HOMEPATH%
-#else
-#define HOME "HOME"
-#endif
-
-
+#include "utils/utils.h"
 
 AppConfig::AppConfig()
 {
-	boost::filesystem::path configDir;
 	// guess the directory where configuration is stored
-	///\todo use freedesktop.org recommmandations for linux, and fallback on system variables if they are not supported on client computer
 	std::unique_ptr<TextFile> rootConfigFile;
-	std::string homepath(getenv("HOME"));
-
-	///\todo move that OS related code in an extern function
-	if(boost::filesystem::exists(homepath+"/.autorealm"))
-		configDir=boost::filesystem::path(homepath+".autorealm/");
-	else if(boost::filesystem::exists(homepath+"/.config/autorealm"))
-		configDir=boost::filesystem::path(homepath+"/.config/autorealm/");
 
 	// read global configuration
-	rootConfigFile=TextFile::OpenFile(boost::filesystem::path(configDir.string()+"config"));
+	///\todo split
+	rootConfigFile=TextFile::OpenFile(getPosixConfDir(),"config");
 
 	///\todo support incomplete file
 	for(uint8_t i=GRP_RES;i<LASTINDEX && !rootConfigFile->eofReached();++i)

File src/gui/appconfig.h

 #define APPCONFIG_H
 
 #include <string>
-
-#include <boost/filesystem.hpp>
+#include <vector>
 
 class TextFile;
-//#include <utils/textfile.h>
 
 #include "singleton.h"
 

File src/gui/splash.cpp

 
 #include <utils/utils.h>
 
+#include <boost/filesystem.hpp>
+
 Splash::Splash()
 :wxFrame(nullptr,-1,"")
 {

File src/pluginEngine/drawer.h

 #include "plugin.h"
 
 class RenderWindow;
-class Render::Vertex;
 class wxMouseEvent;
 class wxContextMenuEvent;
 class wxCommandEvent;

File src/utils/textfile.cpp

 	return std::unique_ptr<TextFile>(new TextFile(file));
 }
 
+std::unique_ptr<TextFile> TextFile::OpenFile(std::string const &directory, std::string const &file)
+{
+	return TextFile::OpenFile(boost::filesystem::path (directory+file));
+}
+
 std::unique_ptr<TextFile> TextFile::CreateFile(boost::filesystem::path const &file)
 {
 	if(exists(file))

File src/utils/textfile.h

      */
 	static std::unique_ptr<TextFile> OpenFile(boost::filesystem::path const &path);
 
+	static std::unique_ptr<TextFile> OpenFile(std::string const &directory, std::string const &file);
+
     /** \brief create and open an inexisting file
      *
      *	\param file boost::filesystem::path const& name of the file to open

File src/utils/utils.cpp

 
 #include <wx/image.h>
 
+#ifdef WIN32
+#define HOME "HOMEPATH" ///\todo check that it should not be %APPDATA% instead of %HOMEPATH%
+#else
+#define HOME "HOME"
+#endif
+
+
+#include <boost/filesystem.hpp>
+
 wxBitmap loadImage(std::string const & fileName)
 {
 	if(fileName.empty())
 
 	return wxBitmap(wxImage(AppConfig::buildPath(AppConfig::INFO::GRP_RES)+fileName));
 }
+
+std::string getPosixConfDir(void)
+{
+	///\todo find a better solution to follow freeDesktop.org's recommmandations
+	std::string homepath(getenv("HOME"));
+
+	if(boost::filesystem::exists(homepath+"/.autorealm"))
+		return boost::filesystem::path(homepath+".autorealm/").string();
+	else if(boost::filesystem::exists(homepath+"/.config/autorealm"))
+		return boost::filesystem::path(homepath+"/.config/autorealm/").string();
+#ifndef WIN32
+	else if(boost::filesystem::exists("/etc/autorealm"))
+		return boost::filesystem::path("/etc/autorealm").string();
+#endif
+	throw std::runtime_error("configuration not found");
+}

File src/utils/utils.h

 	return nullptr;
 }
 
+std::string getPosixConfDir(void);
+
 #endif // UTILS_H