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