Fixed Directory for Windows.
This commit is contained in:
parent
0b298c6130
commit
2a2296685e
@ -164,8 +164,6 @@ set(EHS_SOURCES
|
||||
include/ehs/io/mdl/MdlCodec.h
|
||||
include/ehs/io/UsbBase.h
|
||||
src/io/UsbBase.cpp
|
||||
include/ehs/io/Usb_LNX.h
|
||||
src/io/Usb_LNX.cpp
|
||||
include/ehs/db/DbTable.h
|
||||
include/ehs/db/DbObject.h
|
||||
include/ehs/db/DbVar.h
|
||||
@ -177,8 +175,6 @@ set(EHS_SOURCES
|
||||
src/db/DbTable.cpp
|
||||
include/ehs/io/BaseDirectory.h
|
||||
src/io/BaseDirectory.cpp
|
||||
include/ehs/io/Directory_LNX.h
|
||||
src/io/Directory_LNX.cpp
|
||||
include/ehs/io/Directory.h
|
||||
)
|
||||
|
||||
@ -196,6 +192,7 @@ if (IS_OS_WINDOWS)
|
||||
src/io/Window_W32.cpp include/ehs/io/Window_W32.h
|
||||
src/io/COM.cpp include/ehs/io/COM.h
|
||||
src/system/CPU_MSVC_AMD64.asm src/HRNG_MSVC.asm src/Math_MSVC_AMD64.asm
|
||||
src/io/Directory_W32.cpp include/ehs/io/Directory_W32.h
|
||||
)
|
||||
elseif (IS_OS_LINUX)
|
||||
list(APPEND EHS_SOURCES
|
||||
@ -210,6 +207,8 @@ elseif (IS_OS_LINUX)
|
||||
src/io/audio/AudioDevice_ALSA.cpp include/ehs/io/audio/AudioDevice_ALSA.h
|
||||
src/system/FileSystem.cpp include/ehs/system/FileSystem.h
|
||||
src/system/User.cpp include/ehs/system/User.h
|
||||
src/io/Directory_LNX.cpp include/ehs/io/Directory_LNX.h
|
||||
src/io/Usb_LNX.cpp include/ehs/io/Usb_LNX.h
|
||||
)
|
||||
|
||||
set(LINUX_WINDOW_SYSTEM "Wayland" CACHE STRING "Linux Window System")
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include "ehs/system/OS.h"
|
||||
|
||||
#if defined(EHS_OS_WINDOWS)
|
||||
#include "Directory_W32.h"
|
||||
#include "Directory_W32.h"
|
||||
#elif defined(EHS_OS_LINUX)
|
||||
#include "Directory_LNX.h"
|
||||
#include "Directory_LNX.h"
|
||||
#endif
|
16
include/ehs/io/Directory_W32.h
Normal file
16
include/ehs/io/Directory_W32.h
Normal file
@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include "BaseDirectory.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class Directory : public BaseDirectory
|
||||
{
|
||||
public:
|
||||
static Array<Str_8> GetAllFiles(const Str_8 &dir);
|
||||
|
||||
static void CreateRecursive(Str_8 dir);
|
||||
|
||||
static void Create(const Str_8 &dir);
|
||||
};
|
||||
}
|
@ -13,14 +13,14 @@ namespace ehs
|
||||
|
||||
if (!dir.Size())
|
||||
{
|
||||
EHS_LOG_INT(LogType::WARN, 2, "The given directory was empty.");
|
||||
EHS_LOG_INT(LogType::WARN, 1, "The given directory was empty.");
|
||||
return result;
|
||||
}
|
||||
|
||||
DIR* hdl = opendir(dir);
|
||||
if (!hdl)
|
||||
{
|
||||
EHS_LOG_INT(LogType::ERR, 3, "Failed to open directory, \"" + dir + "\".");
|
||||
EHS_LOG_INT(LogType::ERR, 2, "Failed to open directory, \"" + dir + "\".");
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -31,7 +31,7 @@ namespace ehs
|
||||
|
||||
if (closedir(hdl) == -1)
|
||||
{
|
||||
EHS_LOG_INT(LogType::ERR, 4, "Failed to close directory, \"" + dir + "\".");
|
||||
EHS_LOG_INT(LogType::ERR, 3, "Failed to close directory, \"" + dir + "\".");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
87
src/io/Directory_W32.cpp
Normal file
87
src/io/Directory_W32.cpp
Normal file
@ -0,0 +1,87 @@
|
||||
#include "ehs/io/Directory_W32.h"
|
||||
#include "ehs/UTF.h"
|
||||
#include "ehs/Log.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
Array<Str_8> GetAllFiles(const Str_8 &dir)
|
||||
{
|
||||
Array<Str_8> result;
|
||||
|
||||
if (!dir.Size())
|
||||
{
|
||||
EHS_LOG_INT(LogType::WARN, 1, "The given directory was empty.");
|
||||
return result;
|
||||
}
|
||||
|
||||
WIN32_FIND_DATAW fData;
|
||||
HANDLE hFind = FindFirstFileW(UTF::To_16(dir) + L"\\*", &fData);
|
||||
|
||||
if (hFind == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
EHS_LOG_INT(LogType::ERR, 2, "Failed to open directory, \"" + dir + "\".");
|
||||
return result;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
Str_8 fName = UTF::To_8(fData.cFileName);
|
||||
if (fName == "." || fName == "..")
|
||||
continue;
|
||||
|
||||
result.Push(fName);
|
||||
}
|
||||
while (FindNextFileW(hFind, &fData) != 0);
|
||||
|
||||
if (!FindClose(hFind))
|
||||
{
|
||||
EHS_LOG_INT(LogType::ERR, 3, "Failed to close directory, \"" + dir + "\".");
|
||||
return result;
|
||||
}
|
||||
|
||||
EHS_LOG_SUCCESS();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void CreateRecursive(Str_8 dir)
|
||||
{
|
||||
dir = dir.ReplaceAll("\\", "/");
|
||||
|
||||
const Vector<Str_8> dirs = dir.Split("/");
|
||||
|
||||
for (UInt_64 i = 0; i < dirs.Size(); ++i)
|
||||
{
|
||||
const Str_8 final = (Str_8&&)dirs[i];
|
||||
for (UInt_64 x = 0; x < i; ++x)
|
||||
dirs[i] += dirs[x] + "/";
|
||||
|
||||
dirs[i] += final;
|
||||
|
||||
if (!CreateDirectoryW(UTF::To_16(dirs[i]), nullptr))
|
||||
{
|
||||
if (const DWORD code = GetLastError(); code != ERROR_ALREADY_EXISTS)
|
||||
{
|
||||
EHS_LOG_INT(LogType::ERR, 1, "Failed to create directory, \"" + dirs[i] + "\" with error #" + Str_8::FromNum(code) + ".");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EHS_LOG_SUCCESS();
|
||||
}
|
||||
|
||||
void Create(const Str_8 &dir)
|
||||
{
|
||||
if (!CreateDirectoryW(UTF::To_16(dir), nullptr))
|
||||
{
|
||||
if (const DWORD code = GetLastError(); code != ERROR_ALREADY_EXISTS)
|
||||
{
|
||||
EHS_LOG_INT(LogType::ERR, 1, "Failed to create directory, \"" + dir + "\" with error #" + Str_8::FromNum(code) + ".");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
EHS_LOG_SUCCESS();
|
||||
}
|
||||
}
|
@ -1,8 +1,6 @@
|
||||
#include "ehs/io/UsbBase.h"
|
||||
#include "ehs/Util.h"
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
UsbBase::UsbBase()
|
||||
|
Loading…
Reference in New Issue
Block a user