Release me
[asdcplib.git] / src / KM_fileio.h
index 1bf2822077c416b9af998a93645ea3daa8f1e881..60e1e6a3c37988d61e5968841e9e224f8eece206 100755 (executable)
@@ -1,5 +1,5 @@
 /*
-Copyright (c) 2004-2014, John Hurst
+Copyright (c) 2004-2016, John Hurst
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
@@ -37,6 +37,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 #ifdef KM_WIN32
 # include <io.h>
+# include "dirent_win.h"
 #else
 # include <dirent.h>
 # include <unistd.h>
@@ -55,12 +56,7 @@ 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(); }
@@ -83,12 +79,7 @@ namespace Kumu
   class DirScannerEx
   {
     std::string m_Dirname;
-#ifdef KM_WIN32
-    __int64               m_Handle;
-    struct _finddatai64_t m_FileInfo;
-#else
     DIR*       m_Handle;
-#endif
 
     KM_NO_COPY_CONSTRUCT(DirScannerEx);
 
@@ -220,7 +211,7 @@ namespace Kumu
   {
   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
@@ -261,6 +252,8 @@ namespace Kumu
   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
   //------------------------------------------------------------------------------------------
@@ -274,6 +267,9 @@ namespace Kumu
   // 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
   //------------------------------------------------------------------------------------------
@@ -304,6 +300,16 @@ namespace Kumu
   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
   //------------------------------------------------------------------------------------------