Ticket #12779: 0001-12779-Handle-version-info-in-resource-in-other-endia.2.patch

File 0001-12779-Handle-version-info-in-resource-in-other-endia.2.patch, 2.0 KB (added by markh, 8 years ago)
  • src/kits/storage/ResourceFile.cpp

    From cbbde3f5e1ba1973ea1cb88f490c039885bdc835 Mon Sep 17 00:00:00 2001
    From: Mark Hellegers <mark@firedisk.net>
    Date: Sat, 14 May 2016 16:33:38 +0200
    Subject: [PATCH] #12779: Handle version info in resource in other endianness
     than host
    
    ---
     src/kits/storage/ResourceFile.cpp | 25 ++++++++++++++++++++++---
     1 file changed, 22 insertions(+), 3 deletions(-)
    
    diff --git a/src/kits/storage/ResourceFile.cpp b/src/kits/storage/ResourceFile.cpp
    index 907ee87..fb8c265 100644
    a b const char* kFileTypeNames[] = {  
    6767#define DBG(x)
    6868#define OUT printf
    6969
     70#define B_VERSION_INFO_TYPE 'APPV'
     71
     72static const uint32 kVersionInfoIntCount = 5;
    7073
    7174// #pragma mark - helper functions/classes
    7275
    ResourceFile::ReadResource(ResourceItem& resource, bool force)  
    323326        }
    324327        if (error == B_OK) {
    325328            // convert the data, if necessary
    326             if (!fHostEndianess)
    327                 swap_data(resource.Type(), data, size, B_SWAP_ALWAYS);
     329            if (!fHostEndianess) {
     330                if (resource.Type() == B_VERSION_INFO_TYPE) {
     331                    // Version info contains integers that need to be swapped
     332                    swap_data(B_UINT32_TYPE, data,
     333                        kVersionInfoIntCount * sizeof(uint32),
     334                        B_SWAP_ALWAYS);
     335                }
     336                else
     337                    swap_data(resource.Type(), data, size, B_SWAP_ALWAYS);
     338            }
    328339            resource.SetLoaded(true);
    329340            resource.SetModified(false);
    330341        }
    ResourceFile::_WriteResources(ResourcesContainer& container)  
    12001211                // swap data, if necessary
    12011212                if (!fHostEndianess) {
    12021213                    memcpy(data, itemData, itemSize);
    1203                     swap_data(item->Type(), data, itemSize, B_SWAP_ALWAYS);
     1214                    if (item->Type() == B_VERSION_INFO_TYPE) {
     1215                        // Version info contains integers
     1216                        // that need to be swapped
     1217                        swap_data(B_UINT32_TYPE, data,
     1218                            kVersionInfoIntCount * sizeof(uint32),
     1219                            B_SWAP_ALWAYS);
     1220                    }
     1221                    else
     1222                        swap_data(item->Type(), data, itemSize, B_SWAP_ALWAYS);
    12041223                    itemData = data;
    12051224                }
    12061225                write_exactly(fFile, itemOffset, itemData, itemSize,