Nuclide
Software Development Kit for id Tech
platform.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016-2022 Vera Visions LLC.
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
13 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
14 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15*/
16
17typedef enum
18{
26
28
29/* fast way to query which system we're on */
32{
34 string osname = cvar_string("sys_platform");
36
37 switch (osname) {
38 case "Web":
40 break;
41 case "WinCE":
42 case "Xbox":
44 break;
45 case "WinRT":
46 case "iOSSim":
47 case "iOS":
48 case "Android":
50 break;
51 case "Unknown":
52 case "Nacl":
53 case "Win":
54 case "Win16":
55 case "Cygwin":
56 case "Linux":
57 case "Mac":
58 case "Apple":
59 case "FreeBSD":
60 case "OpenBSD":
61 case "NetBSD":
62 case "BSD":
63 case "MorphOS":
64 case "AmigaOS":
65 case "MacOS X":
66 case "Dos":
67 default:
69 break;
70 }
71 }
72
73 return g_platform;
74}
75
76bool
77Platform_FileInGamedir(string fileName, string gameDir)
78{
79 searchhandle fileSearch;
80 int fileCount = 0i;
81
82 fileSearch = search_begin(fileName, SEARCH_FULLPACKAGE, TRUE);
83 fileCount = search_getsize(fileSearch);
84
85 NSLog("Looking for %S in %S", fileName, gameDir);
86
87 /* doesn't exist */
88 if (fileCount <= 0)
89 return false;
90
91 for (int i = 0; i < fileCount; i++) {
92 string fileDir;
93 string fullPath = search_getpackagename(fileSearch, i);
94 fileDir = substring(fullPath, 0, strlen(gameDir)); /* only need to check same-ness */
95
96 if (fileDir == gameDir) {
97 NSLog("Found %S in %S", fileName, gameDir);
98 return true;
99 }
100 }
101
102 NSError("Did not find %S in %S", fileName, gameDir);
103
104 /* file exists but is in a different gamedir */
105 return false;
106}
107
108bool
110{
111 string gameDir = cvar_string("game");
112 return Platform_FileInGamedir(fileName, gameDir);
113}
#define NSError(...)
Logs an error message, with timestamp.
Definition: global.h:85
#define NSLog(...)
Logs an message, with timestamp.
Definition: global.h:79
platform Platform_GetPlatform(void)
Definition: platform.h:31
var platform g_platform
Definition: platform.h:27
bool Platform_FileInCurrentGamedir(string fileName)
Definition: platform.h:109
bool Platform_FileInGamedir(string fileName, string gameDir)
Definition: platform.h:77
platform
Definition: platform.h:18
@ PLATFORM_UNKNOWN
Definition: platform.h:20
@ PLATFORM_UNINITIALIZED
Definition: platform.h:19
@ PLATFORM_CONSOLE
Definition: platform.h:22
@ PLATFORM_WEB
Definition: platform.h:24
@ PLATFORM_TOUCH
Definition: platform.h:23
@ PLATFORM_PC
Definition: platform.h:21
@ SEARCH_FULLPACKAGE
Definition: defs.h:190