1 /* 2 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 #ifndef RESOURCEEDITOR_H 27 #define RESOURCEEDITOR_H 28 29 #include <windows.h> 30 #include <vector> 31 #include <string> 32 33 34 class ResourceEditor { 35 public: 36 class FileLock { 37 public: 38 FileLock(const std::wstring& binaryPath); 39 ~FileLock(); 40 41 HANDLE get() const { 42 return h; 43 } 44 45 void discard(bool v = true) { 46 theDiscard = v; 47 } 48 49 private: 50 FileLock(const FileLock&); 51 FileLock& operator=(const FileLock&); 52 private: 53 HANDLE h; 54 bool theDiscard; 55 }; 56 57 public: 58 ResourceEditor(); 59 60 /** 61 * Set the language identifier of the resource to be updated. 62 */ 63 ResourceEditor& language(unsigned v) { 64 lang = v; 65 return *this; 66 } 67 68 /** 69 * Set the resource type to be updated. 70 */ 71 ResourceEditor& type(unsigned v); 72 73 /** 74 * Set the resource type to be updated. 75 */ 76 ResourceEditor& type(LPCWSTR v); 77 78 /** 79 * Set resource ID. 80 */ 81 ResourceEditor& id(unsigned v); 82 83 /** 84 * Set resource ID. 85 */ 86 ResourceEditor& id(LPCWSTR v); 87 88 /** 89 * Relaces resource configured in the given binary with the given data stream. 90 */ 91 ResourceEditor& apply(const FileLock& dstBinary, std::istream& srcStream, std::streamsize size=0); 92 93 /** 94 * Relaces resource configured in the given binary with contents of 95 * the given binary file. 96 */ 97 ResourceEditor& apply(const FileLock& dstBinary, const std::wstring& srcFile); 98 99 private: 100 unsigned lang; 101 std::wstring theId; 102 LPCWSTR theIdPtr; 103 std::wstring theType; 104 LPCWSTR theTypePtr; 105 }; 106 107 #endif // #ifndef RESOURCEEDITOR_H