| 1 | /* |
| 2 | * Copyright (C) 2004 Lector |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; either version 2 |
| 7 | * of the License, or (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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 17 | */ |
| 18 | |
| 19 | #include "common/setup_before.h" |
| 20 | #include "support.h" |
| 21 | |
| 22 | #include <cstdio> |
| 23 | #include <cerrno> |
| 24 | #include <cstring> |
| 25 | |
| 26 | #include "compat/access.h" |
| 27 | #include "common/eventlog.h" |
| 28 | #include "common/util.h" |
| 29 | #include "common/xalloc.h" |
| 30 | |
| 31 | #include "prefs.h" |
| 32 | #include "common/setup_after.h" |
| 33 | |
| 34 | namespace pvpgn |
| 35 | { |
| 36 | |
| 37 | namespace bnetd |
| 38 | { |
| 39 | |
| 40 | extern int support_check_files(char const * supportfile) |
| 41 | { |
| 42 | |
| 43 | std::FILE *fp; |
| 44 | char *buff; |
| 45 | unsigned int line; |
| 46 | int filedirlen; |
| 47 | char * namebuff; |
| 48 | |
| 49 | if (!(supportfile)) |
| 50 | { |
| 51 | eventlog(eventlog_level_error, __FUNCTION__, "got NULL supportfile"); |
| 52 | return -1; |
| 53 | } |
| 54 | |
| 55 | if (!(fp = std::fopen(supportfile, "r"))) |
| 56 | { |
| 57 | eventlog(eventlog_level_error, __FUNCTION__, "could not open file \"{}\" for reading (std::fopen: {})", supportfile, std::strerror(errno)); |
| 58 | eventlog(eventlog_level_error, __FUNCTION__, "can't guarantee that everything will run smooth"); |
| 59 | return 0; |
| 60 | } |
| 61 | |
| 62 | filedirlen = std::strlen(prefs_get_filedir()); |
| 63 | |
| 64 | for (line = 1; (buff = file_get_line(fp)); line++) |
| 65 | { |
| 66 | if (buff[0] == '#' || buff[0] == '\0') |
| 67 | { |
| 68 | continue; |
| 69 | } |
| 70 | |
| 71 | namebuff = (char*)xmalloc(filedirlen + 1 + std::strlen(buff) + 1); |
| 72 | std::sprintf(namebuff, "%s/%s", prefs_get_filedir(), buff); |
| 73 | |
| 74 | if (access(namebuff, F_OK) < 0) |
| 75 | { |
| 76 | eventlog(eventlog_level_fatal, __FUNCTION__, "necessary file \"{}\" missing", namebuff); |
| 77 | xfree((void *)namebuff); |
| 78 | std::fclose(fp); |
| 79 | return -1; |
| 80 | } |
| 81 | |
| 82 | xfree((void *)namebuff); |
| 83 | } |
| 84 | |
| 85 | file_get_line(NULL); // clear file_get_line buffer |
| 86 | std::fclose(fp); |
| 87 | |
| 88 | return 0; |
| 89 | } |
| 90 | |
| 91 | } |
| 92 | |
| 93 | } |