From 37d027937ff15d041750dcafe958656820024afb Mon Sep 17 00:00:00 2001 From: philenius Date: Thu, 30 Mar 2023 23:09:39 +0200 Subject: [PATCH 1/4] change white checkmarks to green ones --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f44001bd..e603027e 100644 --- a/README.md +++ b/README.md @@ -37,10 +37,10 @@ If you have any feature that you want to see in this package, please feel free t | API | Android | iOS | Linux | macOS | Windows | Web | | --------------------- | ------------------ | ------------------ | ------------------ | ------------------ | ------------------ | ------------------ | -| clearTemporaryFiles() | :white_check_mark: | :white_check_mark: | :x: | :x: | :x: | :x: | -| getDirectoryPath() | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | -| pickFiles() | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| saveFile() | :x: | :x: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | +| clearTemporaryFiles() | :heavy_check_mark: | :heavy_check_mark: | :x: | :x: | :x: | :x: | +| getDirectoryPath() | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :x: | +| pickFiles() | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | +| saveFile() | :x: | :x: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :x: | See the [API section of the File Picker Wiki](https://github.com/miguelpruivo/flutter_file_picker/wiki/api) or the [official API reference on pub.dev](https://pub.dev/documentation/file_picker/latest/file_picker/FilePicker-class.html) for further details. From 6dc9d8929d469b9ddd4b2bf6e87611c7597e38db Mon Sep 17 00:00:00 2001 From: philenius Date: Thu, 30 Mar 2023 23:09:48 +0200 Subject: [PATCH 2/4] remove duplicate Flutter setup --- .github/workflows/main.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 051689ee..2c19035a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,7 +18,6 @@ jobs: steps: - uses: actions/checkout@v3 - - uses: subosito/flutter-action@v1 - uses: subosito/flutter-action@v2 with: channel: 'stable' From 3c7a50e8fd6fcfd9b4c00b311e43b705563cbb08 Mon Sep 17 00:00:00 2001 From: philenius Date: Thu, 30 Mar 2023 23:11:23 +0200 Subject: [PATCH 3/4] add overwrite prompt for saveFile() on Windows --- lib/src/windows/file_picker_windows.dart | 56 +++++++++++-------- .../file_picker_windows_ffi_types.dart | 3 + 2 files changed, 35 insertions(+), 24 deletions(-) diff --git a/lib/src/windows/file_picker_windows.dart b/lib/src/windows/file_picker_windows.dart index d567c58b..6d9983cd 100644 --- a/lib/src/windows/file_picker_windows.dart +++ b/lib/src/windows/file_picker_windows.dart @@ -67,8 +67,8 @@ class FilePickerWindows extends FilePicker { final comdlg32 = DynamicLibrary.open('comdlg32.dll'); final getOpenFileNameW = - comdlg32.lookupFunction( - 'GetOpenFileNameW'); + comdlg32.lookupFunction( + 'GetOpenFileNameW'); final Pointer openFileNameW = _instantiateOpenFileNameW( allowMultiple: allowMultiple, @@ -184,13 +184,15 @@ class FilePickerWindows extends FilePicker { await Isolate.spawn( _callSaveFile, _OpenSaveFileArgs( - port: port.sendPort, - fileName: fileName, - dialogTitle: dialogTitle, - initialDirectory: initialDirectory, - type: type, - allowedExtensions: allowedExtensions, - lockParentWindow: lockParentWindow)); + port: port.sendPort, + fileName: fileName, + dialogTitle: dialogTitle, + initialDirectory: initialDirectory, + type: type, + allowedExtensions: allowedExtensions, + lockParentWindow: lockParentWindow, + confirmOverwrite: true, + )); return (await port.first) as String?; } @@ -205,8 +207,8 @@ class FilePickerWindows extends FilePicker { final comdlg32 = DynamicLibrary.open('comdlg32.dll'); final getSaveFileNameW = - comdlg32.lookupFunction( - 'GetSaveFileNameW'); + comdlg32.lookupFunction( + 'GetSaveFileNameW'); final Pointer openFileNameW = _instantiateOpenFileNameW( allowedExtensions: allowedExtensions, @@ -310,6 +312,7 @@ class FilePickerWindows extends FilePicker { List? allowedExtensions, FileType type = FileType.any, bool lockParentWindow = false, + bool confirmOverwrite = false, }) { final lpstrFileBufferSize = 8192 * maximumPathLength; final Pointer openFileNameW = calloc(); @@ -333,6 +336,10 @@ class FilePickerWindows extends FilePicker { openFileNameW.ref.flags |= ofnAllowMultiSelect; } + if (confirmOverwrite) { + openFileNameW.ref.flags |= ofnOverwritePrompt; + } + if (defaultFileName != null) { validateFileName(defaultFileName); @@ -373,7 +380,6 @@ class FilePickerWindows extends FilePicker { calloc.free(openFileNameW); } - static void _callPickFiles(_OpenSaveFileArgs args) { final impl = FilePickerWindows(); args.port.send(impl._pickFiles( @@ -396,7 +402,6 @@ class FilePickerWindows extends FilePicker { allowedExtensions: args.allowedExtensions, lockParentWindow: args.lockParentWindow)); } - } class _OpenSaveFileArgs { @@ -409,15 +414,18 @@ class _OpenSaveFileArgs { final bool allowCompression; final bool allowMultiple; final bool lockParentWindow; - - _OpenSaveFileArgs( - {required this.port, - this.dialogTitle, - this.fileName, - this.initialDirectory, - this.type = FileType.any, - this.allowedExtensions, - this.allowCompression = true, - this.allowMultiple = false, - this.lockParentWindow = false}); + final bool confirmOverwrite; + + _OpenSaveFileArgs({ + required this.port, + this.dialogTitle, + this.fileName, + this.initialDirectory, + this.type = FileType.any, + this.allowedExtensions, + this.allowCompression = true, + this.allowMultiple = false, + this.lockParentWindow = false, + this.confirmOverwrite = false, + }); } diff --git a/lib/src/windows/file_picker_windows_ffi_types.dart b/lib/src/windows/file_picker_windows_ffi_types.dart index d8d6d263..1e6bb432 100644 --- a/lib/src/windows/file_picker_windows_ffi_types.dart +++ b/lib/src/windows/file_picker_windows_ffi_types.dart @@ -219,3 +219,6 @@ const ofnFileMustExist = 0x00001000; /// Hides the Read Only check box. const ofnHideReadOnly = 0x00000004; + +/// Causes the Save As dialog box to generate a message box if the selected file already exists. The user must confirm whether to overwrite the file. +const ofnOverwritePrompt = 0x00000002; From a314b5bb79ae238f932615c71672a55a69951217 Mon Sep 17 00:00:00 2001 From: philenius Date: Thu, 30 Mar 2023 23:27:25 +0200 Subject: [PATCH 4/4] update changelog and bump version to 5.2.7 --- CHANGELOG.md | 4 ++++ pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e3ca047d..b5d15b2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 5.2.7 +### Desktop (Windows) +Fixes the behavior of the `saveFile()` dialog on Windows. Now, when the user selects an already existing file, then Windows prompts the user to confirm overwriting this file. This change makes the dialog behave the same on all desktop platforms (macOS, Linux, and Windows). Previously, Windows would not have asked the user for confirmation ([#989](https://github.com/miguelpruivo/flutter_file_picker/issues/989)). + ## 5.2.6 ### Web - Increase time to wait on js result diff --git a/pubspec.yaml b/pubspec.yaml index 329f0311..8c391577 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,7 +3,7 @@ description: A package that allows you to use a native file explorer to pick sin homepage: https://github.com/miguelpruivo/plugins_flutter_file_picker repository: https://github.com/miguelpruivo/flutter_file_picker issue_tracker: https://github.com/miguelpruivo/flutter_file_picker/issues -version: 5.2.6 +version: 5.2.7 dependencies: flutter: