summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2012-12-01 18:51:07 +0000
committerCarl Hetherington <cth@carlh.net>2012-12-01 18:51:07 +0000
commit5edd130eafacda6233df537a76a3c1fe69c7e660 (patch)
tree10cce1b97051fff356977a19285d00a3c8642e0a
parent56f27201d8d882a4064a69314c78e1fcf1b0bb77 (diff)
Reimplement Kumu::DirScanner using boost to avoid dependency on msvcr100 on Windows.
-rw-r--r--asdcplib/src/KM_fileio.cpp184
-rwxr-xr-xasdcplib/src/KM_fileio.h31
-rw-r--r--asdcplib/src/wscript2
-rw-r--r--wscript1
4 files changed, 31 insertions, 187 deletions
diff --git a/asdcplib/src/KM_fileio.cpp b/asdcplib/src/KM_fileio.cpp
index 4bc92af7..b13d8ba2 100644
--- a/asdcplib/src/KM_fileio.cpp
+++ b/asdcplib/src/KM_fileio.cpp
@@ -1211,186 +1211,38 @@ Kumu::WriteBufferIntoFile(const Kumu::ByteString& Buffer, const std::string& Fil
//------------------------------------------------------------------------------------------
//
-
-// Win32 directory scanner
-//
-#ifdef KM_WIN32
-
-//
-Kumu::DirScanner::DirScanner(void) : m_Handle(-1) {}
-
-//
-//
-Result_t
-Kumu::DirScanner::Open(const char* filename)
-{
- KM_TEST_NULL_STR_L(filename);
-
- // we need to append a '*' to read the entire directory
- ui32_t fn_len = strlen(filename);
- char* tmp_file = (char*)malloc(fn_len + 8);
-
- if ( tmp_file == 0 )
- return RESULT_ALLOC;
-
- strcpy(tmp_file, filename);
- char* p = &tmp_file[fn_len] - 1;
-
- if ( *p != '/' && *p != '\\' )
- {
- p++;
- *p++ = '/';
- }
-
- *p++ = '*';
- *p = 0;
- // whew...
-
- m_Handle = _findfirsti64(tmp_file, &m_FileInfo);
- Result_t result = RESULT_OK;
-
- if ( m_Handle == -1 )
- result = RESULT_NOT_FOUND;
-
- return result;
-}
-
-
-//
-//
-Result_t
-Kumu::DirScanner::Close()
+Kumu::DirScanner::DirScanner()
{
- if ( m_Handle == -1 )
- return RESULT_FILEOPEN;
-
- if ( _findclose((long)m_Handle) == -1 )
- return RESULT_FAIL;
-
- m_Handle = -1;
- return RESULT_OK;
-}
-
-
-// This sets filename param to the same per-instance buffer every time, so
-// the value will change on the next call
-Result_t
-Kumu::DirScanner::GetNext(char* filename)
-{
- KM_TEST_NULL_L(filename);
-
- if ( m_Handle == -1 )
- return RESULT_FILEOPEN;
-
- if ( m_FileInfo.name[0] == '\0' )
- return RESULT_ENDOFFILE;
-
- strncpy(filename, m_FileInfo.name, MaxFilePath);
- Result_t result = RESULT_OK;
-
- if ( _findnexti64((long)m_Handle, &m_FileInfo) == -1 )
- {
- m_FileInfo.name[0] = '\0';
-
- if ( errno != ENOENT )
- result = RESULT_FAIL;
- }
- return result;
}
-
-#else // KM_WIN32
-
-// POSIX directory scanner
-
-//
-Kumu::DirScanner::DirScanner(void) : m_Handle(NULL) {}
-
-//
Result_t
-Kumu::DirScanner::Open(const char* filename)
+Kumu::DirScanner::Open (const char* filename)
{
- KM_TEST_NULL_STR_L(filename);
-
- Result_t result = RESULT_OK;
+ KM_TEST_NULL_L (filename);
- if ( ( m_Handle = opendir(filename) ) == NULL )
- {
- switch ( errno )
- {
- case ENOENT:
- case ENOTDIR:
- result = RESULT_NOTAFILE;
- case EACCES:
- result = RESULT_NO_PERM;
- case ELOOP:
- case ENAMETOOLONG:
- result = RESULT_PARAM;
- case EMFILE:
- case ENFILE:
- result = RESULT_STATE;
- default:
- DefaultLogSink().Error("DirScanner::Open(%s): %s\n", filename, strerror(errno));
- result = RESULT_FAIL;
+ if (!boost::filesystem::is_directory(filename)) {
+ return RESULT_NOT_FOUND;
}
- }
-
- return result;
-}
-
-
-//
-Result_t
-Kumu::DirScanner::Close()
-{
- if ( m_Handle == NULL )
- return RESULT_FILEOPEN;
-
- if ( closedir(m_Handle) == -1 ) {
- switch ( errno )
- {
- case EBADF:
- case EINTR:
- return RESULT_STATE;
- default:
- DefaultLogSink().Error("DirScanner::Close(): %s\n", strerror(errno));
- return RESULT_FAIL;
- }
- }
-
- m_Handle = NULL;
- return RESULT_OK;
+
+ _iterator = boost::filesystem::directory_iterator (filename);
+ return RESULT_OK;
}
-
-//
Result_t
-Kumu::DirScanner::GetNext(char* filename)
+Kumu::DirScanner::GetNext (char* filename)
{
- KM_TEST_NULL_L(filename);
-
- if ( m_Handle == NULL )
- return RESULT_FILEOPEN;
-
- struct dirent* entry;
-
- for (;;)
- {
- if ( ( entry = readdir(m_Handle)) == NULL )
- return RESULT_ENDOFFILE;
-
- break;
- }
-
- strncpy(filename, entry->d_name, MaxFilePath);
- return RESULT_OK;
+ KM_TEST_NULL_L (filename);
+
+ if (_iterator == boost::filesystem::directory_iterator()) {
+ return RESULT_ENDOFFILE;
+ }
+
+ strncpy (filename, boost::filesystem::path(*_iterator).filename().generic_string().c_str(), MaxFilePath);
+ ++_iterator;
+ return RESULT_OK;
}
-
-#endif // KM_WIN32
-
-
//------------------------------------------------------------------------------------------
//
diff --git a/asdcplib/src/KM_fileio.h b/asdcplib/src/KM_fileio.h
index 2f2718cd..b078e32b 100755
--- a/asdcplib/src/KM_fileio.h
+++ b/asdcplib/src/KM_fileio.h
@@ -34,6 +34,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <KM_util.h>
#include <string>
+#include <boost/filesystem.hpp>
#ifdef KM_WIN32
# include <io.h>
@@ -51,24 +52,16 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace Kumu
{
- //
class DirScanner
- {
- public:
-#ifdef KM_WIN32
- __int64 m_Handle;
- struct _finddatai64_t m_FileInfo;
-#else
- DIR* m_Handle;
-#endif
-
- DirScanner(void);
- ~DirScanner() { Close(); }
-
- Result_t Open(const char*);
- Result_t Close();
- Result_t GetNext(char*);
- };
+ {
+ public:
+ DirScanner();
+ Result_t Open(const char *);
+ Result_t GetNext(char *);
+ Result_t Close();
+ private:
+ boost::filesystem::directory_iterator _iterator;
+ };
#ifdef KM_WIN32
typedef __int64 fsize_t;
@@ -91,8 +84,8 @@ namespace Kumu
SP_POS = SEEK_CUR,
SP_END = SEEK_END
};
-#endif
-
+#endif
+
//
#ifndef KM_SMALL_FILES_OK
template <bool sizecheck> void compile_time_size_checker();
diff --git a/asdcplib/src/wscript b/asdcplib/src/wscript
index a2756dfa..e079fa2f 100644
--- a/asdcplib/src/wscript
+++ b/asdcplib/src/wscript
@@ -11,7 +11,7 @@ def build(bld):
obj = bld(features = 'cxx cxxshlib')
obj.name = 'libkumu-libdcp'
obj.target = 'kumu-libdcp'
- obj.uselib = 'OPENSSL'
+ obj.uselib = 'OPENSSL BOOST_FILESYSTEM'
obj.includes = ['.']
obj.export_includes = ['.']
obj.source = """
diff --git a/wscript b/wscript
index 2d881029..fd64c821 100644
--- a/wscript
+++ b/wscript
@@ -19,7 +19,6 @@ def configure(conf):
if conf.options.target_windows:
conf.env.append_value('CXXFLAGS', '-DLIBDCP_WINDOWS')
- conf.env.append_value('LIB', 'msvcr100')
else:
conf.env.append_value('CXXFLAGS', '-DLIBDCP_POSIX')