core/file: Move exists() out of the file struct
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
aa21ede894
commit
7e9eb9e7d2
|
@ -79,7 +79,7 @@ void audio :: init()
|
|||
{
|
||||
unsigned int id;
|
||||
|
||||
if (f_cur_track.exists()) {
|
||||
if (file_exists(&f_cur_track)) {
|
||||
f_cur_track.open(OPEN_READ);
|
||||
f_cur_track >> id;
|
||||
f_cur_track.close();
|
||||
|
|
|
@ -48,14 +48,14 @@ const unsigned int file_version(struct file *file)
|
|||
return file->f_version;
|
||||
}
|
||||
|
||||
bool file :: exists()
|
||||
bool file_exists(struct file *file)
|
||||
{
|
||||
return g_file_test(file_path(this).c_str(), G_FILE_TEST_EXISTS);
|
||||
return g_file_test(file_path(file).c_str(), G_FILE_TEST_EXISTS);
|
||||
}
|
||||
|
||||
bool file :: _open_read()
|
||||
{
|
||||
if (!exists())
|
||||
if (!file_exists(this))
|
||||
return false;
|
||||
|
||||
std::fstream::open(file_path(this).c_str(), std::fstream::in);
|
||||
|
|
|
@ -54,7 +54,7 @@ void Database<T> :: load()
|
|||
unsigned int db_size;
|
||||
bool valid;
|
||||
|
||||
if (_file.exists() == false)
|
||||
if (file_exists(&_file) == false)
|
||||
return;
|
||||
else if (_file.open(OPEN_READ) == false)
|
||||
return;
|
||||
|
|
|
@ -64,11 +64,6 @@ struct file : public std::fstream {
|
|||
*/
|
||||
~file();
|
||||
|
||||
/**
|
||||
* @return True if the file exists on disk, False otherwise.
|
||||
*/
|
||||
bool exists();
|
||||
|
||||
/**
|
||||
* Call to open a file for either reading or writing.
|
||||
*
|
||||
|
@ -113,5 +108,8 @@ const std::string file_path(struct file *);
|
|||
/* Returns the version number of the file. */
|
||||
const unsigned int file_version(struct file *);
|
||||
|
||||
/* Returns true if the file exists on disk and false otherwise. */
|
||||
bool file_exists(struct file *);
|
||||
|
||||
|
||||
#endif /* OCARINA_CORE_FILE_H */
|
||||
|
|
|
@ -18,8 +18,8 @@ static void test_filepath()
|
|||
test_equal(file_version(&b), (unsigned)0);
|
||||
test_equal((std::string)file_path(&b), filepath);
|
||||
|
||||
test_equal(a.exists(), false);
|
||||
test_equal(b.exists(), false);
|
||||
test_equal(file_exists(&a), false);
|
||||
test_equal(file_exists(&b), false);
|
||||
test_equal(test_data_file_exists(NULL), false);
|
||||
|
||||
g_free(filepath);
|
||||
|
@ -49,7 +49,7 @@ static void test_io()
|
|||
test_equal(a.open(OPEN_WRITE), true);
|
||||
a << "ABCDE FGHIJ KLMNO PQRST UVWXYZ" << std::endl;
|
||||
a.close();
|
||||
test_equal(a.exists(), true);
|
||||
test_equal(file_exists(&a), true);
|
||||
|
||||
file b("file.txt", 0);
|
||||
std::string res;
|
||||
|
|
Loading…
Reference in New Issue