File indexing completed on 2024-04-28 13:37:55

0001 /*
0002   SPDX-FileCopyrightText: 2003-2006, Sergey Zorin. All rights reserved.
0003   SPDX-FileCopyrightText:  2018-2020 Michael Reeves reeves.87@gmail.com
0004   SPDX-License-Identifier: BSD-2-Clause
0005 */
0006 #ifndef server_h
0007 #define server_h
0008 
0009 //This option is not compatible with our shell extention.
0010 #undef WIN32_LEAN_AND_MEAN
0011 
0012 #include <list>   // std::list
0013 #include <windows.h>
0014 
0015 #include <string> // std::wstring
0016 
0017 #ifdef UNICODE
0018 
0019 typedef std::wstring tstring;
0020 
0021 #define toQString(s) QString::fromStdWString(s)
0022 #define fromQString(s) (s).toStdWString()
0023 
0024 #else
0025 
0026 #error  "Unsupported configuration"
0027 
0028 #endif
0029 
0030 #define MESSAGELOG( msg ) SERVER::logMessage( __FUNCTION__, __FILE__, __LINE__, msg )
0031 #define LOG()             MESSAGELOG( TEXT("") )
0032 #define ERRORLOG( msg )   MESSAGELOG( TEXT("Error: ")+tstring(msg) )
0033 #define SYSERRORLOG( msg )                                                                    \
0034    {                                                                                          \
0035       LPTSTR message;                                                                         \
0036       FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, 0,           \
0037          GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &message, 0, 0); \
0038       ERRORLOG( (tstring(msg) + TEXT(": ")) + message );                                        \
0039       LocalFree(message);                                                                     \
0040    }
0041 
0042 
0043 class SERVER {
0044   public:
0045     static SERVER* instance();
0046     void initLogging();
0047 
0048   public:
0049     virtual ~SERVER();
0050 
0051     tstring getRegistryKeyString( const tstring& subKey, const tstring& value );
0052 
0053     HINSTANCE handle() const;
0054 
0055     HRESULT do_register();
0056     HRESULT do_unregister();
0057 
0058     void lock();
0059     void release();
0060 
0061     ULONG reference_count() const {
0062       return _reference_count;
0063     }
0064 
0065     std::list< tstring >& recent_files();
0066 
0067     void save_history() const;
0068 
0069     static void logMessage( const char* function, const char* file, int line, const tstring& msg );
0070 
0071   private:
0072     SERVER();
0073     SERVER(const SERVER&) {}
0074 
0075   private:
0076     LONG _reference_count;
0077     std::list<tstring>* m_pRecentFiles;
0078     static SERVER* _instance;
0079     tstring m_registryBaseName;
0080     FILE* m_pLogFile;
0081 };
0082 
0083 #endif // __server_h__