pub struct WineConfig { /* private fields */ }Expand description
The main conversion struct: create one of these to do conversions.
Tracks the WINEPREFIX and the drive letter mappings so they don’t have to be recomputed every time you convert a path.
Implementations§
Source§impl WineConfig
impl WineConfig
Sourcepub fn from_env() -> Result<Self, WinePathError>
pub fn from_env() -> Result<Self, WinePathError>
Determine the wine prefix from the environment.
Examples found in repository?
examples/winepath.rs (line 31)
9fn main() {
10 let mut action = Action::ToUnix;
11 let mut path = None;
12
13 if let Some(arg) = std::env::args().nth(1) {
14 match arg.as_str() {
15 "-u" => action = Action::ToUnix,
16 "-w" => action = Action::ToWindows,
17 _ => path = Some(arg),
18 }
19 } else {
20 panic!("usage: winepath [OPTION] [PATH]")
21 };
22
23 let path = if let Some(path) = path {
24 path
25 } else if let Some(path) = std::env::args().nth(2) {
26 path
27 } else {
28 panic!("usage: winepath [OPTION] [PATH]");
29 };
30
31 let config = WineConfig::from_env().unwrap();
32 println!(
33 "{}",
34 match action {
35 Action::ToUnix => config
36 .to_native_path(path)
37 .unwrap()
38 .to_string_lossy()
39 .to_string(),
40 Action::ToWindows => {
41 let path = std::fs::canonicalize(path).unwrap();
42 config.to_wine_path(path).unwrap().to_string()
43 }
44 }
45 )
46}Sourcepub fn from_prefix(path: impl Into<PathBuf>) -> Self
pub fn from_prefix(path: impl Into<PathBuf>) -> Self
Create a config assuming that the given path is a valid WINEPREFIX.
Note that this is not validated, and you will end up with empty drive mappings if it is not actually a wine prefix.
You can manually validate if a directory is Wine-y enough by doing:
ⓘ
use std::path::Path;
fn is_wineprefix_like(some_path: &Path) -> bool {
some_path.join("dosdevices").is_dir()
}Sourcepub fn to_wine_path(
&self,
path: impl AsRef<Path>,
) -> Result<WinePath, WinePathError>
pub fn to_wine_path( &self, path: impl AsRef<Path>, ) -> Result<WinePath, WinePathError>
Convert a native file path to a Wine path.
use winepath::WineConfig;
let config = WineConfig::from_env().unwrap();
let path = config.to_wine_path("/home/username/.wine/drive_c/Program Files/CoolApp/start.exe").unwrap();
assert_eq!(path.to_string(), r"c:\Program Files\CoolApp\start.exe");
let path = config.to_wine_path("/home/username/some-path/some-file").unwrap();
assert_eq!(path.to_string(), r"z:\home\username\some-path\some-file");Examples found in repository?
examples/winepath.rs (line 42)
9fn main() {
10 let mut action = Action::ToUnix;
11 let mut path = None;
12
13 if let Some(arg) = std::env::args().nth(1) {
14 match arg.as_str() {
15 "-u" => action = Action::ToUnix,
16 "-w" => action = Action::ToWindows,
17 _ => path = Some(arg),
18 }
19 } else {
20 panic!("usage: winepath [OPTION] [PATH]")
21 };
22
23 let path = if let Some(path) = path {
24 path
25 } else if let Some(path) = std::env::args().nth(2) {
26 path
27 } else {
28 panic!("usage: winepath [OPTION] [PATH]");
29 };
30
31 let config = WineConfig::from_env().unwrap();
32 println!(
33 "{}",
34 match action {
35 Action::ToUnix => config
36 .to_native_path(path)
37 .unwrap()
38 .to_string_lossy()
39 .to_string(),
40 Action::ToWindows => {
41 let path = std::fs::canonicalize(path).unwrap();
42 config.to_wine_path(path).unwrap().to_string()
43 }
44 }
45 )
46}Sourcepub fn to_native_path(
&self,
path: impl Into<WinePath>,
) -> Result<PathBuf, WinePathError>
pub fn to_native_path( &self, path: impl Into<WinePath>, ) -> Result<PathBuf, WinePathError>
Convert a Wine path to a native file path.
use winepath::WineConfig;
use std::path::PathBuf;
let config = WineConfig::from_env().unwrap();
let path = config.to_native_path(r"c:\Program Files\CoolApp\start.exe").unwrap();
assert_eq!(path, PathBuf::from("/home/username/.wine/drive_c/Program Files/CoolApp/start.exe"));
let path = config.to_native_path(r"z:\home\username\some-path\some-file").unwrap();
assert_eq!(path, PathBuf::from("/home/username/some-path/some-file"));Examples found in repository?
examples/winepath.rs (line 36)
9fn main() {
10 let mut action = Action::ToUnix;
11 let mut path = None;
12
13 if let Some(arg) = std::env::args().nth(1) {
14 match arg.as_str() {
15 "-u" => action = Action::ToUnix,
16 "-w" => action = Action::ToWindows,
17 _ => path = Some(arg),
18 }
19 } else {
20 panic!("usage: winepath [OPTION] [PATH]")
21 };
22
23 let path = if let Some(path) = path {
24 path
25 } else if let Some(path) = std::env::args().nth(2) {
26 path
27 } else {
28 panic!("usage: winepath [OPTION] [PATH]");
29 };
30
31 let config = WineConfig::from_env().unwrap();
32 println!(
33 "{}",
34 match action {
35 Action::ToUnix => config
36 .to_native_path(path)
37 .unwrap()
38 .to_string_lossy()
39 .to_string(),
40 Action::ToWindows => {
41 let path = std::fs::canonicalize(path).unwrap();
42 config.to_wine_path(path).unwrap().to_string()
43 }
44 }
45 )
46}Trait Implementations§
Auto Trait Implementations§
impl Freeze for WineConfig
impl RefUnwindSafe for WineConfig
impl Send for WineConfig
impl Sync for WineConfig
impl Unpin for WineConfig
impl UnwindSafe for WineConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more