This repository has been archived by the owner on Feb 18, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move implementations to shared dirs-sys crate
- Loading branch information
Showing
10 changed files
with
38 additions
and
198 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
Cargo.lock | ||
/target | ||
**/*.rs.bk | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,20 @@ | ||
use std; | ||
use std::path::PathBuf; | ||
extern crate dirs_sys; | ||
|
||
extern crate winapi; | ||
use self::winapi::shared::winerror; | ||
use self::winapi::um::knownfolders; | ||
use self::winapi::um::combaseapi; | ||
use self::winapi::um::shlobj; | ||
use self::winapi::um::shtypes; | ||
use self::winapi::um::winbase; | ||
use self::winapi::um::winnt; | ||
use std::path::PathBuf; | ||
|
||
pub fn home_dir() -> Option<PathBuf> { known_folder(&knownfolders::FOLDERID_Profile) } | ||
pub fn data_dir() -> Option<PathBuf> { known_folder(&knownfolders::FOLDERID_RoamingAppData) } | ||
pub fn data_local_dir() -> Option<PathBuf> { known_folder(&knownfolders::FOLDERID_LocalAppData) } | ||
pub fn home_dir() -> Option<PathBuf> { dirs_sys::known_folder_profile() } | ||
pub fn data_dir() -> Option<PathBuf> { dirs_sys::known_folder_roaming_app_data() } | ||
pub fn data_local_dir() -> Option<PathBuf> { dirs_sys::known_folder_local_app_data() } | ||
pub fn cache_dir() -> Option<PathBuf> { data_local_dir() } | ||
pub fn config_dir() -> Option<PathBuf> { data_dir() } | ||
pub fn executable_dir() -> Option<PathBuf> { None } | ||
pub fn runtime_dir() -> Option<PathBuf> { None } | ||
pub fn audio_dir() -> Option<PathBuf> { known_folder(&knownfolders::FOLDERID_Music) } | ||
pub fn desktop_dir() -> Option<PathBuf> { known_folder(&knownfolders::FOLDERID_Desktop) } | ||
pub fn document_dir() -> Option<PathBuf> { known_folder(&knownfolders::FOLDERID_Documents) } | ||
pub fn download_dir() -> Option<PathBuf> { known_folder(&knownfolders::FOLDERID_Downloads) } | ||
pub fn audio_dir() -> Option<PathBuf> { dirs_sys::known_folder_music() } | ||
pub fn desktop_dir() -> Option<PathBuf> { dirs_sys::known_folder_desktop() } | ||
pub fn document_dir() -> Option<PathBuf> { dirs_sys::known_folder_documents() } | ||
pub fn download_dir() -> Option<PathBuf> { dirs_sys::known_folder_downloads() } | ||
pub fn font_dir() -> Option<PathBuf> { None } | ||
pub fn picture_dir() -> Option<PathBuf> { known_folder(&knownfolders::FOLDERID_Pictures) } | ||
pub fn public_dir() -> Option<PathBuf> { known_folder(&knownfolders::FOLDERID_Public) } | ||
pub fn template_dir() -> Option<PathBuf> { known_folder(&knownfolders::FOLDERID_Templates) } | ||
pub fn video_dir() -> Option<PathBuf> { known_folder(&knownfolders::FOLDERID_Videos) } | ||
|
||
fn known_folder(folder_id: shtypes::REFKNOWNFOLDERID) -> Option<PathBuf> { | ||
unsafe { | ||
let mut path_ptr: winnt::PWSTR = std::ptr::null_mut(); | ||
let result = shlobj::SHGetKnownFolderPath(folder_id, 0, std::ptr::null_mut(), &mut path_ptr); | ||
if result == winerror::S_OK { | ||
let len = winbase::lstrlenW(path_ptr) as usize; | ||
let path = std::slice::from_raw_parts(path_ptr, len); | ||
let ostr: std::ffi::OsString = std::os::windows::ffi::OsStringExt::from_wide(path); | ||
combaseapi::CoTaskMemFree(path_ptr as *mut winapi::ctypes::c_void); | ||
Some(PathBuf::from(ostr)) | ||
} else { | ||
None | ||
} | ||
} | ||
} | ||
pub fn picture_dir() -> Option<PathBuf> { dirs_sys::known_folder_pictures() } | ||
pub fn public_dir() -> Option<PathBuf> { dirs_sys::known_folder_public()} | ||
pub fn template_dir() -> Option<PathBuf> { dirs_sys::known_folder_templates() } | ||
pub fn video_dir() -> Option<PathBuf> { dirs_sys::known_folder_videos() } |