Skip to content

Commit a0c2a42

Browse files
committed
Let Program plugin use plugin cache path
1 parent 47adfd1 commit a0c2a42

File tree

1 file changed

+37
-2
lines changed
  • Plugins/Flow.Launcher.Plugin.Program

1 file changed

+37
-2
lines changed

Plugins/Flow.Launcher.Plugin.Program/Main.cs

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Diagnostics;
4+
using System.IO;
45
using System.Linq;
56
using System.Threading;
67
using System.Threading.Tasks;
78
using System.Windows.Controls;
9+
using Flow.Launcher.Infrastructure;
810
using Flow.Launcher.Infrastructure.Logger;
911
using Flow.Launcher.Infrastructure.Storage;
12+
using Flow.Launcher.Infrastructure.UserSettings;
1013
using Flow.Launcher.Plugin.Program.Programs;
1114
using Flow.Launcher.Plugin.Program.Views;
1215
using Flow.Launcher.Plugin.Program.Views.Models;
@@ -188,9 +191,41 @@ public async Task InitAsync(PluginInitContext context)
188191

189192
await Stopwatch.NormalAsync("|Flow.Launcher.Plugin.Program.Main|Preload programs cost", async () =>
190193
{
191-
_win32Storage = new BinaryStorage<Win32[]>("Win32");
194+
Helper.ValidateDirectory(Context.CurrentPluginMetadata.PluginCacheDirectoryPath);
195+
196+
static bool MoveFile(string sourcePath, string destinationPath)
197+
{
198+
if (!File.Exists(sourcePath))
199+
{
200+
return false;
201+
}
202+
203+
if (File.Exists(destinationPath))
204+
{
205+
File.Delete(sourcePath);
206+
return false;
207+
}
208+
209+
var destinationDirectory = Path.GetDirectoryName(destinationPath);
210+
if (!Directory.Exists(destinationDirectory) && (!string.IsNullOrEmpty(destinationDirectory)))
211+
{
212+
Directory.CreateDirectory(destinationDirectory);
213+
}
214+
File.Move(sourcePath, destinationPath);
215+
return true;
216+
}
217+
218+
// Move old cache files to the new cache directory
219+
var oldWin32CacheFile = Path.Combine(DataLocation.CacheDirectory, $"Win32.cache");
220+
var newWin32CacheFile = Path.Combine(Context.CurrentPluginMetadata.PluginCacheDirectoryPath, $"Win32.cache");
221+
MoveFile(oldWin32CacheFile, newWin32CacheFile);
222+
var oldUWPCacheFile = Path.Combine(DataLocation.CacheDirectory, $"UWP.cache");
223+
var newUWPCacheFile = Path.Combine(Context.CurrentPluginMetadata.PluginCacheDirectoryPath, $"UWP.cache");
224+
MoveFile(oldUWPCacheFile, newUWPCacheFile);
225+
226+
_win32Storage = new BinaryStorage<Win32[]>("Win32", Context.CurrentPluginMetadata.PluginCacheDirectoryPath);
192227
_win32s = await _win32Storage.TryLoadAsync(Array.Empty<Win32>());
193-
_uwpStorage = new BinaryStorage<UWPApp[]>("UWP");
228+
_uwpStorage = new BinaryStorage<UWPApp[]>("UWP", Context.CurrentPluginMetadata.PluginCacheDirectoryPath);
194229
_uwps = await _uwpStorage.TryLoadAsync(Array.Empty<UWPApp>());
195230
});
196231
Log.Info($"|Flow.Launcher.Plugin.Program.Main|Number of preload win32 programs <{_win32s.Length}>");

0 commit comments

Comments
 (0)