1
- using System ;
2
- using System . IO ;
3
- using System . Reflection ;
4
- using System . Runtime . Serialization ;
5
- using System . Runtime . Serialization . Formatters ;
6
- using System . Runtime . Serialization . Formatters . Binary ;
1
+ using System . IO ;
7
2
using System . Threading . Tasks ;
8
3
using Flow . Launcher . Infrastructure . Logger ;
9
4
using Flow . Launcher . Infrastructure . UserSettings ;
@@ -16,18 +11,16 @@ namespace Flow.Launcher.Infrastructure.Storage
16
11
/// Normally, it has better performance, but not readable
17
12
/// </summary>
18
13
/// <remarks>
19
- /// It utilize MemoryPack, which means the object must be MemoryPackSerializable
20
- /// https://github.com/Cysharp/MemoryPack
14
+ /// It utilize MemoryPack, which means the object must be MemoryPackSerializable <see href="https://github.com/Cysharp/MemoryPack"/>
21
15
/// </remarks>
22
16
public class BinaryStorage < T >
23
17
{
24
- const string DirectoryName = Constant . Cache ;
18
+ public const string FileSuffix = ".cache" ;
25
19
26
- const string FileSuffix = ".cache" ;
27
-
28
- public BinaryStorage ( string filename )
20
+ // Let the derived class to set the file path
21
+ public BinaryStorage ( string filename , string directoryPath = null )
29
22
{
30
- var directoryPath = Path . Combine ( DataLocation . DataDirectory ( ) , DirectoryName ) ;
23
+ directoryPath ??= DataLocation . CacheDirectory ;
31
24
Helper . ValidateDirectory ( directoryPath ) ;
32
25
33
26
FilePath = Path . Combine ( directoryPath , $ "{ filename } { FileSuffix } ") ;
@@ -58,14 +51,14 @@ public async ValueTask<T> TryLoadAsync(T defaultData)
58
51
}
59
52
}
60
53
61
- private async ValueTask < T > DeserializeAsync ( Stream stream , T defaultData )
54
+ private static async ValueTask < T > DeserializeAsync ( Stream stream , T defaultData )
62
55
{
63
56
try
64
57
{
65
58
var t = await MemoryPackSerializer . DeserializeAsync < T > ( stream ) ;
66
59
return t ;
67
60
}
68
- catch ( System . Exception e )
61
+ catch ( System . Exception )
69
62
{
70
63
// Log.Exception($"|BinaryStorage.Deserialize|Deserialize error for file <{FilePath}>", e);
71
64
return defaultData ;
0 commit comments