mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-26 01:51:41 +00:00
[wpiutil] Check MSVC Runtime (#7301)
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
package edu.wpi.first.util;
|
||||
|
||||
/** Exception thrown due to a bad MSVC Runtime. */
|
||||
public class MsvcRuntimeException extends RuntimeException {
|
||||
private static final long serialVersionUID = -9155939328084105142L;
|
||||
|
||||
private static String generateMessage(
|
||||
int foundMajor, int foundMinor, int expectedMajor, int expectedMinor, String runtimePath) {
|
||||
String jvmLocation = ProcessHandle.current().info().command().orElse("Unknown");
|
||||
|
||||
StringBuffer builder = new StringBuffer(100);
|
||||
builder
|
||||
.append("Invalid MSVC Runtime Detected.\n")
|
||||
.append(
|
||||
String.format(
|
||||
"Expected at least %d.%d, but found %d.%d\n",
|
||||
expectedMajor, expectedMinor, foundMajor, foundMinor))
|
||||
.append(String.format("JVM Location: %s\n", jvmLocation))
|
||||
.append(String.format("Runtime DLL Location: %s\n", runtimePath))
|
||||
.append("See https://wpilib.org/jvmruntime for more information\n");
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a runtime exception.
|
||||
*
|
||||
* @param foundMajor found major
|
||||
* @param foundMinor found minor
|
||||
* @param expectedMajor expected major
|
||||
* @param expectedMinor expected minor
|
||||
* @param runtimePath path of runtime
|
||||
*/
|
||||
public MsvcRuntimeException(
|
||||
int foundMajor, int foundMinor, int expectedMajor, int expectedMinor, String runtimePath) {
|
||||
super(generateMessage(foundMajor, foundMinor, expectedMajor, expectedMinor, runtimePath));
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a runtime exception.
|
||||
*
|
||||
* @param msg message
|
||||
*/
|
||||
public MsvcRuntimeException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
}
|
||||
@@ -63,6 +63,9 @@ public class WPIUtilJNI {
|
||||
libraryLoaded = true;
|
||||
}
|
||||
|
||||
/** Checks if the MSVC runtime is valid. Throws a runtime exception if not. */
|
||||
public static native void checkMsvcRuntime();
|
||||
|
||||
/**
|
||||
* Write the given string to stderr.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user