| 78 | } |
| 79 | |
| 80 | bool LIFImage::initializeType(const std::string& imagePath) { |
| 81 | cleanup(); |
| 82 | if (!core::fileExists(imagePath)) { |
| 83 | return false; |
| 84 | } |
| 85 | std::ifstream lif; |
| 86 | lif.open(imagePath.c_str(), std::ios::in | std::ios::binary); |
| 87 | if (lif.good()) { |
| 88 | _fileName = imagePath; |
| 89 | // First check file size |
| 90 | lif.seekg(0, std::ifstream::end); |
| 91 | _fileSize = lif.tellg(); |
| 92 | lif.seekg(0); |
| 93 | |
| 94 | // Buffers to hold int and long |
| 95 | char* memblock = new char[4]; |
| 96 | char* memblockLong = new char[8]; |
| 97 | |
| 98 | char checkOne; |
| 99 | lif.read(&checkOne,1); |
| 100 | lif.seekg(2, std::ios::cur); |
| 101 | char checkTwo; |
| 102 | lif.read(&checkTwo,1); |
| 103 | if (checkOne != LIF_MAGIC_BYTE && checkTwo != LIF_MAGIC_BYTE) { |
| 104 | return false; |
| 105 | } |
| 106 | |
| 107 | lif.seekg(4, std::ios::cur); |
| 108 | lif.read(&checkTwo,1); |
| 109 | if (checkTwo != LIF_MEMORY_BYTE) { |
| 110 | return false; |
| 111 | } |
| 112 | |
| 113 | // Reading and cleaning up XML |
| 114 | lif.read(memblock,4); |
| 115 | int nc = *reinterpret_cast<int*>(memblock); |
| 116 | char* rawXml = new char[nc*2]; |
| 117 | char* editedXml = new char[nc*2]; |
| 118 | lif.read(rawXml, nc*2); |
| 119 | int index = 0; |
| 120 | for (int i =0; i < nc*2; ++i) { |
| 121 | if(rawXml[i]) { |
| 122 | editedXml[index] = rawXml[i]; |
| 123 | ++index; |
| 124 | } |
| 125 | } |
| 126 | if (index < nc*2) { |
| 127 | editedXml[index] = '\0'; |
| 128 | } |
| 129 | std::string xml(editedXml); |
| 130 | |
| 131 | // Read the image offsets |
| 132 | while (lif.tellg() < _fileSize) { |
| 133 | lif.read(memblock,4); |
| 134 | int magicByte = *reinterpret_cast<int*>(memblock); |
| 135 | if (magicByte != LIF_MAGIC_BYTE) { |
| 136 | return false; |
| 137 | } |
nothing calls this directly
no test coverage detected