1
- using System . IO ;
1
+ using System ;
2
+ using System . IO ;
2
3
using System . Threading . Tasks ;
3
4
using Flow . Launcher . Infrastructure . Logger ;
4
5
using Flow . Launcher . Infrastructure . UserSettings ;
@@ -40,6 +41,16 @@ public BinaryStorage(string filename)
40
41
FilePath = Path . Combine ( DirectoryPath , $ "{ filename } { FileSuffix } ") ;
41
42
}
42
43
44
+ // Let the old Program plugin get this constructor
45
+ [ Obsolete ( "This constructor is obsolete. Use BinaryStorage(string filename) instead." ) ]
46
+ public BinaryStorage ( string filename , string directoryPath = null ! )
47
+ {
48
+ directoryPath ??= DataLocation . CacheDirectory ;
49
+ FilesFolders . ValidateDirectory ( directoryPath ) ;
50
+
51
+ FilePath = Path . Combine ( directoryPath , $ "{ filename } { FileSuffix } ") ;
52
+ }
53
+
43
54
public async ValueTask < T > TryLoadAsync ( T defaultData )
44
55
{
45
56
if ( Data != null ) return Data ;
@@ -82,8 +93,10 @@ private static async ValueTask<T> DeserializeAsync(Stream stream, T defaultData)
82
93
83
94
public void Save ( )
84
95
{
85
- var serialized = MemoryPackSerializer . Serialize ( Data ) ;
96
+ // User may delete the directory, so we need to check it
97
+ FilesFolders . ValidateDirectory ( DirectoryPath ) ;
86
98
99
+ var serialized = MemoryPackSerializer . Serialize ( Data ) ;
87
100
File . WriteAllBytes ( FilePath , serialized ) ;
88
101
}
89
102
@@ -103,6 +116,9 @@ public void ClearData()
103
116
// so we need to pass it to SaveAsync
104
117
public async ValueTask SaveAsync ( T data )
105
118
{
119
+ // User may delete the directory, so we need to check it
120
+ FilesFolders . ValidateDirectory ( DirectoryPath ) ;
121
+
106
122
await using var stream = new FileStream ( FilePath , FileMode . Create ) ;
107
123
await MemoryPackSerializer . SerializeAsync ( stream , data ) ;
108
124
}
0 commit comments