Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions builder/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <editor/pluginmanager.h>
#include <editor/projectsettings.h>
#include <editor/editorsettings.h>
#include <editor/editorplatform.h>

#include "builder.h"

Expand Down Expand Up @@ -74,14 +75,13 @@ int main(int argc, char *argv[]) {
parser.showHelp(1);
}

Log::overrideHandler(new ConsoleLog());
Log::setHandler(new ConsoleLog());
Log::setLogLevel(Log::DBG);
File *file = new File();
file->finit(qPrintable(QCoreApplication::arguments().at(0)));

aInfo() << "Starting builder...";

Engine engine(file, argv[0]);
Engine engine(argv[0]);
Engine::setPlatformAdaptor(&EditorPlatform::instance());

ProjectSettings::instance()->init(parser.value(sourceFileOption).toStdString(), parser.value(targetDirectoryOption).toStdString());

Expand Down
80 changes: 0 additions & 80 deletions engine/includes/adapters/androidfile.h

This file was deleted.

78 changes: 0 additions & 78 deletions engine/includes/adapters/emscriptenfile.h

This file was deleted.

80 changes: 80 additions & 0 deletions engine/includes/adapters/handlers/androidfilehandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#ifndef ANDROIDFILE_H
#define ANDROIDFILE_H

#include <file.h>

#include <glfm.h>

class AndroidFileHandler : public FileHandler {
public:
StringList list(const char *path, bool recursive) override {
AAssetDir *dir = AAssetManager_openDir(glfmAndroidGetActivity()->assetManager, path);
StringList result;
const char *name = nullptr;
while((name = AAssetDir_getNextFileName(dir)) != nullptr) {
result.push_back(name);
}
AAssetDir_close(dir);
return result;
}

bool mkdir(const char *path) override {
A_UNUSED(path);
return false;
}

bool remove(const char *path) override {
A_UNUSED(path);
return false;
}

bool exists(const char *path) override {
A_UNUSED(path);
return true;
}

bool isdir(const char *path) override {
AAssetDir *dir = AAssetManager_openDir(glfmAndroidGetActivity()->assetManager, path);
if(dir) {
AAssetDir_close(dir);
return true;
}
return false;
}

int close(int *handle) override {
AAsset_close(reinterpret_cast<AAsset *>(handle));
return 0;
}

size_t seek(int *handle, uint64_t origin) override {
return AAsset_seek(reinterpret_cast<AAsset *>(handle), origin, SEEK_SET);
}

int *open(const char *path, File::OpenMode) override {
return reinterpret_cast<int *>(AAssetManager_open(glfmAndroidGetActivity()->assetManager, path, AASSET_MODE_UNKNOWN));
}

size_t read(void *ptr, size_t size, size_t count, int *handle) override {
return AAsset_read(reinterpret_cast<AAsset *>(handle), ptr, size);
}

size_t write(const void *ptr, size_t size, size_t count, int *handle) override {
A_UNUSED(ptr);
A_UNUSED(size);
A_UNUSED(count);
A_UNUSED(handle);
return -1;
}

size_t size(int *handle) override {
return AAsset_getLength(reinterpret_cast<AAsset *>(handle));
}

size_t tell(int *handle) override {
return size(handle) - AAsset_getRemainingLength(reinterpret_cast<AAsset *>(handle));
}

};

#endif // ANDROIDFILE_H
109 changes: 109 additions & 0 deletions engine/includes/adapters/handlers/defaultfilehandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#ifndef DEFAULTFILEHANDLER_H
#define DEFAULTFILEHANDLER_H

#include <file.h>
#include <log.h>

#include <stdio.h>
#include <filesystem>

class DefaultFileHandler : public FileHandler {
public:
void clearSearchPaths() {
m_searchPath.clear();
}

void searchPathAdd(const TString &path) {
m_searchPath.push_back(path);
}

protected:
StringList list(const char *path, bool recursive) override {
StringList result;
for(auto const &it : std::filesystem::directory_iterator{path}) {
result.push_back(TString(it.path().string()));
}
return result;
}

bool mkdir(const char *path) override {
return std::filesystem::create_directory(path);
}

bool remove(const char *path) override {
return std::filesystem::remove(path);
}

bool exists(const char *path) override {
return std::filesystem::exists(path);
}

bool isdir(const char *path) override {
return std::filesystem::is_directory(path);
}

int close(int *handle) override {
return ::fclose(reinterpret_cast<FILE *>(handle));
}

size_t seek(int *handle, uint64_t origin) override {
return ::fseek(reinterpret_cast<FILE *>(handle), origin, SEEK_SET);
}

int *open(const char *path, File::OpenMode mode) override {
TString s;
if(mode & File::ReadOnly) {
s += 'r';
}

if(mode & File::WriteOnly) {
s += 'w';
}

if(mode & File::Append) {
s += 'a';
}

s += 'b';

FILE *fp = ::fopen(path, s.data());
if(fp == nullptr) {
for(auto &it : m_searchPath) {
fp = ::fopen((it + "/" + path).data(), s.data());
if(fp) {
return reinterpret_cast<int *>(fp);
}
}

aWarning() << "[DefaultFileHandler] Can't open file" << path;
}

return reinterpret_cast<int *>(fp);
}

size_t read(void *ptr, size_t size, size_t count, int *handle) override {
return ::fread(ptr, size, count, reinterpret_cast<FILE *>(handle));
}

size_t write(const void *ptr, size_t size, size_t count, int *handle) override {
return ::fwrite(ptr, size, count, reinterpret_cast<FILE *>(handle));
}

size_t size(int *handle) override {
::fseek(reinterpret_cast<FILE *>(handle), 0, SEEK_END);
size_t size = ::ftell(reinterpret_cast<FILE *>(handle));
::fseek(reinterpret_cast<FILE *>(handle), 0, SEEK_SET);

return size;
}

size_t tell(int *handle) override {
return ::ftell(reinterpret_cast<FILE *>(handle));
}

protected:
StringList m_searchPath;

};

#endif // DEFAULTFILEHANDLER_H
Loading
Loading