/*
-Copyright (c) 2004-2009, John Hurst
+Copyright (c) 2004-2016, John Hurst
All rights reserved.
Redistribution and use in source and binary forms, with or without
#ifdef KM_WIN32
# include <io.h>
+# include "dirent_win.h"
#else
# include <dirent.h>
# include <unistd.h>
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 GetNext(char*);
};
+
+ //
+ enum DirectoryEntryType_t {
+ DET_FILE,
+ DET_DIR,
+ DET_DEV,
+ DET_LINK
+ };
+
+ //
+ class DirScannerEx
+ {
+ std::string m_Dirname;
+ DIR* m_Handle;
+
+ KM_NO_COPY_CONSTRUCT(DirScannerEx);
+
+ public:
+
+ DirScannerEx();
+ ~DirScannerEx() { Close(); }
+
+ Result_t Open(const std::string& dirname);
+ Result_t Close();
+
+
+ inline Result_t GetNext(std::string& next_item_name) {
+ DirectoryEntryType_t ft;
+ return GetNext(next_item_name, ft);
+ }
+
+ Result_t GetNext(std::string& next_item_name, DirectoryEntryType_t& next_item_type);
+ };
+
#ifdef KM_WIN32
typedef __int64 fsize_t;
typedef __int64 fpos_t;
{
public:
virtual ~PathMatchAny() {}
- inline bool Match(const std::string& s) const { return true; }
+ inline bool Match(const std::string&) const { return true; }
};
#ifndef KM_WIN32
PathList_t& FindInPaths(const IPathMatch& Pattern, const PathList_t& SearchPaths,
PathList_t& FoundPaths, bool one_shot = false, char separator = '/');
+ std::string GetExecutablePath(const std::string& default_path);
+
//------------------------------------------------------------------------------------------
// Directory Manipulation
//------------------------------------------------------------------------------------------
// Recursively remove a file or directory
Result_t DeletePath(const std::string& pathname);
+ // Remove the path only if it is a directory that is empty.
+ Result_t DeleteDirectoryIfEmpty(const std::string& path);
+
//------------------------------------------------------------------------------------------
// File I/O Wrappers
//------------------------------------------------------------------------------------------
Result_t WriteBufferIntoFile(const Kumu::ByteString& Buffer, const std::string& Filename);
+#ifdef KM_WIN32_UTF8
+ //------------------------------------------------------------------------------------------
+ // wide char support for win32 file I/O
+ //------------------------------------------------------------------------------------------
+
+ //
+ Result_t wbstr_to_utf8(const Kumu::ByteString& in, std::string& out);
+ Result_t utf8_to_wbstr(const std::string& in, Kumu::ByteString& out);
+#endif
+
//------------------------------------------------------------------------------------------
// File I/O
//------------------------------------------------------------------------------------------