Update the Logging Messages of the Migrating Process

This commit is contained in:
Nascher 2016-02-10 22:03:58 +01:00
parent f93a7dac79
commit 700d329917
2 changed files with 54 additions and 29 deletions

View File

@ -332,20 +332,27 @@ void initializePaths(char* argv0)
path_data = std::string(buf) + "/share/" + PROJECT_NAME;
//path_data = std::string(INSTALL_PREFIX) + "/share/" + PROJECT_NAME;
if (!fs::PathExists(path_data)) {
if (!fs::PathExists(path_data))
{
dstream<<"WARNING: data path " << path_data << " not found!";
path_data = std::string(buf) + "/data";
dstream<<" Trying " << path_data << std::endl;
}
if(getenv("XDG_CONFIG_HOME") == NULL) {
path_configdata = std::string(getenv("HOME")) + "/.config/" + PROJECT_NAME;
} else {
if (getenv("XDG_CONFIG_HOME") == NULL)
{
path_configdata = std::string(getenv("HOME"))
+ "/.config/" + PROJECT_NAME;
} else
{
path_configdata = std::string(getenv("XDG_CONFIG_HOME"));
}
if(getenv("XDG_DATA_HOME") == NULL) {
path_userdata = std::string(getenv("HOME")) + "/.local/share/" + PROJECT_NAME;
} else {
if (getenv("XDG_DATA_HOME") == NULL)
{
path_userdata = std::string(getenv("HOME"))
+ "/.local/share/" + PROJECT_NAME;
} else
{
path_userdata = std::string(getenv("XDG_DATA_HOME"));
}
@ -380,14 +387,18 @@ void initializePaths(char* argv0)
path_data = std::string(INSTALL_PREFIX) + "/share/" + PROJECT_NAME;
if (getenv("XDG_CONFIG_HOME") == NULL) {
if (getenv("XDG_CONFIG_HOME") == NULL)
{
path_configdata = std::string(getenv("HOME")) + "/.config/" + PROJECT_NAME;
} else {
} else
{
path_configdata = std::string(getenv("XDG_CONFIG_HOME"));
}
if (getenv("XDG_DATA_HOME") == NULL) {
if (getenv("XDG_DATA_HOME") == NULL)
{
path_userdata = std::string(getenv("HOME")) + "/.local/share/" + PROJECT_NAME;
} else {
} else
{
path_userdata = std::string(getenv("XDG_DATA_HOME"));
}
@ -403,32 +414,45 @@ void initializePaths(char* argv0)
std::string path_olddirectory = std::string(getenv("HOME")) + "/." + PROJECT_NAME;
if (fs::PathExists(path_olddirectory)) {
dstream<<"Found the old Directory! I will try to migrate the Directory." << std::endl;
if (fs::PathExists(path_olddirectory))
{
dstream<<"Old directory found, Migrating process will start now." << std::endl;
if (!fs::PathExists(path_configdata)) {
if (!fs::PathExists(path_configdata))
{
fs::CreateDir(path_configdata);
std::string path_oldconfig = std::string(getenv("HOME")) + "/.voxelands/voxelands.conf";
std::string path_oldconfig = std::string(getenv("HOME"))
+ "/.voxelands/voxelands.conf";
std::string path_newconfig = path_configdata + "/voxelands.conf";
if (rename( path_oldconfig.c_str() , path_newconfig.c_str() ) == 0) {
dstream<<"Config was sucessful migrated." << std::endl;
} else {
dstream<<"Error while move the Config Directory: " << strerror(errno) << std::endl;
if (rename( path_oldconfig.c_str() , path_newconfig.c_str() ) == 0)
{
dstream<<"Config is successful migrated." << std::endl;
} else
{
dstream<<"Error while moving the Config directory: " << std::endl;
dstream<<strerror(errno) << std::endl;
}
} else {
dstream<<"There is already a Directory for the config!" << std::endl;
} else
{
dstream<<"Warning: There is already a directory for the Config!" << std::endl;
dstream<<"The Config directory will not be migrated." << std::endl;
}
// Move the rest of the rest
if (!fs::PathExists(path_userdata)) {
if (!fs::PathExists(path_userdata))
{
if (rename( path_olddirectory.c_str() ,
path_userdata.c_str() ) == 0) {
dstream<<"Data Directory was sucessful migrated." << std::endl;
} else {
dstream<<"Error while move the Data Directory: " << strerror(errno) << std::endl;
path_userdata.c_str() ) == 0)
{
dstream<<"Data Directory is successful migrated." << std::endl;
} else
{
dstream<<"Error while move the Data directory: " << std::endl;
dstream<<strerror(errno) << std::endl;
}
} else {
dstream<<"There is already a Directory for the Data!" << std::endl;
} else
{
dstream<<"Warning: There is already a Directory for the Data!" << std::endl;
dstream<<"The Data directory will not be migrated. " << std::endl;
}
}
#endif

View File

@ -95,6 +95,7 @@ extern std::string path_userdata;
Mac: "~/Library/Application Support/<PROJECT_NAME>"
*/
std::string getDataPath(const char *subpath);
/*
Initialize path_data and path_userdata.
*/