1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef CHROME_INSTALLER_MINI_INSTALLER_MINI_INSTALLER_H_
6 #define CHROME_INSTALLER_MINI_INSTALLER_MINI_INSTALLER_H_
7 
8 #include <windows.h>
9 
10 #include "chrome/installer/mini_installer/exit_code.h"
11 #include "chrome/installer/mini_installer/mini_string.h"
12 #include "chrome/installer/mini_installer/path_string.h"
13 
14 namespace mini_installer {
15 
16 class Configuration;
17 
18 // A container of a process exit code (eventually passed to ExitProcess) and
19 // a Windows error code for cases where the exit code is non-zero.
20 struct ProcessExitResult {
21   DWORD exit_code;
22   DWORD windows_error;
23 
ProcessExitResultProcessExitResult24   explicit ProcessExitResult(DWORD exit) : exit_code(exit), windows_error(0) {}
ProcessExitResultProcessExitResult25   ProcessExitResult(DWORD exit, DWORD win)
26       : exit_code(exit), windows_error(win) {}
27 
IsSuccessProcessExitResult28   bool IsSuccess() const { return exit_code == SUCCESS_EXIT_CODE; }
29 };
30 
31 // A stack-based string large enough to hold an executable to run
32 // (which is a path), two additional path arguments, plus a few extra
33 // arguments. Figure that MAX_PATH (260) is sufficient breathing room for the
34 // extra arguments.
35 using CommandString = StackString<MAX_PATH * 4>;
36 
37 // Populates |path| with the path to the previous version's setup.exe, stripping
38 // quotes if present.
39 ProcessExitResult GetPreviousSetupExePath(const Configuration& configuration,
40                                           wchar_t* path,
41                                           size_t size);
42 
43 // Populates |directory| with the directory portion of the path to |module|.
44 // Returns false in case of failure, in which case the contents of |directory|
45 // are undefined and may have been modified.
46 bool GetModuleDir(HMODULE module, PathString* directory);
47 
48 // Populates |directory| with the process's current temp directory. Returns
49 // false in case of failure, in which case |exit_code| is populated with details
50 // and the contents of |directory| are undefined and may have been modified.
51 bool GetTempDir(PathString* directory, ProcessExitResult* exit_code);
52 
53 // Appends everything following the path to the executable in |command_line|
54 // verbatim to |buffer|, including all whitespace, quoted arguments,
55 // etc. |buffer| is unchanged in case of error.
56 void AppendCommandLineFlags(const wchar_t* command_line, CommandString* buffer);
57 
58 // Main function for Chrome's mini_installer. First gets a working dir, unpacks
59 // the resources, and finally executes setup.exe to do the install/update. Also
60 // handles invoking a previous version's setup.exe to patch itself in the case
61 // of differential updates.
62 ProcessExitResult WMain(HMODULE module);
63 
64 }  // namespace mini_installer
65 
66 #endif  // CHROME_INSTALLER_MINI_INSTALLER_MINI_INSTALLER_H_
67