-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
156 lines (134 loc) · 5.54 KB
/
main.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
// XIVRP-Formatter Copyright (C) 2024 Ethan Henderson <[email protected]>
// Licensed under GPLv3 - Refer to the LICENSE file for the complete text
#include "images/related_images.h"
#include "includes/date.h"
#include "messages/gaps.h"
#include "messages/loading.h"
#include "messages/messages.h"
#include "settings/settings.h"
#include "templating/templating.h"
#include <iostream>
#include <windows.h>
using messages::load;
using settings::loader;
using settings::structure;
// 0 : success
// 1 : messages file not verified
// 2 : template file not verified
// 3 : messages file could not open
// 4 : template file could not open
// 5 : contents not provided to templator
// 6 : output file could not be created
int main(int arg_count, char *arguments[]) {
std::cout << "XIVRP-Formatter Copyright (C) 2024 Ethan Henderson"
<< std::endl
<< std::endl;
//<editor-fold desc="Settings">
// Get the user's settings
settings::loader user = settings::loader(arg_count, arguments);
// Fail out if the settings were not suitable
if (!user.log_verified) {
std::cout << std::endl
<< "The log file could not be verified. Please try again."
<< std::endl;
return 2;
}
if (!user.template_verified) {
std::cout << std::endl
<< "The template file could not be verified. Please try again."
<< std::endl;
return 3;
}
//</editor-fold>
// Check for the debug flag
for (int i = 0; i < arg_count; ++i)
if (std::string(arguments[i]) == "--debug")
user.settings.debug = true;
std::cout << std::endl << "---" << std::endl << std::endl;
// Load the messages
messages::load load(user.settings);
// Save the loaded messages
messages::structure messages = load.messages;
int count;
// Remove OOC messages if requested
if (user.settings.remove_out_of_character) {
std::cout << std::endl << "Removing OOC messages..." << std::endl;
count = messages.remove_ooc();
std::cout << "...Removed " << count << " messages." << std::endl;
}
if (user.settings.debug)
messages.debug_print();
// Combine messages that are continuations of others if requested
if (user.settings.combine_messages) {
std::cout << std::endl << "Combining messages..." << std::endl;
count = messages.combine(user.settings.debug);
std::cout << "...Combined " << count << " messages." << std::endl;
}
// Highlight emphatics if requested
if (user.settings.highlight_emphatics) {
std::cout << std::endl << "Highlighting emphatics..." << std::endl;
count =
messages.highlight_emphatics(user.settings.emphatic_highlight_color);
std::cout << "...Highlighted " << count << " messages." << std::endl;
}
// Find images, and relate them to messages if requested
related_images::related_images related;
if (user.settings.find_related_images) {
std::cout << std::endl << "Finding related images..." << std::endl;
related =
related_images::related_images(user.settings.log_file_path, messages);
std::cout << "...Found " << related.related_images_found << " image"
<< (related.related_images_found == 1 ? "" : "s") << "."
<< std::endl;
std::cout << "......" << related.images_assigned_manually
<< " manually related." << std::endl;
std::cout << "......" << related.images_assigned_by_timestamp
<< " related by filename time." << std::endl;
std::cout << "......" << related.images_assigned_by_creation_time
<< " related by creation time." << std::endl;
std::cout << "..." << related.images_pushed_down
<< " were pushed down, to unrelated messages." << std::endl;
std::cout << "......" << related.images_assigned_randomly
<< " related randomly." << std::endl;
}
// Find and squash time gaps, if requested
messages::gaps gaps;
if (user.settings.squash_time_gaps) {
std::cout << std::endl << "Squashing time gaps..." << std::endl;
gaps = messages::gaps(messages);
std::cout << "...Average of "
<< date::format(
"%R", floor<std::chrono::milliseconds>(gaps.average_gap))
<< " between messages." << std::endl;
std::cout << "...Squashed " << gaps.number_of_gaps_found << " gap"
<< (gaps.number_of_gaps_found == 1 ? "" : "s") << "."
<< std::endl;
std::cout << "......Removing "
<< date::format(
"%R", floor<std::chrono::milliseconds>(gaps.gap_squashed))
<< " from the session." << std::endl;
messages = gaps.messages;
}
// Format the messages
std::map<std::string, std::string> formatted_messages;
std::cout << std::endl << "Formatting messages..." << std::endl;
if (user.settings.find_related_images)
formatted_messages = messages.format(related.images);
else
formatted_messages = messages.format();
// Fill the template with the messages
std::cout << "Filling template..." << std::endl;
templating::templator templator(user.settings.template_file_path);
templator.content = formatted_messages;
templator.fill_template(user.settings.output_file_path);
// Done!
std::cout << std::endl << "Done!" << std::endl;
std::cout << "Output file written to " << user.settings.output_file_path
<< std::endl;
// Open the output file
std::filesystem::path absolute_path =
std::filesystem::absolute(user.settings.output_file_path);
std::string url = "file:///" + absolute_path.string();
ShellExecute(nullptr, "open", url.c_str(), nullptr, nullptr, SW_SHOWNORMAL);
return 0;
}