1
+ module std::io::os;
2
+
3
+ enum NativeSystemDir
4
+ {
5
+ DESKTOP ,
6
+ DOCUMENTS ,
7
+ VIDEOS ,
8
+ MUSIC ,
9
+ DOWNLOADS ,
10
+ PICTURES ,
11
+ TEMPLATES ,
12
+ PUBLIC_SHARE ,
13
+ SAVED_GAMES ,
14
+ SCREENSHOTS
15
+ }
16
+
1
17
module std::io::os @if (env::LIBC );
2
- import std::io::path, std::os;
18
+ import std::io, std::os;
19
+
20
+ fn String ? win32_get_known_folder_temp (Win32_REFKNOWNFOLDERID rfid ) @private @if (env::WIN32 )
21
+ {
22
+ Win32_PWSTR path ;
23
+ Win32_HRESULT res = win32::shGetKnownFolderPath (rfid , 0x00008000 /* KF_FLAG_CREATE */ , null , & path );
24
+ if (res ) return io::PATH_COULD_NOT_BE_FOUND ? ;
25
+ return string::from_wstring (tmem , (WString )path );
26
+ }
27
+
28
+ fn Path ? native_home_directory (Allocator allocator ) => @pool ()
29
+ {
30
+ $switch env::OS_TYPE :
31
+ $case IOS :
32
+ $case MACOS :
33
+ $case TVOS :
34
+ $case WATCHOS :
35
+ $case FREEBSD :
36
+ $case KFREEBSD :
37
+ $case LINUX :
38
+ $case NETBSD :
39
+ $case OPENBSD :
40
+ $case HAIKU :
41
+ return path::new (allocator , env::tget_var (" HOME " )) ?? io::PATH_COULD_NOT_BE_FOUND ? ;
42
+ $case WIN32 :
43
+ return path::new (allocator , win32_get_known_folder_temp (& win32::FOLDERID_PROFILE ));
44
+ $default :
45
+ return io::PATH_COULD_NOT_BE_FOUND ? ;
46
+ $endswitch
47
+ }
48
+
49
+ fn Path ? native_user_directory (Allocator allocator , NativeSystemDir dir ) => @pool ()
50
+ {
51
+ $switch env::OS_TYPE :
52
+ $case FREEBSD :
53
+ $case KFREEBSD :
54
+ $case LINUX :
55
+ $case NETBSD :
56
+ $case OPENBSD :
57
+ $case HAIKU :
58
+ switch (dir )
59
+ {
60
+ case DESKTOP : return path::new (allocator , posix::xdg_user_dir_lookup (tmem , " DESKTOP " ));
61
+ case DOWNLOADS : return path::new (allocator , posix::xdg_user_dir_lookup (tmem , " DOWNLOAD " ));
62
+ case DOCUMENTS : return path::new (allocator , posix::xdg_user_dir_lookup (tmem , " DOCUMENTS " ));
63
+ case MUSIC : return path::new (allocator , posix::xdg_user_dir_lookup (tmem , " MUSIC " ));
64
+ case VIDEOS : return path::new (allocator , posix::xdg_user_dir_lookup (tmem , " VIDEOS " ));
65
+ case PICTURES : return path::new (allocator , posix::xdg_user_dir_lookup (tmem , " PICTURES " ));
66
+ case PUBLIC_SHARE : return path::new (allocator , posix::xdg_user_dir_lookup (tmem , " PUBLICSHARE " ));
67
+ case TEMPLATES : return path::new (allocator , posix::xdg_user_dir_lookup (tmem , " TEMPLATES " ));
68
+ case SAVED_GAMES :
69
+ case SCREENSHOTS : nextcase ;
70
+ default : return io::PATH_COULD_NOT_BE_FOUND ? ;
71
+ }
72
+ $case IOS :
73
+ $case MACOS :
74
+ $case WATCHOS :
75
+ $case TVOS :
76
+ switch (dir )
77
+ {
78
+ case DESKTOP : return path::new (allocator , darwin::find_first_directory_temp (DESKTOP , USER ));
79
+ case DOWNLOADS : return path::new (allocator , darwin::find_first_directory_temp (DOWNLOADS , USER ));
80
+ case DOCUMENTS : return path::new (allocator , darwin::find_first_directory_temp (DOCUMENT , USER ));
81
+ case MUSIC : return path::new (allocator , darwin::find_first_directory_temp (MUSIC , USER ));
82
+ case VIDEOS : return path::new (allocator , darwin::find_first_directory_temp (MOVIES , USER ));
83
+ case PICTURES : return path::new (allocator , darwin::find_first_directory_temp (PICTURES , USER ));
84
+ case PUBLIC_SHARE : return path::new (allocator , darwin::find_first_directory_temp (SHARED_PUBLIC , USER ));
85
+ case SAVED_GAMES :
86
+ case SCREENSHOTS :
87
+ case TEMPLATES : nextcase ;
88
+ default : return io::PATH_COULD_NOT_BE_FOUND ? ;
89
+ }
90
+ $case WIN32 :
91
+ switch (dir )
92
+ {
93
+ case DOWNLOADS : return path::new (allocator , win32_get_known_folder_temp (& win32::FOLDERID_DOWNLOADS ));
94
+ case DOCUMENTS : return path::new (allocator , win32_get_known_folder_temp (& win32::FOLDERID_DOCUMENTS ));
95
+ case DESKTOP : return path::new (allocator , win32_get_known_folder_temp (& win32::FOLDERID_DESKTOP ));
96
+ case MUSIC : return path::new (allocator , win32_get_known_folder_temp (& win32::FOLDERID_MUSIC ));
97
+ case VIDEOS : return path::new (allocator , win32_get_known_folder_temp (& win32::FOLDERID_VIDEOS ));
98
+ case PICTURES : return path::new (allocator , win32_get_known_folder_temp (& win32::FOLDERID_PICTURES ));
99
+ case SAVED_GAMES : return path::new (allocator , win32_get_known_folder_temp (& win32::FOLDERID_SAVED_GAMES ));
100
+ case SCREENSHOTS : return path::new (allocator , win32_get_known_folder_temp (& win32::FOLDERID_SCREENSHOTS ));
101
+ case TEMPLATES : return path::new (allocator , win32_get_known_folder_temp (& win32::FOLDERID_TEMPLATES ));
102
+ case PUBLIC_SHARE : nextcase ;
103
+ default : return io::PATH_COULD_NOT_BE_FOUND ? ;
104
+ }
105
+ $default :
106
+ return io::PATH_COULD_NOT_BE_FOUND ? ;
107
+ $endswitch
108
+ }
109
+
3
110
4
111
fn Path ? native_temp_directory (Allocator allocator ) @if (! env::WIN32 )
5
112
{
@@ -23,7 +130,6 @@ fn Path? native_temp_directory(Allocator allocator) @if(env::WIN32) => @pool()
23
130
module std::io::os @if (env::NO_LIBC );
24
131
import std::io::path;
25
132
26
- macro Path ? native_temp_directory (Allocator allocator )
27
- {
28
- return io::UNSUPPORTED_OPERATION ? ;
29
- }
133
+ macro Path ? native_home_directory (Allocator allocator ) => io::PATH_COULD_NOT_BE_FOUND ? ;
134
+ macro Path ? native_temp_directory (Allocator allocator ) => io::PATH_COULD_NOT_BE_FOUND ? ;
135
+ fn Path ? native_user_directory (Allocator allocator , NativeSystemDir dir ) => io::PATH_COULD_NOT_BE_FOUND ? ;
0 commit comments