1 #include <algorithm>
   2 #include <windows.h>
   3 
   4 #include "SysInfo.h"
   5 #include "FileUtils.h"
   6 #include "Executor.h"
   7 #include "Resources.h"
   8 #include "WinErrorHandling.h"
   9 
  10 
  11 int __stdcall WinMain(HINSTANCE, HINSTANCE, LPSTR lpCmdLine, int nShowCmd)
  12 {
  13     JP_TRY;
  14 
  15     // Create temporary directory where to extract msi file.
  16     const auto tempMsiDir = FileUtils::createTempDirectory();
  17 
  18     // Schedule temporary directory for deletion.
  19     FileUtils::Deleter cleaner;
  20     cleaner.appendRecursiveDirectory(tempMsiDir);
  21 
  22     const auto msiPath = FileUtils::mkpath() << tempMsiDir << L"main.msi";
  23 
  24     // Extract msi file.
  25     Resource(L"msi", RT_RCDATA).saveToFile(msiPath);
  26 
  27     // Setup executor to run msiexec
  28     Executor msiExecutor(SysInfo::getWIPath());
  29     msiExecutor.arg(L"/i").arg(msiPath);
  30     const auto args = SysInfo::getCommandArgs();
  31     std::for_each(args.begin(), args.end(),
  32             [&msiExecutor] (const tstring& arg) {
  33         msiExecutor.arg(arg);
  34     });
  35 
  36     // Install msi file.
  37     return msiExecutor.execAndWaitForExit();
  38 
  39     JP_CATCH_ALL;
  40 
  41     return -1;
  42 }