Skip to content

Commit

Permalink
Android file system: enabled directory manipulation functions (close #…
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMostDiligent committed Dec 5, 2023
1 parent 1897655 commit 19e6432
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 55 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,12 @@ elseif(PLATFORM_MACOS)
set(GL_SUPPORTED TRUE CACHE INTERNAL "OpenGL is supported on MacOS platform")
set(VULKAN_SUPPORTED TRUE CACHE INTERNAL "Vulkan is enabled through MoltenVK on MacOS platform")
set(ARCHIVER_SUPPORTED TRUE CACHE INTERNAL "Archiver is supported on MacOS platform")
target_compile_definitions(Diligent-PublicBuildSettings INTERFACE PLATFORM_MACOS=1)
target_compile_definitions(Diligent-PublicBuildSettings INTERFACE PLATFORM_MACOS=1 PLATFORM_APPLE=1)
elseif(PLATFORM_IOS)
set(GLES_SUPPORTED TRUE CACHE INTERNAL "OpenGLES is supported on iOS platform")
target_compile_definitions(Diligent-PublicBuildSettings INTERFACE PLATFORM_IOS=1)
target_compile_definitions(Diligent-PublicBuildSettings INTERFACE PLATFORM_IOS=1 PLATFORM_APPLE=1)
elseif(PLATFORM_TVOS)
target_compile_definitions(Diligent-PublicBuildSettings INTERFACE PLATFORM_TVOS=1)
target_compile_definitions(Diligent-PublicBuildSettings INTERFACE PLATFORM_TVOS=1 PLATFORM_APPLE=1)
elseif(PLATFORM_EMSCRIPTEN)
set(GLES_SUPPORTED TRUE CACHE INTERNAL "OpenGLES is supported on Emscripten platform")
target_compile_definitions(Diligent-PublicBuildSettings INTERFACE PLATFORM_EMSCRIPTEN=1)
Expand Down
1 change: 1 addition & 0 deletions Platforms/Android/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ set(SOURCE
src/AndroidDebug.cpp
src/AndroidFileSystem.cpp
src/AndroidPlatformMisc.cpp
../Linux/src/LinuxFileSystem.cpp
)

add_library(Diligent-AndroidPlatform ${SOURCE} ${INTERFACE} ${PLATFORM_INTERFACE_HEADERS})
Expand Down
14 changes: 3 additions & 11 deletions Platforms/Android/interface/AndroidFileSystem.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Diligent Graphics LLC
* Copyright 2019-2023 Diligent Graphics LLC
* Copyright 2015-2019 Egor Yusov
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -32,7 +32,7 @@
#include <fstream>
#include <android/asset_manager.h>

#include "../../Basic/interface/BasicFileSystem.hpp"
#include "../../Linux/interface/LinuxFileSystem.hpp"
#include "../../../Primitives/interface/DataBlob.h"

struct ANativeActivity;
Expand Down Expand Up @@ -69,7 +69,7 @@ class AndroidFile : public BasicFile


/// Android file system implementation.
struct AndroidFileSystem : public BasicFileSystem
struct AndroidFileSystem : public LinuxFileSystem
{
public:
/// Initializes the file system.
Expand All @@ -91,14 +91,6 @@ struct AndroidFileSystem : public BasicFileSystem
static AndroidFile* OpenFile(const FileOpenAttribs& OpenAttribs);

static bool FileExists(const Char* strFilePath);
static bool PathExists(const Char* strPath);

static bool CreateDirectory(const Char* strPath);
static void ClearDirectory(const Char* strPath);
static void DeleteFile(const Char* strPath);
static bool IsDirectory(const Char* strPath);

static std::vector<std::unique_ptr<FindFileData>> Search(const Char* SearchPattern);

static std::string GetLocalAppDataDirectory(const char* AppName = nullptr, bool Create = true);
};
Expand Down
34 changes: 0 additions & 34 deletions Platforms/Android/src/AndroidFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,40 +249,6 @@ bool AndroidFileSystem::FileExists(const Char* strFilePath)
return Exists;
}

bool AndroidFileSystem::PathExists(const Char* strPath)
{
UNSUPPORTED("Not implemented");
return false;
}

