@@ -94,11 +94,10 @@ impl From<PermissionError> for DirectoryError {
9494pub fn get_app_support_directory ( ) -> PathBuf {
9595 #[ cfg( target_os = "windows" ) ]
9696 {
97- let program_data =
98- std:: env:: var_os ( "ProgramData" ) . expect ( "ProgramData environment variable not found" ) ;
99- let mut path = PathBuf :: from ( program_data) ;
100- path. push ( "OpenFrame" ) ;
101- path
97+ std:: env:: var_os ( "ProgramData" )
98+ . map ( PathBuf :: from)
99+ . unwrap_or_else ( || PathBuf :: from ( "C:\\ ProgramData" ) )
100+ . join ( "OpenFrame" )
102101 }
103102
104103 #[ cfg( target_os = "macos" ) ]
@@ -136,12 +135,7 @@ pub fn get_logs_directory() -> PathBuf {
136135 // If no override, use platform-specific defaults
137136 #[ cfg( target_os = "windows" ) ]
138137 {
139- let program_data =
140- std:: env:: var_os ( "ProgramData" ) . expect ( "ProgramData environment variable not found" ) ;
141- let mut path = PathBuf :: from ( program_data) ;
142- path. push ( "OpenFrame" ) ;
143- path. push ( "logs" ) ;
144- path
138+ get_app_support_directory ( ) . join ( "logs" )
145139 }
146140
147141 #[ cfg( target_os = "macos" ) ]
@@ -159,12 +153,7 @@ pub fn get_logs_directory() -> PathBuf {
159153pub fn get_secured_directory ( ) -> PathBuf {
160154 #[ cfg( target_os = "windows" ) ]
161155 {
162- let program_data =
163- std:: env:: var_os ( "ProgramData" ) . expect ( "ProgramData environment variable not found" ) ;
164- let mut path = PathBuf :: from ( program_data) ;
165- path. push ( "OpenFrame" ) ;
166- path. push ( "secured" ) ;
167- path
156+ get_app_support_directory ( ) . join ( "secured" )
168157 }
169158
170159 #[ cfg( target_os = "macos" ) ]
@@ -178,6 +167,29 @@ pub fn get_secured_directory() -> PathBuf {
178167 }
179168}
180169
170+ /// Returns the Windows install root, %ProgramFiles%\OpenFrame (the binary is in `bin`)
171+ #[ cfg( target_os = "windows" ) ]
172+ pub fn get_install_directory ( ) -> PathBuf {
173+ let program_files =
174+ std:: env:: var ( "ProgramFiles" ) . unwrap_or_else ( |_| "C:\\ Program Files" . to_string ( ) ) ;
175+ PathBuf :: from ( program_files) . join ( "OpenFrame" )
176+ }
177+
178+ /// Returns where the self-update stages the new binary and the updater script.
179+ /// On Windows it is under Program Files\OpenFrame, which our published AV exclusions
180+ /// cover: script-blocking tools deny PowerShell reading scripts from SystemTemp.
181+ pub fn get_update_staging_directory ( ) -> PathBuf {
182+ #[ cfg( target_os = "windows" ) ]
183+ {
184+ get_install_directory ( ) . join ( "update" )
185+ }
186+
187+ #[ cfg( not( target_os = "windows" ) ) ]
188+ {
189+ std:: env:: temp_dir ( )
190+ }
191+ }
192+
181193/// Sets the correct platform-specific permissions on a directory
182194pub fn set_directory_permissions ( path : & Path ) -> io:: Result < ( ) > {
183195 #[ cfg( target_os = "windows" ) ]
0 commit comments