@@ -22,20 +22,19 @@ import 'folders.dart';
22
22
class VersionInfoQuerier {
23
23
/// Returns the value for [key] in [versionInfo] s English strings section, or
24
24
/// null if there is no such entry, or if versionInfo is null.
25
- getStringValue (Pointer <Uint8 > versionInfo, key) {
25
+ getStringValue (Pointer <Uint8 >? versionInfo, key) {
26
26
if (versionInfo == null ) {
27
27
return null ;
28
28
}
29
29
const kEnUsLanguageCode = '040904e4' ;
30
30
final keyPath = TEXT ('\\ StringFileInfo\\ $kEnUsLanguageCode \\ $key ' );
31
31
final length = allocate <Uint32 >();
32
- final valueAddress = allocate <IntPtr >();
32
+ final valueAddress = allocate <Pointer < Utf16 > >();
33
33
try {
34
34
if (VerQueryValue (versionInfo, keyPath, valueAddress, length) == 0 ) {
35
35
return null ;
36
36
}
37
- return Pointer <Utf16 >.fromAddress (valueAddress.value)
38
- .unpackString (length.value);
37
+ return valueAddress.value.unpackString (length.value);
39
38
} finally {
40
39
free (keyPath);
41
40
free (length);
@@ -54,7 +53,7 @@ class PathProviderWindows extends PathProviderPlatform {
54
53
55
54
/// This is typically the same as the TMP environment variable.
56
55
@override
57
- Future <String > getTemporaryPath () async {
56
+ Future <String ? > getTemporaryPath () async {
58
57
final buffer = allocate <Uint16 >(count: MAX_PATH + 1 ).cast <Utf16 >();
59
58
String path;
60
59
@@ -88,7 +87,7 @@ class PathProviderWindows extends PathProviderPlatform {
88
87
}
89
88
90
89
@override
91
- Future <String > getApplicationSupportPath () async {
90
+ Future <String ? > getApplicationSupportPath () async {
92
91
final appDataRoot = await getPath (WindowsKnownFolder .RoamingAppData );
93
92
final directory = Directory (
94
93
path.join (appDataRoot, _getApplicationSpecificSubdirectory ()));
@@ -105,25 +104,23 @@ class PathProviderWindows extends PathProviderPlatform {
105
104
}
106
105
107
106
@override
108
- Future <String > getApplicationDocumentsPath () =>
107
+ Future <String ? > getApplicationDocumentsPath () =>
109
108
getPath (WindowsKnownFolder .Documents );
110
109
111
110
@override
112
- Future <String > getDownloadsPath () => getPath (WindowsKnownFolder .Downloads );
111
+ Future <String ? > getDownloadsPath () => getPath (WindowsKnownFolder .Downloads );
113
112
114
113
/// Retrieve any known folder from Windows.
115
114
///
116
115
/// folderID is a GUID that represents a specific known folder ID, drawn from
117
116
/// [WindowsKnownFolder] .
118
117
Future <String > getPath (String folderID) {
119
- final pathPtrPtr = allocate <IntPtr >();
120
- Pointer <Utf16 > pathPtr ;
118
+ final pathPtrPtr = allocate <Pointer < Utf16 > >();
119
+ final Pointer <GUID > knownFolderID = calloc < GUID >().. setGUID (folderID) ;
121
120
122
121
try {
123
- GUID knownFolderID = GUID .fromString (folderID);
124
-
125
122
final hr = SHGetKnownFolderPath (
126
- knownFolderID.addressOf, // ignore: deprecated_member_use
123
+ knownFolderID,
127
124
KF_FLAG_DEFAULT ,
128
125
NULL ,
129
126
pathPtrPtr,
@@ -135,12 +132,11 @@ class PathProviderWindows extends PathProviderPlatform {
135
132
}
136
133
}
137
134
138
- pathPtr = Pointer <Utf16 >.fromAddress (pathPtrPtr.value);
139
- final path = pathPtr.unpackString (MAX_PATH );
135
+ final path = pathPtrPtr.value.unpackString (MAX_PATH );
140
136
return Future .value (path);
141
137
} finally {
142
- CoTaskMemFree (pathPtr.cast ());
143
138
free (pathPtrPtr);
139
+ free (knownFolderID);
144
140
}
145
141
}
146
142
@@ -155,13 +151,13 @@ class PathProviderWindows extends PathProviderPlatform {
155
151
/// - If the product name isn't there, it will use the exe's filename (without
156
152
/// extension).
157
153
String _getApplicationSpecificSubdirectory () {
158
- String companyName;
159
- String productName;
154
+ String ? companyName;
155
+ String ? productName;
160
156
161
157
final Pointer <Utf16 > moduleNameBuffer =
162
158
allocate <Uint16 >(count: MAX_PATH + 1 ).cast <Utf16 >();
163
159
final Pointer <Uint32 > unused = allocate <Uint32 >();
164
- Pointer <Uint8 > infoBuffer;
160
+ Pointer <Uint8 >? infoBuffer;
165
161
try {
166
162
// Get the module name.
167
163
final moduleNameLength = GetModuleFileName (0 , moduleNameBuffer, MAX_PATH );
@@ -207,7 +203,7 @@ class PathProviderWindows extends PathProviderPlatform {
207
203
/// https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions
208
204
///
209
205
/// If after sanitizing the string is empty, returns null.
210
- String _sanitizedDirectoryName (String rawString) {
206
+ String ? _sanitizedDirectoryName (String ? rawString) {
211
207
if (rawString == null ) {
212
208
return null ;
213
209
}
0 commit comments