MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / PPic_InitDatabase

Function PPic_InitDatabase

Descent3/PilotPicsAPI.cpp:127–179  ·  view source on GitHub ↗

--------------------------------------------------------- PPic_InitDatabase Purpose: Initializes the database for the pictures. Call before any other Pilot Picture function ---------------------------------------------------------

Source from the content-addressed store, hash-verified

125// any other Pilot Picture function
126// ---------------------------------------------------------
127bool PPic_InitDatabase(void) {
128 if (PilotPic_init) {
129 mprintf(0, "PPIC: InitDatabase already called\n");
130 return true;
131 }
132
133 // attempt to open the hog database
134 // --------------------------------
135 char fullpath[_MAX_PATH];
136 ddio_MakePath(fullpath, LocalD3Dir, PILOTPIC_DATABASE_HOG, NULL);
137 PilotPic_database_hog_handle = cf_OpenLibrary(fullpath);
138
139 if (PilotPic_database_hog_handle == 0) {
140 // there was an error opening the hog database
141 // -----------------------------------------
142 mprintf(0, "PPIC: Error opening %s database\n", PILOTPIC_DATABASE_HOG);
143 PilotPic_database_index_handle = NULL;
144 return false;
145 }
146
147 // attempt to open the pilotpicture database index
148 // -----------------------------------------------
149 PilotPic_database_index_handle = cfopen(PILOTPIC_DATABASE_INDEX, "rb");
150
151 if (PilotPic_database_index_handle == NULL) {
152 // there was an error opening the database index
153 // ---------------------------------------------
154 mprintf(0, "PPIC: Error opening database index '%s'\n", PILOTPIC_DATABASE_INDEX);
155 cf_CloseLibrary(PilotPic_database_hog_handle);
156 PilotPic_database_hog_handle = 0;
157 return false;
158 }
159
160 // when we get to this point, all of our files have been opened successfully, so to
161 // make searching, etc fast, we'll build some databases in memory, for quick lookup
162 // ---------------------------------------------------------------------------------
163 if (!PPic_BuildDatabases()) {
164 // there was an error building the databases
165 // -----------------------------------------
166 mprintf(0, "PPIC: Error building databases\n");
167 cfclose(PilotPic_database_index_handle);
168 PilotPic_database_index_handle = NULL;
169 cf_CloseLibrary(PilotPic_database_hog_handle);
170 PilotPic_database_hog_handle = 0;
171 return false;
172 }
173
174 PilotPic_init = true;
175
176 atexit(PPic_CloseDatabase);
177
178 return true;
179}
180
181// ---------------------------------------------------------
182// PPic_CloseDatabase

Callers 1

InitD3Systems2Function · 0.85

Calls 6

cf_OpenLibraryFunction · 0.85
cfopenFunction · 0.85
cf_CloseLibraryFunction · 0.85
PPic_BuildDatabasesFunction · 0.85
cfcloseFunction · 0.85
ddio_MakePathFunction · 0.50

Tested by

no test coverage detected