improved my replacement for plib detectory detection functions

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3517 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2009-05-18 18:38:51 +00:00
parent bbce1a0407
commit d38c6672a1
3 changed files with 30 additions and 20 deletions

View File

@ -4,7 +4,7 @@
#include "io/file_manager.hpp"
#include <iostream>
#include <fstream>
#include "user_config.hpp"
DeviceManager::DeviceManager()
{
@ -200,6 +200,8 @@ bool DeviceManager::deserialize()
void DeviceManager::serialize()
{
static std::string filepath = file_manager->getHomeDir() + "/input.config";
user_config->CheckAndCreateDir();
std::cout << "writing " << filepath.c_str() << std::endl;
std::ofstream configfile;

View File

@ -170,33 +170,40 @@ void UserConfig::loadConfig()
int UserConfig::CheckAndCreateDir()
{
// the standard C/C++ libraries don't include anything allowing to check
// for directory existance. I work around this by trying to write to it
// (no file will be created)
const std::string filename = file_manager->getHomeDir() + "/test";
// for directory existance. I work around this by checking if trying to
// check for the config file (first reading, then writing)
const std::string filename = file_manager->getHomeDir() + "/config";
std::ofstream test(filename.c_str(), std::ios::in);
std::ofstream test(filename.c_str(), std::ios::out);
if(test.fail() || !test.is_open())
{
int bError;
std::ofstream test2(filename.c_str(), std::ios::out);
if(test2.fail() || !test2.is_open())
{
int bError;
#if defined(WIN32) && !defined(__CYGWIN__)
bError = _mkdir(file_manager->getHomeDir().c_str() ) != 0;
bError = _mkdir(file_manager->getHomeDir().c_str() ) != 0;
#else
bError = mkdir(file_manager->getHomeDir().c_str(), 0755) != 0;
bError = mkdir(file_manager->getHomeDir().c_str(), 0755) != 0;
#endif
if(bError)
{
fprintf(stderr, "Couldn't create '%s', config files will not be saved.\n",
file_manager->getHomeDir().c_str());
return 0;
}
else
{
printf("Config directory '%s' successfully created.\n", file_manager->getHomeDir().c_str());
return 2;
if(bError)
{
fprintf(stderr, "Couldn't create '%s', config files will not be saved.\n",
file_manager->getHomeDir().c_str());
return 0;
}
else
{
printf("Config directory '%s' successfully created.\n", file_manager->getHomeDir().c_str());
return 2;
}
}
if(test2.is_open()) test2.close();
}
if(test.is_open()) test.close();
return 1;

View File

@ -104,7 +104,6 @@ private:
InputMapEntry m_input_map[GA_COUNT];
void setFilename ();
int CheckAndCreateDir();
// Attributes which have setter/getter
int m_sfx;
@ -160,6 +159,8 @@ private:
public:
enum UC_Mode {UC_ENABLE, UC_DISABLE, UC_TEMPORARY_DISABLE};
int CheckAndCreateDir();
// Attributes that are accessed directly.
bool m_gamepad_debug;
int m_track_debug;