summaryrefslogtreecommitdiffstats
path: root/mmc_updater/src/UpdateInstaller.h
blob: 5cbac561331dd7fea421d2b6e150a2240952f21b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#pragma once

#include "Platform.h"
#include "FileUtils.h"
#include "UpdateScript.h"

#include <list>
#include <string>
#include <map>

class UpdateObserver;

/** Central class responsible for installing updates,
  * launching an elevated copy of the updater if required
  * and restarting the main application once the update
  * is installed.
  */
class UpdateInstaller
{
	public:
		enum Mode
		{
			Setup,
			Main
		};

		void setInstallDir(const std::string& path);
		void setPackageDir(const std::string& path);
		void setBackupDir(const std::string& path);
		void setMode(Mode mode);
		void setScript(UpdateScript* script);
		void setWaitPid(PLATFORM_PID pid);
		void setForceElevated(bool elevated);
		void setAutoClose(bool autoClose);
		void setDryRun(bool dryRun);
		void setFinishCmd(const std::string& cmd);

		void setObserver(UpdateObserver* observer);

		void run() throw ();

		void restartMainApp();

	private:
		void cleanup();
		void revert();
		void removeBackups();
		bool checkAccess();

		void installFiles();
		void uninstallFiles();
		void installFile(const UpdateScriptFile& file);
		void backupFile(const std::string& path);
		void reportError(const std::string& error);
		void postInstallUpdate();

		std::list<std::string> updaterArgs() const;
		std::string friendlyErrorForError(const FileUtils::IOException& ex) const;

		Mode m_mode = Setup;
		std::string m_installDir;
		std::string m_packageDir;
		std::string m_backupDir;
		std::string m_finishCmd;
		PLATFORM_PID m_waitPid = 0;
		UpdateScript* m_script = nullptr;
		UpdateObserver* m_observer = nullptr;
		std::map<std::string,std::string> m_backups;
		bool m_forceElevated = false;
		bool m_autoClose = false;
		bool m_dryRun = false;
};