-
Notifications
You must be signed in to change notification settings - Fork 19
Add various path utility functions #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| extern crate xplm; | ||
|
|
||
| use xplm::paths::{aircraft_path, plugin_path, prefs_path, system_path}; | ||
| use xplm::plugin::{Plugin, PluginInfo}; | ||
| use xplm::{debugln, xplane_plugin}; | ||
|
|
||
| struct PathsDemo; | ||
|
|
||
| impl Plugin for PathsDemo { | ||
| type Error = std::convert::Infallible; | ||
|
|
||
| fn start() -> Result<Self, Self::Error> { | ||
| debugln!( | ||
| "[Rust-XPLM] X-Plane root folder: {}", | ||
| system_path().unwrap().display() | ||
| ); | ||
| debugln!( | ||
| "[Rust-XPLM] X-Plane prefs file: {}", | ||
| prefs_path().unwrap().display() | ||
| ); | ||
| debugln!( | ||
| "[Rust-XPLM] Plugin path: {}", | ||
| plugin_path().unwrap().display() | ||
| ); | ||
| debugln!( | ||
| "[Rust-XPLM] Aircraft path: {}", | ||
| aircraft_path().unwrap().display() | ||
| ); | ||
|
|
||
| Ok(PathsDemo) | ||
| } | ||
|
|
||
| fn info(&self) -> PluginInfo { | ||
| PluginInfo { | ||
| name: String::from("Paths Demo Rust Plugin"), | ||
| signature: String::from("org.samcrow.xplm.examples.paths"), | ||
| description: String::from("Demonstrates paths functions"), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| xplane_plugin!(PathsDemo); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,8 +8,6 @@ use std::ffi::CString; | |
|
|
||
| /// FFI utilities | ||
| mod ffi; | ||
| /// Path conversion | ||
| mod paths; | ||
| /// Plugin macro | ||
| mod plugin_macro; | ||
|
|
||
|
|
@@ -34,6 +32,8 @@ pub mod flight_loop; | |
| pub mod geometry; | ||
| /// User interface menus | ||
| pub mod menu; | ||
| /// X-Plane and plugin paths | ||
| pub mod paths; | ||
|
Comment on lines
+35
to
+36
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should add docs to the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I missed this... these functions return |
||
| /// Plugin creation and management | ||
| pub mod plugin; | ||
| /// X-Plane and XPLM version info | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,50 @@ | ||
| use super::feature; | ||
|
|
||
| /// Enables native paths | ||
| pub fn path_init() { | ||
| // Feature specified to exist in SDK 2.1 | ||
| let native_path_feature = | ||
| feature::find_feature("XPLM_USE_NATIVE_PATHS").expect("No native paths feature"); | ||
| native_path_feature.set_enabled(true); | ||
| use std::{path::PathBuf, ptr::null_mut, str::Utf8Error}; | ||
|
|
||
| use xplm_sys::{ | ||
| XPLMGetMyID, XPLMGetNthAircraftModel, XPLMGetPluginInfo, XPLMGetPrefsPath, XPLMGetSystemPath, | ||
| }; | ||
|
|
||
| use super::ffi::StringBuffer; | ||
|
|
||
| /// Get path to this plugin | ||
| pub fn plugin_path() -> Result<PathBuf, Utf8Error> { | ||
| let mut path = StringBuffer::new(512); | ||
| unsafe { | ||
| XPLMGetPluginInfo( | ||
| XPLMGetMyID(), | ||
| null_mut(), | ||
| path.as_mut_ptr(), | ||
| null_mut(), | ||
| null_mut(), | ||
| ); | ||
| } | ||
| Ok(PathBuf::from(path.as_str()?)) | ||
| } | ||
|
|
||
| /// Get path to X-Plane's preferences file | ||
| /// (usually "Output/preferences/Set X-Plane.prf") | ||
| pub fn prefs_path() -> Result<PathBuf, Utf8Error> { | ||
| let mut path = StringBuffer::new(512); | ||
| unsafe { | ||
| XPLMGetPrefsPath(path.as_mut_ptr()); | ||
| } | ||
| Ok(PathBuf::from(path.as_str()?)) | ||
| } | ||
|
|
||
| /// Get path to X-Plane root folder | ||
| pub fn system_path() -> Result<PathBuf, Utf8Error> { | ||
| let mut path = StringBuffer::new(512); | ||
| unsafe { | ||
| XPLMGetSystemPath(path.as_mut_ptr()); | ||
| } | ||
| Ok(PathBuf::from(path.as_str()?)) | ||
| } | ||
|
|
||
| /// Get path to loaded aircraft's .acf file | ||
| pub fn aircraft_path() -> Result<PathBuf, Utf8Error> { | ||
| let mut path = StringBuffer::new(512); | ||
| unsafe { | ||
| XPLMGetNthAircraftModel(0, StringBuffer::new(256).as_mut_ptr(), path.as_mut_ptr()); | ||
| } | ||
| Ok(PathBuf::from(path.as_str()?)) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless I am missing something, there should be no reason anymore for this to be public