roblox_studio_utils/paths/
mod.rs

1use std::{
2    path::{Path, PathBuf},
3    sync::Arc,
4};
5
6use crate::RobloxStudioResult;
7
8#[cfg(target_os = "macos")]
9mod macos;
10
11#[cfg(target_os = "windows")]
12mod windows;
13
14#[cfg(target_os = "linux")]
15mod linux;
16
17/**
18    References to discovered, validated paths to the current
19    Roblox Studio executable, content, and plugins directories.
20
21    Can be cheaply cloned and shared between threads.
22*/
23#[derive(Debug, Clone)]
24pub struct RobloxStudioPaths {
25    inner: Arc<RobloxStudioPathsInner>,
26}
27
28impl RobloxStudioPaths {
29    /**
30        Tries to locate the current Roblox Studio installation and directories.
31
32        # Errors
33
34        - If Roblox Studio is not installed.
35    */
36    pub fn new() -> RobloxStudioResult<Self> {
37        RobloxStudioPathsInner::new().map(Self::from)
38    }
39
40    /**
41        Returns the path to the Roblox Studio executable.
42    */
43    #[must_use]
44    pub fn exe(&self) -> &Path {
45        self.inner.exe.as_path()
46    }
47
48    /**
49        Returns the path to the Roblox Studio content directory.
50
51        This directory contains Roblox bundled assets, in sub-directories such as:
52
53        - `fonts` - bundled font files, typically in OpenType or TrueType format
54        - `sounds` - bundled basic sounds, such as the character reset sound
55        - `textures` - bundled texture files, typically used for `CoreGui`
56    */
57    #[must_use]
58    pub fn content(&self) -> &Path {
59        self.inner.content.as_path()
60    }
61
62    /**
63        Returns the path to the Roblox Studio **user plugins** directory.
64
65        For the path to built-in plugins, see [`RobloxStudioPaths::built_in_plugins`].
66
67        # Warning
68
69        This directory may or may not exist as it is created on demand,
70        either when a user opens it through the Roblox Studio settings,
71        or when they install their first plugin.
72    */
73    #[must_use]
74    pub fn user_plugins(&self) -> &Path {
75        self.inner.plugins_user.as_path()
76    }
77
78    /**
79        Returns the path to the Roblox Studio **built-in plugins** directory.
80
81        These plugins are bundled with Roblox Studio itself, and the directory is guaranteed
82        to exist unlike the user plugins directory ([`RobloxStudioPaths::user_plugins`]).
83    */
84    #[must_use]
85    pub fn built_in_plugins(&self) -> &Path {
86        self.inner.plugins_builtin.as_path()
87    }
88}
89
90// Private inner struct to make RobloxStudioPaths cheaper to clone
91#[derive(Debug, Clone)]
92struct RobloxStudioPathsInner {
93    exe: PathBuf,
94    content: PathBuf,
95    plugins_user: PathBuf,
96    plugins_builtin: PathBuf,
97}
98
99impl From<RobloxStudioPathsInner> for RobloxStudioPaths {
100    fn from(inner: RobloxStudioPathsInner) -> Self {
101        Self {
102            inner: Arc::new(inner),
103        }
104    }
105}