Line data Source code
1 : /* Copyright (C) 2026 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 "JSInterface_UserReport.h" 21 : 22 : #include "lib/file/vfs/vfs.h" 23 : #include "lib/path.h" 24 : #include "lib/status.h" 25 : #include "ps/Filesystem.h" 26 : #include "ps/Pyrogenesis.h" 27 : #include "ps/UserReport.h" 28 : #include "scriptinterface/FunctionWrapper.h" 29 : 30 : #include <string> 31 : 32 : namespace JSI_UserReport 33 : { 34 0 : bool IsUserReportEnabled() 35 : { 36 0 : return g_UserReporter.IsReportingEnabled(); 37 : } 38 : 39 0 : void SetUserReportEnabled(bool enabled) 40 : { 41 0 : g_UserReporter.SetReportingEnabled(enabled); 42 0 : } 43 : 44 0 : std::string GetUserReportStatus() 45 : { 46 0 : return g_UserReporter.GetStatus(); 47 : } 48 : 49 0 : std::string GetUserReportLogPath() 50 : { 51 0 : return psLogDir().string8(); 52 : } 53 : 54 0 : std::string GetUserReportConfigPath() 55 : { 56 0 : OsPath configPath; 57 0 : WARN_IF_ERR(g_VFS->GetDirectoryRealPath("config/", configPath)); 58 0 : return configPath.string8(); 59 0 : } 60 : 61 26 : void RegisterScriptFunctions(const Script::Request& rq) 62 : { 63 26 : Script::Function::Register<&IsUserReportEnabled>(rq, "IsUserReportEnabled"); 64 26 : Script::Function::Register<&SetUserReportEnabled>(rq, "SetUserReportEnabled"); 65 26 : Script::Function::Register<&GetUserReportStatus>(rq, "GetUserReportStatus"); 66 26 : Script::Function::Register<&GetUserReportLogPath>(rq, "GetUserReportLogPath"); 67 26 : Script::Function::Register<&GetUserReportConfigPath>(rq, "GetUserReportConfigPath"); 68 26 : } 69 : }