Skip to content

Commit

Permalink
Path provider windows crash fix (flutter#3814)
Browse files Browse the repository at this point in the history
Failures to get a known folder that don't throw Windows exceptions need
to return null.

Fixes flutter/flutter#80712
  • Loading branch information
stuartmorgan authored and fotiDim committed Sep 13, 2021
1 parent 6c2ba0c commit c4e8235
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
4 changes: 4 additions & 0 deletions packages/path_provider/path_provider_windows/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.0.1

* Fix a crash when a known folder can't be located.

## 2.0.0

* Migrate to null safety
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ class PathProviderWindows extends PathProviderPlatform {

@override
Future<String?> getApplicationSupportPath() async {
final String appDataRoot = await getPath(WindowsKnownFolder.RoamingAppData);
final String? appDataRoot =
await getPath(WindowsKnownFolder.RoamingAppData);
if (appDataRoot == null) {
return null;
}
final Directory directory = Directory(
path.join(appDataRoot, _getApplicationSpecificSubdirectory()));
// Ensure that the directory exists if possible, since it will on other
Expand All @@ -114,7 +118,7 @@ class PathProviderWindows extends PathProviderPlatform {
///
/// folderID is a GUID that represents a specific known folder ID, drawn from
/// [WindowsKnownFolder].
Future<String> getPath(String folderID) {
Future<String?> getPath(String folderID) {
final Pointer<Pointer<Utf16>> pathPtrPtr = calloc<Pointer<Utf16>>();
final Pointer<GUID> knownFolderID = calloc<GUID>()..ref.setGUID(folderID);

Expand All @@ -130,6 +134,7 @@ class PathProviderWindows extends PathProviderPlatform {
if (hr == E_INVALIDARG || hr == E_FAIL) {
throw WindowsException(hr);
}
return Future<String?>.value(null);
}

final String path = pathPtrPtr.value.toDartString();
Expand Down
2 changes: 1 addition & 1 deletion packages/path_provider/path_provider_windows/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: path_provider_windows
description: Windows implementation of the path_provider plugin
homepage: https://github.com/flutter/plugins/tree/master/packages/path_provider/path_provider_windows
version: 2.0.0
version: 2.0.1

flutter:
plugin:
Expand Down

0 comments on commit c4e8235

Please sign in to comment.