CreateCRCFileName Given a filename, this function will open the file, make a CRC of the data and then fill in dest buffer with _ where is the original filename and is the converted string of the CRC in hex. returns true on success. dest should be size of src + 9 (for the _ & CRC)
| 2189 | // returns true on success. |
| 2190 | // dest should be size of src + 9 (for the _ & CRC) |
| 2191 | bool CreateCRCFileName(const char *src, char *dest) { |
| 2192 | ASSERT(src); |
| 2193 | ASSERT(dest); |
| 2194 | |
| 2195 | if (cfexist(src) != CFES_ON_DISK) |
| 2196 | return false; |
| 2197 | |
| 2198 | uint32_t crc_value = cf_GetfileCRC((char *)src); |
| 2199 | if (crc_value == 0) { |
| 2200 | mprintf(0, "CRC WARNING: A CRC of 0 HAS BEEN GENERATED!\n"); |
| 2201 | } |
| 2202 | char hex_string[10]; |
| 2203 | snprintf(hex_string, sizeof(hex_string), "_%08X", crc_value); |
| 2204 | |
| 2205 | char ext[256]; |
| 2206 | ddio_SplitPath(src, NULL, NULL, ext); |
| 2207 | |
| 2208 | // now create the full filename |
| 2209 | // first strip any possible CRC on the file |
| 2210 | StripCRCFileName(src, dest); |
| 2211 | dest[strlen(dest) - strlen(ext)] = '\0'; // lose the extension |
| 2212 | strcat(dest, hex_string); |
| 2213 | strcat(dest, ext); // put extension back |
| 2214 | |
| 2215 | return true; |
| 2216 | } |
| 2217 | |
| 2218 | // CreateCRCFileName |
| 2219 | // |
no test coverage detected