"Fossies" - the Fresh Open Source Software Archive

Member "src/Setup/ComSetup.cpp" (10 Oct 2018, 3740 Bytes) of package /windows/misc/VeraCrypt_1.23-Hotfix-2_Source.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "ComSetup.cpp" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 1.22_Source_vs_1.23_Source.

    1 /*
    2  Derived from source code of TrueCrypt 7.1a, which is
    3  Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
    4  by the TrueCrypt License 3.0.
    5 
    6  Modifications and additions to the original source code (contained in this file) 
    7  and all other portions of this file are Copyright (c) 2013-2017 IDRIX
    8  and are governed by the Apache License 2.0 the full text of which is
    9  contained in the file License.txt included in VeraCrypt binary and source
   10  code distribution packages.
   11 */
   12 
   13 #define TC_MAIN_COM_VERSION_MAJOR 2
   14 #define TC_MAIN_COM_VERSION_MINOR 10
   15 
   16 #define TC_FORMAT_COM_VERSION_MAJOR 2
   17 #define TC_FORMAT_COM_VERSION_MINOR 8
   18 
   19 #include <atlbase.h>
   20 #include <comdef.h>
   21 #include <statreg.h>
   22 #include <windows.h>
   23 #include "ComSetup.h"
   24 #include "Dlgcode.h"
   25 #include "Resource.h"
   26 #include "../Mount/MainCom_i.c"
   27 #include "../Format/FormatCom_i.c"
   28 
   29 
   30 extern "C" BOOL RegisterComServers (wchar_t *modulePath)
   31 {
   32     BOOL ret = TRUE;
   33     wchar_t mainModule[1024], formatModule[1024];
   34     CComPtr<ITypeLib> tl, tl2;
   35 
   36     wsprintfW (mainModule, L"%sVeraCrypt.exe", modulePath);
   37     wsprintfW (formatModule, L"%sVeraCrypt Format.exe", modulePath);
   38 
   39     UnRegisterTypeLib (LIBID_TrueCryptMainCom, TC_MAIN_COM_VERSION_MAJOR, TC_MAIN_COM_VERSION_MINOR, 0, SYS_WIN32);
   40     UnRegisterTypeLib (LIBID_TrueCryptFormatCom, TC_FORMAT_COM_VERSION_MAJOR, TC_FORMAT_COM_VERSION_MINOR, 0, SYS_WIN32);
   41     // unregister older versions that may still exist
   42     for (WORD i = 6; i >= 1; i--)
   43         UnRegisterTypeLib (LIBID_TrueCryptMainCom, TC_MAIN_COM_VERSION_MAJOR, TC_MAIN_COM_VERSION_MINOR-i, 0, SYS_WIN32);
   44     for (WORD i = 4; i >= 1; i--)
   45         UnRegisterTypeLib (LIBID_TrueCryptFormatCom, TC_FORMAT_COM_VERSION_MAJOR, TC_FORMAT_COM_VERSION_MINOR-i, 0, SYS_WIN32);
   46 
   47     wchar_t setupModule[MAX_PATH];
   48     GetModuleFileNameW (NULL, setupModule, sizeof (setupModule) / sizeof (setupModule[0]));
   49 
   50     CRegObject ro;
   51     HRESULT r;
   52 
   53     if (!SUCCEEDED (r = ro.FinalConstruct ())
   54         || !SUCCEEDED (r = ro.AddReplacement (L"MAIN_MODULE", mainModule))
   55         || !SUCCEEDED (r = ro.AddReplacement (L"FORMAT_MODULE", formatModule))
   56         || !SUCCEEDED (r = ro.ResourceRegister (setupModule, IDR_COMREG, L"REGISTRY"))
   57         || !SUCCEEDED (r = LoadTypeLib (mainModule, &tl))
   58         || !SUCCEEDED (r = RegisterTypeLib (tl, mainModule, 0))
   59         || !SUCCEEDED (r = LoadTypeLib (formatModule, &tl2))
   60         || !SUCCEEDED (r = RegisterTypeLib (tl2, formatModule, 0)))
   61     {
   62         MessageBox (MainDlg, _com_error (r).ErrorMessage(), _T(TC_APP_NAME), MB_ICONERROR);
   63         ret = FALSE;
   64     }
   65 
   66     ro.FinalRelease ();
   67     return ret;
   68 }
   69 
   70 
   71 extern "C" BOOL UnregisterComServers (wchar_t *modulePath)
   72 {
   73     BOOL ret;
   74 
   75     if (UnRegisterTypeLib (LIBID_TrueCryptMainCom, TC_MAIN_COM_VERSION_MAJOR, TC_MAIN_COM_VERSION_MINOR, 0, SYS_WIN32) != S_OK)
   76         return FALSE;
   77     if (UnRegisterTypeLib (LIBID_TrueCryptFormatCom, TC_FORMAT_COM_VERSION_MAJOR, TC_FORMAT_COM_VERSION_MINOR, 0, SYS_WIN32) != S_OK)
   78         return FALSE;
   79 
   80     // unregister older versions that may still exist
   81     for (WORD i = 6; i >= 1; i--)
   82         UnRegisterTypeLib (LIBID_TrueCryptMainCom, TC_MAIN_COM_VERSION_MAJOR, TC_MAIN_COM_VERSION_MINOR-i, 0, SYS_WIN32);
   83     for (WORD i = 4; i >= 1; i--)
   84         UnRegisterTypeLib (LIBID_TrueCryptFormatCom, TC_FORMAT_COM_VERSION_MAJOR, TC_FORMAT_COM_VERSION_MINOR-i, 0, SYS_WIN32);
   85 
   86     wchar_t module[1024];
   87     CRegObject ro;
   88     ro.FinalConstruct ();
   89 
   90     wsprintfW (module, L"%sVeraCrypt.exe", modulePath);
   91     ro.AddReplacement (L"MAIN_MODULE", module);
   92 
   93     wsprintfW (module, L"%sVeraCrypt Format.exe", modulePath);
   94     ro.AddReplacement (L"FORMAT_MODULE", module);
   95 
   96     wchar_t setupModule[MAX_PATH];
   97     GetModuleFileNameW (NULL, setupModule, sizeof (setupModule) / sizeof (setupModule[0]));
   98 
   99     ret = ro.ResourceUnregister (setupModule, IDR_COMREG, L"REGISTRY") == S_OK;
  100 
  101     ro.FinalRelease ();
  102     return ret;
  103 }