-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpatch.cpp
78 lines (64 loc) · 1.43 KB
/
patch.cpp
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
73
74
75
76
77
78
#include "config.h"
#include "patch.h"
std::vector<std::reference_wrapper<File>> File::g_files;
int main(int argc, char* argv[])
{
struct ExitGuard
{
~ExitGuard()
{
std::cout << "Press enter to exit...";
std::cin.ignore();
}
} guard;
if (!g_productName.empty() || !g_newVersion.empty())
{
std::cout << g_productName << " ";
if (!g_newVersion.empty())
std::cout << g_newVersion << " ";
std::cout << "patch" << std::endl;
}
if (argc > 2)
{
std::cerr << "Invalid arguments" << std::endl;
return EXIT_FAILURE;
}
auto root = std::filesystem::current_path();
if (argc > 1)
{
root = std::filesystem::absolute(argv[1]);
}
if (!std::filesystem::is_directory(root))
{
std::cerr << "Invalid directory: " << root.string() << std::endl;
return EXIT_FAILURE;
}
for (File& file : File::getFiles())
{
if (!file.validate(root))
{
if (g_oldVersion.empty())
{
std::cerr << "Failed to find required version" << std::endl;
}
else
{
std::cerr << "Failed to find version " << g_oldVersion << std::endl;
}
return EXIT_FAILURE;
}
}
std::cout << "Installing to: " << root.string() << std::endl;
std::cout << "Press enter to continue...";
std::cin.ignore();
for (File& file : File::getFiles())
{
if (!file.perform(root))
{
std::cout << "Installation failed" << std::endl;
return EXIT_FAILURE;
}
}
std::cout << "Installation successful" << std::endl;
return EXIT_SUCCESS;
}