diff --git a/src/utils/pathut.cpp b/src/utils/pathut.cpp index fd4d4466..5dd7510c 100644 --- a/src/utils/pathut.cpp +++ b/src/utils/pathut.cpp @@ -98,67 +98,10 @@ static bool path_isdriveabs(const string& s) } return false; } - -#include -#pragma comment(lib, "shlwapi.lib") - -string path_tchartoutf8(TCHAR *text) -{ -#ifdef UNICODE - // Simple C - // const size_t size = ( wcslen(text) + 1 ) * sizeof(wchar_t); - // wcstombs(&buffer[0], text, size); - // std::vector buffer(size); - // Or: - // Windows API - std::vector buffer; - int size = WideCharToMultiByte(CP_UTF8, 0, text, -1, NULL, 0, NULL, NULL); - if (size > 0) { - buffer.resize(size); - WideCharToMultiByte(CP_UTF8, 0, text, -1, - &buffer[0], int(buffer.size()), NULL, NULL); - } else { - return string(); - } - return string(&buffer[0]); -#else - return text; -#endif -} - -string path_thisexecpath() -{ - TCHAR text[MAX_PATH]; - GetModuleFileName(NULL, text, MAX_PATH); -#ifdef NTDDI_WIN8_future - PathCchRemoveFileSpec(text, MAX_PATH); -#else - PathRemoveFileSpec(text); -#endif - string path = path_tchartoutf8(text); - if (path.empty()) { - path = "c:/"; - } - - return path; -} - -string path_wingettempfilename(TCHAR *pref) -{ - TCHAR buf[(MAX_PATH + 1)*sizeof(TCHAR)]; - TCHAR dbuf[(MAX_PATH + 1)*sizeof(TCHAR)]; - GetTempPath(MAX_PATH + 1, dbuf); - GetTempFileName(dbuf, pref, 0, buf); - // Windows will have created a temp file, we delete it. - string filename = path_tchartoutf8(buf); - unlink(filename.c_str()); - path_slashize(filename); - return filename; -} #endif #if defined(HAVE_SYS_MOUNT_H) || defined(HAVE_SYS_STATFS_H) || \ - defined(HAVE_SYS_STATVFS_H) || defined(HAVE_SYS_VFS_H) + defined(HAVE_SYS_STATVFS_H) || defined(HAVE_SYS_VFS_H) || defined(_WIN32) bool fsocc(const string& path, int *pc, long long *avmbs) { static const int FSOCC_MB = 1024 * 1024; diff --git a/src/utils/rclutil.cpp b/src/utils/rclutil.cpp index cd4778b8..e70b5e55 100644 --- a/src/utils/rclutil.cpp +++ b/src/utils/rclutil.cpp @@ -56,6 +56,79 @@ void map_ss_cp_noshr(const map s, map *d) } } +#ifdef _WIN32 +static bool path_hasdrive(const string& s) +{ + if (s.size() >= 2 && isalpha(s[0]) && s[1] == ':') { + return true; + } + return false; +} +static bool path_isdriveabs(const string& s) +{ + if (s.size() >= 3 && isalpha(s[0]) && s[1] == ':' && s[2] == '/') { + return true; + } + return false; +} + +#include +#pragma comment(lib, "shlwapi.lib") + +string path_tchartoutf8(TCHAR *text) +{ +#ifdef UNICODE + // Simple C + // const size_t size = ( wcslen(text) + 1 ) * sizeof(wchar_t); + // wcstombs(&buffer[0], text, size); + // std::vector buffer(size); + // Or: + // Windows API + std::vector buffer; + int size = WideCharToMultiByte(CP_UTF8, 0, text, -1, NULL, 0, NULL, NULL); + if (size > 0) { + buffer.resize(size); + WideCharToMultiByte(CP_UTF8, 0, text, -1, + &buffer[0], int(buffer.size()), NULL, NULL); + } else { + return string(); + } + return string(&buffer[0]); +#else + return text; +#endif +} +string path_thisexecpath() +{ + TCHAR text[MAX_PATH]; + GetModuleFileName(NULL, text, MAX_PATH); +#ifdef NTDDI_WIN8_future + PathCchRemoveFileSpec(text, MAX_PATH); +#else + PathRemoveFileSpec(text); +#endif + string path = path_tchartoutf8(text); + if (path.empty()) { + path = "c:/"; + } + + return path; +} +string path_wingettempfilename(TCHAR *pref) +{ + TCHAR buf[(MAX_PATH + 1)*sizeof(TCHAR)]; + TCHAR dbuf[(MAX_PATH + 1)*sizeof(TCHAR)]; + GetTempPath(MAX_PATH + 1, dbuf); + GetTempFileName(dbuf, pref, 0, buf); + // Windows will have created a temp file, we delete it. + string filename = path_tchartoutf8(buf); + unlink(filename.c_str()); + path_slashize(filename); + return filename; +} + +#endif // _WIN32 + string path_defaultrecollconfsubdir() { #ifdef _WIN32 diff --git a/src/windows/qmkrecoll/librecoll.pro b/src/windows/qmkrecoll/librecoll.pro index 5b403a8b..2367a334 100644 --- a/src/windows/qmkrecoll/librecoll.pro +++ b/src/windows/qmkrecoll/librecoll.pro @@ -91,6 +91,7 @@ SOURCES += \ ../../windows/fnmatch.c \ ../../utils/fileudi.cpp \ ../../utils/fstreewalk.cpp \ +../../utils/hldata.cpp \ ../../utils/idfile.cpp \ ../../utils/md5.cpp \ ../../utils/md5ut.cpp \ @@ -98,6 +99,7 @@ SOURCES += \ ../../utils/pathut.cpp \ ../../utils/pxattr.cpp \ ../../utils/rclionice.cpp \ +../../utils/rclutil.cpp \ ../../utils/readfile.cpp \ ../../utils/smallut.cpp \ ../../utils/strmatcher.cpp \