diff --git a/server/Cargo.toml b/server/Cargo.toml index e38cedd9..69c9bfe1 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -14,6 +14,10 @@ path = "src/lib.rs" name = "rojo" path = "src/bin.rs" +[features] +default = [] +bundle-plugin = [] + [dependencies] clap = "2.27" rouille = "2.1" diff --git a/server/src/commands/serve.rs b/server/src/commands/serve.rs index 497c4ccb..b70261fd 100644 --- a/server/src/commands/serve.rs +++ b/server/src/commands/serve.rs @@ -7,6 +7,7 @@ use rand; use project::Project; use web::{self, WebConfig}; use session::Session; +use roblox_studio; pub fn serve(project_dir: &PathBuf, override_port: Option) { let server_id = rand::random::(); @@ -26,6 +27,8 @@ pub fn serve(project_dir: &PathBuf, override_port: Option) { println!("Using project {:#?}", project); + roblox_studio::install_bundled_plugin(); + let mut session = Session::new(project.clone()); session.start(); diff --git a/server/src/roblox_studio.rs b/server/src/roblox_studio.rs index 6f461285..a79cb059 100644 --- a/server/src/roblox_studio.rs +++ b/server/src/roblox_studio.rs @@ -1,10 +1,19 @@ //! Interactions with Roblox Studio's installation, including its location and //! mechanisms like PluginSettings. +#![allow(dead_code)] + use std::path::PathBuf; use std::env; -static ROJO_PLUGIN_ID: &'static str = "1211549683"; +#[cfg(all(not(debug_assertions), not(feature = "bundle-plugin")))] +compile_error!("`bundle-plugin` feature must be set for release builds."); + +#[cfg(feature = "bundle-plugin")] +static PLUGIN_RBXM: &'static [u8] = include_bytes!("../target/plugin.rbxm"); + +const ROJO_HOTSWAP_PLUGIN_ID: &'static str = "0"; +const ROJO_RELEASE_PLUGIN_ID: &'static str = "1997686364"; #[cfg(target_os = "windows")] pub fn get_install_location() -> Option { @@ -25,4 +34,45 @@ pub fn get_install_location() -> Option { pub fn get_install_location() -> Option { // Roblox Studio doesn't install on any other platforms! None +} + +#[cfg(feature = "bundle-plugin")] +pub fn get_plugin_location() -> Option { + let mut location = get_install_location()?; + + location.push("InstalledPlugins"); + location.push(ROJO_RELEASE_PLUGIN_ID); + + Some(location) +} + +#[cfg(not(feature = "bundle-plugin"))] +pub fn get_plugin_location() -> Option { + let mut location = get_install_location()?; + + location.push("InstalledPlugins"); + location.push(ROJO_HOTSWAP_PLUGIN_ID); + + Some(location) +} + +#[cfg(feature = "bundle-plugin")] +pub fn install_bundled_plugin() -> Option<()> { + use std::fs::create_dir_all; + + println!("Installing plugin..."); + + // TODO: Check error of this value; the only one we actually want to ignore + // is ErrorKind::AlreadyExists probably. + let _ = create_dir_all(get_plugin_location()?); + + // TODO: Copy PLUGIN_RBXM to plugin_location/Plugin.rbxm + // TODO: Update PluginMetadata.json + + Some(()) +} + +#[cfg(not(feature = "bundle-plugin"))] +pub fn install_bundled_plugin() { + println!("Skipping plugin installation, bundle-plugin not set."); } \ No newline at end of file