Checks to see if a new version text file exists (such a file should only be created if the user does a manual patch update). If one is found, the version info is read from it. If this version is newer than the version stored in the registry, it is then written into the registry as the new game version.
| 702 | // than the version stored in the registry, it is then written into |
| 703 | // the registry as the new game version. |
| 704 | bool ProcessUpdatedVersionFile(void) { |
| 705 | FILE *f; |
| 706 | uint32_t cur_major, cur_minor, cur_build; |
| 707 | uint32_t new_major, new_minor, new_build; |
| 708 | char buffer[_MAX_PATH + 1]; |
| 709 | char verbuffer[_MAX_PATH + 1]; |
| 710 | |
| 711 | // See if the updated version text file exists |
| 712 | f = fopen(UPDATED_VERSION_FNAME, "rt"); |
| 713 | if (f == NULL) { |
| 714 | return FALSE; |
| 715 | } |
| 716 | |
| 717 | // Read in the Version info from the text file |
| 718 | new_major = 0; |
| 719 | new_minor = 0; |
| 720 | new_build = 0; |
| 721 | strcpy(buffer, ""); |
| 722 | while (!feof(f)) { |
| 723 | |
| 724 | // Read the line into a temporary buffer |
| 725 | fgets(buffer, _MAX_PATH, f); |
| 726 | |
| 727 | // take the \n off the end of it |
| 728 | if (strlen(buffer) > 0 && buffer[strlen(buffer) - 1] == '\n') |
| 729 | buffer[strlen(buffer) - 1] = 0; |
| 730 | |
| 731 | // If the line is empty, go get another one |
| 732 | if (strlen(buffer) == 0) |
| 733 | continue; |
| 734 | |
| 735 | // If the line is a comment, go get another one |
| 736 | if (buffer[0] == VERSION_FILE_COMMENT_CHAR) |
| 737 | continue; |
| 738 | |
| 739 | // Read in the version line |
| 740 | strcpy(verbuffer, buffer); |
| 741 | sscanf(verbuffer, "%i %i %i", &new_major, &new_minor, &new_build); |
| 742 | } |
| 743 | fclose(f); |
| 744 | |
| 745 | if (VER(new_major, new_minor, new_build) == 0) { |
| 746 | DeleteFile(UPDATED_VERSION_FNAME); |
| 747 | return FALSE; |
| 748 | } |
| 749 | |
| 750 | // Read in the current version values from the registry |
| 751 | cur_major = os_config_read_uint("Version", "Major", 0); |
| 752 | cur_minor = os_config_read_uint("Version", "Minor", 0); |
| 753 | cur_build = os_config_read_uint("Version", "Build", 0); |
| 754 | |
| 755 | // Is the version found in the text file newer than the current version? |
| 756 | if (VER(new_major, new_minor, new_build) <= VER(cur_major, cur_minor, cur_build)) { |
| 757 | DeleteFile(UPDATED_VERSION_FNAME); |
| 758 | return FALSE; |
| 759 | } |
| 760 | |
| 761 | // Write the new version into the registry |
no test coverage detected