MCPcopy Create free account
hub / github.com/TASEmulators/fceux / UpdateRecentArray

Function UpdateRecentArray

src/drivers/win/window.cpp:703–759  ·  view source on GitHub ↗

Helper function to populate the recent directories and recent files arrays. @param addString String to add to the array. @param bufferArray Array where the string will be added. @param arrayLen Length of the bufferArray. @param menu Menu handle of the main menu. @param menuItem @param baseID

Source from the content-addressed store, hash-verified

701/// @param menuItem
702/// @param baseID
703void UpdateRecentArray(const char* addString, char** bufferArray, unsigned int arrayLen, HMENU menu, unsigned int menuItem, unsigned int baseId)
704{
705 // Try to find out if the filename is already in the recent files list.
706 for(unsigned int x = 0; x < arrayLen; x++)
707 {
708 if(bufferArray[x])
709 {
710 if(!strcmp(bufferArray[x], addString)) // Item is already in list.
711 {
712 // If the filename is in the file list don't add it again.
713 // Move it up in the list instead.
714
715 int y;
716 char *tmp;
717
718 // Save pointer.
719 tmp = bufferArray[x];
720
721 for(y = x; y; y--)
722 {
723 // Move items down.
724 bufferArray[y] = bufferArray[y - 1];
725 }
726
727 // Put item on top.
728 bufferArray[0] = tmp;
729
730 // Update the recent files menu
731 UpdateRMenu(menu, bufferArray, menuItem, baseId);
732
733 return;
734 }
735 }
736 }
737
738 // The filename wasn't found in the list. That means we need to add it.
739
740 // If there's no space left in the recent files list, get rid of the last
741 // item in the list.
742 if(bufferArray[arrayLen - 1])
743 {
744 free(bufferArray[arrayLen - 1]);
745 }
746
747 // Move the other items down.
748 for(unsigned int x = arrayLen - 1; x; x--)
749 {
750 bufferArray[x] = bufferArray[x - 1];
751 }
752
753 // Add the new item.
754 bufferArray[0] = (char*)malloc(strlen(addString) + 1); //mbg merge 7/17/06 added cast
755 strcpy(bufferArray[0], addString);
756
757 // Update the recent files menu
758 UpdateRMenu(menu, bufferArray, menuItem, baseId);
759}
760

Callers 1

AddRecentFileFunction · 0.85

Calls 1

UpdateRMenuFunction · 0.85

Tested by

no test coverage detected