From 3b6718d67fbbf467cb710b65b7625403bb229186 Mon Sep 17 00:00:00 2001 From: qPCR4vir Date: Fri, 24 Jun 2016 14:22:04 +0200 Subject: [PATCH] using explicit namespaces --- include/nana/filesystem/filesystem.hpp | 4 +-- include/nana/filesystem/filesystem_ext.hpp | 17 +++++++++-- source/filesystem/filesystem.cpp | 19 ++++++------ source/gui/filebox.cpp | 35 ++++++++++------------ source/paint/image.cpp | 10 ++++--- 5 files changed, 48 insertions(+), 37 deletions(-) diff --git a/include/nana/filesystem/filesystem.hpp b/include/nana/filesystem/filesystem.hpp index a62a5707..33799b74 100644 --- a/include/nana/filesystem/filesystem.hpp +++ b/include/nana/filesystem/filesystem.hpp @@ -241,8 +241,8 @@ namespace nana { namespace experimental { namespace filesystem //observers file_status status() const; - operator const filesystem::path&() const; - const filesystem::path& path() const; + operator const path&() const { return path_; }; + const path& path() const; private: filesystem::path path_; }; diff --git a/include/nana/filesystem/filesystem_ext.hpp b/include/nana/filesystem/filesystem_ext.hpp index feb68fa9..526f3370 100644 --- a/include/nana/filesystem/filesystem_ext.hpp +++ b/include/nana/filesystem/filesystem_ext.hpp @@ -18,7 +18,11 @@ #include #include -namespace nana {namespace experimental {namespace filesystem {namespace ext { +namespace nana +{ +namespace filesystem_ext +{ + #if defined(NANA_WINDOWS) constexpr auto def_root = "C:"; constexpr auto def_rootstr = "C:\\"; @@ -153,6 +157,13 @@ inline std::string pretty_file_date(const std::experimental::filesystem::path& p { try { auto ftime = std::experimental::filesystem::last_write_time(path); + + // crash: VS2015 will not read the time for some files (for example: C:/hiberfil.sys) + // and will return file_time_type(-1) without throwing + // https://msdn.microsoft.com/en-us/library/dn823784.aspx + + if (ftime == ((std::experimental::filesystem::file_time_type::min)())) return {}; + std::time_t cftime = decltype(ftime)::clock::to_time_t(ftime); std::stringstream tm; tm << std::put_time(std::localtime(&cftime), "%Y-%m-%d, %H:%M:%S"); @@ -163,5 +174,7 @@ inline std::string pretty_file_date(const std::experimental::filesystem::path& p } } -}}}} +} // filesystem_ext +} // nana + #endif //NANA_FILESYSTEM_EXT_HPP diff --git a/source/filesystem/filesystem.cpp b/source/filesystem/filesystem.cpp index 69f467cf..7377fa70 100644 --- a/source/filesystem/filesystem.cpp +++ b/source/filesystem/filesystem.cpp @@ -36,6 +36,7 @@ #include #endif +namespace nana_fs = nana::experimental::filesystem; namespace nana { namespace experimental { namespace filesystem { @@ -143,7 +144,7 @@ namespace nana { namespace experimental { namespace filesystem path path::parent_path() const { - return{filesystem::parent_path(pathstr_)}; + return{nana_fs::parent_path(pathstr_)}; } file_type path::what() const @@ -342,17 +343,17 @@ namespace nana { namespace experimental { namespace filesystem } //class directory_entry - directory_entry::directory_entry(const filesystem::path& p) + directory_entry::directory_entry(const nana_fs::path& p) :path_{ p } {} //modifiers - void directory_entry::assign(const filesystem::path& p) + void directory_entry::assign(const nana_fs::path& p) { path_ = p; } - void directory_entry::replace_filename(const filesystem::path& p) + void directory_entry::replace_filename(const nana_fs::path& p) { path_ = path_.parent_path() / p; } @@ -360,13 +361,13 @@ namespace nana { namespace experimental { namespace filesystem //observers file_status directory_entry::status() const { - return filesystem::status(path_); + return nana_fs::status(path_); } - directory_entry::operator const filesystem::path&() const - { - return path_; - } + //directory_entry::operator const nana_fs::path&() const + //{ + // return path_; + //} const path& directory_entry::path() const { diff --git a/source/gui/filebox.cpp b/source/gui/filebox.cpp index 5f8f1311..bc697d24 100644 --- a/source/gui/filebox.cpp +++ b/source/gui/filebox.cpp @@ -30,6 +30,8 @@ #include #endif +namespace fs = nana::experimental::filesystem; + namespace nana { #if defined(NANA_POSIX) @@ -142,7 +144,7 @@ namespace nana auto path = path_.caption(); auto root = path.substr(0, path.find('/')); if(root == "HOME") - path.replace(0, 4, nana::experimental::filesystem::path_user().native()); + path.replace(0, 4, fs::path_user().native()); else if(root == "FILESYSTEM") path.erase(0, 10); else @@ -344,7 +346,7 @@ namespace nana else dir = saved_selected_path; - _m_load_cat_path(dir.size() ? dir : nana::experimental::filesystem::path_user().native()); + _m_load_cat_path(dir.size() ? dir : fs::path_user().native()); tb_file_.caption(file_with_path_removed); } @@ -427,8 +429,6 @@ namespace nana nodes_.filesystem = tree_.insert("FS.ROOT", "Filesystem"); nodes_.filesystem.value(kind::filesystem); - namespace fs = ::nana::experimental::filesystem; - std::vector paths; paths.emplace_back(fs::path_user().native()); paths.emplace_back("/"); @@ -474,7 +474,7 @@ namespace nana { auto begstr = path.substr(0, pos); if(begstr == "FS.HOME") - path.replace(0, 7, nana::experimental::filesystem::path_user().native()); + path.replace(0, 7, fs::path_user().native()); else path.erase(0, pos); return begstr; @@ -490,8 +490,6 @@ namespace nana file_container_.clear(); - namespace fs = ::nana::experimental::filesystem; - fs::directory_iterator end; for(fs::directory_iterator i(path); i != end; ++i) { @@ -508,13 +506,13 @@ namespace nana { m.bytes = fs::file_size(path + m.name); m.directory = fs::is_directory(fattr); - ::nana::experimental::filesystem::modified_file_time(path + m.name, m.modified_time); + fs::modified_file_time(path + m.name, m.modified_time); } else { m.bytes = 0; m.directory = fs::is_directory(*i); - ::nana::experimental::filesystem::modified_file_time(path + i->path().filename().native(), m.modified_time); + fs::modified_file_time(path + i->path().filename().native(), m.modified_time); } file_container_.push_back(m); @@ -530,11 +528,13 @@ namespace nana if((path.size() == 0) || (path[path.size() - 1] != '/')) path += '/'; + namespace fs = ::nana::experimental::filesystem; + auto beg_node = tree_.selected(); while(!beg_node.empty() && (beg_node != nodes_.home) && (beg_node != nodes_.filesystem)) beg_node = beg_node.owner(); - auto head = nana::experimental::filesystem::path_user().native(); + auto head = fs::path_user().native(); if(path.size() >= head.size() && (path.substr(0, head.size()) == head)) {//This is HOME path_.caption("HOME"); @@ -552,7 +552,6 @@ namespace nana if(head.size() == 0 || head[head.size() - 1] != '/') head += '/'; - namespace fs = ::nana::experimental::filesystem; fs::directory_iterator end; for(fs::directory_iterator i(head); i != end; ++i) @@ -649,20 +648,20 @@ namespace nana return; } - using file_type = nana::experimental::filesystem::file_type; + using file_type = fs::file_type; - experimental::filesystem::path fspath(fb_.addr_.filesystem + path); + fs::path fspath(fb_.addr_.filesystem + path); - auto fs = experimental::filesystem::status(fspath); + auto fst = fs::status(fspath); - if(fs.type() != file_type::not_found && fs.type() != file_type::none) + if(fst.type() != file_type::not_found && fst.type() != file_type::none) { mb<path = ipstr; } diff --git a/source/paint/image.cpp b/source/paint/image.cpp index a1e2c889..f9b6f6cf 100644 --- a/source/paint/image.cpp +++ b/source/paint/image.cpp @@ -36,6 +36,8 @@ #include "image_accessor.hpp" +namespace fs = nana::experimental::filesystem; + namespace nana { namespace paint @@ -60,7 +62,7 @@ namespace paint //class image_ico image_ico::image_ico(bool is_ico): is_ico_(is_ico){} - bool image_ico::open(const nana::experimental::filesystem::path& file) + bool image_ico::open(const fs::path& file) { close(); #if defined(NANA_WINDOWS) @@ -231,7 +233,7 @@ namespace paint return *this; } - std::shared_ptr create_image(const ::nana::experimental::filesystem::path & p) + std::shared_ptr create_image(const fs::path & p) { std::shared_ptr ptr; @@ -314,14 +316,14 @@ namespace paint bool image::open(const ::std::string& file) { - ::nana::experimental::filesystem::path path(file); + fs::path path(file); image_ptr_ = create_image(path); return (image_ptr_ ? image_ptr_->open(path) : false); } bool image::open(const std::wstring& file) { - ::nana::experimental::filesystem::path path(file); + fs::path path(file); image_ptr_ = create_image(path); return (image_ptr_ ? image_ptr_->open(path) : false); }