X-Git-Url: https://feistymeow.org/gitweb/?a=blobdiff_plain;f=nucleus%2Flibrary%2Ffilesystem%2Fdirectory.cpp;h=f1341e683f50f197122882ce781c2094fd8a2ddc;hb=0f0df8de389914b66cf70759575eef0b8261c797;hp=8e7789521e434281fb47837dcea7477efc403d1e;hpb=6027706dda64d8c7179306263358702354efddc7;p=feisty_meow.git diff --git a/nucleus/library/filesystem/directory.cpp b/nucleus/library/filesystem/directory.cpp index 8e778952..f1341e68 100644 --- a/nucleus/library/filesystem/directory.cpp +++ b/nucleus/library/filesystem/directory.cpp @@ -15,7 +15,6 @@ #include "directory.h" #include "filename.h" -#include #include #include #include @@ -27,13 +26,15 @@ #include #include #include -#ifdef __UNIX__ + +#include "../algorithms/sorts.h" +#if defined(__UNIX__) || defined(__GNU_WINDOWS__) #include #include #include #include #endif -#ifdef __WIN32__ +#ifdef _MSC_VER #include #endif @@ -101,7 +102,7 @@ astring directory::absolute_path(const astring &rel_path) { char abs_path[MAX_ABS_PATH + 1]; abs_path[0] = '\0'; -#ifdef __WIN32__ +#ifdef _MSC_VER if (!_fullpath(abs_path, rel_path.s(), MAX_ABS_PATH)) return ""; return abs_path; #else @@ -113,7 +114,7 @@ astring directory::absolute_path(const astring &rel_path) astring directory::current() { astring to_return("."); // failure result. -#ifdef __WIN32__ +#ifdef _MSC_VER flexichar buffer[MAX_ABS_PATH + 1] = { '\0' }; GetCurrentDirectory(MAX_ABS_PATH, buffer); to_return = from_unicode_temp(buffer); @@ -151,7 +152,7 @@ bool directory::rescan() _folders->reset(); astring cur_dir = "."; astring par_dir = ".."; -#ifdef __WIN32__ +#ifdef _MSC_VER // start reading the directory. WIN32_FIND_DATA wfd; astring real_path_spec = *_path + "/" + *_pattern; @@ -194,8 +195,7 @@ bool directory::rescan() } } while (FindNextFile(search_handle, &wfd)); FindClose(search_handle); -#endif -#ifdef __UNIX__ +#else DIR *dir = opendir(_path->s()); //hmmm: could check errno to determine what caused the problem. if (!dir) return false; @@ -209,9 +209,9 @@ bool directory::rescan() if (add_it && !fnmatch(_pattern->s(), file, 0)) { filename temp_name(*_path, file); if (!temp_name.is_normal()) { -#ifdef DEBUG_DIRECTORY +//#ifdef DEBUG_DIRECTORY LOG(astring("skipping abnormal file: ") + temp_name); -#endif +//#endif entry = readdir(dir); continue; // cannot be adding goofy named pipes etc; cannot manage those. } @@ -234,10 +234,9 @@ bool directory::rescan() bool directory::make_directory(const astring &path) { -#ifdef __UNIX__ +#if defined(__UNIX__) || defined(__GNU_WINDOWS__) int mk_ret = mkdir(path.s(), 0777); -#endif -#ifdef __WIN32__ +#else int mk_ret = mkdir(path.s()); #endif return !mk_ret; @@ -245,10 +244,9 @@ bool directory::make_directory(const astring &path) bool directory::remove_directory(const astring &path) { -#ifdef __UNIX__ +#if defined(__UNIX__) || defined(__GNU_WINDOWS__) int rm_ret = rmdir(path.s()); -#endif -#ifdef __WIN32__ +#else int rm_ret = rmdir(path.s()); #endif return !rm_ret; @@ -259,12 +257,13 @@ bool directory::recursive_create(const astring &directory_name) FUNCDEF("recursive_create"); filename dir(directory_name); string_array pieces; - dir.separate(pieces); + bool rooted; + dir.separate(rooted, pieces); for (int i = 0; i < pieces.length(); i++) { // check each location along the way. string_array partial = pieces.subarray(0, i); filename curr; - curr.join(partial); // this is our current location. + curr.join(rooted, partial); // this is our current location. // make sure, if we see a drive letter component, that we call it // a proper directory name. if (curr.raw()[curr.raw().end()] == ':') @@ -282,3 +281,4 @@ bool directory::recursive_create(const astring &directory_name) } } // namespace. +