--------------------------------------------------------- PPic_InitDatabase Purpose: Initializes the database for the pictures. Call before any other Pilot Picture function ---------------------------------------------------------
| 125 | // any other Pilot Picture function |
| 126 | // --------------------------------------------------------- |
| 127 | bool 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 |
no test coverage detected