use std::path::PathBuf;
use dirs::data_local_dir;
use crate::interface::InstallMethod;
#[cfg(unix)]
pub fn get_install_dir(method: &InstallMethod) -> PathBuf
{
match method
{
InstallMethod::SystemInstall => return PathBuf::from("/usr/local"),
InstallMethod::UserInstall =>
{
match data_local_dir()
{
Some(o) => return o.join(".."), None => panic!("Your system is insane: you do not have any local user data directory, as such you cannot install apps as your local user!\nYou may try a system-wide install if this installer permits it.")
}
}
}
}
#[cfg(windows)]
pub fn get_install_dir(method: &InstallMethod) -> PathBuf
{
use std::ffi::OsString;
use std::os::windows::ffi::OsStringExt;
use winapi::um::winnt::WCHAR;
use winapi::shared::minwindef::MAX_PATH;
use winapi::um::shlobj::SHGetSpecialFolderPathW;
use winapi::um::shlobj::CSIDL_PROGRAM_FILES;
use winapi::shared::minwindef::FALSE;
use winapi::shared::ntdef::NULL;
use winapi::shared::windef::HWND;
match method
{
InstallMethod::SystemInstall =>
{
let mut buf: [WCHAR; MAX_PATH] = [0; MAX_PATH];
unsafe
{
if SHGetSpecialFolderPathW(NULL as HWND, buf.as_mut_ptr(), CSIDL_PROGRAM_FILES, FALSE) == FALSE
{
panic!("Your system is insane: you do not have any system program folder, as such you cannot install apps system wide!\nYou may try a user install if this installer permits it.");
}
let len = buf.iter().take_while(|&&c| c != 0).count();
return PathBuf::from(OsString::from_wide(&buf[..len]));
}
}
InstallMethod::UserInstall =>
{
match data_local_dir()
{
Some(o) => return o.join(".."), None => panic!("Your system is insane: you do not have any local user data directory, as such you cannot install apps as your local user!\nYou may try a system-wide install if this installer permits it.")
}
}
}
}