1 /* UMark
2  * Copyright (C)2003-2005 Jeffrey Bakker
3 
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8 
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13 
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17    ___________________________________ .. .
18  */
19 
20 /*****
21 	The following block defines the source of a PERL script used to
22 	collect system information. This script has to be generated and
23 	deleted before and after use respectively, to ensure the script
24 	does not get modified by users (for cheat protection purposes).
25 **/
26 
27 /***** BEGIN PERL BLOCK ******************************************************/
28 #define _SYSTEM_INFO_PL "#!/usr/bin/perl -w\n\
29 # obtains system info\n\
30 use strict;\n\
31 use Digest::MD5 'md5_hex';\n\
32 \n\
33 use constant STR_MAP => 0;\n\
34 use constant STR_BOT => 1;\n\
35 use constant STR_DTL => 2;\n\
36 use constant STR_RES => 3;\n\
37 use constant STR_MIN => 4;\n\
38 use constant STR_AVG => 5;\n\
39 use constant STR_MAX => 6;\n\
40 use constant STR_SCR => 7;\n\
41 use constant STR_VER => 8;\n\
42 use constant STR_TYP => 9;\n\
43 \n\
44 my $ulogpath = shift or die \"Error: no input file.\\n\";\n\
45 \n\
46 my $i;\n\
47 my $benchtype;\n\
48 my $AUID = md5_hex(\"UMark for Linux\");\n\
49 my $EHSH = md5_hex(\"UMark for Linux\");\n\
50 \n\
51 chomp(my $os_versn = `uname -s -r`);\n\
52 \n\
53 # collect various system information\n\
54 chomp(my @cpuinfo = `cat /proc/cpuinfo`);\n\
55 chomp(my @pciinfo = `cat /proc/pci`);\n\
56 chomp(my @glxinfo = `glxinfo`);\n\
57 chomp(my @meminfo = `free -m`);\n\
58 \n\
59 # collect specific cpu info\n\
60 (my $cpu_mhzs = $cpuinfo[6]) =~ s/cpu MHz.*: //g;\n\
61 (my $cpu_vend = $cpuinfo[1]) =~ s/vendor_id.*: //g;\n\
62 (my $cpu_modl = $cpuinfo[4]) =~ s/model name.*: //g;\n\
63 \n\
64 # find the number of processors\n\
65 my $a_size = @cpuinfo;\n\
66 my $num_cpus;\n\
67 \n\
68 $num_cpus = $a_size / 19;\n\
69 $num_cpus = sprintf(\"%%d\", $num_cpus);\n\
70 \n\
71 # round off MHz to an integer value\n\
72 $cpu_mhzs = sprintf(\"%%d\", $cpu_mhzs);\n\
73 \n\
74 # formulate CPU name\n\
75 #my $cpu_name = $cpu_vend . \" \" . $cpu_modl;\n\
76 my $cpu_name = $cpu_modl;\n\
77 \n\
78 \n\
79 # collect video information\n\
80 my $vid_card;\n\
81 my $vid_drvr;\n\
82 \n\
83 foreach my $line (@pciinfo)\n\
84 {\n\
85 	if($line =~ m/VGA compatible controller/)\n\
86 	{\n\
87 		($vid_card = $line) =~ s/VGA compatible controller://g;\n\
88 		chop $vid_card;\n\
89 	}\n\
90 }\n\
91 $vid_card =~ s/^\\s{0,}//g;\n\
92 \n\
93 foreach my $line (@glxinfo)\n\
94 {\n\
95 	if($line =~ m/OpenGL version string:/)\n\
96 	{\n\
97 		($vid_drvr = $line) =~ s/OpenGL version string://g;\n\
98 		chomp $vid_drvr;\n\
99 	}\n\
100 }\n\
101 $vid_drvr =~ s/^\\s{0,}//g;\n\
102 \n\
103 \n\
104 # collect memory information\n\
105 (my $mem = $meminfo[1]) =~ s/Mem:\\s{0,}(\\d{0,}).*/$1/g;\n\
106 (my $swp = $meminfo[3]) =~ s/Swap:\\s{0,}(\\d{0,}).*/$1/g;\n\
107 \n\
108 # collect scores for form submission\n\
109 open(UMTMP_LOG, \"<$ulogpath/Benchmark/UMTMP_LOG\") or die \"$1: cannot read $ulogpath/Benchmark/UMTMP_LOG\";\n\
110 \n\
111 my @scores = <UMTMP_LOG>;\n\
112 chomp @scores;\n\
113 close(UMTMP_LOG);\n\
114 \n\
115 print <<'_HTML_';\n\
116 \n\
117 <html>\n\
118 <head>\n\
119 <title>UMark Results</title>\n\
120 <link rel=\"stylesheet\" type=\"text/css\" href=\"html/umarks.css\">\n\
121 </head>\n\
122 </body>\n\
123 \n\
124 <div id=\"headbg\"></div>\n\
125 <div id=\"header\"></div>\n\
126 <div id=\"banner\"></div>\n\
127 <div id=\"neck\">Offline UMark Results</div>\n\
128 \n\
129 <div id=\"login\">\n\
130 <form action=\"http://unrealmark.net/results_linux.php\" method=\"post\">\n\
131 <input type=\"hidden\" name=\"system_config\"\n\
132 _HTML_\n\
133 \n\
134 print \" value=\\\"\";\n\
135 \n\
136 print \"$os_versn|$num_cpus|$cpu_mhzs|$cpu_name|$vid_card|$vid_drvr|$mem|$swp\\\">\\n\";\n\
137 print \"<input type=\\\"hidden\\\" name=\\\"auth_id\\\" value=\\\"$AUID\\\">\\n\";\n\
138 print \"<input type=\\\"hidden\\\" name=\\\"exe_hash\\\" value=\\\"$EHSH\\\">\\n\";\n\
139 \n\
140 #TODO: count num_maps and post each map\n\
141 my $mapnum;\n\
142 my @map;\n\
143 for($i = 0; $i < @scores; $i++)\n\
144 {\n\
145 	@map = split(/\\|/, $scores[$i]);\n\
146 	$mapnum = $i + 1;\n\
147 	print \"<input type=\\\"hidden\\\" name=\\\"umark_map$mapnum\\\" \";\n\
148 	print \"value=\\\"$map[STR_MAP]|$map[STR_BOT]|$map[STR_DTL]|$map[STR_RES]|$map[STR_MIN]|$map[STR_AVG]|$map[STR_MAX]|$map[STR_SCR]|$map[STR_VER]|$map[STR_TYP]|\\\">\\n\";\n\
149 \n\
150 	$benchtype = $map[STR_TYP];\n\
151 }\n\
152 \n\
153 my $ini_file_name;\n\
154 my $ini_user_name;\n\
155 \n\
156 if($map[STR_DTL] eq \"Low\")\n\
157 {\n\
158 	$ini_file_name = \"UMarkPerformance.ini\";\n\
159 	$ini_user_name = \"UMarkPerformanceUser.ini\";\n\
160 }\n\
161 elsif($map[STR_DTL] eq \"High\")\n\
162 {\n\
163 	$ini_file_name = \"UMarkQuality.ini\";\n\
164 	$ini_user_name = \"UMarkQualityUser.ini\";\n\
165 }\n\
166 else\n\
167 {\n\
168 	$ini_file_name = \"N/A\";\n\
169 	$ini_user_name = \"N/A\";\n\
170 }\n\
171 (my $ini_file_hash = `md5sum $ulogpath/Benchmark/Stuff/$ini_file_name -t`) =~ s/(.{32}).*/$1/;\n\
172 (my $ini_user_hash = `md5sum $ulogpath/Benchmark/Stuff/$ini_user_name -t`) =~ s/(.{32}).*/$1/;\n\
173 \n\
174 chomp $ini_file_hash;\n\
175 chomp $ini_user_hash;\n\
176 \n\
177 print \"<input type=\\\"hidden\\\" name=\\\"ini_hash\\\" value=\\\"$ini_file_hash\\\">\\n\";\n\
178 print \"<input type=\\\"hidden\\\" name=\\\"usr_hash\\\" value=\\\"$ini_user_hash\\\">\\n\";\n\
179 print \"<input type=\\\"hidden\\\" name=\\\"num_maps\\\" value=\\\"$mapnum\\\">\\n\";\n\
180 \n\
181 print <<'_HTML_';\n\
182 \n\
183 <table cellpadding=\"0\">\n\
184 <tr>\n\
185 <td><input type=\"text\" name=\"uname\" maxlength=\"40\" style=\"width: 92px;\"></td>\n\
186 <td><input type=\"password\" name=\"passwd\" maxlength=\"50\" style=\"width: 92px;\"></td>\n\
187 <td><input type=\"submit\" value=\"Submit Score\" style=\"width: 92px;\"></td>\n\
188 </tr><tr>\n\
189 <td>username</td>\n\
190 <td>password</td>\n\
191 <td><a href=\"http://unrealmark.net/register.php\">register</a></td>\n\
192 </tr></table>\n\
193 </form>\n\
194 </div>\n\
195 \n\
196 <div id=\"content\">\n\
197 <div id=\"title\"><img src=\"html/results.png\" alt=\"UMark Results\"></div>\n\
198 <table class=\"info\" cellspacing=\"0\">\n\
199 <tr>\n\
200 <td class=\"ul\"></td>\n\
201 <td class=\"uc\"></td>\n\
202 <td class=\"ur\"></td>\n\
203 </tr><tr>\n\
204 <td class=\"ml\"></td>\n\
205 <td class=\"mc\">\n\
206 \n\
207 _HTML_\n\
208 \n\
209 print \"<h2 align=\\\"center\\\">$benchtype Benchmark</h2>\\n\";\n\
210 \n\
211 print \"<h2 style=\\\"margin-bottom: 0px;\\\">System</h2>\";\n\
212 print \"OS Version: $os_versn<br>\\n\";\n\
213 print \"Processors: $num_cpus<br>\\nCPU Speed: ~$cpu_mhzs MHz<br>\\nCPU Name: $cpu_name<br>\\n\";\n\
214 print \"Video Card: $vid_card<br>\\n\";\n\
215 print \"OpenGL Driver: $vid_drvr<br>\\n\";\n\
216 print \"Memory: $mem MB<br>\\n\";\n\
217 print \"Swap File: $swp MB<br><br>\\n\";\n\
218 \n\
219 my $total;\n\
220 \n\
221 foreach my $line (@scores)\n\
222 {\n\
223 	my $highest;\n\
224 	my $hundred;\n\
225 	my @calchis;\n\
226 	my @percent;\n\
227 	my @map = split(/\\|/, $line);\n\
228 \n\
229 	$calchis[0] = $map[STR_MIN];\n\
230 	$calchis[1] = $map[STR_AVG];\n\
231 	$calchis[2] = $map[STR_MAX];\n\
232 	$calchis[3] = $map[STR_SCR];\n\
233 \n\
234 	for($i = 0; $i <= 3; $i++)\n\
235 	{\n\
236 		if($i == 0)\n\
237 		{\n\
238 			$highest = $calchis[$i];\n\
239 		}\n\
240 \n\
241 		if($calchis[$i] > $highest)\n\
242 		{\n\
243 			$highest = $calchis[$i];\n\
244 		}\n\
245 	}\n\
246 	for($i = 0; $i <= 3; $i++)\n\
247 	{\n\
248 		$hundred = $highest / 100;\n\
249 		$percent[$i] = $calchis[$i] / $hundred;\n\
250 	}\n\
251 \n\
252 	print \"<h2 style=\\\"margin-bottom: 0px;\\\">$map[STR_MAP]</h2>\\n<b>Build $map[STR_VER]</b><br><br>\\n\";\n\
253 	print \"Bots: $map[STR_BOT]<br>\\nDetail: $map[STR_DTL]<br>\\nResolution: $map[STR_RES]<br><br>\\n\";\n\
254 \n\
255 	print \"<div id=\\\"results\\\">\\n\";\n\
256 	print \"<div id=\\\"bar\\\" style=\\\"width: $percent[0]%\\\">Min $map[STR_MIN]</div>\\n\";\n\
257 	print \"<div id=\\\"bar\\\" style=\\\"width: $percent[1]%\\\">Avg $map[STR_AVG]</div>\\n\";\n\
258 	print \"<div id=\\\"bar\\\" style=\\\"width: $percent[2]%\\\">Max $map[STR_MAX]</div>\\n\";\n\
259 	print \"<div id=\\\"bar\\\" style=\\\"width: $percent[3]%\\\">Score $map[STR_SCR]</div>\\n\";\n\
260 	print \"</div>\\n\\n\";\n\
261 \n\
262 	$total += $map[STR_SCR];\n\
263 }\n\
264 \n\
265 my $totsize = length($total);\n\
266 \n\
267 print \"<center>\\n\";\n\
268 for($i = 0; $i <= $totsize -1; $i++)\n\
269 {\n\
270 	print \"<img src=\\\"html/0\";\n\
271 	print substr($total,$i,1);\n\
272 	print \".png\\\">\\n\";\n\
273 }\n\
274 print \"<h1 style=\\\"margin-bottom: 24px;\\\">$total UMarks</h1>\\n</center>\\n\";\n\
275 \n\
276 print <<'_HTML_';\n\
277 \n\
278 </td>\n\
279 <td class=\"mr\"></td>\n\
280 </tr><tr>\n\
281 <td class=\"ll\"></td>\n\
282 <td class=\"lc\"></td>\n\
283 <td class=\"lr\"></td>\n\
284 </tr></table>\n\
285 <div id=\"foot\">UMark &copy;2004 Jeffrey Bakker. Unreal&#174; Tournament 2004 &copy;2004 Epic games, Inc.</div>\n\
286 </div>\n\
287 </body>\n\
288 </html>\n\
289 \n\
290 _HTML_\n"
291 /***** END PERL BLOCK ********************************************************/
292 
293 
294 #ifdef HAVE_CONFIG_H
295 #  include <config.h>
296 #endif
297 
298 #include <sys/stat.h>
299 #include <gtk/gtk.h>
300 #include <stdio.h>
301 
302 #include "callbacks.h"
303 #include "interface.h"
304 #include "support.h"
305 
306 
307 #define	DTL_LO	2
308 #define	DTL_HI	3
309 #define	DTL_CR	0
310 #define	DTL_CS	1
311 
312 #define AUGMENT 0x3a
313 
314 /* resolution */
315 enum
316 {
317 	RES_640	= 0,
318 	RES_800,
319 	RES_1024,
320 	RES_1280,
321 	RES_1600
322 };
323 /* presets */
324 enum
325 {
326 	PRE_BM	= 1,
327 	PRE_FB,
328 	PRE_DM,
329 	PRE_D4,
330 	PRE_DE,
331 	PRE_EG,
332 	PRE_U3,
333 	PRE_U4,
334 	PRE_TD
335 };
336 /* columns */
337 enum
338 {
339 	COL_MAP	= 0,
340 	COL_BOT,
341 	COL_DTL,
342 	COL_RES,
343 	COL_MIN,
344 	COL_AVG,
345 	COL_MAX,
346 	COL_SCR,
347 	COL_VER,
348 	COL_TYP
349 };
350 /* results */
351 struct UResults
352 {
353 	char	Map[44];
354 	int	Bot;
355 	int	Res;
356 	int	Dtl;
357 	double	Min;
358 	double	Avg;
359 	double	Max;
360 	double	Scr;
361 	int	Ver;
362 	int	Typ;
363 };
364 
365 
366 /* additional dialogs */
367 GtkWidget*	UMsgBox;
368 GtkWidget*	ConfBox;
369 GtkWidget*	AboutBox;
370 GtkWidget*	PresetsBox;
371 GtkWidget*	ResultsBox;
372 
373 
374 /* main window data */
375 gboolean	run_batch	= TRUE;
376 gboolean	fullscreen	= TRUE;
377 gboolean	res640x480	= FALSE;
378 gboolean	res800x600	= FALSE;
379 gboolean	res1024x768	= FALSE;
380 gboolean	res1280x1024	= FALSE;
381 gboolean	res1600x1200	= FALSE;
382 
383 gboolean	dotimedemo	= FALSE;
384 
385 gchar*		Command;
386 gchar*		inifile	= "";
387 gchar*		iniuser = "";
388 gchar*		strres	= "";
389 gchar*		strdtl	= "";
390 gchar*		map	= "";
391 gchar*		utver	= "";	/* ut2003, ut2004, etc */
392 gchar*		utdir	= "";	/* ut200x install dir */
393 gchar*		utpath	= "";	/* $HOME/.ut200x */
394 gchar*		bswitch = "";
395 
396 
397 gchar*		instdir1;
398 gchar*		instdir2;
399 gchar*		instdir3;
400 gchar*		instdir4;
401 
402 gint		builds[4];
403 gint		build = 0;
404 gint		numbots	= 12;
405 gint		detail	= DTL_CR;
406 
407 /* presets data */
408 gint		presetchosen	= 0;
409 
410 
411 /* gtktreeview */
412 /*GtkListStore	*lsBatchList;
413 */
414 GtkListStore	*lsResultList;
415 
416 
417 /*** error messages **********************************************************/
418 void
umark_message_dialog(gchar * message)419 umark_message_dialog(gchar* message)
420 {
421 	GtkLabel	*label;
422 
423 	UMsgBox = create_MsgDlg();
424 	label = GTK_LABEL( lookup_widget(GTK_WIDGET(UMsgBox), "lblMsgDlg") );
425 
426 	gtk_label_set_text(label, message);
427 	gtk_dialog_run(GTK_DIALOG(UMsgBox));
428 
429 	gtk_widget_destroy(GTK_WIDGET(UMsgBox));
430 }
431 
432 
433 /*** init dialog *************************************************************/
434 static GtkTreeModel *
create_fill_resultlist(void)435 create_fill_resultlist(void)
436 {
437 	GtkListStore	*store;
438 	GtkTreeIter	iter;
439 
440 	store = gtk_list_store_new(10, G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_DOUBLE, G_TYPE_DOUBLE, G_TYPE_DOUBLE, G_TYPE_DOUBLE, G_TYPE_INT, G_TYPE_STRING);
441 
442 	return GTK_TREE_MODEL(store);
443 }
444 
445 static GtkWidget*
create_model_resultlist(GtkWidget * TVRL)446 create_model_resultlist(GtkWidget *TVRL)
447 {
448 	GtkTreeSelection	*selection;
449 
450 	GtkTreeViewColumn	*col;
451 	GtkCellRenderer		*renderer;
452 	GtkTreeModel		*model;
453 	GtkWidget		*view;
454 
455 	view = TVRL; /* gtk_tree_view_new(); */
456 
457 	renderer = gtk_cell_renderer_text_new();
458 	gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
459 							-1,
460 							"Map",
461 							renderer,
462 							"text", COL_MAP,
463 							NULL);
464 
465 	col = gtk_tree_view_column_new();
466 	gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
467 							-1,
468 							"Bots",
469 							renderer,
470 							"text", COL_BOT,
471 							NULL);
472 
473 	gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
474 							-1,
475 							"Detail",
476 							renderer,
477 							"text", COL_DTL,
478 							NULL);
479 
480 	gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
481 							-1,
482 							"Resolution",
483 							renderer,
484 							"text", COL_RES,
485 							NULL);
486 
487 	gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
488 							-1,
489 							"Min FPS",
490 							renderer,
491 							"text", COL_MIN,
492 							NULL);
493 
494 	gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
495 							-1,
496 							"Avg FPS",
497 							renderer,
498 							"text", COL_AVG,
499 							NULL);
500 
501 	gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
502 							-1,
503 							"Max FPS",
504 							renderer,
505 							"text", COL_MAX,
506 							NULL);
507 
508 	gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
509 							-1,
510 							"Score",
511 							renderer,
512 							"text", COL_SCR,
513 							NULL);
514 
515 	gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
516 							-1,
517 							"Build",
518 							renderer,
519 							"text", COL_VER,
520 							NULL);
521 
522 	gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
523 							-1,
524 							"Type",
525 							renderer,
526 							"text", COL_TYP,
527 							NULL);
528 
529 	model = create_fill_resultlist();
530 
531 	selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(view) );
532 	gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
533 
534 	gtk_tree_view_set_model(GTK_TREE_VIEW(view), model);
535 	g_object_unref(model);
536 
537 	return view;
538 }
539 
540 
541 /*** benchmark options *******************************************************/
542 void
on_spnbots_changed(GtkEditable * editable,gpointer user_data)543 on_spnbots_changed                     (GtkEditable     *editable,
544                                         gpointer         user_data)
545 {
546 	/* FIXME: now crashes after choosing flyby, it now calls this function twice */
547 
548 	if(numbots == 1 && atoi(gtk_entry_get_text(GTK_ENTRY(editable))) < 1)
549 	{
550 		gchar*		FlybyMsg;
551 
552 		FlybyMsg = "With Zero bots selected, flyby benchmark is enabled. However, not all maps support automated flyby paths. Run the flyby preset tests to use supported maps.";
553 /*		umark_message_dialog(FlybyMsg);
554 */	}
555 	numbots = atoi(gtk_entry_get_text(GTK_ENTRY(editable)));
556 }
557 
558 
559 void
on_version_changed(GtkComboBox * combobox,gpointer user_data)560 on_version_changed                     (GtkComboBox     *combobox,
561                                         gpointer         user_data)
562 {
563 
564 /*
565 default paths:
566 
567 Demo
568 2206 /usr/local/games/ut2003_demo/ut2003_demo symlink ut2003_demo config $HOME/.ut2003
569 3334 /usr/local/games/ut2004demo/ut2004-demo symlink ut2004 config $HOME/.ut2004demo
570 
571 Retail
572 2107 /usr/local/games/ut2003/ut2003 symlink ut2003 config $HOME/.ut2003
573 3186 /usr/local/games/ut2004//ut2004 symlink ut2004 config $HOME/.ut2004
574 */
575 	GtkWidget	*UMarkDialog;
576 	GtkComboBox	*cbMaps;
577 	GtkTreeModel	*cbTmod;
578 
579 	FILE		*MapList;
580 	gchar		*lcurmap;
581 	gchar		*MapPath;
582 	gchar		*LogPath;
583 	char		buffer;
584 
585 	gchar		*umarkrc;
586 	gchar		*line;
587 	gint		lnum;
588 	FILE		*RCFILE;
589 
590 	/* set game paths */
591 	GtkWidget *W = GTK_BIN(combobox)->child;
592 	utver = (gchar *)gtk_entry_get_text( GTK_ENTRY(W) );
593 	if(strcmp(utver, "Uninitialized") == 0)
594 	{
595 		return;
596 	}
597 
598 	/* game config home paths */
599 	if(strcmp(utver, "ut2003_demo") == 0)
600 	{
601 		utpath = g_strdup_printf("%s/.%s", getenv("HOME"), "ut2003");
602 	}
603 	else
604 	if(strcmp(utver, "ut2004-demo") == 0)
605 	{
606 		utpath = g_strdup_printf("%s/.%s", getenv("HOME"), "ut2004demo");
607 	}
608 	else
609 	utpath = g_strdup_printf("%s/.%s", getenv("HOME"), utver);
610 
611 	/* game install paths */
612 	umarkrc = g_strdup_printf("%s/.umarkrc", getenv("HOME"));
613 	if((RCFILE = fopen(umarkrc, "r")) == NULL)
614 	{
615 		gchar* FOpenErrMsg = "Could not find the UMark config file. Please run the UMark/install_umark_data.sh script.";
616 		umark_message_dialog(FOpenErrMsg);
617 	}
618 	else
619 	{
620 		line = "";
621 		lnum = 0;
622 
623 		while((buffer = getc(RCFILE)) != EOF)
624 		{
625 			if(buffer == '\n')
626 			{
627 				if(lnum == 0 && strcmp(line, "n/a|n/a") != 0)
628 				{
629 					instdir1 = line;
630 				}
631 				else
632 				if(lnum == 1 && strcmp(line, "n/a|n/a") != 0)
633 				{
634 					instdir2 = line;
635 				}
636 				else
637 				if(lnum == 2 && strcmp(line, "n/a|n/a") != 0)
638 				{
639 					instdir3 = line;
640 				}
641 				else
642 				if(lnum == 3 && strcmp(line, "n/a|n/a") != 0)
643 				{
644 					instdir4 = line;
645 				}
646 				line = "";
647 				lnum++;
648 			}
649 			else
650 			if(buffer == '|')
651 			{
652 				builds[lnum] = atoi(line);
653 				line = "";
654 			}
655 			else
656 			{
657 				line = g_strdup_printf("%s%c", line, buffer);
658 			}
659 		}
660 		fclose(RCFILE);
661 	}
662 
663 	if(strcmp(utver, "ut2003") == 0)
664 	{
665 		utdir = instdir1;
666 		build = builds[0];
667 	}
668 	else
669 	if(strcmp(utver, "ut2004") == 0)
670 	{
671 		utdir = instdir2;
672 		build = builds[1];
673 
674 		utver = g_strdup_printf("%s/%s", utdir, utver);
675 	}
676 	else
677 	if(strcmp(utver, "ut2003_demo") == 0)
678 	{
679 		utdir = instdir3;
680 		build = builds[2];
681 	}
682 	else
683 	if(strcmp(utver, "ut2004-demo") == 0)
684 	{
685 		utdir = instdir4;
686 		build = builds[3];
687 
688 		utver = g_strdup_printf("%s/%s", utdir, utver);
689 	}
690 
691 /** TEST
692 	GtkWidget* FOpenErrBox;
693 	FOpenErrBox = gnome_ok_dialog(utdir);
694 	gtk_widget_show(FOpenErrBox);
695 **/
696 
697 	UMarkDialog = GTK_WIDGET(gtk_widget_get_toplevel(GTK_WIDGET(combobox)));
698 	cbMaps = GTK_COMBO_BOX(lookup_widget(UMarkDialog , "CmbMaps"));
699 	cbTmod = GTK_TREE_MODEL(gtk_combo_box_get_model(cbMaps));
700 
701 	if(dotimedemo)
702 	{
703 		dotimedemo = !dotimedemo;
704 		on_chkTimeDemo_clicked(GTK_BUTTON(lookup_widget(UMarkDialog, "chkTimeDemo")), user_data);
705 		return;
706 	}
707 
708 /*	g_object_set(GTK_WIDGET(cbMaps), "appears-as-list", TRUE, NULL);
709 */	gtk_list_store_clear(GTK_LIST_STORE(cbTmod));
710 
711 	MapPath = g_strdup_printf("ls -1 %s/Maps | grep \"AS-\\|BR-\\|CTF-\\|DM-\\|DOM-\\|MOV-\\|ONS-\" >%s/Benchmark/.UMMAP_LST", utdir, utpath);
712 	system(MapPath);
713 	g_free(MapPath);
714 	MapPath = g_strdup_printf("%s/Benchmark/.UMMAP_LST", utpath);
715 	MapList = fopen(MapPath, "r");
716 
717 	lcurmap = "";
718 
719 	while((buffer = getc(MapList)) != EOF)
720 	{
721 		if(buffer != '\n')
722 		{
723 			lcurmap = g_strdup_printf("%s%c", lcurmap, buffer); /* TODO: find a better way to append */
724 		}
725 		else
726 		{
727 			gtk_combo_box_append_text(GTK_COMBO_BOX(cbMaps), lcurmap);
728 			g_free(lcurmap);
729 			lcurmap = "";
730 		}
731 	}
732 	fclose(MapList);
733 	remove(MapPath);
734 	g_free(MapPath);
735 
736 /*
737 	if(strcmp(map,"") != 0)
738 	{
739 		g_free(map);
740 		map = "";
741 	}
742 */
743 }
744 
745 
746 void
on_chkfullscr_toggled(GtkToggleButton * togglebutton,gpointer user_data)747 on_chkfullscr_toggled                   (GtkToggleButton *togglebutton,
748                                         gpointer         user_data)
749 {
750 	fullscreen = !fullscreen;
751 }
752 
753 
754 void
on_maps_changed(GtkComboBox * combobox,gpointer user_data)755 on_maps_changed                        (GtkComboBox     *combobox,
756                                         gpointer         user_data)
757 {
758 /*	if(strcmp(map,"") != 0)
759 	{
760 		g_free(map);
761 	}
762 */
763 	GtkWidget* W = GTK_BIN(combobox)->child;
764 	map = (gchar *)gtk_entry_get_text( GTK_ENTRY(W) );
765 }
766 
767 
768 /*** benchmarking code *******************************************************/
769 gboolean
foreach_batchlist_benchmark(GtkTreeModel * model,GtkTreePath * path,GtkTreeIter * iter,gpointer user_data)770 foreach_batchlist_benchmark(	GtkTreeModel	*model,
771 				GtkTreePath	*path,
772 				GtkTreeIter	*iter,
773 				gpointer	user_data)
774 {
775 	GtkWidget	*UMarkDialog;
776 	gchar*		rm_file;
777 
778 	gtk_tree_model_get(model, iter, 0, &map, -1);
779 
780 	run_batch = TRUE;
781 
782 	if(dotimedemo)
783 	{
784 		rm_file = g_strdup_printf("%s/Benchmark/benchmark.log", utpath);
785 	}
786 	else
787 	{
788 		rm_file = g_strdup_printf("%s/Benchmark/lowframerate.log", utpath);
789 	}
790 	remove(rm_file);
791 	g_free(rm_file);
792 	run_benchmark();
793 
794 /*	g_free(map);
795 */
796 	return FALSE;
797 }
798 
799 void
on_btnbenchmark_clicked(GtkButton * button,gpointer user_data)800 on_btnbenchmark_clicked                (GtkButton       *button,
801                                         gpointer         user_data)
802 {
803 	gint	res;
804 	gchar*	rm_file;
805 
806 /*	GtkProgressBar	*pBar; */
807 	GtkWidget	*UMarkDialog;
808 	GtkListStore	*lsBatchList;
809 	GtkTreeIter	iter;
810 
811 	UMarkDialog = GTK_WIDGET(gtk_widget_get_toplevel(GTK_WIDGET(button)));
812 	lsBatchList = GTK_LIST_STORE( gtk_tree_view_get_model( GTK_TREE_VIEW(lookup_widget(UMarkDialog , "tvBatchList"))) );
813 /*	pBar = GTK_PROGRESS_BAR(lookup_widget(UMarkDialog, "batchprogress")); */
814 
815 	run_batch = FALSE;
816 	gboolean res_check = FALSE;
817 
818 	bswitch = "1";
819 
820 	if(res640x480)   res_check = TRUE;
821 	if(res800x600)   res_check = TRUE;
822 	if(res1024x768)  res_check = TRUE;
823 	if(res1280x1024) res_check = TRUE;
824 	if(res1600x1200) res_check = TRUE;
825 
826 	if(!res_check)
827 	{
828 		gchar* BenchErrBox = "Please select a resolution in which to run the benchmark.";
829 		umark_message_dialog(BenchErrBox);
830 		return;
831 	}
832 
833 	if(strcmp(utver,"ut2003") == 0 || strcmp(utver,"ut2003_demo") == 0)
834 	{
835 		bswitch = "true";
836 	}
837 	else
838 	if(strcmp(utver,"ut2004") == 0)
839 	{
840 		bswitch = "1";
841 	}
842 
843 	/* run the benchmark for each resolution selected */
844 	for(res = RES_640; res <= RES_1600; res++)
845 	{
846 		switch(res)
847 		{
848 			case RES_640:  if(res640x480)   strres = "-640x480";   break;
849 			case RES_800:  if(res800x600)   strres = "-800x600";   break;
850 			case RES_1024: if(res1024x768)  strres = "-1024x768";  break;
851 			case RES_1280: if(res1280x1024) strres = "-1280x1024"; break;
852 			case RES_1600: if(res1600x1200) strres = "-1600x1200"; break;
853 		}
854 
855 		if(strres != "")
856 		{
857 /*			gtk_progress_bar_set_fraction(pBar, 0.0); */
858 			gtk_tree_model_foreach(GTK_TREE_MODEL(lsBatchList), foreach_batchlist_benchmark, NULL);
859 
860 			if(!run_batch)
861 			{
862 				if(strcmp(map,"") == 0)
863 				{
864 					gchar* BenchErrBox = "You must select a map to benchmark.";
865 					umark_message_dialog(BenchErrBox);
866 					return;
867 				}
868 
869 				/* clear previous log entries */
870 				if(dotimedemo)
871 				{
872 					rm_file = g_strdup_printf("%s/Benchmark/benchmark.log", utpath);
873 				}
874 				else
875 				{
876 					rm_file = g_strdup_printf("%s/Benchmark/lowframerate.log", utpath);
877 				}
878 				remove(rm_file);
879 				g_free(rm_file);
880 
881 				run_benchmark();
882 			}
883 		}
884 		strres = "";
885 	}
886 	ResultsBox = create_ResultsDlg();
887 	create_model_resultlist(lookup_widget( GTK_WIDGET(ResultsBox), "tvResults") );
888 
889 	read_results_log(button);
890 	gtk_widget_show(ResultsBox);
891 }
892 
893 
894 void
run_benchmark()895 run_benchmark()
896 {
897 	/* .ini files and exec files need to be moved to the ut home dirs */
898 
899 	strdtl = "";
900 
901 	switch(detail)
902 	{
903 		case DTL_LO: strdtl = g_strdup_printf(" -ini=%s/System/UMarkPerformance.ini -userini=%s/System/UMarkPerformanceUser.ini", utpath, utpath); break;
904 		case DTL_HI: strdtl = g_strdup_printf(" -ini=%s/System/UMarkQuality.ini -userini=%s/System/UMarkQualityUser.ini", utpath, utpath); break;
905 		case DTL_CS: strdtl = g_strdup_printf(" -ini=%s -userini=%s", inifile, iniuser); break;
906 		default	: break;
907 	}
908 	if(dotimedemo)
909 	{
910 		gchar	*tdfile;
911 		FILE	*UMarkTime;
912 
913 		/* TODO: Timedemos are also currently only tested in UT2004 */
914 
915 		/* create UMarkTime.txt file */
916 		tdfile = g_strdup_printf("%s/Benchmark/Stuff/UMarkTime.txt", utpath);
917 
918 		if((UMarkTime = fopen(tdfile, "w")) == NULL)
919 		{
920 			umark_message_dialog(tdfile);
921 			return;
922 		}
923 		fprintf(UMarkTime, "demoplay %s?timedemo\nship\nstat fps", map);
924 		fclose(UMarkTime);
925 
926 		if(build >= 3000)
927 		{
928 			Command = g_strdup_printf("%s -exitafterdemo -benchmark -nosound -seconds=77 -exec=%s/Benchmark/Stuff/UMarkTime.txt", utver, utpath);
929 		}
930 		else
931 		{
932 			Command = g_strdup_printf("%s -exitafterdemo -benchmark -nosound -exec=%s/Benchmark/Stuff/UMarkTime.txt", utver, utpath);
933 		}
934 		presetchosen = PRE_TD;
935 	}
936 	else
937 	if(numbots == 0)
938 	{
939 		Command = g_strdup_printf("%s %s?game=engine.gameinfo -benchmark -seconds=77 -nosound -exec=%s/Benchmark/Stuff/UMarkFly.txt %s %s",
940 					utver, map, utpath, strdtl, strres);
941 	}
942 	else
943 	{
944 		Command = g_strdup_printf("%s %s?spectatoronly=%s?numbots=%d?quickstart=%s?attractcam=%s -benchmark -seconds=77 -nosound -exec=%s/Benchmark/Stuff/UMarkBot.txt %s %s",
945 					utver, map, bswitch, numbots, bswitch, bswitch, utpath, strdtl, strres);
946 	}
947 
948 	if(!fullscreen)
949 	{
950 		Command = g_strconcat(Command, " -windowed", NULL);
951 	}
952 
953 
954 /* TEST
955 	gchar* test = g_strdup_printf("Executing: %s", Command);
956 	umark_message_dialog(test);
957 	g_free(test);
958 */
959 
960 	system(Command);
961 
962 	if(dotimedemo)
963 	{
964 		write_log_td();
965 	}
966 	else
967 	{
968 		write_log();
969 	}
970 }
971 
972 
973 void
write_log()974 write_log()
975 {
976 	int	lines;
977 	char	buffer;
978 	FILE*	UTLog;
979 	FILE*	UMarkLog;
980 
981 	gchar*	logfile_name;
982 	gchar*	umarklog_name;
983 	gchar*	logdetail;
984 	gchar*	logres;
985 	gchar*	btype;
986 
987 	lines = 0;
988 
989 	logfile_name = g_strdup_printf("%s/Benchmark/lowframerate.log", utpath);
990 	umarklog_name = g_strdup_printf("%s/Benchmark/UMTMP_LOG", utpath);
991 
992 	if((UTLog = fopen(logfile_name, "r")) == NULL)
993 	{
994 		umark_message_dialog(logfile_name);
995 		return;
996 	}
997 	if((UMarkLog = fopen(umarklog_name, "a")) == NULL)
998 	{
999 		umark_message_dialog(umarklog_name);
1000 		return;
1001 	}
1002 	g_free(logfile_name);
1003 	g_free(umarklog_name);
1004 
1005 	// detail level string
1006 	switch(detail)
1007 	{
1008 		case DTL_LO :	logdetail = "Low"; break;
1009 		case DTL_HI :	logdetail = "High"; break;
1010 		case DTL_CS :	logdetail = "Custom"; break;
1011 		default	:	logdetail = "Current"; break;
1012 	}
1013 
1014 	// resolution string
1015 	if(strcmp(strres, "-640x480") == 0)
1016 	{
1017 		logres = "640x480";
1018 	}
1019 	else
1020 	if(strcmp(strres, "-800x600") == 0)
1021 	{
1022 		logres = "800x600";
1023 	}
1024 	else
1025 	if(strcmp(strres, "-1024x768") == 0)
1026 	{
1027 		logres = "1024x768";
1028 	}
1029 	else
1030 	if(strcmp(strres, "-1280x1024") == 0)
1031 	{
1032 		logres = "1280x1024";
1033 	}
1034 	else
1035 	if(strcmp(strres, "-1600x1200") == 0)
1036 	{
1037 		logres = "1600x1200";
1038 	}
1039 
1040 	switch(presetchosen)
1041 	{
1042 		case PRE_BM: btype = "UT2003 Botmatch"; break;
1043 		case PRE_FB: btype = "UT2003 Flyby"; break;
1044 		case PRE_DM: btype = "UT2003 Demo"; break;
1045 		case PRE_D4: btype = "UT2004 Demo"; break;
1046 		case PRE_DE: btype = "DE Bonus Pack"; break;
1047 		case PRE_EG: btype = "Epic Bonus Pack"; break;
1048 		case PRE_U3: btype = "UMark 2003"; break;
1049 		case PRE_U4: btype = "UMark 2004"; break;
1050 		default: btype = "Custom";
1051 	}
1052 
1053 	// read lowframerate.log and write a reformatted umark temp log
1054 	while((buffer = getc(UTLog)) != EOF)
1055 	{
1056 		if(buffer == '\n') lines++;
1057 
1058 		if(lines == 0)
1059 		{
1060 			if(buffer != '\n' && buffer != '\r')
1061 			{
1062 				putc(buffer, UMarkLog);
1063 			}
1064 		}
1065 		else
1066 		if(lines == 3)
1067 		{
1068 			/* do nothing */
1069 		}
1070 		else
1071 		if(lines == 1 && buffer == '\n')
1072 		{
1073 			fprintf(UMarkLog, "|%d|%s|%s|", numbots, logdetail, logres);
1074 		}
1075 		else
1076 		{
1077 			switch(buffer)
1078 			{
1079 				case  'c':
1080 				case  'e':
1081 				case  'f':
1082 				case  'o':
1083 				case  'p':
1084 				case  'r':
1085 				case  's':
1086 				case  'S':
1087 				case  '=':
1088 				case '\r':
1089 				case  ' ': break;
1090 				case  '/':
1091 				case '\n': putc('|', UMarkLog); break;
1092 				default  : putc(buffer, UMarkLog); break;
1093 			}
1094 		}
1095 	}
1096 	fprintf(UMarkLog, "%d|%s\n", build, btype);
1097 
1098 	fclose(UTLog);
1099 	fclose(UMarkLog);
1100 }
1101 
1102 
1103 void
write_log_td()1104 write_log_td()
1105 {
1106 	char	buffer;
1107 	FILE*	UTLog;
1108 	FILE*	UMarkLog;
1109 
1110 	gchar*	logfile_name;
1111 	gchar*	umarklog_name;
1112 	gchar*	logdetail;
1113 	gchar*	logres;
1114 	gchar*	btype;
1115 
1116 	logfile_name = g_strdup_printf("%s/Benchmark/benchmark.log", utpath);
1117 	umarklog_name = g_strdup_printf("%s/Benchmark/UMTMP_LOG", utpath);
1118 
1119 	if((UTLog = fopen(logfile_name, "r")) == NULL)
1120 	{
1121 		umark_message_dialog(logfile_name);
1122 		return;
1123 	}
1124 	if((UMarkLog = fopen(umarklog_name, "a")) == NULL)
1125 	{
1126 		umark_message_dialog(umarklog_name);
1127 		return;
1128 	}
1129 	g_free(logfile_name);
1130 	g_free(umarklog_name);
1131 
1132 	// detail level string
1133 	switch(detail)
1134 	{
1135 		case DTL_LO :	logdetail = "Low"; break;
1136 		case DTL_HI :	logdetail = "High"; break;
1137 		case DTL_CS :	logdetail = "Custom"; break;
1138 		default	:	logdetail = "Current"; break;
1139 	}
1140 
1141 	// resolution string
1142 	if(strcmp(strres, "-640x480") == 0)
1143 	{
1144 		logres = "640x480";
1145 	}
1146 	else
1147 	if(strcmp(strres, "-800x600") == 0)
1148 	{
1149 		logres = "800x600";
1150 	}
1151 	else
1152 	if(strcmp(strres, "-1024x768") == 0)
1153 	{
1154 		logres = "1024x768";
1155 	}
1156 	else
1157 	if(strcmp(strres, "-1280x1024") == 0)
1158 	{
1159 		logres = "1280x1024";
1160 	}
1161 	else
1162 	if(strcmp(strres, "-1600x1200") == 0)
1163 	{
1164 		logres = "1600x1200";
1165 	}
1166 	btype = "Timedemo";
1167 
1168 	fprintf(UMarkLog, "%s|-1|%s|%s|-1|-1|-1|", map, logdetail, logres);
1169 
1170 	// read benchmark.log and write a reformatted umark temp log
1171 	while((buffer = getc(UTLog)) != ' ')
1172 	{
1173 		putc(buffer, UMarkLog);
1174 	}
1175 	fprintf(UMarkLog, "|%d|%s\n", build, btype);
1176 
1177 	fclose(UTLog);
1178 	fclose(UMarkLog);
1179 }
1180 
1181 
1182 void
read_results_log(GtkButton * button)1183 read_results_log(GtkButton *button)
1184 {
1185 	FILE		*UMTmpLog;
1186 	gchar		*umarklog;
1187 	gchar		*strtmp;
1188 	char		buffer;
1189 	int		colnum;
1190 
1191 	gint		itmp;
1192 	gdouble		dtmp;
1193 
1194 	GtkWidget	*ResultsDialog;
1195 	GtkListStore	*lsResultList;
1196 	GtkTreeIter	iter;
1197 
1198 	ResultsDialog = GTK_WIDGET(gtk_widget_get_toplevel(GTK_WIDGET(button)));
1199 	lsResultList = GTK_LIST_STORE(gtk_tree_view_get_model( GTK_TREE_VIEW(lookup_widget(ResultsBox , "tvResults")) ));
1200 
1201 	umarklog = g_strdup_printf("%s/Benchmark/UMTMP_LOG", utpath);
1202 	if((UMTmpLog = fopen(umarklog, "r")) == NULL)
1203 	{
1204 		gchar* FOpenErrBox = "ERROR: Could not read the UMTMP_LOG file.";
1205 		umark_message_dialog(FOpenErrBox);
1206 		return;
1207 	}
1208 
1209 	gtk_list_store_clear(GTK_LIST_STORE(lsResultList));
1210 	strtmp = "";
1211 	colnum = 0;
1212 
1213 	gtk_list_store_append(lsResultList, &iter);
1214 
1215 	while(( buffer = getc(UMTmpLog) ) != EOF)
1216 	{
1217 		if(buffer == '\n')
1218 		{
1219 			gtk_list_store_set(lsResultList, &iter, COL_TYP, strtmp, -1);
1220 
1221 			/* new map in log */
1222 			gtk_list_store_append (lsResultList, &iter);
1223 			strtmp = "";
1224 			colnum = 0;
1225 		}
1226 		else
1227 		if(buffer == '|')
1228 		{
1229 			/* next column in log */
1230 			switch(colnum)
1231 			{
1232 				case COL_VER:
1233 				case COL_BOT: gtk_list_store_set(lsResultList, &iter, colnum, atoi(strtmp), -1); break;
1234 				case COL_MIN:
1235 				case COL_AVG:
1236 				case COL_MAX:
1237 				case COL_SCR: gtk_list_store_set(lsResultList, &iter, colnum, g_strtod(strtmp, NULL), -1); break;
1238 				default: gtk_list_store_set(lsResultList, &iter, colnum, strtmp, -1);
1239 			}
1240 			strtmp = "";
1241 			colnum++;
1242 		}
1243 		else
1244 		{
1245 			strtmp = g_strdup_printf("%s%c", strtmp, buffer); /* TODO: use a better method for appending */
1246 		}
1247 	}
1248 	fclose(UMTmpLog);
1249 	g_free(umarklog);
1250 
1251 	gtk_list_store_remove(lsResultList, &iter);
1252 }
1253 
1254 
1255 void
on_btnresults_clicked(GtkButton * button,gpointer user_data)1256 on_btnresults_clicked                  (GtkButton       *button,
1257                                         gpointer         user_data)
1258 {
1259 	ResultsBox = create_ResultsDlg();
1260 	create_model_resultlist(lookup_widget( GTK_WIDGET(ResultsBox), "tvResults") );
1261 
1262 /* TEST
1263 	read_results_log(button);
1264 */
1265 	gtk_widget_show(ResultsBox);
1266 }
1267 
1268 
1269 void
on_btnabout_clicked(GtkButton * button,gpointer user_data)1270 on_btnabout_clicked                    (GtkButton       *button,
1271                                         gpointer         user_data)
1272 {
1273 	AboutBox = create_AboutDlg();
1274 	gtk_widget_show(AboutBox);
1275 }
1276 
1277 
1278 void
on_btnquit_clicked(GtkButton * button,gpointer user_data)1279 on_btnquit_clicked                     (GtkButton       *button,
1280                                         gpointer         user_data)
1281 {
1282 	/* TODO: free up unfreed non-constant assigned gchar* variables */
1283 	if(strcmp(utdir, "") != 0)	g_free(utdir);
1284 	if(strcmp(utpath, "") != 0)	g_free(utpath);
1285 
1286 	gtk_main_quit();
1287 }
1288 
1289 
1290 /*** resolution checkboxes ***************************************************/
1291 void
on_chkres640_toggled(GtkToggleButton * togglebutton,gpointer user_data)1292 on_chkres640_toggled                   (GtkToggleButton *togglebutton,
1293                                         gpointer         user_data)
1294 {
1295 	res640x480 = !res640x480;
1296 }
1297 
1298 
1299 void
on_chkres800_toggled(GtkToggleButton * togglebutton,gpointer user_data)1300 on_chkres800_toggled                   (GtkToggleButton *togglebutton,
1301                                         gpointer         user_data)
1302 {
1303 	res800x600 = !res800x600;
1304 }
1305 
1306 
1307 void
on_chkres1024_toggled(GtkToggleButton * togglebutton,gpointer user_data)1308 on_chkres1024_toggled                  (GtkToggleButton *togglebutton,
1309                                         gpointer         user_data)
1310 {
1311 	res1024x768 = !res1024x768;
1312 }
1313 
1314 
1315 void
on_chkres1280_toggled(GtkToggleButton * togglebutton,gpointer user_data)1316 on_chkres1280_toggled                  (GtkToggleButton *togglebutton,
1317                                         gpointer         user_data)
1318 {
1319 	res1280x1024 = !res1280x1024;
1320 }
1321 
1322 
1323 void
on_chkres1600_toggled(GtkToggleButton * togglebutton,gpointer user_data)1324 on_chkres1600_toggled                  (GtkToggleButton *togglebutton,
1325                                         gpointer         user_data)
1326 {
1327 	res1600x1200 = !res1600x1200;
1328 }
1329 
1330 
1331 /*** detail selection ********************************************************/
1332 void
on_raddtllow_clicked(GtkButton * button,gpointer user_data)1333 on_raddtllow_clicked                   (GtkButton       *button,
1334                                         gpointer         user_data)
1335 {
1336 	detail = DTL_LO;
1337 }
1338 
1339 
1340 void
on_raddtlhigh_clicked(GtkButton * button,gpointer user_data)1341 on_raddtlhigh_clicked                  (GtkButton       *button,
1342                                         gpointer         user_data)
1343 {
1344 	detail = DTL_HI;
1345 }
1346 
1347 
1348 void
on_raddtlcurrent_clicked(GtkButton * button,gpointer user_data)1349 on_raddtlcurrent_clicked               (GtkButton       *button,
1350                                         gpointer         user_data)
1351 {
1352 	detail = DTL_CR;
1353 }
1354 
1355 
1356 void
on_raddtlcustom_clicked(GtkButton * button,gpointer user_data)1357 on_raddtlcustom_clicked                (GtkButton       *button,
1358                                         gpointer         user_data)
1359 {
1360 	detail = DTL_CS;
1361 }
1362 
1363 /*
1364 void
1365 on_fileentryini_changed                (GtkEditable     *editable,
1366                                         gpointer         user_data)
1367 {
1368 	inifile = (gchar *)gtk_entry_get_text(GTK_ENTRY(editable));
1369 }
1370 */
1371 
1372 void
on_btnarrow_clicked(GtkButton * button,gpointer user_data)1373 on_btnarrow_clicked                   (GtkButton       *button,
1374                                         gpointer         user_data)
1375 {
1376 	on_btnadd_clicked(button, user_data);
1377 }
1378 
1379 /*** batch map list controls *************************************************/
1380 void
on_btnpreset_clicked(GtkButton * button,gpointer user_data)1381 on_btnpreset_clicked                   (GtkButton       *button,
1382                                         gpointer         user_data)
1383 {
1384 	GtkWidget	*UMarkDialog;
1385 	GtkListStore	*lsBatchList;
1386 	GtkTreeIter	iter;
1387 
1388 	presetchosen = -1;
1389 	PresetsBox = create_PresetDlg();
1390 
1391 	if(gtk_dialog_run(GTK_DIALOG(PresetsBox)) == GTK_RESPONSE_OK)
1392 	{
1393 		UMarkDialog = GTK_WIDGET( gtk_widget_get_toplevel(GTK_WIDGET(button)) );
1394 		lsBatchList = GTK_LIST_STORE(gtk_tree_view_get_model( GTK_TREE_VIEW(lookup_widget(UMarkDialog , "tvBatchList")) ));
1395 
1396 		if(presetchosen == 0)
1397 		{
1398 			return;
1399 		}
1400 
1401 		if(presetchosen < 0)
1402 		{
1403 			gtk_list_store_clear(GTK_LIST_STORE(lsBatchList));
1404 		}
1405 
1406 		if(presetchosen == PRE_BM || presetchosen == -PRE_BM)
1407 		{
1408 			gtk_list_store_append(lsBatchList, &iter);
1409 			gtk_list_store_set(lsBatchList, &iter, 0, "DM-Antalus", -1);
1410 			gtk_list_store_append(lsBatchList, &iter);
1411 			gtk_list_store_set(lsBatchList, &iter, 0, "BR-Anubis", -1);
1412 			gtk_list_store_append(lsBatchList, &iter);
1413 			gtk_list_store_set(lsBatchList, &iter, 0, "DM-Asbestos", -1);
1414 			gtk_list_store_append(lsBatchList, &iter);
1415 			gtk_list_store_set(lsBatchList, &iter, 0, "CTF-Citadel", -1);
1416 			gtk_list_store_append(lsBatchList, &iter);
1417 			gtk_list_store_set(lsBatchList, &iter, 0, "DM-Inferno", -1);
1418 			gtk_list_store_append(lsBatchList, &iter);
1419 			gtk_list_store_set(lsBatchList, &iter, 0, "DOM-Suntemple", -1);
1420 		}
1421 		if(presetchosen == PRE_FB || presetchosen == -PRE_FB)
1422 		{
1423 			gtk_list_store_append(lsBatchList, &iter);
1424 			gtk_list_store_set(lsBatchList, &iter, 0, "DM-Antalus", -1);
1425 			gtk_list_store_append(lsBatchList, &iter);
1426 			gtk_list_store_set(lsBatchList, &iter, 0, "DM-Asbestos", -1);
1427 			gtk_list_store_append(lsBatchList, &iter);
1428 			gtk_list_store_set(lsBatchList, &iter, 0, "CTF-Citadel", -1);
1429 			gtk_list_store_append(lsBatchList, &iter);
1430 			gtk_list_store_set(lsBatchList, &iter, 0, "CTF-Face3", -1);
1431 			gtk_list_store_append(lsBatchList, &iter);
1432 			gtk_list_store_set(lsBatchList, &iter, 0, "DM-Inferno", -1);
1433 			gtk_list_store_append(lsBatchList, &iter);
1434 			gtk_list_store_set(lsBatchList, &iter, 0, "DM-Phobos2", -1);
1435 			gtk_list_store_append(lsBatchList, &iter);
1436 			gtk_list_store_set(lsBatchList, &iter, 0, "DOM-Suntemple", -1);
1437 		}
1438 		if(presetchosen == PRE_DM || presetchosen == -PRE_DM)
1439 		{
1440 			gtk_list_store_append(lsBatchList, &iter);
1441 			gtk_list_store_set(lsBatchList, &iter, 0, "DM-Antalus", -1);
1442 			gtk_list_store_append(lsBatchList, &iter);
1443 			gtk_list_store_set(lsBatchList, &iter, 0, "BR-Anubis", -1);
1444 			gtk_list_store_append(lsBatchList, &iter);
1445 			gtk_list_store_set(lsBatchList, &iter, 0, "DM-Asbestos", -1);
1446 			gtk_list_store_append(lsBatchList, &iter);
1447 			gtk_list_store_set(lsBatchList, &iter, 0, "CTF-Citadel", -1);
1448 		}
1449 		if(presetchosen == PRE_D4 || presetchosen == -PRE_D4)
1450 		{
1451 			gtk_list_store_append(lsBatchList, &iter);
1452 			gtk_list_store_set(lsBatchList, &iter, 0, "AS-Convoy", -1);
1453 			gtk_list_store_append(lsBatchList, &iter);
1454 			gtk_list_store_set(lsBatchList, &iter, 0, "BR-Colossus", -1);
1455 			gtk_list_store_append(lsBatchList, &iter);
1456 			gtk_list_store_set(lsBatchList, &iter, 0, "CTF-BridgeOfFate", -1);
1457 			gtk_list_store_append(lsBatchList, &iter);
1458 			gtk_list_store_set(lsBatchList, &iter, 0, "DM-Rankin", -1);
1459 			gtk_list_store_append(lsBatchList, &iter);
1460 			gtk_list_store_set(lsBatchList, &iter, 0, "ONS-Torlan", -1);
1461 			gtk_list_store_append(lsBatchList, &iter);
1462 			gtk_list_store_set(lsBatchList, &iter, 0, "CTF-FaceClassic", -1);
1463 			gtk_list_store_append(lsBatchList, &iter);
1464 			gtk_list_store_set(lsBatchList, &iter, 0, "ONS-Primeval", -1);
1465 		}
1466 		if(presetchosen == PRE_DE || presetchosen == -PRE_DE)
1467 		{
1468 			gtk_list_store_append(lsBatchList, &iter);
1469 			gtk_list_store_set(lsBatchList, &iter, 0, "CTF-DE-ElecFields", -1);
1470 			gtk_list_store_append(lsBatchList, &iter);
1471 			gtk_list_store_set(lsBatchList, &iter, 0, "DM-DE-GrendelKeep", -1);
1472 			gtk_list_store_append(lsBatchList, &iter);
1473 			gtk_list_store_set(lsBatchList, &iter, 0, "CTF-DE-LavaGiant2", -1);
1474 			gtk_list_store_append(lsBatchList, &iter);
1475 			gtk_list_store_set(lsBatchList, &iter, 0, "DM-DE-Ironic", -1);
1476 			gtk_list_store_append(lsBatchList, &iter);
1477 			gtk_list_store_set(lsBatchList, &iter, 0, "DM-DE-Osiris2", -1);
1478 			gtk_list_store_append(lsBatchList, &iter);
1479 			gtk_list_store_set(lsBatchList, &iter, 0, "BR-DE-ElecFields", -1);
1480 		}
1481 		if(presetchosen == PRE_EG || presetchosen == -PRE_EG)
1482 		{
1483 			gtk_list_store_append(lsBatchList, &iter);
1484 			gtk_list_store_set(lsBatchList, &iter, 0, "DM-IronDeity", -1);
1485 			gtk_list_store_append(lsBatchList, &iter);
1486 			gtk_list_store_set(lsBatchList, &iter, 0, "DM-IceTomb", -1);
1487 			gtk_list_store_append(lsBatchList, &iter);
1488 			gtk_list_store_set(lsBatchList, &iter, 0, "BR-Canyon", -1);
1489 			gtk_list_store_append(lsBatchList, &iter);
1490 			gtk_list_store_set(lsBatchList, &iter, 0, "DOM-Junkyard", -1);
1491 			gtk_list_store_append(lsBatchList, &iter);
1492 			gtk_list_store_set(lsBatchList, &iter, 0, "DM-Rustatorium", -1);
1493 			gtk_list_store_append(lsBatchList, &iter);
1494 			gtk_list_store_set(lsBatchList, &iter, 0, "DM-1on1-Crash", -1);
1495 			gtk_list_store_append(lsBatchList, &iter);
1496 			gtk_list_store_set(lsBatchList, &iter, 0, "DM-1on1-Mixer", -1);
1497 			gtk_list_store_append(lsBatchList, &iter);
1498 			gtk_list_store_set(lsBatchList, &iter, 0, "DM-Injector", -1);
1499 			gtk_list_store_append(lsBatchList, &iter);
1500 			gtk_list_store_set(lsBatchList, &iter, 0, "CTF-Avaris", -1);
1501 			gtk_list_store_append(lsBatchList, &iter);
1502 			gtk_list_store_set(lsBatchList, &iter, 0, "CTF-DoubleDamage", -1);
1503 		}
1504 		if(presetchosen == PRE_U3 || presetchosen == -PRE_U3)
1505 		{
1506 			gtk_list_store_append(lsBatchList, &iter);
1507 			gtk_list_store_set(lsBatchList, &iter, 0, "BR-IceFields", -1);
1508 			gtk_list_store_append(lsBatchList, &iter);
1509 			gtk_list_store_set(lsBatchList, &iter, 0, "DM-Inferno", -1);
1510 			gtk_list_store_append(lsBatchList, &iter);
1511 			gtk_list_store_set(lsBatchList, &iter, 0, "CTF-Maul", -1);
1512 			gtk_list_store_append(lsBatchList, &iter);
1513 			gtk_list_store_set(lsBatchList, &iter, 0, "CTF-Magma", -1);
1514 			gtk_list_store_append(lsBatchList, &iter);
1515 			gtk_list_store_set(lsBatchList, &iter, 0, "DOM-Ruination", -1);
1516 			gtk_list_store_append(lsBatchList, &iter);
1517 			gtk_list_store_set(lsBatchList, &iter, 0, "BR-Slaughterhouse", -1);
1518 		}
1519 		if(presetchosen == PRE_U4 || presetchosen == -PRE_U4)
1520 		{
1521 			gtk_list_store_append(lsBatchList, &iter);
1522 			gtk_list_store_set(lsBatchList, &iter, 0, "AS-FallenCity", -1);
1523 			gtk_list_store_append(lsBatchList, &iter);
1524 			gtk_list_store_set(lsBatchList, &iter, 0, "BR-Slaughterhouse", -1);
1525 			gtk_list_store_append(lsBatchList, &iter);
1526 			gtk_list_store_set(lsBatchList, &iter, 0, "CTF-MoonDragon", -1);
1527 			gtk_list_store_append(lsBatchList, &iter);
1528 			gtk_list_store_set(lsBatchList, &iter, 0, "DM-Inferno", -1);
1529 			gtk_list_store_append(lsBatchList, &iter);
1530 			gtk_list_store_set(lsBatchList, &iter, 0, "DOM-Ruination", -1);
1531 			gtk_list_store_append(lsBatchList, &iter);
1532 			gtk_list_store_set(lsBatchList, &iter, 0, "ONS-Dawn", -1);
1533 		}
1534 	}
1535 	gtk_widget_destroy(PresetsBox);
1536 }
1537 
1538 
1539 void
on_btnmoveup_clicked(GtkButton * button,gpointer user_data)1540 on_btnmoveup_clicked                   (GtkButton       *button,
1541                                         gpointer         user_data)
1542 {
1543 	GtkWidget	*UMarkDialog;
1544 	GtkListStore	*lsBatchList;
1545 	GtkTreeIter	iter;
1546 
1547 	GtkTreeSelection *select;
1548 
1549 	UMarkDialog = GTK_WIDGET(gtk_widget_get_toplevel(GTK_WIDGET(button)));
1550 	lsBatchList = GTK_LIST_STORE(gtk_tree_view_get_model( GTK_TREE_VIEW(lookup_widget(UMarkDialog , "tvBatchList")) ));
1551 
1552 	select = gtk_tree_view_get_selection(GTK_TREE_VIEW(lookup_widget(UMarkDialog , "tvBatchList")));
1553 	gtk_tree_selection_get_selected(select, (GtkTreeModel **)&lsBatchList, &iter);
1554 
1555 	gtk_list_store_move_after(lsBatchList, &iter, NULL);
1556 }
1557 
1558 
1559 void
on_btnmovedown_clicked(GtkButton * button,gpointer user_data)1560 on_btnmovedown_clicked                 (GtkButton       *button,
1561                                         gpointer         user_data)
1562 {
1563 	GtkWidget	*UMarkDialog;
1564 	GtkListStore	*lsBatchList;
1565 	GtkTreeIter	iter;
1566 
1567 	GtkTreeSelection *select;
1568 
1569 	UMarkDialog = GTK_WIDGET(gtk_widget_get_toplevel(GTK_WIDGET(button)));
1570 	lsBatchList = GTK_LIST_STORE(gtk_tree_view_get_model( GTK_TREE_VIEW(lookup_widget(UMarkDialog , "tvBatchList")) ));
1571 
1572 	select = gtk_tree_view_get_selection(GTK_TREE_VIEW(lookup_widget(UMarkDialog , "tvBatchList")));
1573 	gtk_tree_selection_get_selected(select, (GtkTreeModel **)&lsBatchList, &iter);
1574 
1575 	gtk_list_store_move_before(lsBatchList, &iter, NULL);
1576 }
1577 
1578 
1579 void
on_btnadd_clicked(GtkButton * button,gpointer user_data)1580 on_btnadd_clicked                      (GtkButton       *button,
1581                                         gpointer         user_data)
1582 {
1583 	GtkWidget	*UMarkDialog;
1584 	GtkListStore	*lsBatchList;
1585 	GtkTreeIter	iter;
1586 
1587 	UMarkDialog = GTK_WIDGET(gtk_widget_get_toplevel(GTK_WIDGET(button)));
1588 	lsBatchList = GTK_LIST_STORE(gtk_tree_view_get_model( GTK_TREE_VIEW(lookup_widget(UMarkDialog , "tvBatchList")) ));
1589 
1590 	gtk_list_store_append(lsBatchList, &iter);
1591 	gtk_list_store_set(lsBatchList, &iter, 0, map, -1);
1592 
1593 	presetchosen = 0;
1594 }
1595 
1596 
1597 void
on_btnremove_clicked(GtkButton * button,gpointer user_data)1598 on_btnremove_clicked                   (GtkButton       *button,
1599                                         gpointer         user_data)
1600 {
1601 	GtkWidget	*UMarkDialog;
1602 	GtkListStore	*lsBatchList;
1603 	GtkTreeIter	iter;
1604 
1605 	GtkTreeSelection *select;
1606 
1607 	UMarkDialog = GTK_WIDGET(gtk_widget_get_toplevel(GTK_WIDGET(button)));
1608 	lsBatchList = GTK_LIST_STORE(gtk_tree_view_get_model( GTK_TREE_VIEW(lookup_widget(UMarkDialog , "tvBatchList")) ));
1609 
1610 	select = gtk_tree_view_get_selection(GTK_TREE_VIEW(lookup_widget(UMarkDialog , "tvBatchList")));
1611 	gtk_tree_selection_get_selected(select, (GtkTreeModel **)&lsBatchList, &iter);
1612 	gtk_list_store_remove(GTK_LIST_STORE(lsBatchList), &iter);
1613 
1614 	presetchosen = 0;
1615 }
1616 
1617 
1618 void
on_btnclear_clicked(GtkButton * button,gpointer user_data)1619 on_btnclear_clicked                    (GtkButton       *button,
1620                                         gpointer         user_data)
1621 {
1622 	GtkWidget	*UMarkDialog;
1623 	GtkListStore	*lsBatchList;
1624 
1625 	UMarkDialog = GTK_WIDGET(gtk_widget_get_toplevel(GTK_WIDGET(button)));
1626 	lsBatchList = GTK_LIST_STORE(gtk_tree_view_get_model( GTK_TREE_VIEW(lookup_widget(UMarkDialog , "tvBatchList")) ));
1627 
1628 	gtk_list_store_clear(GTK_LIST_STORE(lsBatchList));
1629 
1630 	presetchosen = 0;
1631 }
1632 
1633 
1634 void
on_btnloadlist_clicked(GtkButton * button,gpointer user_data)1635 on_btnloadlist_clicked                 (GtkButton       *button,
1636                                         gpointer         user_data)
1637 {
1638 	char	buffer;
1639 	gchar	*listfile;
1640 	gchar	*lcurmap;
1641 
1642 	GtkWidget *OpenDlg;
1643 	FILE *MapList;
1644 
1645 	GtkWidget	*UMarkDialog;
1646 	GtkListStore	*lsBatchList;
1647 	GtkTreeIter	iter;
1648 
1649 	UMarkDialog = GTK_WIDGET(gtk_widget_get_toplevel(GTK_WIDGET(button)));
1650 	lsBatchList = GTK_LIST_STORE(gtk_tree_view_get_model( GTK_TREE_VIEW(lookup_widget(UMarkDialog , "tvBatchList")) ));
1651 
1652 	OpenDlg = gtk_file_chooser_dialog_new(
1653 		"Open Map List", NULL,
1654 		GTK_FILE_CHOOSER_ACTION_OPEN,
1655 		GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1656 		GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
1657 		NULL);
1658 
1659 	if(gtk_dialog_run(GTK_DIALOG(OpenDlg)) == GTK_RESPONSE_ACCEPT)
1660 	{
1661 		listfile = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(OpenDlg));
1662 
1663 		if((MapList = fopen(listfile, "r")) == NULL)
1664 		{
1665 			gchar* FOpenErrBox = "ERROR: Could not open the file.";
1666 			umark_message_dialog(FOpenErrBox);
1667 			return;
1668 		}
1669 		lcurmap = "";
1670 
1671 		while((buffer = getc(MapList)) != EOF)
1672 		{
1673 			if(buffer != '\n')
1674 			{
1675 				lcurmap = g_strdup_printf("%s%c", lcurmap, buffer);
1676 			}
1677 			else
1678 			{
1679 				gtk_list_store_append(lsBatchList, &iter);
1680 				gtk_list_store_set(lsBatchList, &iter, 0, lcurmap, -1);
1681 
1682 				g_free(lcurmap);
1683 				lcurmap = "";
1684 			}
1685 		}
1686 		fclose(MapList);
1687 		g_free(listfile);
1688 	}
1689 	gtk_widget_destroy(OpenDlg);
1690 
1691 	presetchosen = 0;
1692 }
1693 
1694 
1695 gboolean
foreach_batchlist_save(GtkTreeModel * model,GtkTreePath * path,GtkTreeIter * iter,gpointer user_data)1696 foreach_batchlist_save(	GtkTreeModel	*model,
1697 			GtkTreePath	*path,
1698 			GtkTreeIter	*iter,
1699 			gpointer	user_data)
1700 {
1701 	gchar	*lcurmap;
1702 
1703 	gtk_tree_model_get(model, iter, 0, &lcurmap, -1);
1704 	fprintf(user_data, "%s\n", lcurmap);
1705 	g_free(lcurmap);
1706 
1707 	return FALSE;
1708 }
1709 
1710 
1711 void
on_btnsavelist_clicked(GtkButton * button,gpointer user_data)1712 on_btnsavelist_clicked                 (GtkButton       *button,
1713                                         gpointer         user_data)
1714 {
1715 	gchar		*lcurmap;
1716 	gchar		*listfile;
1717 	FILE		*MapList;
1718 	GtkWidget	*SaveDlg;
1719 
1720 	GtkWidget	*UMarkDialog;
1721 	GtkListStore	*lsBatchList;
1722 	GtkTreeModel	*tmBatchList;
1723 	GtkTreePath	*tpBatchList;
1724 
1725 	UMarkDialog = GTK_WIDGET(gtk_widget_get_toplevel(GTK_WIDGET(button)));
1726 	tmBatchList = gtk_tree_view_get_model( GTK_TREE_VIEW(lookup_widget(UMarkDialog, "tvBatchList")) );
1727 
1728 /*	TODO: rows, not columns
1729 	if(gtk_tree_model_get_n_columns(tmBatchList) == 0)
1730 	{
1731 		GtkWidget* BlErrBox;
1732 		BlErrBox = gnome_ok_dialog("There are no maps in the list to save.");
1733 		gtk_widget_show(BlErrBox);
1734 
1735 		return;
1736 	}
1737 */
1738 	SaveDlg = gtk_file_chooser_dialog_new(
1739 		"Save Map List", NULL,
1740 		GTK_FILE_CHOOSER_ACTION_SAVE,
1741 		GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1742 		GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
1743 		NULL);
1744 
1745 	if(gtk_dialog_run(GTK_DIALOG(SaveDlg)) == GTK_RESPONSE_ACCEPT)
1746 	{
1747 		listfile = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(SaveDlg));
1748 
1749 		if((MapList = fopen(listfile, "w")) == NULL)
1750 		{
1751 			gchar* FOpenErrBox = "ERROR: Could not open the file.";
1752 			umark_message_dialog(FOpenErrBox);
1753 			return;
1754 		}
1755 		gtk_tree_model_foreach(GTK_TREE_MODEL(tmBatchList), foreach_batchlist_save, MapList);
1756 
1757 		fclose(MapList);
1758 		g_free(listfile);
1759 	}
1760 	gtk_widget_destroy(SaveDlg);
1761 }
1762 
1763 
1764 /*** results dialog controls *************************************************/
1765 /*
1766 void
1767 compare_foreach_pass_highest		(GtkTreeModel	*model,
1768 					 GtkTreePath	*path,
1769 					 GtkTreeIter	*iter,
1770 					 gpointer	data)
1771 {
1772 	gdouble fps;
1773 
1774 	gtk_tree_model_get(model, iter, COL_MAP, &fps, -1);
1775 
1776 	if(fps > *data)
1777 	{
1778 		*data = fps;
1779 	}
1780 
1781 }
1782 
1783 
1784 void
1785 compare_foreach_pass_hundred		(GtkTreeModel	*model,
1786 					 GtkTreePath	*path,
1787 					 GtkTreeIter	*iter,
1788 					 gpointer	data)
1789 {
1790 
1791 }
1792 */
1793 
1794 void
on_btncompare_clicked(GtkButton * button,gpointer user_data)1795 on_btncompare_clicked                  (GtkButton       *button,
1796                                         gpointer         user_data)
1797 {
1798 	gdouble *highest;
1799 	gdouble *hundred;
1800 	gdouble	*percent;
1801 
1802 	highest = malloc(sizeof(gdouble));
1803 	hundred = malloc(sizeof(gdouble));
1804 	percent = malloc(sizeof(gdouble));
1805 
1806 	struct UResults Rlt;
1807 	struct UResults *pRlt;
1808 
1809 	pRlt = &Rlt;
1810 
1811 	GtkTreeSelection *selection;
1812 
1813 	GtkWidget	*ResultsDialog;
1814 	GtkListStore	*lsResultList;
1815 	GtkTreeIter	iter;
1816 
1817 	ResultsDialog = GTK_WIDGET(gtk_widget_get_toplevel(GTK_WIDGET(button)));
1818 	lsResultList = GTK_LIST_STORE(gtk_tree_view_get_model( GTK_TREE_VIEW(lookup_widget(ResultsDialog , "tvResults")) ));
1819 	selection = GTK_TREE_SELECTION( gtk_tree_view_get_selection(GTK_TREE_VIEW(lookup_widget(ResultsDialog , "tvResults"))) );
1820 
1821 	/* TODO: use gtk_tree_selection_selected_foreach(selection, func, FILEPOINTER) */
1822 
1823 /*	gtk_tree_selection_selected_foreach(selection, compare_foreach_pass_highest, highest);
1824 	gtk_tree_selection_selected_foreach(selection, compare_foreach_pass_hundred, hundred);
1825 */
1826 
1827 	gtk_tree_selection_selected_foreach(selection, compare_foreach_pass_one, NULL);
1828 
1829 
1830 /*	gchar	*test;
1831 	test = g_strdup_printf("Highest is %.6f", highest);
1832 	umark_message_dialog(test);
1833 	g_free(test);
1834 */
1835 }
1836 
1837 
1838 void
compare_foreach_pass_one(GtkTreeModel * model,GtkTreePath * path,GtkTreeIter * iter,gpointer data)1839 compare_foreach_pass_one		(GtkTreeModel	*model,
1840 					 GtkTreePath	*path,
1841 					 GtkTreeIter	*iter,
1842 					 gpointer	data)
1843 {
1844 	gchar* mapname;
1845 
1846 	gtk_tree_model_get(model, iter, COL_MAP, &mapname, -1);
1847 	umark_message_dialog(mapname);
1848 
1849 	g_free(mapname);
1850 }
1851 
1852 
1853 void
on_btnsubmit_clicked(GtkButton * button,gpointer user_data)1854 on_btnsubmit_clicked                   (GtkButton       *button,
1855                                         gpointer         user_data)
1856 {
1857 	/* TODO: output UMTMP_LOG and delete after calling UMPRL_TMP */
1858 	gchar	*vbrowser;
1859 	gchar	*perlexec;
1860 	gchar	*perlfile;
1861 	FILE	*PERLFILE;
1862 
1863 	perlfile = g_strdup_printf("%s/Benchmark/UMPRL_TMP", utpath);
1864 	PERLFILE = fopen(perlfile, "w");
1865 
1866 	fprintf(PERLFILE, _SYSTEM_INFO_PL);
1867 	fclose(PERLFILE);
1868 
1869 	perlexec = g_strdup_printf("perl %s %s >%s/Benchmark/UMTMP_HTM", perlfile, utpath, utpath);
1870 	system(perlexec);
1871 	g_free(perlexec);
1872 	remove(perlfile);
1873 
1874 	vbrowser = g_strdup_printf("%s %s/Benchmark/UMTMP_HTM &", "mozilla", utpath);
1875 	system(vbrowser);
1876 	g_free(vbrowser);
1877 	g_free(perlfile);
1878 
1879 	/* TODO: delete html file after viewing in HTML viewer */
1880 /*	system("echo '<html></html>' >UMTMP_HTM");
1881 */
1882 }
1883 
1884 
1885 void
on_btnloadlog_clicked(GtkButton * button,gpointer user_data)1886 on_btnloadlog_clicked                  (GtkButton       *button,
1887                                         gpointer         user_data)
1888 {
1889 	char		*umarkfile;
1890 	GtkWidget	*OpenDlg;
1891 	GtkWidget	*ResultsDialog;
1892 	GtkListStore	*lsResultList;
1893 	GtkTreeIter	iter;
1894 
1895 	ResultsDialog = GTK_WIDGET(gtk_widget_get_toplevel(GTK_WIDGET(button)));
1896 	lsResultList = GTK_LIST_STORE(gtk_tree_view_get_model( GTK_TREE_VIEW(lookup_widget(ResultsDialog , "tvResults")) ));
1897 
1898 	OpenDlg = gtk_file_chooser_dialog_new(
1899 		"Open UMark File", NULL,
1900 		GTK_FILE_CHOOSER_ACTION_OPEN,
1901 		GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1902 		GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
1903 		NULL);
1904 
1905 	if(gtk_dialog_run(GTK_DIALOG(OpenDlg)) == GTK_RESPONSE_ACCEPT)
1906 	{
1907 		umarkfile = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(OpenDlg));
1908 
1909 		int	i,j;
1910 		int	nrow;
1911 		int	passes;
1912 
1913 		FILE	*UMarks;
1914 		gchar	*strTmp;
1915 
1916 		struct	stat results;
1917 		struct	UResults Rlt;
1918 		struct	UResults *pRlt;
1919 
1920 		pRlt = &Rlt;
1921 
1922 		/* TODO: check if results.st_size % sizeof(struct UResults) == 0 */
1923 
1924 		if(stat(umarkfile, &results) != 0)
1925 		{
1926 			gchar* FSizeErrBox = "ERROR: Could not read the file size.";
1927 			umark_message_dialog(FSizeErrBox);
1928 			return;
1929 		}
1930 		passes = results.st_size / sizeof(struct UResults);
1931 
1932 		/* verify file is open */
1933 		if((UMarks = fopen(umarkfile, "rb")) == NULL)
1934 		{
1935 			gchar* FOpenErrBox = "ERROR: Could not read the .umark file.";
1936 			umark_message_dialog(FOpenErrBox);
1937 			return;
1938 		}
1939 		gtk_list_store_clear(GTK_LIST_STORE(lsResultList));
1940 
1941 		for(i = 0; i < passes; i++)
1942 		{
1943 			fread(&Rlt, sizeof(struct UResults), 1, UMarks);
1944 
1945 			for(j = 0; j < 44; j++)
1946 			{
1947 				Rlt.Map[j] -= AUGMENT;
1948 			}
1949 			/* nrow = */
1950 
1951 			gtk_list_store_append (lsResultList, &iter);
1952 
1953 			gtk_list_store_set(lsResultList, &iter, COL_MAP, Rlt.Map, -1);
1954 			gtk_list_store_set(lsResultList, &iter, COL_BOT, pRlt->Bot - AUGMENT, -1);
1955 
1956 			switch(pRlt->Dtl - AUGMENT)
1957 			{
1958 				case 0: strTmp = "Low"; break;
1959 				case 1: strTmp = "High"; break;
1960 				case 2: strTmp = "Current"; break;
1961 				case 3: strTmp = "Custom"; break;
1962 				default: strTmp = "Error";
1963 			}
1964 			gtk_list_store_set(lsResultList, &iter, COL_DTL, strTmp, -1);
1965 
1966 			switch(pRlt->Res - AUGMENT)
1967 			{
1968 				case RES_640 : strTmp = "640x480";	break;
1969 				case RES_800 : strTmp = "800x600";	break;
1970 				case RES_1024: strTmp = "1024x768";	break;
1971 				case RES_1280: strTmp = "1280x1024";	break;
1972 				case RES_1600: strTmp = "1600x1200";	break;
1973 				default: strTmp = "Error";
1974 			}
1975 			gtk_list_store_set(lsResultList, &iter, COL_RES, strTmp, -1);
1976 
1977 			gtk_list_store_set(lsResultList, &iter, COL_MIN, pRlt->Min - AUGMENT, -1);
1978 			gtk_list_store_set(lsResultList, &iter, COL_AVG, pRlt->Avg - AUGMENT, -1);
1979 			gtk_list_store_set(lsResultList, &iter, COL_MAX, pRlt->Max - AUGMENT, -1);
1980 			gtk_list_store_set(lsResultList, &iter, COL_SCR, pRlt->Scr - AUGMENT, -1);
1981 			gtk_list_store_set(lsResultList, &iter, COL_VER, pRlt->Ver - AUGMENT, -1);
1982 
1983 			switch((pRlt->Typ - AUGMENT) +1)
1984 			{
1985 				case PRE_BM: strTmp = "UT2003 Botmatch"; break;
1986 				case PRE_FB: strTmp = "UT2003 Flyby"; break;
1987 				case PRE_DM: strTmp = "UT2003 Demo"; break;
1988 				case PRE_D4: strTmp = "UT2004 Demo"; break;
1989 				case PRE_DE: strTmp = "DE Bonus Pack"; break;
1990 				case PRE_EG: strTmp = "Epic Bonus Pack"; break;
1991 				case PRE_U3: strTmp = "UMark 2003"; break;
1992 				case PRE_U4: strTmp = "UMark 2004"; break;
1993 				case PRE_TD: strTmp = "Timedemo"; break;
1994 				default: strTmp = "Custom";
1995 			}
1996 			gtk_list_store_set(lsResultList, &iter, COL_TYP, strTmp, -1);
1997 		}
1998 		fclose(UMarks);
1999 		g_free(umarkfile);
2000 	}
2001 	gtk_widget_destroy(OpenDlg);
2002 }
2003 
2004 
2005 gboolean
foreach_results_save(GtkTreeModel * model,GtkTreePath * path,GtkTreeIter * iter,gpointer user_data)2006 foreach_results_save(	GtkTreeModel	*model,
2007 			GtkTreePath	*path,
2008 			GtkTreeIter	*iter,
2009 			gpointer	user_data)
2010 {
2011 	gint	i;
2012 	gchar	*strTmp;
2013 	gchar	*MapName;
2014 
2015 	struct	UResults Rlt;
2016 
2017 	/* map */
2018 	gtk_tree_model_get(model, iter, COL_MAP, &MapName, -1);
2019 	for(i = 0; MapName[i] == '\0' || i < 44; i++)
2020 	{
2021 		Rlt.Map[i] = MapName[i] + AUGMENT;
2022 	}
2023 
2024 	/* bot */
2025 	gtk_tree_model_get(model, iter, COL_BOT, &Rlt.Bot, -1);
2026 	Rlt.Bot += AUGMENT;
2027 
2028 	/* detail */
2029 	gtk_tree_model_get(model, iter, COL_DTL, &strTmp, -1);
2030 
2031 	if(strcmp(strTmp, "Low") == 0) Rlt.Dtl = 0;
2032 	else
2033 	if(strcmp(strTmp, "High") == 0) Rlt.Dtl = 1;
2034 	else
2035 	if(strcmp(strTmp, "Current") == 0) Rlt.Dtl = 2;
2036 	else
2037 	if(strcmp(strTmp, "Custom") == 0) Rlt.Dtl = 3;
2038 
2039 	Rlt.Dtl += AUGMENT;
2040 	g_free(strTmp);
2041 
2042 	/* resolution */
2043 	gtk_tree_model_get(model, iter, COL_RES, &strTmp, -1);
2044 
2045 	if(strcmp(strTmp, "640x480") == 0) Rlt.Res = 0;
2046 	else
2047 	if(strcmp(strTmp, "800x600") == 0) Rlt.Res = 1;
2048 	else
2049 	if(strcmp(strTmp, "1024x768") == 0) Rlt.Res = 2;
2050 	else
2051 	if(strcmp(strTmp, "1280x1024") == 0) Rlt.Res = 3;
2052 	else
2053 	if(strcmp(strTmp, "1600x1200") == 0) Rlt.Res = 4;
2054 
2055 	Rlt.Res += AUGMENT;
2056 	g_free(strTmp);
2057 
2058 	/* fps & version */
2059 	gtk_tree_model_get(model, iter, COL_MIN, &Rlt.Min, -1);
2060 	Rlt.Min += AUGMENT;
2061 	gtk_tree_model_get(model, iter, COL_AVG, &Rlt.Avg, -1);
2062 	Rlt.Avg += AUGMENT;
2063 	gtk_tree_model_get(model, iter, COL_MAX, &Rlt.Max, -1);
2064 	Rlt.Max += AUGMENT;
2065 	gtk_tree_model_get(model, iter, COL_SCR, &Rlt.Scr, -1);
2066 	Rlt.Scr += AUGMENT;
2067 	gtk_tree_model_get(model, iter, COL_VER, &Rlt.Ver, -1);
2068 	Rlt.Ver += AUGMENT;
2069 
2070 	/* benchmark type */
2071 	gtk_tree_model_get(model, iter, COL_TYP, &strTmp, -1);
2072 
2073 	if(strcmp(strTmp, "UT2003 Botmatch") == 0) Rlt.Typ = 0;
2074 	else
2075 	if(strcmp(strTmp, "UT2003 Flyby") == 0) Rlt.Typ = 1;
2076 	else
2077 	if(strcmp(strTmp, "UT2003 Demo") == 0) Rlt.Typ = 2;
2078 	else
2079 	if(strcmp(strTmp, "UT2004 Demo") == 0) Rlt.Typ = 3;
2080 	else
2081 	if(strcmp(strTmp, "DE Bonus Back") == 0) Rlt.Typ = 4;
2082 	else
2083 	if(strcmp(strTmp, "Epic Bonus Pack") == 0) Rlt.Typ = 5;
2084 	else
2085 	if(strcmp(strTmp, "UMark 2003") == 0) Rlt.Typ = 6;
2086 	else
2087 	if(strcmp(strTmp, "UMark 2004") == 0) Rlt.Typ = 7;
2088 	else
2089 	if(strcmp(strTmp, "Timedemo") == 0) Rlt.Typ = 8;
2090 	else	Rlt.Typ = 9;
2091 
2092 	Rlt.Typ += AUGMENT;
2093 	g_free(strTmp);
2094 
2095 	fwrite(&Rlt, sizeof(struct UResults), 1, user_data);
2096 
2097 	return FALSE;
2098 }
2099 
2100 
2101 void
on_btnsavelog_clicked(GtkButton * button,gpointer user_data)2102 on_btnsavelog_clicked                  (GtkButton       *button,
2103                                         gpointer         user_data)
2104 {
2105 	char		*umarkfile;
2106 	GtkWidget	*SaveDlg;
2107 	GtkWidget	*ResultsDialog;
2108 	GtkListStore	*lsResultList;
2109 	GtkTreeIter	*iter;
2110 
2111 	ResultsDialog = GTK_WIDGET(gtk_widget_get_toplevel(GTK_WIDGET(button)));
2112 	lsResultList = GTK_LIST_STORE(gtk_tree_view_get_model( GTK_TREE_VIEW(lookup_widget(ResultsDialog , "tvResults")) ));
2113 
2114 /*	gtk_tree_model_get_iter_first(tmBatchList, iter);
2115 */
2116 	SaveDlg = gtk_file_chooser_dialog_new(
2117 		"Save UMark File", NULL,
2118 		GTK_FILE_CHOOSER_ACTION_SAVE,
2119 		GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
2120 		GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
2121 		NULL);
2122 
2123 	if(gtk_dialog_run(GTK_DIALOG(SaveDlg)) == GTK_RESPONSE_ACCEPT)
2124 	{
2125 		umarkfile = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(SaveDlg));
2126 
2127 		FILE *UMarks;
2128 		if((UMarks = fopen(umarkfile, "wb")) == NULL)
2129 		{
2130 			gchar* FOpenErrBox = "ERROR: Could not open the .umark file for writing.";
2131 			umark_message_dialog(FOpenErrBox);
2132 			return;
2133 		}
2134 		gtk_tree_model_foreach(GTK_TREE_MODEL(lsResultList), foreach_results_save, UMarks);
2135 
2136 		fclose(UMarks);
2137 		g_free(umarkfile);
2138 	}
2139 	gtk_widget_destroy(SaveDlg);
2140 }
2141 
2142 
2143 void
on_btndismissresults_clicked(GtkButton * button,gpointer user_data)2144 on_btndismissresults_clicked           (GtkButton       *button,
2145                                         gpointer         user_data)
2146 {
2147 	gchar	*rm_log;
2148 
2149 	gtk_widget_destroy(ResultsBox);
2150 	rm_log = g_strdup_printf("%s/Benchmark/UMTMP_LOG", utpath);
2151 
2152 	remove(rm_log);
2153 	g_free(rm_log);
2154 }
2155 
2156 
2157 /*** preset maps dialog ******************************************************/
2158 void
on_radprebm_clicked(GtkButton * button,gpointer user_data)2159 on_radprebm_clicked                    (GtkButton       *button,
2160                                         gpointer         user_data)
2161 {
2162 	presetchosen = PRE_BM;
2163 }
2164 
2165 
2166 void
on_radprefb_clicked(GtkButton * button,gpointer user_data)2167 on_radprefb_clicked                    (GtkButton       *button,
2168                                         gpointer         user_data)
2169 {
2170 	presetchosen = PRE_FB;
2171 }
2172 
2173 
2174 void
on_radpredm_clicked(GtkButton * button,gpointer user_data)2175 on_radpredm_clicked                    (GtkButton       *button,
2176                                         gpointer         user_data)
2177 {
2178 	presetchosen = PRE_DM;
2179 }
2180 
2181 
2182 void
on_radpred4_clicked(GtkButton * button,gpointer user_data)2183 on_radpred4_clicked                    (GtkButton       *button,
2184                                         gpointer         user_data)
2185 {
2186 	presetchosen = PRE_D4;
2187 }
2188 
2189 
2190 void
on_radprede_clicked(GtkButton * button,gpointer user_data)2191 on_radprede_clicked                    (GtkButton       *button,
2192                                         gpointer         user_data)
2193 {
2194 	presetchosen = PRE_DE;
2195 }
2196 
2197 
2198 void
on_radpreeg_clicked(GtkButton * button,gpointer user_data)2199 on_radpreeg_clicked                    (GtkButton       *button,
2200                                         gpointer         user_data)
2201 {
2202 	presetchosen = PRE_EG;
2203 }
2204 
2205 
2206 void
on_radpreu3_clicked(GtkButton * button,gpointer user_data)2207 on_radpreu3_clicked                    (GtkButton       *button,
2208                                         gpointer         user_data)
2209 {
2210 	presetchosen = PRE_U3;
2211 }
2212 
2213 
2214 void
on_radpreu4_clicked(GtkButton * button,gpointer user_data)2215 on_radpreu4_clicked                    (GtkButton       *button,
2216                                         gpointer         user_data)
2217 {
2218 	presetchosen = PRE_U4;
2219 }
2220 
2221 
2222 void
on_BtnPresetUse_clicked(GtkButton * button,gpointer user_data)2223 on_BtnPresetUse_clicked                (GtkButton       *button,
2224                                         gpointer         user_data)
2225 {
2226 	presetchosen = 0 - presetchosen;
2227 	gtk_widget_hide(PresetsBox);
2228 }
2229 
2230 
2231 void
on_BtnPresetAdd_clicked(GtkButton * button,gpointer user_data)2232 on_BtnPresetAdd_clicked                (GtkButton       *button,
2233                                         gpointer         user_data)
2234 {
2235 	if(presetchosen == -1) presetchosen = 1;
2236 
2237 	/* add preset to existing list */
2238 	gtk_widget_hide(PresetsBox);
2239 }
2240 
2241 
2242 void
on_BtnPresetCancel_clicked(GtkButton * button,gpointer user_data)2243 on_BtnPresetCancel_clicked             (GtkButton       *button,
2244                                         gpointer         user_data)
2245 {
2246 	presetchosen = 0;
2247 	gtk_widget_hide(PresetsBox);
2248 }
2249 
2250 void
on_btnMsgOK_clicked(GtkButton * button,gpointer user_data)2251 on_btnMsgOK_clicked                    (GtkButton       *button,
2252                                         gpointer         user_data)
2253 {
2254 	gtk_widget_hide(GTK_WIDGET(UMsgBox));
2255 }
2256 
2257 
2258 void
on_chkTimeDemo_clicked(GtkButton * button,gpointer user_data)2259 on_chkTimeDemo_clicked                 (GtkButton       *button,
2260                                         gpointer         user_data)
2261 {
2262 	/* TODO: disable for non-retail versions */
2263 
2264 	dotimedemo = !dotimedemo;
2265 
2266 	if(build == 0)
2267 	{
2268 		return;
2269 	}
2270 	if(dotimedemo)
2271 	{
2272 		/* get demo directory into map list */
2273 		GtkWidget	*UMarkDialog;
2274 		GtkComboBox	*cbMaps;
2275 		GtkTreeModel	*cbTmod;
2276 
2277 		FILE		*MapList;
2278 		gchar		*lcurmap;
2279 		gchar		*MapPath;
2280 		gchar		*LogPath;
2281 		char		buffer;
2282 
2283 		UMarkDialog = GTK_WIDGET(gtk_widget_get_toplevel(GTK_WIDGET(button)));
2284 		cbMaps = GTK_COMBO_BOX(lookup_widget(UMarkDialog , "CmbMaps"));
2285 		cbTmod = GTK_TREE_MODEL(gtk_combo_box_get_model(cbMaps));
2286 
2287 /*		g_object_set(GTK_WIDGET(cbMaps), "appears-as-list", TRUE, NULL);
2288 */		gtk_list_store_clear(GTK_LIST_STORE(cbTmod));
2289 
2290 		if(build >= 3000)
2291 		{
2292 			MapPath = g_strdup_printf("ls -1 %s/Demos | sed -e 's/.demo4//g' >%s/Benchmark/.UMMAP_LST", utdir, utpath);
2293 		}
2294 		else
2295 		{
2296 			MapPath = g_strdup_printf("ls -1 %s/System/*.dem | sed -e 's/.dem//g' >%s/Benchmark/.UMMAP_LST", utdir, utpath);
2297 		}
2298 		system(MapPath);
2299 		g_free(MapPath);
2300 		MapPath = g_strdup_printf("%s/Benchmark/.UMMAP_LST", utpath);
2301 		MapList = fopen(MapPath, "r");
2302 
2303 		lcurmap = "";
2304 
2305 		while((buffer = getc(MapList)) != EOF)
2306 		{
2307 			if(buffer != '\n')
2308 			{
2309 				lcurmap = g_strdup_printf("%s%c", lcurmap, buffer); /* TODO: find a better way to append */
2310 			}
2311 			else
2312 			{
2313 				gtk_combo_box_append_text(GTK_COMBO_BOX(cbMaps), lcurmap);
2314 				g_free(lcurmap);
2315 				lcurmap = "";
2316 			}
2317 		}
2318 		fclose(MapList);
2319 		remove(MapPath);
2320 		g_free(MapPath);
2321 	}
2322 	else
2323 	{
2324 		/* place maps back into map list */
2325 		GtkWidget	*UMarkDialog;
2326 		GtkComboBox	*cbMaps;
2327 		GtkTreeModel	*cbTmod;
2328 
2329 		FILE		*MapList;
2330 		gchar		*lcurmap;
2331 		gchar		*MapPath;
2332 		gchar		*LogPath;
2333 		char		buffer;
2334 
2335 		UMarkDialog = GTK_WIDGET(gtk_widget_get_toplevel(GTK_WIDGET(button)));
2336 		cbMaps = GTK_COMBO_BOX(lookup_widget(UMarkDialog , "CmbMaps"));
2337 		cbTmod = GTK_TREE_MODEL(gtk_combo_box_get_model(cbMaps));
2338 
2339 /*		g_object_set(GTK_WIDGET(cbMaps), "appears-as-list", TRUE, NULL);
2340 */		gtk_list_store_clear(GTK_LIST_STORE(cbTmod));
2341 
2342 		MapPath = g_strdup_printf("ls -1 %s/Maps | grep \"AS-\\|BR-\\|CTF-\\|DM-\\|DOM-\\|MOV-\\|ONS-\" >%s/Benchmark/.UMMAP_LST", utdir, utpath);
2343 		system(MapPath);
2344 		g_free(MapPath);
2345 		MapPath = g_strdup_printf("%s/Benchmark/.UMMAP_LST", utpath);
2346 		MapList = fopen(MapPath, "r");
2347 
2348 		lcurmap = "";
2349 
2350 		while((buffer = getc(MapList)) != EOF)
2351 		{
2352 			if(buffer != '\n')
2353 			{
2354 				lcurmap = g_strdup_printf("%s%c", lcurmap, buffer); /* TODO: find a better way to append */
2355 			}
2356 			else
2357 			{
2358 				gtk_combo_box_append_text(GTK_COMBO_BOX(cbMaps), lcurmap);
2359 				g_free(lcurmap);
2360 				lcurmap = "";
2361 			}
2362 		}
2363 		fclose(MapList);
2364 		remove(MapPath);
2365 		g_free(MapPath);
2366 	}
2367 }
2368 
2369 
2370 void
on_btnUMarkConf_clicked(GtkButton * button,gpointer user_data)2371 on_btnUMarkConf_clicked                (GtkButton       *button,
2372                                         gpointer         user_data)
2373 {
2374 	ConfBox = create_UMarkConfDlg();
2375 /*
2376 FIXME: garbage characters on choosing ini files, then reopening dialog and clicking OK without changing
2377 ** (umark:29584): CRITICAL **: file pango-layout.c: line 1769 (pango_layout_get_cursor_pos): assertion `index >= 0 && index <= layout->length' failed
2378 */
2379 	gtk_entry_set_text(GTK_ENTRY( lookup_widget(ConfBox, "entryIniFile") ), inifile);
2380 	gtk_entry_set_text(GTK_ENTRY( lookup_widget(ConfBox, "entryIniUser") ), iniuser);
2381 
2382 	if(gtk_dialog_run(GTK_DIALOG(ConfBox)) == GTK_RESPONSE_CANCEL)
2383 	{
2384 		inifile = "";
2385 		iniuser = "";
2386 	}
2387 	gtk_widget_destroy(ConfBox);
2388 
2389 	umark_message_dialog(inifile);
2390 	umark_message_dialog(iniuser);
2391 }
2392 
2393 
2394 /*** ini configuration dialog ************************************************/
2395 void
on_btnConfCancel_clicked(GtkButton * button,gpointer user_data)2396 on_btnConfCancel_clicked               (GtkButton       *button,
2397                                         gpointer         user_data)
2398 {
2399 	gtk_widget_hide(ConfBox);
2400 }
2401 
2402 
2403 void
on_btnConfOK_clicked(GtkButton * button,gpointer user_data)2404 on_btnConfOK_clicked                   (GtkButton       *button,
2405                                         gpointer         user_data)
2406 {
2407 	gtk_widget_hide(ConfBox);
2408 }
2409 
2410 
2411 void
on_entryIniFile_changed(GtkEditable * editable,gpointer user_data)2412 on_entryIniFile_changed                (GtkEditable     *editable,
2413                                         gpointer         user_data)
2414 {
2415 	inifile = (gchar *)gtk_entry_get_text(GTK_ENTRY(editable));
2416 }
2417 
2418 
2419 void
on_btnBrowseIni_clicked(GtkButton * button,gpointer user_data)2420 on_btnBrowseIni_clicked                (GtkButton       *button,
2421                                         gpointer         user_data)
2422 {
2423 	GtkWidget	*ConfDlg;
2424 	GtkWidget	*OpenDlg;
2425 	gchar		*browse_inifile;
2426 
2427 	OpenDlg = gtk_file_chooser_dialog_new(
2428 		"Open Ini File", NULL,
2429 		GTK_FILE_CHOOSER_ACTION_OPEN,
2430 		GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
2431 		GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
2432 		NULL);
2433 
2434 	ConfDlg = GTK_WIDGET( gtk_widget_get_toplevel(GTK_WIDGET(button)) );
2435 
2436 	if(gtk_dialog_run(GTK_DIALOG(OpenDlg)) == GTK_RESPONSE_ACCEPT)
2437 	{
2438 		browse_inifile = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(OpenDlg));
2439 
2440 		gtk_entry_set_text(GTK_ENTRY( lookup_widget(ConfDlg, "entryIniFile") ), browse_inifile);
2441 		inifile = g_strdup(browse_inifile);
2442 
2443 		umark_message_dialog(inifile);
2444 		g_free(browse_inifile);
2445 	}
2446 	gtk_widget_destroy(OpenDlg);
2447 }
2448 
2449 
2450 void
on_entryIniUser_changed(GtkEditable * editable,gpointer user_data)2451 on_entryIniUser_changed                (GtkEditable     *editable,
2452                                         gpointer         user_data)
2453 {
2454 	iniuser = (gchar *)gtk_entry_get_text(GTK_ENTRY(editable));
2455 }
2456 
2457 
2458 void
on_btnBrowseUser_clicked(GtkButton * button,gpointer user_data)2459 on_btnBrowseUser_clicked               (GtkButton       *button,
2460                                         gpointer         user_data)
2461 {
2462 	GtkWidget	*ConfDlg;
2463 	GtkWidget	*OpenDlg;
2464 	gchar		*browse_iniuser;
2465 
2466 	OpenDlg = gtk_file_chooser_dialog_new(
2467 		"Open User Ini", NULL,
2468 		GTK_FILE_CHOOSER_ACTION_OPEN,
2469 		GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
2470 		GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
2471 		NULL);
2472 
2473 	ConfDlg = GTK_WIDGET( gtk_widget_get_toplevel(GTK_WIDGET(button)) );
2474 
2475 	if(gtk_dialog_run(GTK_DIALOG(OpenDlg)) == GTK_RESPONSE_ACCEPT)
2476 	{
2477 		browse_iniuser = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(OpenDlg));
2478 
2479 		gtk_entry_set_text(GTK_ENTRY( lookup_widget(ConfDlg, "entryIniUser") ), browse_iniuser);
2480 		iniuser = g_strdup(browse_iniuser);
2481 
2482 		umark_message_dialog(iniuser);
2483 		g_free(browse_iniuser);
2484 	}
2485 	gtk_widget_destroy(OpenDlg);
2486 }
2487 
2488 
2489 /*** about dialog ************************************************************/
2490 void
on_btnAboutDocs_clicked(GtkButton * button,gpointer user_data)2491 on_btnAboutDocs_clicked                (GtkButton       *button,
2492                                         gpointer         user_data)
2493 {
2494 	system("mozilla http://www.unrealmark.net/docs.php &");
2495 }
2496 
2497 
2498 void
on_btnAboutOnline_clicked(GtkButton * button,gpointer user_data)2499 on_btnAboutOnline_clicked              (GtkButton       *button,
2500                                         gpointer         user_data)
2501 {
2502 	system("mozilla http://www.unrealmark.net/login.php &");
2503 }
2504 
2505 
2506 void
on_btnAboutUpdates_clicked(GtkButton * button,gpointer user_data)2507 on_btnAboutUpdates_clicked             (GtkButton       *button,
2508                                         gpointer         user_data)
2509 {
2510 	system("mozilla http://www.unrealmark.net &");
2511 }
2512 
2513 
2514 void
on_btnCloseAbout_clicked(GtkButton * button,gpointer user_data)2515 on_btnCloseAbout_clicked               (GtkButton       *button,
2516                                         gpointer         user_data)
2517 {
2518 	gtk_widget_destroy(AboutBox);
2519 }
2520 
2521