diff --git a/Makefile b/Makefile index 3bd218b8..4ca26633 100644 --- a/Makefile +++ b/Makefile @@ -921,8 +921,13 @@ $(INSTALLDIR)/radiant.$(EXE): \ libprofile.$(A) \ libquickhull.$(A) \ libxmllib.$(A) \ + libos.$(A) \ $(if $(findstring Win32,$(OS)),icons/radiant.o,) \ +libos.$(A): CPPFLAGS_EXTRA := $(CPPFLAGS_QTCORE) -Ilibs -Iinclude +libos.$(A): \ + libs/os/dir.o \ + libfilematch.$(A): CPPFLAGS_EXTRA := -Ilibs libfilematch.$(A): \ libs/filematch.o \ @@ -1072,13 +1077,14 @@ $(INSTALLDIR)/modules/shaders.$(DLL): \ plugins/shaders/shaders.o \ libcommandlib.$(A) \ -$(INSTALLDIR)/modules/vfspk3.$(DLL): LIBS_EXTRA := $(LIBS_GLIB) -$(INSTALLDIR)/modules/vfspk3.$(DLL): CPPFLAGS_EXTRA := $(CPPFLAGS_GLIB) -Ilibs -Iinclude +$(INSTALLDIR)/modules/vfspk3.$(DLL): LIBS_EXTRA := $(LIBS_GLIB) $(LIBS_QTCORE) +$(INSTALLDIR)/modules/vfspk3.$(DLL): CPPFLAGS_EXTRA := $(CPPFLAGS_GLIB) $(CPPFLAGS_QTCORE) -Ilibs -Iinclude $(INSTALLDIR)/modules/vfspk3.$(DLL): \ plugins/vfspk3/archive.o \ plugins/vfspk3/vfs.o \ plugins/vfspk3/vfspk3.o \ libfilematch.$(A) \ + libos.$(A) \ $(INSTALLDIR)/plugins/bobtoolz.$(DLL): LIBS_EXTRA := $(LIBS_GLIB) $(LIBS_QTCORE) $(LIBS_QTGUI) $(LIBS_QTWIDGETS) $(INSTALLDIR)/plugins/bobtoolz.$(DLL): CPPFLAGS_EXTRA := $(CPPFLAGS_GLIB) $(CPPFLAGS_QTCORE) $(CPPFLAGS_QTGUI) $(CPPFLAGS_QTWIDGETS) -Ilibs -Iinclude diff --git a/libs/os/dir.cpp b/libs/os/dir.cpp new file mode 100644 index 00000000..fcaa4921 --- /dev/null +++ b/libs/os/dir.cpp @@ -0,0 +1,34 @@ +#include "dir.h" + +#include +#include +#include +#include + +Directory::Directory(const char* name) { + this->dir = new QDir(name); + QStringList entryList = this->dir->entryList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot); + for(int i = 0; i < entryList.size(); i++) { + QString file_path = entryList.at(i); + QString file_name = QFileInfo(file_path).fileName(); + this->entries.push_back(file_name.toLatin1().data()); + } +} + +bool Directory::good() { + return this->dir->exists(); +} + +void Directory::close() { + this->entries.clear(); + delete this->dir; +} + +const char* Directory::read_and_increment() { + if(this->entry_idx < this->entries.size()) { + const char* entry = this->entries.at(this->entry_idx); + this->entry_idx++; + return entry; + } + return nullptr; +} \ No newline at end of file diff --git a/libs/os/dir.h b/libs/os/dir.h index 3d5c774f..d119d305 100644 --- a/libs/os/dir.h +++ b/libs/os/dir.h @@ -24,24 +24,46 @@ /// \file /// \brief OS directory-listing object. -#include +#include -typedef GDir Directory; +class QDir; -inline bool directory_good( Directory* directory ){ - return directory != 0; +class Directory { + + private: + QDir* dir; + size_t entry_idx = 0; + std::vector entries; + + public: + Directory(const char* name); + bool good(); + void close(); + const char* read_and_increment(); +}; + +inline bool directory_good(Directory* directory) { + if(directory) { + return directory->good(); + } + return false; } -inline Directory* directory_open( const char* name ){ - return g_dir_open( name, 0, 0 ); +inline Directory* directory_open(const char* name){ + return new Directory(name); } -inline void directory_close( Directory* directory ){ - g_dir_close( directory ); +inline void directory_close(Directory* directory){ + if(directory) { + directory->close(); + } } -inline const char* directory_read_and_increment( Directory* directory ){ - return g_dir_read_name( directory ); +inline const char* directory_read_and_increment(Directory* directory) { + if(directory) { + return directory->read_and_increment(); + } + return nullptr; } template