From f448d7e2e8910ff1db9da690db3b02ec88633176 Mon Sep 17 00:00:00 2001 From: Bennet Bo Fenner Date: Tue, 7 May 2024 16:28:03 +0200 Subject: [PATCH] remove app_version from gpui platform --- crates/gpui/src/platform.rs | 1 - crates/gpui/src/platform/linux/platform.rs | 4 - crates/gpui/src/platform/mac/platform.rs | 20 +---- crates/gpui/src/platform/test/platform.rs | 4 - crates/gpui/src/platform/windows/platform.rs | 94 -------------------- 5 files changed, 1 insertion(+), 122 deletions(-) diff --git a/crates/gpui/src/platform.rs b/crates/gpui/src/platform.rs index aedbef701e2..36d30a28718 100644 --- a/crates/gpui/src/platform.rs +++ b/crates/gpui/src/platform.rs @@ -138,7 +138,6 @@ pub(crate) trait Platform: 'static { fn os_name(&self) -> &'static str; fn os_version(&self) -> Result; - fn app_version(&self) -> Result; fn app_path(&self) -> Result; fn local_timezone(&self) -> UtcOffset; fn path_for_auxiliary_executable(&self, name: &str) -> Result; diff --git a/crates/gpui/src/platform/linux/platform.rs b/crates/gpui/src/platform/linux/platform.rs index 842b0d6f53d..4b251cd566a 100644 --- a/crates/gpui/src/platform/linux/platform.rs +++ b/crates/gpui/src/platform/linux/platform.rs @@ -347,10 +347,6 @@ impl Platform for P { Ok(SemanticVersion::new(1, 0, 0)) } - fn app_version(&self) -> Result { - Ok(SemanticVersion::new(1, 0, 0)) - } - fn app_path(&self) -> Result { // get the path of the executable of the current process let exe_path = std::env::current_exe()?; diff --git a/crates/gpui/src/platform/mac/platform.rs b/crates/gpui/src/platform/mac/platform.rs index b5b220d942a..dc0a51f4ff6 100644 --- a/crates/gpui/src/platform/mac/platform.rs +++ b/crates/gpui/src/platform/mac/platform.rs @@ -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 { - 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 { unsafe { let bundle: id = NSBundle::mainBundle(); diff --git a/crates/gpui/src/platform/test/platform.rs b/crates/gpui/src/platform/test/platform.rs index c243f4fac17..7514c238ba7 100644 --- a/crates/gpui/src/platform/test/platform.rs +++ b/crates/gpui/src/platform/test/platform.rs @@ -248,10 +248,6 @@ impl Platform for TestPlatform { Err(anyhow!("os_version called on TestPlatform")) } - fn app_version(&self) -> Result { - Err(anyhow!("app_version called on TestPlatform")) - } - fn app_path(&self) -> Result { unimplemented!() } diff --git a/crates/gpui/src/platform/windows/platform.rs b/crates/gpui/src/platform/windows/platform.rs index 7f8ec438a39..587777d902d 100644 --- a/crates/gpui/src/platform/windows/platform.rs +++ b/crates/gpui/src/platform/windows/platform.rs @@ -544,100 +544,6 @@ impl Platform for WindowsPlatform { } } - fn app_version(&self) -> Result { - 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 { Ok(std::env::current_exe()?) }