2020-12-26 14:12:05 -08:00
|
|
|
// 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.
|
2018-11-03 04:16:44 +08:00
|
|
|
|
|
|
|
|
package edu.wpi.first.wpilibj;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
|
|
|
|
|
/**
|
2020-12-29 22:45:16 -08:00
|
|
|
* Class for interacting with the Filesystem, particularly, interacting with FRC-related paths on
|
|
|
|
|
* the system, such as the launch and deploy directories.
|
2018-11-03 04:16:44 +08:00
|
|
|
*
|
2025-06-02 16:42:56 -07:00
|
|
|
* <p>This class is primarily used for obtaining resources in src/main/deploy, and the systemcore
|
|
|
|
|
* path /home/systemcore in a simulation-compatible way.
|
2018-11-03 04:16:44 +08:00
|
|
|
*/
|
|
|
|
|
public final class Filesystem {
|
2020-12-29 09:27:48 -08:00
|
|
|
private Filesystem() {}
|
2018-11-03 04:16:44 +08:00
|
|
|
|
|
|
|
|
/**
|
2020-12-29 22:45:16 -08:00
|
|
|
* Obtains the current working path that the program was launched with. This is analogous to the
|
|
|
|
|
* `pwd` command on unix.
|
2018-11-03 04:16:44 +08:00
|
|
|
*
|
|
|
|
|
* @return The current working directory (launch directory)
|
|
|
|
|
*/
|
|
|
|
|
public static File getLaunchDirectory() {
|
2023-05-12 21:26:52 -07:00
|
|
|
// workaround for
|
|
|
|
|
// https://www.chiefdelphi.com/t/filesystem-getdeploydirectory-returning-wrong-location-how-to-fix/427292
|
|
|
|
|
String path =
|
|
|
|
|
System.getProperty("user.dir")
|
|
|
|
|
.replace(
|
|
|
|
|
File.separator + "build" + File.separator + "jni" + File.separator + "release", "");
|
|
|
|
|
return new File(path).getAbsoluteFile();
|
2018-11-03 04:16:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-06-02 16:42:56 -07:00
|
|
|
* Obtains the operating directory of the program. On the systemcore, this is /home/systemcore. In
|
2020-12-29 22:45:16 -08:00
|
|
|
* simulation, it is where the simulation was launched from (`pwd`).
|
2018-11-03 04:16:44 +08:00
|
|
|
*
|
|
|
|
|
* @return The operating directory
|
|
|
|
|
*/
|
|
|
|
|
public static File getOperatingDirectory() {
|
2023-09-15 20:05:16 -07:00
|
|
|
if (!RobotBase.isSimulation()) {
|
2025-06-02 16:42:56 -07:00
|
|
|
return new File("/home/systemcore");
|
2018-11-03 04:16:44 +08:00
|
|
|
} else {
|
|
|
|
|
return getLaunchDirectory();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2022-12-26 14:32:13 -05:00
|
|
|
* Obtains the 'deploy' directory of the program, located at src/main/deploy, which is deployed by
|
2025-06-02 16:42:56 -07:00
|
|
|
* default. On the systemcore, this is /home/systemcore/deploy. In simulation, it is where the
|
|
|
|
|
* simulation was launched from, in the subdirectory "src/main/deploy" (`pwd`/src/main/deploy).
|
2018-11-03 04:16:44 +08:00
|
|
|
*
|
2022-12-26 14:32:13 -05:00
|
|
|
* @return The 'deploy' directory
|
2018-11-03 04:16:44 +08:00
|
|
|
*/
|
|
|
|
|
public static File getDeployDirectory() {
|
2023-09-15 20:05:16 -07:00
|
|
|
if (!RobotBase.isSimulation()) {
|
2020-01-19 16:34:45 -08:00
|
|
|
return new File(getOperatingDirectory(), "deploy");
|
|
|
|
|
} else {
|
2020-12-29 22:45:16 -08:00
|
|
|
return new File(
|
|
|
|
|
getOperatingDirectory(), "src" + File.separator + "main" + File.separator + "deploy");
|
2020-01-19 16:34:45 -08:00
|
|
|
}
|
2018-11-03 04:16:44 +08:00
|
|
|
}
|
|
|
|
|
}
|