1- using System . IO ;
1+ using System ;
2+ using System . IO ;
23using System . Threading . Tasks ;
34using Flow . Launcher . Infrastructure . Logger ;
45using Flow . Launcher . Infrastructure . UserSettings ;
@@ -40,6 +41,16 @@ public BinaryStorage(string filename)
4041 FilePath = Path . Combine ( DirectoryPath , $ "{ filename } { FileSuffix } ") ;
4142 }
4243
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+
4354 public async ValueTask < T > TryLoadAsync ( T defaultData )
4455 {
4556 if ( Data != null ) return Data ;
@@ -82,8 +93,10 @@ private static async ValueTask<T> DeserializeAsync(Stream stream, T defaultData)
8293
8394 public void Save ( )
8495 {
85- var serialized = MemoryPackSerializer . Serialize ( Data ) ;
96+ // User may delete the directory, so we need to check it
97+ FilesFolders . ValidateDirectory ( DirectoryPath ) ;
8698
99+ var serialized = MemoryPackSerializer . Serialize ( Data ) ;
87100 File . WriteAllBytes ( FilePath , serialized ) ;
88101 }
89102
@@ -103,6 +116,9 @@ public void ClearData()
103116 // so we need to pass it to SaveAsync
104117 public async ValueTask SaveAsync ( T data )
105118 {
119+ // User may delete the directory, so we need to check it
120+ FilesFolders . ValidateDirectory ( DirectoryPath ) ;
121+
106122 await using var stream = new FileStream ( FilePath , FileMode . Create ) ;
107123 await MemoryPackSerializer . SerializeAsync ( stream , data ) ;
108124 }
0 commit comments