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, which is the remote location src/main/deploy is 045 * deployed to by default. On the roboRIO, this is /home/lvuser/deploy. In simulation, it is where 046 * the simulation was launched from, in the subdirectory "src/main/deploy" 047 * (`pwd`/src/main/deploy). 048 * 049 * @return The deploy directory 050 */ 051 public static File getDeployDirectory() { 052 if (RobotBase.isReal()) { 053 return new File(getOperatingDirectory(), "deploy"); 054 } else { 055 return new File( 056 getOperatingDirectory(), "src" + File.separator + "main" + File.separator + "deploy"); 057 } 058 } 059}