Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Pyrogenesis.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2009 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 static const wchar_t* translate_no_mem = L"(no mem)";
28 
29 // overrides ah_translate. registered in GameSetup.cpp
30 const wchar_t* psTranslate(const wchar_t* text)
31 {
32  // TODO: implement this somehow
33 
34  // i18n not available: at least try and return the text (unchanged)
35  const wchar_t* ret_dup = wcsdup(text);
36  return ret_dup? ret_dup : translate_no_mem;
37 }
38 
39 void psTranslateFree(const wchar_t* text)
40 {
41  if(text != translate_no_mem)
42  free((void*)text);
43 }
44 
45 
46 // convert contents of file <in_filename> from char to wchar_t and
47 // append to <out> file.
48 static void AppendAsciiFile(FILE* out, const OsPath& pathname)
49 {
50  FILE* in = sys_OpenFile(pathname, "rb");
51  if(!in)
52  {
53  fwprintf(out, L"(unavailable)");
54  return;
55  }
56 
57  const size_t buf_size = 1024;
58  char buf[buf_size+1]; // include space for trailing '\0'
59 
60  while(!feof(in))
61  {
62  size_t bytes_read = fread(buf, 1, buf_size, in);
63  if(!bytes_read)
64  break;
65  buf[bytes_read] = 0; // 0-terminate
66  fwprintf(out, L"%hs", buf);
67  }
68 
69  fclose(in);
70 }
71 
72 // for user convenience, bundle all logs into this file:
73 void psBundleLogs(FILE* f)
74 {
75  fwprintf(f, L"SVN Revision: %ls\n\n", svn_revision);
76 
77  fwprintf(f, L"System info:\n\n");
78  OsPath path1 = psLogDir()/"system_info.txt";
79  AppendAsciiFile(f, path1);
80  fwprintf(f, L"\n\n====================================\n\n");
81 
82  fwprintf(f, L"Main log:\n\n");
83  OsPath path2 = psLogDir()/"mainlog.html";
84  AppendAsciiFile(f, path2);
85  fwprintf(f, L"\n\n====================================\n\n");
86 }
87 
88 
89 static OsPath logDir;
90 
91 void psSetLogDir(const OsPath& newLogDir)
92 {
93  logDir = newLogDir;
94 }
95 
96 const OsPath& psLogDir()
97 {
98  return logDir;
99 }
static OsPath logDir
Definition: Pyrogenesis.cpp:89
void psBundleLogs(FILE *f)
Definition: Pyrogenesis.cpp:73
const OsPath & psLogDir()
Definition: Pyrogenesis.cpp:96
static void out(const wchar_t *fmt,...)
Definition: wdbg_sym.cpp:419
wchar_t svn_revision[]
void psSetLogDir(const OsPath &newLogDir)
Definition: Pyrogenesis.cpp:91
static void AppendAsciiFile(FILE *out, const OsPath &pathname)
Definition: Pyrogenesis.cpp:48
FILE * sys_OpenFile(const OsPath &pathname, const char *mode)
open a file like with fopen (but taking an OsPath argument).
Definition: unix.cpp:373
Definition: path.h:75
void psTranslateFree(const wchar_t *text)
Definition: Pyrogenesis.cpp:39
static const wchar_t * translate_no_mem
Definition: Pyrogenesis.cpp:27
const wchar_t * psTranslate(const wchar_t *text)
Definition: Pyrogenesis.cpp:30