merge ROS Shell without integrated explorer part into trunk
[reactos.git] / reactos / subsys / system / explorer / utility / utility.h
index 36d11da..51c7cf1 100644 (file)
@@ -42,8 +42,8 @@
 
 #ifndef _MSC_VER
 #include <objbase.h>
-#include <oleauto.h>   // for VARIANT
 #endif
+#include <oleauto.h>   // for VARIANT
 
 #include <malloc.h>            // for alloca()
 #include <assert.h>
@@ -59,6 +59,8 @@
 #define _MAX_PATH      260
 #endif
 
+#define        W_VER_NT 0      // constant for HIWORD(GetVersion())>>14
+
 
 #ifdef __cplusplus
 extern "C" {
@@ -70,7 +72,7 @@ extern "C" {
 #define        COUNTOF(x)      (sizeof(x)/sizeof(x[0]))
 
 
-#define        BUFFER_LEN                              1024
+#define        BUFFER_LEN                              2048
 
 
 extern void _log_(LPCTSTR txt);
@@ -149,6 +151,15 @@ extern int find_window_class(LPCTSTR classname);
  // create a directory with all missing parent directories
 BOOL RecursiveCreateDirectory(LPCTSTR path_in);
 
+ // read DWORD value from registry
+DWORD RegGetDWORDValue(HKEY root, LPCTSTR path, LPCTSTR valueName, DWORD def);
+
+ // write DWORD value to registry
+BOOL RegSetDWORDValue(HKEY root, LPCTSTR path, LPCTSTR valueName, DWORD value);
+
+ // test for existing directory
+BOOL exists_path(LPCTSTR path);
+
 
 #ifdef __cplusplus
 } // extern "C"
@@ -170,6 +181,7 @@ using namespace std;
 #include <map>
 #include <set>
 #include <list>
+#include <stack>
 #include <vector>
 
 
@@ -187,9 +199,9 @@ using namespace _com_util;
 
 
  // launch a program or document file
-extern BOOL launch_file(HWND hwnd, LPCTSTR cmd, UINT nCmdShow, LPCTSTR parameters=NULL);
+extern BOOL launch_file(HWND hwnd, LPCTSTR cmd, UINT nCmdShow=SW_SHOWNORMAL, LPCTSTR parameters=NULL);
 #ifdef UNICODE
-extern BOOL launch_fileA(HWND hwnd, LPSTR cmd, UINT nCmdShow, LPCSTR parameters=NULL);
+extern BOOL launch_fileA(HWND hwnd, LPSTR cmd, UINT nCmdShow=SW_SHOWNORMAL, LPCSTR parameters=NULL);
 #else
 #define        launch_fileA launch_file
 #endif
@@ -250,14 +262,16 @@ protected:
 struct HiddenWindow : public WindowHandle
 {
        HiddenWindow(HWND hwnd)
-        :      WindowHandle(hwnd)
+        :      WindowHandle(IsWindowVisible(hwnd)? hwnd: 0)
        {
-               SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_HIDEWINDOW|SWP_NOREDRAW|SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER);
+               if (_hwnd)
+                       SetWindowPos(_hwnd, 0, 0, 0, 0, 0, SWP_HIDEWINDOW|SWP_NOREDRAW|SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER);
        }
 
        ~HiddenWindow()
        {
-               SetWindowPos(_hwnd, 0, 0, 0, 0, 0, SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER);
+               if (_hwnd)
+                       SetWindowPos(_hwnd, 0, 0, 0, 0, 0, SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER);
        }
 };
 
