001// Copyright (c) FIRST and other WPILib contributors. 002// Open Source Software; you can modify and/or share it under the terms of 003// the WPILib BSD license file in the root directory of this project. 004 005package edu.wpi.first.wpilibj; 006 007import java.io.File; 008 009/** 010 * Class for interacting with the Filesystem, particularly, interacting with FRC-related paths on 011 * the system, such as the launch and deploy directories. 012 * 013 * <p>This class is primarily used for obtaining resources in src/main/deploy, and the RoboRIO path 014 * /home/lvuser in a simulation-compatible way. 015 */ 016public final class Filesystem { 017 private Filesystem() {} 018 019 /** 020 * Obtains the current working path that the program was launched with. This is analogous to the 021 * `pwd` command on unix. 022 * 023 * @return The current working directory (launch directory) 024 */ 025 public static File getLaunchDirectory() { 026 return new File(System.getProperty("user.dir")).getAbsoluteFile(); 027 } 028 029 /** 030 * Obtains the operating directory of the program. On the roboRIO, this is /home/lvuser. In 031 * simulation, it is where the simulation was launched from (`pwd`). 032 * 033 * @return The operating directory 034 */ 035 public static File getOperatingDirectory() { 036 if (RobotBase.isReal()) { 037 return new File("/home/lvuser"); 038 } else { 039 return getLaunchDirectory(); 040 } 041 } 042 043 /** 044 * Obtains the 'deploy' directory of the program, located at src/main/deploy, which is deployed by 045 * default. On the roboRIO, this is /home/lvuser/deploy. In simulation, it is where the simulation 046 * was launched from, in the subdirectory "src/main/deploy" (`pwd`/src/main/deploy). 047 * 048 * @return The 'deploy' directory 049 */ 050 public static File getDeployDirectory() { 051 if (RobotBase.isReal()) { 052 return new File(getOperatingDirectory(), "deploy"); 053 } else { 054 return new File( 055 getOperatingDirectory(), "src" + File.separator + "main" + File.separator + "deploy"); 056 } 057 } 058}