update experimental::filesystem
This commit is contained in:
@@ -36,6 +36,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
#include <nana/deploy.hpp>
|
#include <nana/deploy.hpp>
|
||||||
|
|
||||||
@@ -72,6 +73,8 @@ namespace filesystem
|
|||||||
enum class perms
|
enum class perms
|
||||||
{
|
{
|
||||||
none = 0, ///< There are no permissions set for the file.
|
none = 0, ///< There are no permissions set for the file.
|
||||||
|
all = 0x1FF, ///< owner_all | group_all | others_all
|
||||||
|
mask = 0xFFF, ///< all | set_uid | set_gid | sticky_bit.
|
||||||
unknown = 0xFFFF ///< not known, such as when a file_status object is created without specifying the permissions
|
unknown = 0xFFFF ///< not known, such as when a file_status object is created without specifying the permissions
|
||||||
};
|
};
|
||||||
//enum class copy_options;
|
//enum class copy_options;
|
||||||
@@ -96,6 +99,7 @@ namespace filesystem
|
|||||||
uintmax_t free;
|
uintmax_t free;
|
||||||
uintmax_t available;
|
uintmax_t available;
|
||||||
};
|
};
|
||||||
|
|
||||||
using file_time_type = std::chrono::time_point< std::chrono::system_clock>;// trivial-clock> ;
|
using file_time_type = std::chrono::time_point< std::chrono::system_clock>;// trivial-clock> ;
|
||||||
|
|
||||||
class file_status
|
class file_status
|
||||||
@@ -104,26 +108,18 @@ namespace filesystem
|
|||||||
perms m_prms = perms::unknown;
|
perms m_prms = perms::unknown;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit file_status(file_type ft = file_type::none, perms prms = perms::unknown)
|
explicit file_status(file_type ft = file_type::none, perms prms = perms::unknown);
|
||||||
:m_ft{ft}, m_prms{prms}
|
|
||||||
{}
|
|
||||||
|
|
||||||
file_status(const file_status& fs) : m_ft{fs.m_ft}, m_prms{fs.m_prms}{} // = default;
|
|
||||||
file_status(file_status&& fs) : m_ft{fs.m_ft}, m_prms{fs.m_prms}{} // = default;
|
|
||||||
|
|
||||||
~file_status(){};
|
|
||||||
file_status& operator=(const file_status&) = default;
|
|
||||||
file_status& operator=(file_status&&fs) // = default;
|
|
||||||
{
|
|
||||||
m_ft=fs.m_ft; m_prms = fs.m_prms;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
// observers
|
// observers
|
||||||
file_type type() const { return m_ft;}
|
file_type type() const;
|
||||||
perms permissions() const { return m_prms;}
|
perms permissions() const;
|
||||||
|
|
||||||
// modifiers
|
// modifiers
|
||||||
void type (file_type ft) { m_ft=ft ;}
|
void type(file_type ft);
|
||||||
void permissions(perms prms) { m_prms = prms; }
|
void permissions(perms prms);
|
||||||
|
private:
|
||||||
|
file_type value_;
|
||||||
|
perms perms_;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// concerned only with lexical and syntactic aspects and does not necessarily exist in
|
/// concerned only with lexical and syntactic aspects and does not necessarily exist in
|
||||||
@@ -418,11 +414,11 @@ namespace filesystem
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// file_status status(const path& p);
|
file_status status(const path& p);
|
||||||
bool file_attrib(const nana::string& file, attribute&);
|
bool file_attrib(const nana::string& file, attribute&);
|
||||||
|
|
||||||
inline bool is_directory(file_status s) { return s.type() == file_type::directory ;}
|
inline bool is_directory(file_status s) { return s.type() == file_type::directory ;}
|
||||||
inline bool is_directory(const path& p) { return directory_iterator(p)->attr.directory; }//works??
|
bool is_directory(const path& p);
|
||||||
inline bool is_directory(const directory_entry& d) { return d.attr.directory; }
|
inline bool is_directory(const directory_entry& d) { return d.attr.directory; }
|
||||||
//bool is_directory(const path& p, error_code& ec) noexcept;
|
//bool is_directory(const path& p, error_code& ec) noexcept;
|
||||||
|
|
||||||
@@ -436,8 +432,7 @@ namespace filesystem
|
|||||||
}
|
}
|
||||||
//bool is_empty(const path& p, error_code& ec) noexcept;
|
//bool is_empty(const path& p, error_code& ec) noexcept;
|
||||||
|
|
||||||
uintmax_t file_size(const nana::string& file); // deprecate?
|
std::uintmax_t file_size(const path& p);
|
||||||
inline uintmax_t file_size(const path& p){return file_size(p.filename());}
|
|
||||||
//uintmax_t file_size(const path& p, error_code& ec) noexcept;
|
//uintmax_t file_size(const path& p, error_code& ec) noexcept;
|
||||||
//long long filesize(const nana::string& file);
|
//long long filesize(const nana::string& file);
|
||||||
|
|
||||||
@@ -448,18 +443,18 @@ namespace filesystem
|
|||||||
//bool create_directory(const path& p, error_code& ec) noexcept;
|
//bool create_directory(const path& p, error_code& ec) noexcept;
|
||||||
bool create_directory(const path& p, const path& attributes);
|
bool create_directory(const path& p, const path& attributes);
|
||||||
//bool create_directory(const path& p, const path& attributes, error_code& ec) noexcept;
|
//bool create_directory(const path& p, const path& attributes, error_code& ec) noexcept;
|
||||||
bool create_directory(const std::wstring& p, bool & if_exist);
|
|
||||||
|
/*
|
||||||
|
bool create_directory(const std::wstring& p, bool & if_exist); //deprecated
|
||||||
inline bool create_directory(const path& p, bool & if_exist)
|
inline bool create_directory(const path& p, bool & if_exist)
|
||||||
{
|
{
|
||||||
return create_directory(p.filename(), if_exist);
|
return create_directory(p.filename(), if_exist);
|
||||||
};
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
bool modified_file_time(const std::wstring& file, struct tm&);
|
bool modified_file_time(const std::wstring& file, struct tm&);
|
||||||
|
|
||||||
|
|
||||||
path path_user();
|
path path_user();
|
||||||
|
|
||||||
|
|
||||||
path current_path();
|
path current_path();
|
||||||
//path current_path(error_code& ec);
|
//path current_path(error_code& ec);
|
||||||
void current_path(const path& p);
|
void current_path(const path& p);
|
||||||
|
|||||||
@@ -25,9 +25,9 @@ namespace filesystem
|
|||||||
};
|
};
|
||||||
|
|
||||||
bool file_attrib(const ::std::string& file, attribute&);
|
bool file_attrib(const ::std::string& file, attribute&);
|
||||||
long long filesize(const nana::string& file);
|
//long long filesize(const nana::string& file); //deprecated
|
||||||
|
|
||||||
bool mkdir(const ::std::string& dir, bool & if_exist);
|
//bool mkdir(const ::std::string& dir, bool & if_exist); //deprecated
|
||||||
bool modified_file_time(const ::std::string& file, struct tm&);
|
bool modified_file_time(const ::std::string& file, struct tm&);
|
||||||
|
|
||||||
std::wstring path_user();
|
std::wstring path_user();
|
||||||
@@ -37,6 +37,7 @@ namespace filesystem
|
|||||||
bool rmdir(const char* dir, bool fails_if_not_empty);
|
bool rmdir(const char* dir, bool fails_if_not_empty);
|
||||||
nana::string root(const nana::string& path);
|
nana::string root(const nana::string& path);
|
||||||
|
|
||||||
|
/*
|
||||||
class path
|
class path
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -59,6 +60,7 @@ namespace filesystem
|
|||||||
std::string text_;
|
std::string text_;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
}//end namespace filesystem
|
}//end namespace filesystem
|
||||||
}//end namespace nana
|
}//end namespace nana
|
||||||
|
|||||||
@@ -36,9 +36,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace nana {
|
namespace nana { namespace experimental {
|
||||||
namespace experimental
|
|
||||||
{
|
|
||||||
namespace filesystem
|
namespace filesystem
|
||||||
{
|
{
|
||||||
//Because of No wide character version of POSIX
|
//Because of No wide character version of POSIX
|
||||||
@@ -48,6 +46,32 @@ namespace nana {
|
|||||||
const wchar_t* splstr = L"/\\";
|
const wchar_t* splstr = L"/\\";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
//class file_status
|
||||||
|
file_status::file_status(file_type ft, perms prms)
|
||||||
|
: value_{ft}, perms_{prms}
|
||||||
|
{}
|
||||||
|
|
||||||
|
file_type file_status::type() const
|
||||||
|
{
|
||||||
|
return value_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void file_status::type(file_type ft)
|
||||||
|
{
|
||||||
|
value_ = ft;
|
||||||
|
}
|
||||||
|
|
||||||
|
perms file_status::permissions() const
|
||||||
|
{
|
||||||
|
return perms_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void file_status::permissions(perms prms)
|
||||||
|
{
|
||||||
|
perms_ = prms;
|
||||||
|
}
|
||||||
|
//end filestatus
|
||||||
|
|
||||||
//class path
|
//class path
|
||||||
path::path() {}
|
path::path() {}
|
||||||
|
|
||||||
@@ -257,6 +281,51 @@ namespace nana {
|
|||||||
#endif
|
#endif
|
||||||
}//end namespace detail
|
}//end namespace detail
|
||||||
|
|
||||||
|
file_status status(const path& p)
|
||||||
|
{
|
||||||
|
#if defined(NANA_WINDOWS)
|
||||||
|
auto attr = ::GetFileAttributesW(p.c_str());
|
||||||
|
if(INVALID_FILE_ATTRIBUTES == attr)
|
||||||
|
return file_status{file_type::unknown};
|
||||||
|
|
||||||
|
return file_status{(FILE_ATTRIBUTE_DIRECTORY & attr) ? file_type::directory : file_type::regular, perms::all};
|
||||||
|
#elif defined(NANA_POSIX)
|
||||||
|
struct stat path_stat;
|
||||||
|
if(0 != ::stat(p.c_str(), &path_stat))
|
||||||
|
{
|
||||||
|
if(errno == ENOENT || errno == ENOTDIR)
|
||||||
|
return file_status{file_type::not_found};
|
||||||
|
|
||||||
|
return file_status{file_type::unknown};
|
||||||
|
}
|
||||||
|
|
||||||
|
auto prms = static_cast<perms>(path_stat.st_mode & static_cast<unsigned>(perms::mask));
|
||||||
|
|
||||||
|
if(S_ISREG(path_stat.st_mode))
|
||||||
|
return file_status{file_type::regular, prms};
|
||||||
|
|
||||||
|
if(S_ISDIR(path_stat.st_mode))
|
||||||
|
return file_status{file_type::directory, prms};
|
||||||
|
|
||||||
|
if(S_ISLNK(path_stat.st_mode))
|
||||||
|
return file_status{file_type::symlink, prms};
|
||||||
|
|
||||||
|
if(S_ISBLK(path_stat.st_mode))
|
||||||
|
return file_status{file_type::block, prms};
|
||||||
|
|
||||||
|
if(S_ISCHR(path_stat.st_mode))
|
||||||
|
return file_status{file_type::character, prms};
|
||||||
|
|
||||||
|
if(S_ISFIFO(path_stat.st_mode))
|
||||||
|
return file_status{file_type::fifo, prms};
|
||||||
|
|
||||||
|
if(S_ISSOCK(path_stat.st_mode))
|
||||||
|
return file_status{file_type::socket, prms};
|
||||||
|
|
||||||
|
return file_status{file_type::unknown};
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
bool file_attrib(const nana::string& file, attribute& attr)
|
bool file_attrib(const nana::string& file, attribute& attr)
|
||||||
{
|
{
|
||||||
#if defined(NANA_WINDOWS)
|
#if defined(NANA_WINDOWS)
|
||||||
@@ -284,7 +353,12 @@ namespace nana {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
uintmax_t file_size(const nana::string& file)
|
bool is_directory(const path& p)
|
||||||
|
{
|
||||||
|
return (status(p).type() == file_type::directory);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::uintmax_t file_size(const path& p)
|
||||||
{
|
{
|
||||||
#if defined(NANA_WINDOWS)
|
#if defined(NANA_WINDOWS)
|
||||||
//Some compilation environment may fail to link to GetFileSizeEx
|
//Some compilation environment may fail to link to GetFileSizeEx
|
||||||
@@ -292,7 +366,7 @@ namespace nana {
|
|||||||
GetFileSizeEx_fptr_t get_file_size_ex = reinterpret_cast<GetFileSizeEx_fptr_t>(::GetProcAddress(::GetModuleHandleA("Kernel32.DLL"), "GetFileSizeEx"));
|
GetFileSizeEx_fptr_t get_file_size_ex = reinterpret_cast<GetFileSizeEx_fptr_t>(::GetProcAddress(::GetModuleHandleA("Kernel32.DLL"), "GetFileSizeEx"));
|
||||||
if (get_file_size_ex)
|
if (get_file_size_ex)
|
||||||
{
|
{
|
||||||
HANDLE handle = ::CreateFile(file.c_str(), GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
|
HANDLE handle = ::CreateFile(p.c_str(), GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
|
||||||
if (INVALID_HANDLE_VALUE != handle)
|
if (INVALID_HANDLE_VALUE != handle)
|
||||||
{
|
{
|
||||||
LARGE_INTEGER li;
|
LARGE_INTEGER li;
|
||||||
@@ -304,24 +378,19 @@ namespace nana {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
#elif defined(NANA_LINUX)
|
#elif defined(NANA_POSIX)
|
||||||
FILE * stream = ::fopen(static_cast<std::string>(nana::charset(file)).c_str(), "rb");
|
FILE * stream = ::fopen(p.c_str(), "rb");
|
||||||
long long size = 0;
|
long long size = 0;
|
||||||
if (stream)
|
if (stream)
|
||||||
{
|
{
|
||||||
|
# if defined(NANA_LINUX)
|
||||||
fseeko64(stream, 0, SEEK_END);
|
fseeko64(stream, 0, SEEK_END);
|
||||||
size = ftello64(stream);
|
size = ftello64(stream);
|
||||||
fclose(stream);
|
|
||||||
}
|
|
||||||
return size;
|
|
||||||
# elif defined(NANA_MACOS)
|
# elif defined(NANA_MACOS)
|
||||||
FILE * stream = ::fopen(static_cast<std::string>(nana::charset(file)).c_str(), "rb");
|
|
||||||
long long size = 0;
|
|
||||||
if (stream)
|
|
||||||
{
|
|
||||||
fseeko(stream, 0, SEEK_END);
|
fseeko(stream, 0, SEEK_END);
|
||||||
size = ftello(stream);
|
size = ftello(stream);
|
||||||
fclose(stream);
|
# endif
|
||||||
|
::fclose(stream);
|
||||||
}
|
}
|
||||||
return size;
|
return size;
|
||||||
#endif
|
#endif
|
||||||
@@ -361,7 +430,18 @@ namespace nana {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool create_directory(const std::wstring& path, bool & if_exist)
|
|
||||||
|
bool create_directory(const path& p)
|
||||||
|
{
|
||||||
|
#if defined(NANA_WINDOWS)
|
||||||
|
return (FALSE != ::CreateDirectoryW(p.c_str(), 0));
|
||||||
|
#elif defined(NANA_POSIX)
|
||||||
|
return (0 == ::mkdir(p.c_str(), static_cast<int>(perms::all)));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
bool create_directory(const std::wstring& path, bool & if_exist) //deprecated
|
||||||
{
|
{
|
||||||
if_exist = false;
|
if_exist = false;
|
||||||
if (path.size() == 0) return false;
|
if (path.size() == 0) return false;
|
||||||
@@ -411,7 +491,7 @@ namespace nana {
|
|||||||
}
|
}
|
||||||
return mkstat;
|
return mkstat;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
bool rmfile(const path& p)
|
bool rmfile(const path& p)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -47,10 +47,11 @@ namespace filesystem
|
|||||||
typedef std::string string_t;
|
typedef std::string string_t;
|
||||||
const char* splstr = "/\\";
|
const char* splstr = "/\\";
|
||||||
#else
|
#else
|
||||||
typedef nana::string string_t;
|
typedef std::wstring string_t;
|
||||||
const nana::char_t* splstr = L"/\\";
|
const wchar_t* splstr = L"/\\";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
//class path
|
//class path
|
||||||
path::path(){}
|
path::path(){}
|
||||||
|
|
||||||
@@ -122,7 +123,7 @@ namespace filesystem
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
//end class path
|
//end class path
|
||||||
|
*/
|
||||||
|
|
||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
@@ -219,7 +220,8 @@ namespace filesystem
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
long long filesize(const std::string& file)
|
/*
|
||||||
|
long long filesize(const std::string& file) //deprecated
|
||||||
{
|
{
|
||||||
#if defined(NANA_WINDOWS)
|
#if defined(NANA_WINDOWS)
|
||||||
//Some compilation environment may fail to link to GetFileSizeEx
|
//Some compilation environment may fail to link to GetFileSizeEx
|
||||||
@@ -256,6 +258,7 @@ namespace filesystem
|
|||||||
return size;
|
return size;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
bool modified_file_time(const ::std::string& file, struct tm& t)
|
bool modified_file_time(const ::std::string& file, struct tm& t)
|
||||||
{
|
{
|
||||||
@@ -291,7 +294,8 @@ namespace filesystem
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool mkdir(const std::string& path, bool & if_exist)
|
/*
|
||||||
|
bool mkdir(const std::string& path, bool & if_exist) //deprecated
|
||||||
{
|
{
|
||||||
if_exist = false;
|
if_exist = false;
|
||||||
if(path.size() == 0) return false;
|
if(path.size() == 0) return false;
|
||||||
@@ -341,6 +345,7 @@ namespace filesystem
|
|||||||
}
|
}
|
||||||
return mkstat;
|
return mkstat;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
bool rmfile(const char* file)
|
bool rmfile(const char* file)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
#include <nana/gui.hpp>
|
#include <nana/gui.hpp>
|
||||||
#include <nana/gui/filebox.hpp>
|
#include <nana/gui/filebox.hpp>
|
||||||
#include <nana/filesystem/fs_utility.hpp>
|
#include <nana/filesystem/fs_utility.hpp>
|
||||||
|
#include <nana/filesystem/filesystem.hpp>
|
||||||
|
|
||||||
#if defined(NANA_WINDOWS)
|
#if defined(NANA_WINDOWS)
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
@@ -645,8 +646,29 @@ namespace nana
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
using file_type = nana::experimental::filesystem::file_type;
|
||||||
|
|
||||||
|
experimental::filesystem::path fspath(fb_.addr_.filesystem + path);
|
||||||
|
|
||||||
|
auto fs = experimental::filesystem::status(fspath);
|
||||||
|
|
||||||
|
if(fs.type() != file_type::not_found && fs.type() != file_type::none)
|
||||||
|
{
|
||||||
|
mb<<L"The folder is existing, please rename it.";
|
||||||
|
mb();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(false == experimental::filesystem::create_directory(fspath))
|
||||||
|
{
|
||||||
|
mb<<L"Failed to create the folder, please rename it.";
|
||||||
|
mb();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
bool if_exist;
|
bool if_exist;
|
||||||
if(false == nana::filesystem::mkdir(fb_.addr_.filesystem + path, if_exist))
|
if(false == nana::filesystem::mkdir(fb_.addr_.filesystem + path, if_exist)) //deprecated
|
||||||
{
|
{
|
||||||
if(if_exist)
|
if(if_exist)
|
||||||
mb<<L"The folder is existing, please rename it.";
|
mb<<L"The folder is existing, please rename it.";
|
||||||
@@ -655,6 +677,7 @@ namespace nana
|
|||||||
mb();
|
mb();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
fb_._m_load_cat_path(fb_.addr_.filesystem);
|
fb_._m_load_cat_path(fb_.addr_.filesystem);
|
||||||
fm_.close();
|
fm_.close();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user