diff --git a/include/file.h b/include/file.h index a4073b9f..c8da6065 100644 --- a/include/file.h +++ b/include/file.h @@ -21,14 +21,14 @@ private: std::string filename; unsigned int version; - const char *find_dir(); + const std::string find_dir(); bool open_read(); bool open_write(); public: File(const std::string &); ~File(); - const char *get_filepath(); + const std::string get_filepath(); const unsigned int get_version(); bool exists(); bool open(OpenMode); diff --git a/lib/file.cpp b/lib/file.cpp index 0f4a7e76..d215aae2 100644 --- a/lib/file.cpp +++ b/lib/file.cpp @@ -25,22 +25,22 @@ File :: ~File() close(); } -const char *File :: find_dir() +const std::string File :: find_dir() { - std::string res = g_get_user_data_dir(); + std::string res(g_get_user_data_dir()); res += "/" + OCARINA_DIR; - return res.c_str(); + return res; } -const char *File :: get_filepath() +const std::string File :: get_filepath() { - std::string res; + std::string res = ""; if (filename != "") { res = find_dir(); res += "/" + filename; } - return res.c_str(); + return res; } const unsigned int File :: get_version() @@ -50,7 +50,7 @@ const unsigned int File :: get_version() bool File :: exists() { - return g_file_test(get_filepath(), G_FILE_TEST_EXISTS); + return g_file_test(get_filepath().c_str(), G_FILE_TEST_EXISTS); } bool File :: open_read() @@ -58,7 +58,7 @@ bool File :: open_read() if (!exists()) return false; - std::fstream::open(get_filepath(), std::fstream::in); + std::fstream::open(get_filepath().c_str(), std::fstream::in); if (std::fstream::fail()) return false; @@ -70,10 +70,10 @@ bool File :: open_read() bool File :: open_write() { - if (g_mkdir_with_parents(find_dir(), 0755) != 0) + if (g_mkdir_with_parents(find_dir().c_str(), 0755) != 0) return false; - std::fstream::open(get_filepath(), std::fstream::out); + std::fstream::open(get_filepath().c_str(), std::fstream::out); if (std::fstream::fail()) return false;