Skip to content

Commit 0eac865

Browse files
Emscripten: use Linux file system implementation
1 parent 6bc4de5 commit 0eac865

File tree

4 files changed

+5
-102
lines changed

4 files changed

+5
-102
lines changed

Platforms/Emscripten/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ set(INTERFACE
1414
set(SOURCE
1515
src/EmscriptenDebug.cpp
1616
src/EmscriptenFileSystem.cpp
17+
../Linux/src/LinuxFileSystem.cpp
1718
)
1819

1920
add_library(Diligent-EmscriptenPlatform ${SOURCE} ${INTERFACE} ${PLATFORM_INTERFACE_HEADERS})

Platforms/Emscripten/interface/EmscriptenFileSystem.hpp

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,30 +31,15 @@
3131

3232
#include "../../Basic/interface/BasicFileSystem.hpp"
3333
#include "../../Basic/interface/StandardFile.hpp"
34+
#include "../../Linux/interface/LinuxFileSystem.hpp"
3435

3536
namespace Diligent
3637
{
3738

3839
using EmscriptenFile = StandardFile;
3940

40-
struct EmscriptenFileSystem : public BasicFileSystem
41+
struct EmscriptenFileSystem : public LinuxFileSystem
4142
{
42-
public:
43-
static EmscriptenFile* OpenFile(const FileOpenAttribs& OpenAttribs);
44-
45-
static bool FileExists(const Char* strFilePath);
46-
static bool PathExists(const Char* strPath);
47-
48-
static bool CreateDirectory(const Char* strPath);
49-
static void ClearDirectory(const Char* strPath, bool Recursive = false);
50-
static void DeleteFile(const Char* strPath);
51-
static bool DeleteDirectory(const Char* strPath);
52-
static bool IsDirectory(const Char* strPath);
53-
54-
static SearchFilesResult Search(const Char* SearchPattern);
55-
static SearchFilesResult SearchRecursive(const Char* Dir, const Char* SearchPattern);
56-
57-
static std::string GetCurrentDirectory();
5843
static std::string GetLocalAppDataDirectory(const char* AppName = nullptr, bool Create = true);
5944
};
6045

Platforms/Emscripten/src/EmscriptenFileSystem.cpp

Lines changed: 0 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -24,95 +24,12 @@
2424
* of the possibility of such damages.
2525
*/
2626

27-
#include <stdio.h>
28-
#include <unistd.h>
29-
#include <cstdio>
30-
3127
#include "EmscriptenFileSystem.hpp"
32-
#include "Errors.hpp"
3328
#include "DebugUtilities.hpp"
3429

3530
namespace Diligent
3631
{
3732

38-
EmscriptenFile* EmscriptenFileSystem::OpenFile(const FileOpenAttribs& OpenAttribs)
39-
{
40-
EmscriptenFile* pFile = nullptr;
41-
try
42-
{
43-
pFile = new EmscriptenFile{OpenAttribs};
44-
}
45-
catch (const std::runtime_error& err)
46-
{
47-
}
48-
return pFile;
49-
}
50-
51-
bool EmscriptenFileSystem::FileExists(const Char* strFilePath)
52-
{
53-
FileOpenAttribs OpenAttribs;
54-
OpenAttribs.strFilePath = strFilePath;
55-
BasicFile DummyFile{OpenAttribs};
56-
const auto& Path = DummyFile.GetPath(); // This is necessary to correct slashes
57-
FILE* pFile = fopen(Path.c_str(), "r");
58-
bool Exists = (pFile != nullptr);
59-
if (Exists)
60-
fclose(pFile);
61-
return Exists;
62-
}
63-
64-
bool EmscriptenFileSystem::PathExists(const Char* strPath)
65-
{
66-
UNSUPPORTED("Not implemented");
67-
return false;
68-
}
69-
70-
bool EmscriptenFileSystem::CreateDirectory(const Char* strPath)
71-
{
72-
UNSUPPORTED("Not implemented");
73-
return false;
74-
}
75-
76-
void EmscriptenFileSystem::ClearDirectory(const Char* strPath, bool Recursive)
77-
{
78-
UNSUPPORTED("Not implemented");
79-
}
80-
81-
void EmscriptenFileSystem::DeleteFile(const Char* strPath)
82-
{
83-
remove(strPath);
84-
}
85-
86-
bool EmscriptenFileSystem::DeleteDirectory(const Char* strPath)
87-
{
88-
UNSUPPORTED("Not implemented");
89-
return false;
90-
}
91-
92-
bool EmscriptenFileSystem::IsDirectory(const Char* strPath)
93-
{
94-
UNSUPPORTED("Not implemented");
95-
return false;
96-
}
97-
98-
EmscriptenFileSystem::SearchFilesResult EmscriptenFileSystem::Search(const Char* SearchPattern)
99-
{
100-
UNSUPPORTED("Not implemented");
101-
return EmscriptenFileSystem::SearchFilesResult{};
102-
}
103-
104-
EmscriptenFileSystem::SearchFilesResult EmscriptenFileSystem::SearchRecursive(const Char* Dir, const Char* SearchPattern)
105-
{
106-
UNSUPPORTED("Not implemented");
107-
return EmscriptenFileSystem::SearchFilesResult{};
108-
}
109-
110-
std::string EmscriptenFileSystem::GetCurrentDirectory()
111-
{
112-
UNSUPPORTED("Not implemented");
113-
return std::string();
114-
}
115-
11633
std::string EmscriptenFileSystem::GetLocalAppDataDirectory(const char* AppName, bool Create)
11734
{
11835
UNSUPPORTED("Not implemented");

Platforms/Linux/src/LinuxFileSystem.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2023 Diligent Graphics LLC
2+
* Copyright 2019-2024 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -45,7 +45,7 @@
4545
namespace Diligent
4646
{
4747

48-
#if PLATFORM_LINUX || PLATFORM_APPLE
48+
#if PLATFORM_LINUX || PLATFORM_APPLE || PLATFORM_EMSCRIPTEN
4949
LinuxFile* LinuxFileSystem::OpenFile(const FileOpenAttribs& OpenAttribs)
5050
{
5151
LinuxFile* pFile = nullptr;

0 commit comments

Comments
 (0)