| 174 | } |
| 175 | |
| 176 | IpcPacketOpenImage IpcPacket::interpretAsOpenImage() const { |
| 177 | IpcPacketOpenImage result; |
| 178 | IStream payload{mPayload}; |
| 179 | |
| 180 | EType type; |
| 181 | payload >> type; |
| 182 | if (type != EType::OpenImage && type != EType::OpenImageV2) { |
| 183 | throw runtime_error{"Cannot interpret IPC packet as OpenImage."}; |
| 184 | } |
| 185 | |
| 186 | payload >> result.grabFocus; |
| 187 | |
| 188 | string imageString; |
| 189 | payload >> imageString; |
| 190 | |
| 191 | if (type >= EType::OpenImageV2) { |
| 192 | result.imagePath = imageString; |
| 193 | payload >> result.channelSelector; |
| 194 | return result; |
| 195 | } |
| 196 | |
| 197 | const size_t colonPos = imageString.find_last_of(":"); |
| 198 | if (colonPos == string::npos || |
| 199 | // windows path of the form X:/* or X:\* |
| 200 | (colonPos == 1 && imageString.length() >= 3 && (imageString[2] == '\\' || imageString[2] == '/'))) { |
| 201 | result.imagePath = imageString; |
| 202 | result.channelSelector = ""; |
| 203 | } else { |
| 204 | result.imagePath = imageString.substr(0, colonPos); |
| 205 | result.channelSelector = imageString.substr(colonPos + 1); |
| 206 | } |
| 207 | |
| 208 | return result; |
| 209 | } |
| 210 | |
| 211 | IpcPacketReloadImage IpcPacket::interpretAsReloadImage() const { |
| 212 | IpcPacketReloadImage result; |