mirror of
https://github.com/zed-industries/zed.git
synced 2026-05-31 04:54:24 +00:00
remove app_version from gpui platform
This commit is contained in:
parent
4624a0a9f4
commit
f448d7e2e8
5 changed files with 1 additions and 122 deletions
|
|
@ -138,7 +138,6 @@ pub(crate) trait Platform: 'static {
|
|||
|
||||
fn os_name(&self) -> &'static str;
|
||||
fn os_version(&self) -> Result<SemanticVersion>;
|
||||
fn app_version(&self) -> Result<SemanticVersion>;
|
||||
fn app_path(&self) -> Result<PathBuf>;
|
||||
fn local_timezone(&self) -> UtcOffset;
|
||||
fn path_for_auxiliary_executable(&self, name: &str) -> Result<PathBuf>;
|
||||
|
|
|
|||
|
|
@ -347,10 +347,6 @@ impl<P: LinuxClient + 'static> Platform for P {
|
|||
Ok(SemanticVersion::new(1, 0, 0))
|
||||
}
|
||||
|
||||
fn app_version(&self) -> Result<SemanticVersion> {
|
||||
Ok(SemanticVersion::new(1, 0, 0))
|
||||
}
|
||||
|
||||
fn app_path(&self) -> Result<PathBuf> {
|
||||
// get the path of the executable of the current process
|
||||
let exe_path = std::env::current_exe()?;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use crate::{
|
|||
Platform, PlatformDisplay, PlatformTextSystem, PlatformWindow, Result, SemanticVersion, Task,
|
||||
WindowAppearance, WindowParams,
|
||||
};
|
||||
use anyhow::{anyhow, bail};
|
||||
use anyhow::anyhow;
|
||||
use block::ConcreteBlock;
|
||||
use cocoa::{
|
||||
appkit::{
|
||||
|
|
@ -693,24 +693,6 @@ impl Platform for MacPlatform {
|
|||
}
|
||||
}
|
||||
|
||||
fn app_version(&self) -> Result<SemanticVersion> {
|
||||
unsafe {
|
||||
let bundle: id = NSBundle::mainBundle();
|
||||
if bundle.is_null() {
|
||||
Err(anyhow!("app is not running inside a bundle"))
|
||||
} else {
|
||||
let version: id = msg_send![bundle, objectForInfoDictionaryKey: ns_string("CFBundleShortVersionString")];
|
||||
if version.is_null() {
|
||||
bail!("bundle does not have version");
|
||||
}
|
||||
let len = msg_send![version, lengthOfBytesUsingEncoding: NSUTF8StringEncoding];
|
||||
let bytes = version.UTF8String() as *const u8;
|
||||
let version = str::from_utf8(slice::from_raw_parts(bytes, len)).unwrap();
|
||||
version.parse()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn app_path(&self) -> Result<PathBuf> {
|
||||
unsafe {
|
||||
let bundle: id = NSBundle::mainBundle();
|
||||
|
|
|
|||
|
|
@ -248,10 +248,6 @@ impl Platform for TestPlatform {
|
|||
Err(anyhow!("os_version called on TestPlatform"))
|
||||
}
|
||||
|
||||
fn app_version(&self) -> Result<crate::SemanticVersion> {
|
||||
Err(anyhow!("app_version called on TestPlatform"))
|
||||
}
|
||||
|
||||
fn app_path(&self) -> Result<std::path::PathBuf> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -544,100 +544,6 @@ impl Platform for WindowsPlatform {
|
|||
}
|
||||
}
|
||||
|
||||
fn app_version(&self) -> Result<SemanticVersion> {
|
||||
let mut file_name_buffer = vec![0u16; MAX_PATH as usize];
|
||||
let file_name = {
|
||||
let mut file_name_buffer_capacity = MAX_PATH as usize;
|
||||
let mut file_name_length;
|
||||
loop {
|
||||
file_name_length =
|
||||
unsafe { GetModuleFileNameW(None, &mut file_name_buffer) } as usize;
|
||||
if file_name_length < file_name_buffer_capacity {
|
||||
break;
|
||||
}
|
||||
// buffer too small
|
||||
file_name_buffer_capacity *= 2;
|
||||
file_name_buffer = vec![0u16; file_name_buffer_capacity];
|
||||
}
|
||||
PCWSTR::from_raw(file_name_buffer[0..(file_name_length + 1)].as_ptr())
|
||||
};
|
||||
|
||||
let version_info_block = {
|
||||
let mut version_handle = 0;
|
||||
let version_info_size =
|
||||
unsafe { GetFileVersionInfoSizeW(file_name, Some(&mut version_handle)) } as usize;
|
||||
if version_info_size == 0 {
|
||||
log::error!(
|
||||
"unable to get version info size: {}",
|
||||
std::io::Error::last_os_error()
|
||||
);
|
||||
return Err(anyhow!("unable to get version info size"));
|
||||
}
|
||||
let mut version_data = vec![0u8; version_info_size + 2];
|
||||
unsafe {
|
||||
GetFileVersionInfoW(
|
||||
file_name,
|
||||
version_handle,
|
||||
version_info_size as u32,
|
||||
version_data.as_mut_ptr() as _,
|
||||
)
|
||||
}
|
||||
.inspect_err(|_| {
|
||||
log::error!(
|
||||
"unable to retrieve version info: {}",
|
||||
std::io::Error::last_os_error()
|
||||
)
|
||||
})?;
|
||||
version_data
|
||||
};
|
||||
|
||||
let version_info_raw = {
|
||||
let mut buffer = unsafe { std::mem::zeroed() };
|
||||
let mut size = 0;
|
||||
let entry = "\\".encode_utf16().chain(Some(0)).collect_vec();
|
||||
if !unsafe {
|
||||
VerQueryValueW(
|
||||
version_info_block.as_ptr() as _,
|
||||
PCWSTR::from_raw(entry.as_ptr()),
|
||||
&mut buffer,
|
||||
&mut size,
|
||||
)
|
||||
}
|
||||
.as_bool()
|
||||
{
|
||||
log::error!(
|
||||
"unable to query version info data: {}",
|
||||
std::io::Error::last_os_error()
|
||||
);
|
||||
return Err(anyhow!("the specified resource is not valid"));
|
||||
}
|
||||
if size == 0 {
|
||||
log::error!(
|
||||
"unable to query version info data: {}",
|
||||
std::io::Error::last_os_error()
|
||||
);
|
||||
return Err(anyhow!("no value is available for the specified name"));
|
||||
}
|
||||
buffer
|
||||
};
|
||||
|
||||
let version_info = unsafe { &*(version_info_raw as *mut VS_FIXEDFILEINFO) };
|
||||
// https://learn.microsoft.com/en-us/windows/win32/api/verrsrc/ns-verrsrc-vs_fixedfileinfo
|
||||
if version_info.dwSignature == 0xFEEF04BD {
|
||||
return Ok(SemanticVersion::new(
|
||||
((version_info.dwProductVersionMS >> 16) & 0xFFFF) as usize,
|
||||
(version_info.dwProductVersionMS & 0xFFFF) as usize,
|
||||
((version_info.dwProductVersionLS >> 16) & 0xFFFF) as usize,
|
||||
));
|
||||
} else {
|
||||
log::error!(
|
||||
"no version info present: {}",
|
||||
std::io::Error::last_os_error()
|
||||
);
|
||||
return Err(anyhow!("no version info present"));
|
||||
}
|
||||
}
|
||||
|
||||
fn app_path(&self) -> Result<PathBuf> {
|
||||
Ok(std::env::current_exe()?)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue