forked from acaudwell/Gource
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
224 lines (163 loc) · 6.29 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/*
Copyright (C) 2009 Andrew Caudwell ([email protected])
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version
3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "main.h"
int main(int argc, char *argv[]) {
std::string exepath;
#ifndef _WIN32
if(argc > 0) {
exepath = std::string(argv[0]);
}
#endif
SDLAppInit("Gource", "gource", exepath);
#ifdef _WIN32
SDLApp::initConsole();
#endif
ConfFile conf;
std::vector<std::string> files;
//convert args to a conf file
//read the conf file
//apply the conf file to settings
try {
gGourceSettings.parseArgs(argc, argv, conf, &files);
if(gGourceSettings.load_config.empty() && !files.empty()) {
//see if file looks like a config file
for(std::vector<std::string>::iterator fit = files.begin(); fit != files.end(); fit++) {
std::string file = *fit;
int file_length = file.size();
if( (file.rfind(".conf") == (file_length-5) && file_length > 5)
|| (file.rfind(".cfg") == (file_length-4) && file_length > 4)
|| (file.rfind(".ini") == (file_length-4) && file_length > 4) ) {
bool is_conf=true;
try {
ConfFile conftest;
conftest.load(file);
} catch(ConfFileException& exception) {
is_conf = false;
}
if(is_conf) {
gGourceSettings.load_config = file;
files.erase(fit);
break;
}
}
}
}
//set log level
Logger::getDefault()->setLevel(gGourceSettings.log_level);
#ifdef _WIN32
// hide console if not needed
if(gGourceSettings.log_level == LOG_LEVEL_OFF && !SDLApp::existing_console) {
SDLApp::showConsole(false);
}
#endif
//load config
if(!gGourceSettings.load_config.empty()) {
conf.clear();
conf.load(gGourceSettings.load_config);
//apply args to loaded conf file
gGourceSettings.parseArgs(argc, argv, conf);
}
//set path
if(!files.empty()) {
std::string path = files[files.size()-1];
ConfSectionList* sectionlist = conf.getSections("gource");
if(sectionlist!=0) {
for(ConfSectionList::iterator sit = sectionlist->begin(); sit != sectionlist->end(); sit++) {
(*sit)->setEntry("path", path);
}
} else {
conf.setEntry("gource", "path", path);
}
}
//apply the config / see if its valid
gGourceSettings.importDisplaySettings(conf);
gGourceSettings.importGourceSettings(conf);
//save config
if(!gGourceSettings.save_config.empty()) {
conf.save(gGourceSettings.save_config);
exit(0);
}
//write custom log file
if(!gGourceSettings.output_custom_filename.empty() && !gGourceSettings.path.empty()) {
Gource::writeCustomLog(gGourceSettings.path, gGourceSettings.output_custom_filename);
exit(0);
}
} catch(ConfFileException& exception) {
SDLAppQuit(exception.what());
}
//enable frameless
display.enableFrameless(gGourceSettings.frameless);
// this causes corruption on some video drivers
if(gGourceSettings.multisample) {
display.multiSample(4);
}
//background needs alpha channel
if(gGourceSettings.transparent) {
display.enableAlpha(true);
}
//enable vsync
display.enableVsync(gGourceSettings.vsync);
//allow resizing window if we are not recording
if(gGourceSettings.resizable && gGourceSettings.output_ppm_filename.empty()) {
display.enableResize(true);
}
try {
display.init("Gource", gGourceSettings.display_width, gGourceSettings.display_height, gGourceSettings.fullscreen, gGourceSettings.screen);
#if SDL_VERSION_ATLEAST(2,0,0)
if(!display.isFullscreen() && gGourceSettings.window_x >= 0 && gGourceSettings.window_y >= 0) {
SDL_SetWindowPosition(display.sdl_window, gGourceSettings.window_x, gGourceSettings.window_y);
}
SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0");
#endif
} catch(SDLInitException& exception) {
char errormsg[1024];
snprintf(errormsg, 1024, "SDL initialization failed - %s", exception.what());
SDLAppQuit(errormsg);
}
//init frame exporter
FrameExporter* exporter = 0;
if(gGourceSettings.output_ppm_filename.size() > 0) {
try {
exporter = new PPMExporter(gGourceSettings.output_ppm_filename);
} catch(PPMExporterException& exception) {
char errormsg[1024];
snprintf(errormsg, 1024, "could not write to '%s'", exception.what());
SDLAppQuit(errormsg);
}
}
if(display.multiSamplingEnabled()) {
glEnable(GL_MULTISAMPLE_ARB);
}
GourceShell* gourcesh = 0;
try {
gourcesh = gGourceShell = new GourceShell(&conf, exporter);
gourcesh->run();
} catch(ResourceException& exception) {
char errormsg[1024];
snprintf(errormsg, 1024, "failed to load resource '%s'", exception.what());
SDLAppQuit(errormsg);
} catch(SDLAppException& exception) {
if(exception.showHelp()) {
gGourceSettings.help();
} else {
SDLAppQuit(exception.what());
}
}
gGourceShell = 0;
if(gourcesh != 0) delete gourcesh;
if(exporter != 0) delete exporter;
//free resources
display.quit();
return 0;
}