|
1 | 1 | using System;
|
2 | 2 | using System.Collections.Generic;
|
3 | 3 | using System.Diagnostics;
|
| 4 | +using System.IO; |
4 | 5 | using System.Linq;
|
5 | 6 | using System.Threading;
|
6 | 7 | using System.Threading.Tasks;
|
7 | 8 | using System.Windows.Controls;
|
| 9 | +using Flow.Launcher.Infrastructure; |
8 | 10 | using Flow.Launcher.Infrastructure.Logger;
|
9 | 11 | using Flow.Launcher.Infrastructure.Storage;
|
| 12 | +using Flow.Launcher.Infrastructure.UserSettings; |
10 | 13 | using Flow.Launcher.Plugin.Program.Programs;
|
11 | 14 | using Flow.Launcher.Plugin.Program.Views;
|
12 | 15 | using Flow.Launcher.Plugin.Program.Views.Models;
|
@@ -188,9 +191,41 @@ public async Task InitAsync(PluginInitContext context)
|
188 | 191 |
|
189 | 192 | await Stopwatch.NormalAsync("|Flow.Launcher.Plugin.Program.Main|Preload programs cost", async () =>
|
190 | 193 | {
|
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); |
192 | 227 | _win32s = await _win32Storage.TryLoadAsync(Array.Empty<Win32>());
|
193 |
| - _uwpStorage = new BinaryStorage<UWPApp[]>("UWP"); |
| 228 | + _uwpStorage = new BinaryStorage<UWPApp[]>("UWP", Context.CurrentPluginMetadata.PluginCacheDirectoryPath); |
194 | 229 | _uwps = await _uwpStorage.TryLoadAsync(Array.Empty<UWPApp>());
|
195 | 230 | });
|
196 | 231 | Log.Info($"|Flow.Launcher.Plugin.Program.Main|Number of preload win32 programs <{_win32s.Length}>");
|
|
0 commit comments