|
18 | 18 | package org.photonvision;
|
19 | 19 |
|
20 | 20 | import edu.wpi.first.hal.HAL;
|
| 21 | +import java.io.File; |
| 22 | +import java.io.FileWriter; |
21 | 23 | import java.io.IOException;
|
| 24 | +import java.net.URISyntaxException; |
| 25 | +import java.net.URL; |
22 | 26 | import java.nio.file.Path;
|
| 27 | +import java.security.CodeSource; |
| 28 | +import java.security.ProtectionDomain; |
23 | 29 | import java.util.ArrayList;
|
24 | 30 | import java.util.List;
|
25 | 31 | import org.apache.commons.cli.*;
|
@@ -172,6 +178,36 @@ public static void main(String[] args) {
|
172 | 178 | + Platform.getPlatformName()
|
173 | 179 | + (Platform.isRaspberryPi() ? (" (Pi " + PiVersion.getPiVersion() + ")") : ""));
|
174 | 180 |
|
| 181 | + if (Platform.isSystemCore()) { |
| 182 | + File jarLocation = getJarLocation(); |
| 183 | + if (jarLocation == null) { |
| 184 | + logger.error("SystemCore is not a supported platform for PhotonVision!"); |
| 185 | + System.exit(1); |
| 186 | + } |
| 187 | + // Make a file where the PV JAR is located indicating systemcore is not supported |
| 188 | + try { |
| 189 | + File notSupportedFile = |
| 190 | + new File(jarLocation.getParent(), "SYSTEMCORE_NOT_SUPPORTED_BY_PHOTONVISION.txt"); |
| 191 | + try (FileWriter writer = new FileWriter(notSupportedFile)) { |
| 192 | + writer.write("SystemCore is not a supported platform for PhotonVision.\n"); |
| 193 | + writer.write("PhotonVision has been uninstalled from this device.\n"); |
| 194 | + writer.write("Please visit https://docs.photonvision.org for supported platforms."); |
| 195 | + } |
| 196 | + } catch (IOException e) { |
| 197 | + logger.error("Failed to create SystemCore not supported file", e); |
| 198 | + System.exit(1); |
| 199 | + } |
| 200 | + |
| 201 | + // Delete the PV JAR |
| 202 | + if (!jarLocation.delete()) { |
| 203 | + logger.error("Failed to delete PhotonVision JAR file on SystemCore!"); |
| 204 | + System.exit(1); |
| 205 | + } |
| 206 | + |
| 207 | + // Exit |
| 208 | + System.exit(1); |
| 209 | + } |
| 210 | + |
175 | 211 | if (OsImageVersion.IMAGE_VERSION.isPresent()) {
|
176 | 212 | logger.info("PhotonVision image version: " + OsImageVersion.IMAGE_VERSION.get());
|
177 | 213 | }
|
@@ -308,4 +344,21 @@ public static void main(String[] args) {
|
308 | 344 | HardwareManager.getInstance().setRunning(true);
|
309 | 345 | Server.initialize(DEFAULT_WEBPORT);
|
310 | 346 | }
|
| 347 | + |
| 348 | + public static File getJarLocation() { |
| 349 | + try { |
| 350 | + ProtectionDomain protectionDomain = Main.class.getProtectionDomain(); |
| 351 | + CodeSource codeSource = protectionDomain.getCodeSource(); |
| 352 | + if (codeSource != null) { |
| 353 | + URL location = codeSource.getLocation(); |
| 354 | + return new File(location.toURI()); |
| 355 | + } else { |
| 356 | + logger.error("Could not determine JAR location: code source is null"); |
| 357 | + return null; |
| 358 | + } |
| 359 | + } catch (URISyntaxException e) { |
| 360 | + logger.error("Error determining JAR location", e); |
| 361 | + return null; |
| 362 | + } |
| 363 | + } |
311 | 364 | }
|
0 commit comments