this function will look for the config, if it's not there, it will TRY and find an old one and copy it so that the update function can upgrade it to the current version the assumption is that there is a unique config per version
| 100 | // so that the update function can upgrade it to the current version |
| 101 | // the assumption is that there is a unique config per version |
| 102 | void findConfigFile(void) { |
| 103 | // look for the current file |
| 104 | std::string configName = getCurrentConfigFileName(); |
| 105 | FILE* fp = fopen(configName.c_str(), "rb"); |
| 106 | if (fp) { |
| 107 | // we found the current file, nothing to do, just return |
| 108 | fclose(fp); |
| 109 | return; |
| 110 | } |
| 111 | |
| 112 | // try and find the old file |
| 113 | std::string oldConfigName = getOldConfigFileName(); |
| 114 | fp = fopen(oldConfigName.c_str(), "rb"); |
| 115 | if (fp) { |
| 116 | // there is an old config so lets copy it to the new dir and let the update take care of it. |
| 117 | #if defined(_WIN32) |
| 118 | fclose(fp); |
| 119 | // make the dir if we need to |
| 120 | std::string configDir = getConfigDirName(BZ_CONFIG_DIR_VERSION); |
| 121 | mkdir(configDir.c_str()); |
| 122 | // copy the old config to the new dir location with the new name |
| 123 | CopyFile(oldConfigName.c_str(), configName.c_str(), true); |
| 124 | |
| 125 | #else // the other OSs should do what they need to do |
| 126 | mkdir(getConfigDirName(BZ_CONFIG_DIR_VERSION).c_str(), 0755); |
| 127 | |
| 128 | FILE* newFile = fopen(configName.c_str(), "wb"); |
| 129 | if (newFile) { |
| 130 | fseek(fp, 0, SEEK_END); |
| 131 | int len = ftell(fp); |
| 132 | fseek(fp, 0, SEEK_SET); |
| 133 | |
| 134 | unsigned char* temp = (unsigned char*) malloc(len); |
| 135 | |
| 136 | fread(temp, len, 1, fp); |
| 137 | fwrite(temp, len, 1, newFile); |
| 138 | |
| 139 | free(temp); |
| 140 | |
| 141 | fclose(newFile); |
| 142 | fclose(fp); |
| 143 | } |
| 144 | #endif |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | void updateConfigFile(void) { |
| 149 | int configVersion = BZ_CONFIG_FILE_VERSION; |
no test coverage detected