@@ -17,7 +17,6 @@ use windows_sys::core::{PCWSTR, w};
1717
1818use crate :: HMCL_EXPECTED_JAVA_MAJOR_VERSION ;
1919use crate :: debug:: { log_fmt, log_verbose_fmt} ;
20- use crate :: heap:: { HeapVec , alloc_bytes, free_bytes} ;
2120use crate :: platform:: is_regular_file;
2221use crate :: wide:: {
2322 WideDisplay , WideString , is_dot_or_dot_dot, trim_wide_whitespace, wide_contains,
@@ -55,43 +54,31 @@ impl JavaVersion {
5554 return Self :: invalid ( ) ;
5655 }
5756
58- let data = unsafe { alloc_bytes ( size as usize ) } ;
59- if data. is_null ( ) {
60- return Self :: invalid ( ) ;
61- }
62-
63- let result = unsafe { GetFileVersionInfoW ( path. as_pcwstr ( ) , 0 , size, data. cast ( ) ) } ;
57+ let mut data = vec ! [ 0u8 ; size as usize ] ;
58+ let result =
59+ unsafe { GetFileVersionInfoW ( path. as_pcwstr ( ) , 0 , size, data. as_mut_ptr ( ) . cast ( ) ) } ;
6460 if result == 0 {
65- unsafe {
66- free_bytes ( data) ;
67- }
6861 return Self :: invalid ( ) ;
6962 }
7063
7164 // Query the root `VS_FIXEDFILEINFO` block to extract the four numeric
7265 // version components in the same format as the upstream launcher.
7366 let mut info_ptr = ptr:: null_mut ( ) ;
7467 let mut info_len = 0u32 ;
75- let result = unsafe { VerQueryValueW ( data. cast ( ) , w ! ( "\\ " ) , & mut info_ptr, & mut info_len) } ;
68+ let result = unsafe {
69+ VerQueryValueW ( data. as_ptr ( ) . cast ( ) , w ! ( "\\ " ) , & mut info_ptr, & mut info_len)
70+ } ;
7671 if result == 0 || info_ptr. is_null ( ) || info_len < size_of :: < VS_FIXEDFILEINFO > ( ) as u32 {
77- unsafe {
78- free_bytes ( data) ;
79- }
8072 return Self :: invalid ( ) ;
8173 }
8274
8375 let info = unsafe { & * ( info_ptr as * const VS_FIXEDFILEINFO ) } ;
84- let version = Self {
76+ Self {
8577 major : ( ( info. dwFileVersionMS >> 16 ) & 0xFFFF ) as u16 ,
8678 minor : ( info. dwFileVersionMS & 0xFFFF ) as u16 ,
8779 build : ( ( info. dwFileVersionLS >> 16 ) & 0xFFFF ) as u16 ,
8880 revision : ( info. dwFileVersionLS & 0xFFFF ) as u16 ,
89- } ;
90-
91- unsafe {
92- free_bytes ( data) ;
9381 }
94- version
9582 }
9683
9784 #[ cfg( test) ]
@@ -159,14 +146,14 @@ pub struct JavaRuntime {
159146
160147/// Own the set of discovered Java runtimes before launch selection.
161148pub struct JavaList {
162- pub runtimes : HeapVec < JavaRuntime > ,
149+ pub runtimes : Vec < JavaRuntime > ,
163150}
164151
165152impl JavaList {
166153 /// Create an empty runtime list.
167154 pub fn new ( ) -> Self {
168155 Self {
169- runtimes : HeapVec :: new ( ) ,
156+ runtimes : Vec :: new ( ) ,
170157 }
171158 }
172159
@@ -208,14 +195,14 @@ impl JavaList {
208195 self . runtimes . push ( JavaRuntime {
209196 version,
210197 executable_path : java_executable,
211- } )
198+ } ) ;
199+ true
212200 }
213201
214202 /// Sort runtimes from lowest to highest version so callers can try the best
215203 /// match last-to-first.
216204 pub fn sort_by_version ( & mut self ) {
217- self . runtimes
218- . sort_by ( |left, right| left. version . cmp ( & right. version ) ) ;
205+ self . runtimes . sort_by ( |left, right| left. version . cmp ( & right. version ) ) ;
219206 }
220207}
221208
0 commit comments