15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef CHROME_INSTALLER_MINI_INSTALLER_PE_RESOURCE_H_ 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CHROME_INSTALLER_MINI_INSTALLER_PE_RESOURCE_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <windows.h> 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This class models a windows PE resource. It does not pretend to be a full 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// API wrapper and it is just concerned with loading it to memory and writing 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// it to disk. Each resource is unique only in the context of a loaded module, 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// that is why you need to specify one on each constructor. 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class PEResource { 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This ctor takes the handle to the resource and the module where it was 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // found. Ownership of the resource is transfered to this object. 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PEResource(HRSRC resource, HMODULE module); 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This ctor takes the resource name, the resource type and the module where 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // to look for the resource. If the resource is found IsValid() returns true. 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PEResource(const wchar_t* name, const wchar_t* type, HMODULE module); 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if the resource is valid. 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool IsValid(); 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the size in bytes of the resource. Returns zero if the resource is 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // not valid. 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) size_t Size(); 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Creates a file in 'path' with a copy of the resource. If the resource can 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // not be loaded into memory or if it cannot be written to disk it returns 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // false. 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool WriteToDisk(const wchar_t* path); 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) HRSRC resource_; 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) HMODULE module_; 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // CHROME_INSTALLER_MINI_INSTALLER_PE_RESOURCE_H_ 42