@@ -303,16 +317,22 @@ protected:
 struct Thread
 {
        Thread()
-        :      _alive(false)
+        :      _alive(false),
+               _destroy(false)
        {
                _hThread = INVALID_HANDLE_VALUE;
+               _evtFinish = CreateEvent(NULL, TRUE, FALSE, NULL);
        }
 
        virtual ~Thread()
        {
                Stop();
 
+               CloseHandle(_evtFinish);
                CloseHandle(_hThread);
+
+               if (_destroy)
+                       delete this;
        }
 
        void Start()
@@ -325,6 +345,8 @@ struct Thread
 
        void Stop()
        {
+               SetEvent(_evtFinish);
+
                if (_alive) {
                        {
                        Lock lock(_crit_sect);
@@ -346,7 +368,9 @@ protected:
        static DWORD WINAPI ThreadProc(void* para);
 
        HANDLE  _hThread;
+       HANDLE  _evtFinish;
        bool    _alive;
+       bool    _destroy;
 };
 
 
@@ -680,7 +704,7 @@ struct BStr
                WCHAR b[BUFFER_LEN];
 
                if (s)
-                       _p = SysAllocStringLen(b, MultiByteToWideChar(CP_ACP, 0, s, -1, b, BUFFER_LEN));
+                       _p = SysAllocStringLen(b, MultiByteToWideChar(CP_ACP, 0, s, -1, b, BUFFER_LEN)-1);
                else
                        _p = NULL;
        }
@@ -719,7 +743,7 @@ protected:
 };
 
 
- /// string class for convenience
+ /// string class for TCHAR strings
 struct String
 #ifdef UNICODE
  : public wstring
@@ -734,8 +758,10 @@ struct String
 #endif
 
        String() {}
+
        String(LPCTSTR s) {if (s) super::assign(s);}
        String(LPCTSTR s, int l) : super(s, l) {}
+
        String(const super& other) : super(other) {}
        String(const String& other) : super(other) {}
 
@@ -744,7 +770,7 @@ struct String
        String(LPCSTR s, int l) {assign(s, l);}
        String(const string& other) {assign(other.c_str());}
        String& operator=(LPCSTR s) {assign(s); return *this;}
-       void assign(LPCSTR s) {if (s) {TCHAR b[BUFFER_LEN]; super::assign(b, MultiByteToWideChar(CP_ACP, 0, s, -1, b, BUFFER_LEN));} else erase();}
+       void assign(LPCSTR s) {if (s) {TCHAR b[BUFFER_LEN]; super::assign(b, MultiByteToWideChar(CP_ACP, 0, s, -1, b, BUFFER_LEN)-1);} else erase();}
        void assign(LPCSTR s, int l) {if (s) {TCHAR b[BUFFER_LEN]; super::assign(b, MultiByteToWideChar(CP_ACP, 0, s, l, b, BUFFER_LEN));} else erase();}
        void assign(const BStr& s) {int l = s.length(); super::assign(s, l);}
 #else
@@ -752,7 +778,7 @@ struct String
        String(LPCWSTR s, int l) {assign(s, l);}
        String(const wstring& other) {assign(other.c_str());}
        String& operator=(LPCWSTR s) {assign(s); return *this;}
-       void assign(LPCWSTR s) {if (s) {char b[BUFFER_LEN]; super::assign(b, WideCharToMultiByte(CP_ACP, 0, s, -1, b, BUFFER_LEN, 0, 0));} else erase();}
+       void assign(LPCWSTR s) {if (s) {char b[BUFFER_LEN]; super::assign(b, WideCharToMultiByte(CP_ACP, 0, s, -1, b, BUFFER_LEN, 0, 0)-1);} else erase();}
        void assign(LPCWSTR s, int l) {if (s) {char b[BUFFER_LEN]; super::assign(b, WideCharToMultiByte(CP_ACP, 0, s, l, b, BUFFER_LEN, 0, 0));} else erase();}
        void assign(const BStr& s) {int l = s.length(); if (l) {char b[BUFFER_LEN]; super::assign(b, WideCharToMultiByte(CP_ACP, 0, s, l, b, BUFFER_LEN, 0, 0));} else erase();}
 #endif
@@ -766,6 +792,12 @@ struct String
 
        operator LPCTSTR() const {return c_str();}
 
+#ifdef UNICODE
+       operator string() const {char b[BUFFER_LEN]; return string(b, WideCharToMultiByte(CP_ACP, 0, c_str(), -1, b, BUFFER_LEN, 0, 0)-1);}
+#else
+       operator wstring() const {WCHAR b[BUFFER_LEN]; return wstring(b, MultiByteToWideChar(CP_ACP, 0, c_str(), -1, b, BUFFER_LEN)-1);}
+#endif
+
        String& printf(LPCTSTR fmt, ...)
        {
                va_list l;
@@ -809,6 +841,8 @@ struct String
        }
 };
 
+#define        _STRING_DEFINED
+
 
 struct FmtString : public String
 {
@@ -878,6 +912,10 @@ protected:
 #endif
 
 
+ // determine windows version string
+String get_windows_version_str();
+
+
  /// link dynamicly to functions by using GetModuleHandle() and GetProcAddress()
 template<typename FCT> struct DynamicFct
 {
@@ -992,7 +1030,10 @@ protected:
 #define        CONTEXT_OBJ __ctx__._obj
 #define        CONTEXT(c) Context __ctx__(c)
 #define        CURRENT_CONTEXT Context::current()
-#define        OBJ_CONTEXT(c, o) Context __ctx__(c, o);
+#define        OBJ_CONTEXT(c, o) Context __ctx__(c, o)
+
+
+extern bool SplitFileSysURL(LPCTSTR url, String& dir_out, String& fname_out);
 
 
 #endif // __cplusplus