Commit dbd35d1a authored by nanahira's avatar nanahira

add missing functions in myfilesystem in Linux/Mac

parent 9806dea0
......@@ -75,6 +75,12 @@ public:
return SHFileOperationW(&lpFileOp) == 0;
}
static bool DeleteDir(const char* dir) {
wchar_t wdir[1024];
BufferIO::DecodeUTF8(dir, wdir);
return DeleteDir(wdir);
}
static void TraversalDir(const wchar_t* wpath, const std::function<void(const wchar_t*, bool)>& cb) {
wchar_t findstr[1024];
wcscpy(findstr, wpath);
......@@ -137,6 +143,47 @@ public:
return MakeDir(dir);
}
static bool Rename(const wchar_t* woldname, const wchar_t* wnewname) {
char oldname[1024];
char newname[1024];
BufferIO::EncodeUTF8(woldname, oldname);
BufferIO::EncodeUTF8(wnewname, newname);
return Rename(oldname, newname);
}
static bool Rename(const char* oldname, const char* newname) {
return rename(oldname, newname) == 0;
}
static bool DeleteDir(const wchar_t* wdir) {
char dir[1024];
BufferIO::EncodeUTF8(wdir, dir);
return DeleteDir(dir);
}
static bool DeleteDir(const char* dir) {
bool success = true;
TraversalDir(dir, [dir, &success](const char *name, bool isdir) {
if(strcmp(name, ".") == 0 || strcmp(name, "..") == 0)
return;
char full_path[256];
sprintf(full_path, "%s/%s", dir, name);
if (isdir)
{
if(!DeleteDir(full_path))
success = false;
}
else
{
if(unlink(full_path) != 0)
success = false;
}
});
if (rmdir(dir) != 0)
success = false;
return success;
}
struct file_unit {
std::string filename;
bool is_dir;
......@@ -158,6 +205,8 @@ public:
stat(fname, &fileStat);
funit.filename = std::string(dirp->d_name);
funit.is_dir = S_ISDIR(fileStat.st_mode);
if(funit.is_dir && (strcmp(dirp->d_name, ".") == 0 || strcmp(dirp->d_name, "..") == 0))
continue;
file_list.push_back(funit);
}
closedir(dir);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment