Added addon folder support and option to stream directly from the addon

This commit is contained in:
KiritoDev 2021-05-21 22:51:43 -05:00
parent 64066deb48
commit 8bec24fc57
4 changed files with 81 additions and 11 deletions

View File

@ -580,6 +580,20 @@ else
endif
################################
# Moon64 Custom Flags #
################################
# Moon64 Enable filesystem library and C++17
CXXFLAGS := -std=c++17
LDFLAGS += -lstdc++fs
# ifeq ($(TOGGLE_GAME_DEBUG),1)
# VERSION_CFLAGS += -DTOGGLE_GAME_DEBUG
# endif
################################
# Check for enhancement options
# Check for Puppycam option
@ -826,8 +840,8 @@ $(GLOBAL_ASM_DEP).$(NON_MATCHING):
touch $@
$(BUILD_DIR)/%.o: %.cpp
@$(CXX) -fsyntax-only $(CFLAGS) -MMD -MP -MT $@ -MF $(BUILD_DIR)/$*.d $<
$(CXX) -c $(CFLAGS) -o $@ $<
@$(CXX) -fsyntax-only $(CFLAGS) $(CXXFLAGS) -MMD -MP -MT $@ -MF $(BUILD_DIR)/$*.d $<
$(CXX) -c $(CFLAGS) $(CXXFLAGS) -o $@ $<
$(BUILD_DIR)/%.o: %.c
@$(CC_CHECK) $(CC_CHECK_CFLAGS) -MMD -MP -MT $@ -MF $(BUILD_DIR)/$*.d $<

View File

@ -2987,8 +2987,8 @@ static FILE *mz_fopen(const char *pFilename, const char *pMode)
#define MZ_FCLOSE fclose
#define MZ_FREAD fread
#define MZ_FWRITE fwrite
#define MZ_FTELL64 ftello
#define MZ_FSEEK64 fseeko
#define MZ_FTELL64 ftell
#define MZ_FSEEK64 fseek
#define MZ_FILE_STAT_STRUCT stat
#define MZ_FILE_STAT stat
#define MZ_FFLUSH fflush

View File

@ -19,6 +19,7 @@ extern "C" {
#include "text/libs/io_utils.h"
#include "pc/platform.h"
#include "pc/fs/fs.h"
#include "pc/configfile.h"
}
namespace Moon {
@ -84,9 +85,11 @@ namespace Moon {
if(std::count(allowedTextures.begin(), allowedTextures.end(), fileExtension)){
string texName = name.substr(path.length());
string rawname = texName.substr(0, texName.find_last_of("."));
TextureFileEntry *entry = new TextureFileEntry();
file.read(name, entry);
TextureFileEntry *entry;
if(configPrecacheRes)
file.read(name, entry = new TextureFileEntry());
else
entry = new TextureFileEntry({.path = name});
Moon::saveAddonTexture(bit, rawname, entry);
}
if(!fileExtension.compare("json")){
@ -135,8 +138,7 @@ namespace MoonInternal {
if (dir) {
struct dirent *de;
while ((de = readdir(dir)) != NULL) {
string extension = string(get_filename_ext(de->d_name));
if (extension.compare("bit") == 0) {
if (de->d_name[0] != '.') {
string file = addonsDir + de->d_name;
Moon::loadAddon(file);
}

View File

@ -1,24 +1,78 @@
#include "straw.h"
#include "moon/libs/miniz/zip_file.hpp"
#include <sys/types.h>
#include <sys/stat.h>
#include <filesystem>
namespace fs = std::filesystem;
using namespace std;
using namespace miniz_cpp;
bool isDirectory;
#ifdef __MINGW32__
#define SEPARATOR "\\"
#else
#define SEPARATOR "/"
#endif
zip_file zipFile;
void StrawFile::open(){
zipFile.load(this->path);
if(!(isDirectory = fs::is_directory(this->path)))
zipFile.load(this->path);
}
bool StrawFile::exists(string path){
return zipFile.has_file(path);
return isDirectory ? fs::exists(this->path + SEPARATOR + path) : zipFile.has_file(path);
}
vector<string> StrawFile::entries(){
if(isDirectory) {
vector<string> fileList;
for (auto & entry : fs::recursive_directory_iterator(this->path)){
#ifndef TARGET_SWITCH
fileList.push_back(fs::relative(entry, this->path).string());
#else
fileList.push_back(entry.path().string());
#endif
}
return fileList;
}
return zipFile.namelist();
}
string StrawFile::read(string file){
if(isDirectory){
std::ifstream in(this->path + SEPARATOR + file, std::ios::in | std::ios::binary);
if (in)
return(std::string((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>()));
}
return zipFile.read(file);
}
void StrawFile::read(string file, TextureFileEntry *entry){
if(isDirectory){
char *data;
long size;
FILE* f = fopen((this->path + SEPARATOR + file).c_str(), "r");
fseek(f, 0, SEEK_END);
size = ftell(f);
rewind(f);
data = new char[size];
fread(data, sizeof(char), size, f);
entry->data = data;
entry->size = size;
fclose(f);
return;
}
zipFile.read_texture(file, &entry);
}