Updates the Recent Files array
| 138 | |
| 139 | //Updates the Recent Files array |
| 140 | void UpdateMemwRecentArray(const char* addString, char** bufferArray, unsigned int arrayLen, HMENU menu, unsigned int menuItem, unsigned int baseId) |
| 141 | { |
| 142 | // Try to find out if the filename is already in the recent files list. |
| 143 | for(unsigned int x = 0; x < arrayLen; x++) |
| 144 | { |
| 145 | if(bufferArray[x]) |
| 146 | { |
| 147 | if(!strcmp(bufferArray[x], addString)) // Item is already in list. |
| 148 | { |
| 149 | // If the filename is in the file list don't add it again. |
| 150 | // Move it up in the list instead. |
| 151 | |
| 152 | int y; |
| 153 | char *tmp; |
| 154 | |
| 155 | // Save pointer. |
| 156 | tmp = bufferArray[x]; |
| 157 | |
| 158 | for(y = x; y; y--) |
| 159 | { |
| 160 | // Move items down. |
| 161 | bufferArray[y] = bufferArray[y - 1]; |
| 162 | } |
| 163 | |
| 164 | // Put item on top. |
| 165 | bufferArray[0] = tmp; |
| 166 | |
| 167 | // Update the recent files menu |
| 168 | UpdateMemw_RMenu(menu, bufferArray, menuItem, baseId); |
| 169 | |
| 170 | return; |
| 171 | } |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | // The filename wasn't found in the list. That means we need to add it. |
| 176 | |
| 177 | // If there's no space left in the recent files list, get rid of the last |
| 178 | // item in the list. |
| 179 | if(bufferArray[arrayLen - 1]) |
| 180 | { |
| 181 | free(bufferArray[arrayLen - 1]); |
| 182 | } |
| 183 | |
| 184 | // Move the other items down. |
| 185 | for(unsigned int x = arrayLen - 1; x; x--) |
| 186 | { |
| 187 | bufferArray[x] = bufferArray[x - 1]; |
| 188 | } |
| 189 | |
| 190 | // Add the new item. |
| 191 | bufferArray[0] = (char*)malloc(strlen(addString) + 1); |
| 192 | strcpy(bufferArray[0], addString); |
| 193 | |
| 194 | // Update the recent files menu |
| 195 | UpdateMemw_RMenu(menu, bufferArray, menuItem, baseId); |
| 196 | } |
| 197 |
no test coverage detected