| 109 | } |
| 110 | |
| 111 | void CommandInfo::executeInfo() { |
| 112 | InputStream inputStream(options.inputFilepath, *this); |
| 113 | |
| 114 | KTX_error_code result; |
| 115 | bool v2 = true; |
| 116 | |
| 117 | ktx_uint8_t ktx_ident_ref[12] = KTX_IDENTIFIER_REF; |
| 118 | ktx_uint8_t identifier[12] = {}; |
| 119 | inputStream->read((char*)identifier, 12); |
| 120 | inputStream->clear(); // Clear an unexpected EOF so seekg works. |
| 121 | inputStream->seekg(0); // Rewind to give validation a clean slate. |
| 122 | if (!memcmp(identifier, ktx_ident_ref, 12)) { |
| 123 | if (options.format != OutputFormat::text) |
| 124 | fatal_usage("JSON output formats are not supported for KTX v1 files."); |
| 125 | v2 = false; |
| 126 | StreambufStream<std::streambuf*> ktxStream{inputStream->rdbuf(), std::ios::in | std::ios::binary}; |
| 127 | result = ktxPrintKTX1InfoTextForStream(ktxStream.stream()); |
| 128 | } else { |
| 129 | switch (options.format) { |
| 130 | case OutputFormat::text: |
| 131 | result = printInfoText(inputStream); |
| 132 | break; |
| 133 | case OutputFormat::json: |
| 134 | result = printInfoJSON(inputStream, false); |
| 135 | break; |
| 136 | case OutputFormat::json_mini: |
| 137 | result = printInfoJSON(inputStream, true); |
| 138 | break; |
| 139 | default: |
| 140 | assert(false && "Internal error"); |
| 141 | return; |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | if (result != KTX_SUCCESS) |
| 146 | fatal(rc::INVALID_FILE, "Failed to process KTX {} file \"{}\": {}", |
| 147 | v2 ? "v2" : "v1", |
| 148 | fmtInFile(options.inputFilepath), ktxErrorString(result)); |
| 149 | } |
| 150 | |
| 151 | KTX_error_code CommandInfo::printInfoText(std::istream& file) { |
| 152 | std::ostringstream messagesOS; |
nothing calls this directly
no test coverage detected