Skip to content

Commit c1c656f

Browse files
Added upgrade section to README.
1 parent 9ba925f commit c1c656f

1 file changed

Lines changed: 65 additions & 0 deletions

File tree

README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,71 @@ Then you can use `IFileSystemAccessService` to open one of the three dialogs ava
9797
}
9898
```
9999

100+
# Upgrade to version 4
101+
Version 4 of this library made several breaking changes. To make the transition from version 3 or earlier to this version easier, I have made a small guide below for how you can upgrade.
102+
## File/Directory picker options
103+
We changed the method signatures for opening the directory and file picker dialogs to make them simpler to use.
104+
105+
To migrate replace the following:
106+
- `OpenFilePickerOptionsStartInWellKnownDirectory` or `OpenFilePickerOptionsStartInFileSystemHandle` with `OpenFilePickerOptions`.
107+
- `SaveFilePickerOptionsStartInWellKnownDirectory` or `SaveFilePickerOptionsStartInFileSystemHandle` with `SaveFilePickerOptions`.
108+
- `DirectoryPickerOptionsStartInWellKnownDirectory` or `DirectoryPickerOptionsStartInFileSystemHandle` with `DirectoryPickerOptions`.
109+
110+
As an example, if you had the following before:
111+
```csharp
112+
OpenFilePickerOptionsStartInWellKnownDirectory options = new()
113+
{
114+
Multiple = false,
115+
StartIn = WellKnownDirectory.Downloads
116+
};
117+
var fileHandles = await FileSystemAccessService.ShowOpenFilePickerAsync(options);
118+
```
119+
Update it as follows:
120+
```csharp
121+
OpenFilePickerOptions options = new()
122+
{
123+
Multiple = false,
124+
StartIn = WellKnownDirectory.Downloads
125+
};
126+
var fileHandles = await FileSystemAccessService.ShowOpenFilePickerAsync(options);
127+
```
128+
129+
## Removed `FileSystemAccessOptions`
130+
We removed the `FileSystemAccessOptions` parameter and all methods that previously accepted it as it duplicated functionality that could be achived in other ways.
131+
132+
Instead of using them, you need to configure an [importmap](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/script/type/importmap) if you want to define custom paths for loading the helper modules from this library.
133+
134+
Blazor also has a native [ImportMap component](https://learn.microsoft.com/en-us/aspnet/core/blazor/fundamentals/static-files?view=aspnetcore-10.0#importmap-component) that that plays well with fingerprinted resources.
135+
136+
## Blazor.FileSystem removed `FileSystemDirectoryHandle.ValuesAsync`
137+
The `ValuesAsync` method was removed from Blazor.FileSystem, and instead you should now use the `ValuesAsync` extension method available from Blazor.WebIDL.
138+
139+
This change was made to make easier to handle memory safely.
140+
141+
So if you had the following before:
142+
```csharp
143+
var values = await directoryHandle.ValuesAsync();
144+
for (int i = 0; i < values.Count(); i++)
145+
{
146+
var value = values[i];
147+
string name = await value.GetNameAsync();
148+
FileSystemHandleKind kind = await value.GetKindAsync();
149+
Console.WriteLine($"'{name} is an {kind}'");
150+
await value.DisposeAsync();
151+
}
152+
```
153+
Then you should change it to the following:
154+
```csharp
155+
await using var valuesIterator = await directoryHandle.ValuesAsync(disposePreviousValueWhenMovingToNextValue: true);
156+
await foreach (FileSystemHandle value in valuesIterator)
157+
{
158+
string name = await value.GetNameAsync();
159+
FileSystemHandleKind kind = await value.GetKindAsync();
160+
Console.WriteLine($"'{name} is an {kind}'");
161+
}
162+
```
163+
In the above example, we pass `true` for the `disposePreviousValueWhenMovingToNextValue` parameter, which is also the default. This means that it will dispose of each handle once it iterates past it. If you need the handles after iterating, you can pass `false` for this parameter instead.
164+
100165
# Issues
101166
Feel free to open issues on the repository if you find any errors with the package or have wishes for features.
102167

0 commit comments

Comments
 (0)