1
1
use std:: env:: consts:: EXE_SUFFIX ;
2
+ use std:: ffi:: { OsStr , OsString } ;
3
+ use std:: os:: windows:: ffi:: OsStrExt ;
2
4
use std:: path:: Path ;
3
5
use std:: process:: Command ;
4
6
@@ -10,6 +12,9 @@ use crate::process;
10
12
use crate :: utils:: utils;
11
13
use crate :: utils:: Notification ;
12
14
15
+ use winreg:: enums:: { RegType , HKEY_CURRENT_USER , KEY_READ , KEY_WRITE } ;
16
+ use winreg:: { RegKey , RegValue } ;
17
+
13
18
pub fn ensure_prompt ( ) -> Result < ( ) > {
14
19
writeln ! ( process( ) . stdout( ) , ) ?;
15
20
writeln ! ( process( ) . stdout( ) , "Press the Enter key to continue." ) ?;
@@ -42,7 +47,6 @@ pub fn do_msvc_check(opts: &InstallOpts<'_>) -> Result<bool> {
42
47
43
48
/// Run by rustup-gc-$num.exe to delete CARGO_HOME
44
49
pub fn complete_windows_uninstall ( ) -> Result < utils:: ExitCode > {
45
- use std:: ffi:: OsStr ;
46
50
use std:: process:: Stdio ;
47
51
48
52
wait_for_parent ( ) ?;
@@ -150,8 +154,6 @@ fn _apply_new_path(new_path: Option<Vec<u16>>) -> Result<()> {
150
154
use winapi:: um:: winuser:: {
151
155
SendMessageTimeoutA , HWND_BROADCAST , SMTO_ABORTIFHUNG , WM_SETTINGCHANGE ,
152
156
} ;
153
- use winreg:: enums:: { RegType , HKEY_CURRENT_USER , KEY_READ , KEY_WRITE } ;
154
- use winreg:: { RegKey , RegValue } ;
155
157
156
158
let new_path = match new_path {
157
159
Some ( new_path) => new_path,
@@ -198,8 +200,6 @@ fn _apply_new_path(new_path: Option<Vec<u16>>) -> Result<()> {
198
200
// should not mess with it.
199
201
fn get_windows_path_var ( ) -> Result < Option < Vec < u16 > > > {
200
202
use std:: io;
201
- use winreg:: enums:: { HKEY_CURRENT_USER , KEY_READ , KEY_WRITE } ;
202
- use winreg:: RegKey ;
203
203
204
204
let root = RegKey :: predef ( HKEY_CURRENT_USER ) ;
205
205
let environment = root
@@ -270,9 +270,6 @@ fn _with_path_cargo_home_bin<F>(f: F) -> Result<Option<Vec<u16>>>
270
270
where
271
271
F : FnOnce ( Vec < u16 > , Vec < u16 > ) -> Option < Vec < u16 > > ,
272
272
{
273
- use std:: ffi:: OsString ;
274
- use std:: os:: windows:: ffi:: OsStrExt ;
275
-
276
273
let windows_path = get_windows_path_var ( ) ?;
277
274
let mut path_str = utils:: cargo_home ( ) ?;
278
275
path_str. push ( "bin" ) ;
@@ -285,6 +282,36 @@ pub fn do_remove_from_path() -> Result<()> {
285
282
_apply_new_path ( new_path)
286
283
}
287
284
285
+ fn do_add_to_programs ( ) -> Result < ( ) > {
286
+ let key = RegKey :: predef ( HKEY_CURRENT_USER )
287
+ . create_subkey ( r"Software\Microsoft\Windows\CurrentVersion\Uninstall\rustup" )
288
+ . chain_err ( || ErrorKind :: PermissionDenied ) ?
289
+ . 0 ;
290
+
291
+ let mut path = utils:: cargo_home ( ) ?;
292
+ path. push ( "bin\r ustup.exe" ) ;
293
+ let mut uninstall_cmd = path. into_os_string ( ) ;
294
+ uninstall_cmd. push ( " self uninstall" ) ;
295
+
296
+ let reg_value = RegValue {
297
+ bytes : to_winreg_bytes ( uninstall_cmd. encode_wide ( ) . collect ( ) ) ,
298
+ vtype : RegType :: REG_SZ ,
299
+ } ;
300
+
301
+ key. set_raw_value ( "UninstallString" , & reg_value)
302
+ . chain_err ( || ErrorKind :: PermissionDenied ) ?;
303
+ key. set_value ( "DisplayName" , & "rustup" )
304
+ . chain_err ( || ErrorKind :: PermissionDenied ) ?;
305
+
306
+ Ok ( ( ) )
307
+ }
308
+
309
+ fn do_remove_from_programs ( ) -> Result < ( ) > {
310
+ RegKey :: predef ( HKEY_CURRENT_USER )
311
+ . delete_subkey_all ( r"Software\Microsoft\Windows\CurrentVersion\Uninstall\rustup" )
312
+ . chain_err ( || ErrorKind :: PermissionDenied )
313
+ }
314
+
288
315
/// Convert a vector UCS-2 chars to a null-terminated UCS-2 string in bytes
289
316
pub fn to_winreg_bytes ( mut v : Vec < u16 > ) -> Vec < u8 > {
290
317
v. push ( 0 ) ;
@@ -296,7 +323,6 @@ pub fn to_winreg_bytes(mut v: Vec<u16>) -> Vec<u8> {
296
323
/// does a lossy unicode conversion.
297
324
pub fn from_winreg_value ( val : & winreg:: RegValue ) -> Option < Vec < u16 > > {
298
325
use std:: slice;
299
- use winreg:: enums:: RegType ;
300
326
301
327
match val. vtype {
302
328
RegType :: REG_SZ | RegType :: REG_EXPAND_SZ => {
@@ -364,7 +390,6 @@ pub fn self_replace() -> Result<utils::ExitCode> {
364
390
pub fn delete_rustup_and_cargo_home ( ) -> Result < ( ) > {
365
391
use std:: io;
366
392
use std:: mem;
367
- use std:: os:: windows:: ffi:: OsStrExt ;
368
393
use std:: ptr;
369
394
use std:: thread;
370
395
use std:: time:: Duration ;
0 commit comments