From b7b7292bd443224862c84b16084af697d3780b54 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sat, 19 Nov 2016 20:39:39 +0100 Subject: [PATCH] [IO] Use C++17 filesystem features for directory interaction --- src/STDInclude.hpp | 3 +++ src/Utils/IO.cpp | 42 ++++++++---------------------------------- src/Utils/IO.hpp | 1 + 3 files changed, 12 insertions(+), 34 deletions(-) diff --git a/src/STDInclude.hpp b/src/STDInclude.hpp index 17952024..26fa0ff7 100644 --- a/src/STDInclude.hpp +++ b/src/STDInclude.hpp @@ -39,6 +39,9 @@ #include #include +// Experimental C++17 features +#include + #ifdef ENABLE_DXSDK #include #pragma comment(lib, "D3dx9.lib") diff --git a/src/Utils/IO.cpp b/src/Utils/IO.cpp index e6685624..79b59507 100644 --- a/src/Utils/IO.cpp +++ b/src/Utils/IO.cpp @@ -56,45 +56,19 @@ namespace Utils bool CreateDirectory(std::string dir) { - char opath[MAX_PATH] = { 0 }; - char *p; - size_t len; + return std::experimental::filesystem::create_directories(dir); + } - strncpy_s(opath, dir.data(), sizeof(opath)); - len = strlen(opath); + std::vector ListFiles(std::string dir) + { + std::vector files; - if (opath[len - 1] == L'/') + for (auto& file : std::experimental::filesystem::directory_iterator(dir)) { - opath[len - 1] = L'\0'; + files.push_back(file.path().generic_string()); } - for (p = opath; *p; p++) - { - if (*p == L'/' || *p == L'\\') - { - *p = L'\0'; - - if (_access(opath, 0)) - { - if (_mkdir(opath) == -1) - { - return false; - } - } - - *p = L'\\'; - } - } - - if (_access(opath, 0)) - { - if (_mkdir(opath) == -1) - { - return false; - } - } - - return true; + return files; } } } diff --git a/src/Utils/IO.hpp b/src/Utils/IO.hpp index 817eb7d4..e4ee4262 100644 --- a/src/Utils/IO.hpp +++ b/src/Utils/IO.hpp @@ -6,5 +6,6 @@ namespace Utils void WriteFile(std::string file, std::string data); std::string ReadFile(std::string file); bool CreateDirectory(std::string dir); + std::vector ListFiles(std::string dir); } }