bool AndroidFileSystem::CreateDirectory(const Char* strPath)
{
UNSUPPORTED("Not implemented");
return false;
}

void AndroidFileSystem::ClearDirectory(const Char* strPath)
{
UNSUPPORTED("Not implemented");
}

void AndroidFileSystem::DeleteFile(const Char* strPath)
{
UNSUPPORTED("Not implemented");
}

bool AndroidFileSystem::IsDirectory(const Char* strPath)
{
UNSUPPORTED("Not implemented");
return false;
}

std::vector<std::unique_ptr<FindFileData>> AndroidFileSystem::Search(const Char* SearchPattern)
{
UNSUPPORTED("Not implemented");
return std::vector<std::unique_ptr<FindFileData>>();
}

std::string AndroidFileSystem::GetLocalAppDataDirectory(const char* AppName /*= nullptr*/, bool Create /*= true*/)
{
const std::string& OutputFilesDir = AndroidFileSystemHelper::GetInstance().GetOutputFilesDir();
Expand Down
24 changes: 17 additions & 7 deletions Platforms/Linux/src/LinuxFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@
#include <pwd.h>
#include <errno.h>

#include "LinuxFileSystem.hpp"
#include "../interface/LinuxFileSystem.hpp"
#include "Errors.hpp"
#include "DebugUtilities.hpp"

namespace Diligent
{

#if PLATFORM_LINUX || PLATFORM_APPLE
LinuxFile* LinuxFileSystem::OpenFile(const FileOpenAttribs& OpenAttribs)
{
LinuxFile* pFile = nullptr;
Expand All @@ -56,6 +57,7 @@ LinuxFile* LinuxFileSystem::OpenFile(const FileOpenAttribs& OpenAttribs)
}
return pFile;
}
#endif

bool LinuxFileSystem::FileExists(const Char* strFilePath)
{
Expand Down Expand Up @@ -108,6 +110,7 @@ bool LinuxFileSystem::CreateDirectory(const Char* strPath)
return true;
}

// The maximum number of file descriptors that shall be used by nftw() while traversing the file tree.
static constexpr int MaxOpenNTFWDescriptors = 32;

void LinuxFileSystem::ClearDirectory(const Char* strPath, bool Recursive)
Expand Down Expand Up @@ -182,6 +185,7 @@ std::vector<std::unique_ptr<FindFileData>> LinuxFileSystem::Search(const Char* S
{
std::vector<std::unique_ptr<FindFileData>> SearchRes;

#if PLATFORM_LINUX || PLATFORM_APPLE
glob_t glob_result = {};
if (glob(SearchPattern, GLOB_TILDE, NULL, &glob_result) == 0)
{
Expand All @@ -198,6 +202,9 @@ std::vector<std::unique_ptr<FindFileData>> LinuxFileSystem::Search(const Char* S
}
}
globfree(&glob_result);
#else
UNSUPPORTED("Not implemented");
#endif

return SearchRes;
}
Expand Down Expand Up @@ -228,25 +235,27 @@ std::string LinuxFileSystem::GetCurrentDirectory()
return CurrDir;
}

#if PLATFORM_LINUX || PLATFORM_APPLE
std::string LinuxFileSystem::GetLocalAppDataDirectory(const char* AppName, bool Create)
{
const auto* pwuid = getpwuid(getuid());
std::string AppDataDir{pwuid->pw_dir};
if (!IsSlash(AppDataDir.back()))
AppDataDir += SlashSymbol;
#if PLATFORM_MACOS

# if PLATFORM_APPLE
AppDataDir += "Library/Caches";
#else
# else
AppDataDir += ".cache";
#endif
# endif

if (AppName == nullptr)
{
#ifdef _GNU_SOURCE
# ifdef _GNU_SOURCE
AppName = program_invocation_short_name;
#elif defined(__APPLE__)
# elif defined(__APPLE__)
AppName = getprogname();
#endif
# endif
}

if (AppName != nullptr)
Expand All @@ -258,5 +267,6 @@ std::string LinuxFileSystem::GetLocalAppDataDirectory(const char* AppName, bool
}
return AppDataDir;
}
#endif

} // namespace Diligent

0 comments on commit 19e6432

Please sign in to comment.