1 /* Copyright (C) 2015 Wildfire Games.
2 * This file is part of 0 A.D.
3 *
4 * 0 A.D. 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 * 0 A.D. 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 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #include "precompiled.h"
19
20 #include <cstdio>
21
22 #include "Pyrogenesis.h"
23
24 #include "lib/sysdep/sysdep.h"
25 #include "lib/svn_revision.h"
26
27 const char engine_version[] = "0.0.23";
28
29 // convert contents of file <in_filename> from char to wchar_t and
30 // append to <out> file.
AppendAsciiFile(FILE * out,const OsPath & pathname)31 static void AppendAsciiFile(FILE* out, const OsPath& pathname)
32 {
33 FILE* in = sys_OpenFile(pathname, "rb");
34 if (!in)
35 {
36 fwprintf(out, L"(unavailable)");
37 return;
38 }
39
40 const size_t buf_size = 1024;
41 char buf[buf_size+1]; // include space for trailing '\0'
42
43 while (!feof(in))
44 {
45 size_t bytes_read = fread(buf, 1, buf_size, in);
46 if (!bytes_read)
47 break;
48 buf[bytes_read] = 0; // 0-terminate
49 fwprintf(out, L"%hs", buf);
50 }
51
52 fclose(in);
53 }
54
55 // for user convenience, bundle all logs into this file:
psBundleLogs(FILE * f)56 void psBundleLogs(FILE* f)
57 {
58 fwprintf(f, L"SVN Revision: %ls\n\n", svn_revision);
59 fwprintf(f, L"Engine Version: %hs\n\n", engine_version);
60
61 fwprintf(f, L"System info:\n\n");
62 OsPath path1 = psLogDir()/"system_info.txt";
63 AppendAsciiFile(f, path1);
64 fwprintf(f, L"\n\n====================================\n\n");
65
66 fwprintf(f, L"Main log:\n\n");
67 OsPath path2 = psLogDir()/"mainlog.html";
68 AppendAsciiFile(f, path2);
69 fwprintf(f, L"\n\n====================================\n\n");
70 }
71
72
73 static OsPath logDir;
74
psSetLogDir(const OsPath & newLogDir)75 void psSetLogDir(const OsPath& newLogDir)
76 {
77 logDir = newLogDir;
78 }
79
psLogDir()80 const OsPath& psLogDir()
81 {
82 return logDir;
83 }
84