Skip to content

Commit 47adfd1

Browse files
committed
Improve code quality
1 parent 58de625 commit 47adfd1

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

Flow.Launcher.Infrastructure/Storage/BinaryStorage.cs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
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;
72
using System.Threading.Tasks;
83
using Flow.Launcher.Infrastructure.Logger;
94
using Flow.Launcher.Infrastructure.UserSettings;
@@ -16,18 +11,16 @@ namespace Flow.Launcher.Infrastructure.Storage
1611
/// Normally, it has better performance, but not readable
1712
/// </summary>
1813
/// <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"/>
2115
/// </remarks>
2216
public class BinaryStorage<T>
2317
{
24-
const string DirectoryName = Constant.Cache;
18+
public const string FileSuffix = ".cache";
2519

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)
2922
{
30-
var directoryPath = Path.Combine(DataLocation.DataDirectory(), DirectoryName);
23+
directoryPath ??= DataLocation.CacheDirectory;
3124
Helper.ValidateDirectory(directoryPath);
3225

3326
FilePath = Path.Combine(directoryPath, $"{filename}{FileSuffix}");
@@ -58,14 +51,14 @@ public async ValueTask<T> TryLoadAsync(T defaultData)
5851
}
5952
}
6053

61-
private async ValueTask<T> DeserializeAsync(Stream stream, T defaultData)
54+
private static async ValueTask<T> DeserializeAsync(Stream stream, T defaultData)
6255
{
6356
try
6457
{
6558
var t = await MemoryPackSerializer.DeserializeAsync<T>(stream);
6659
return t;
6760
}
68-
catch (System.Exception e)
61+
catch (System.Exception)
6962
{
7063
// Log.Exception($"|BinaryStorage.Deserialize|Deserialize error for file <{FilePath}>", e);
7164
return defaultData;

Flow.Launcher.Infrastructure/UserSettings/DataLocation.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public static bool PortableDataLocationInUse()
2828
public static string VersionLogDirectory => Path.Combine(LogDirectory, Constant.Version);
2929
public static string LogDirectory => Path.Combine(DataDirectory(), Constant.Logs);
3030

31+
public static readonly string CacheDirectory = Path.Combine(DataDirectory(), Constant.Cache);
3132
public static readonly string SettingsDirectorty = Path.Combine(DataDirectory(), Constant.Settings);
3233
public static readonly string PluginsDirectory = Path.Combine(DataDirectory(), Constant.Plugins);
3334
public static readonly string ThemesDirectory = Path.Combine(DataDirectory(), Constant.Themes);

0 commit comments

Comments
 (0)