Skip to content

Commit c4cbf94

Browse files
committed
Add directory null check
1 parent 9be2ef0 commit c4cbf94

File tree

1 file changed

+11
-9
lines changed
  • Plugins/Flow.Launcher.Plugin.Program

1 file changed

+11
-9
lines changed

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -237,15 +237,17 @@ static void MoveFile(string sourcePath, string destinationPath)
237237
// then the parent directory is: D:\\Data\\Cache
238238
// So we can use the parent of the parent directory to get the cache directory path
239239
var directoryInfo = new DirectoryInfo(pluginCacheDirectory);
240-
var cacheDirectory = directoryInfo.Parent.Parent.FullName;
241-
242-
// Move old cache files to the new cache directory
243-
var oldWin32CacheFile = Path.Combine(cacheDirectory, $"{Win32CacheName}.cache");
244-
var newWin32CacheFile = Path.Combine(pluginCacheDirectory, $"{Win32CacheName}.cache");
245-
MoveFile(oldWin32CacheFile, newWin32CacheFile);
246-
var oldUWPCacheFile = Path.Combine(cacheDirectory, $"{UwpCacheName}.cache");
247-
var newUWPCacheFile = Path.Combine(pluginCacheDirectory, $"{UwpCacheName}.cache");
248-
MoveFile(oldUWPCacheFile, newUWPCacheFile);
240+
var cacheDirectory = directoryInfo.Parent?.Parent?.FullName;
241+
// Move old cache files to the new cache directory if cache directory exists
242+
if (!string.IsNullOrEmpty(cacheDirectory))
243+
{
244+
var oldWin32CacheFile = Path.Combine(cacheDirectory, $"{Win32CacheName}.cache");
245+
var newWin32CacheFile = Path.Combine(pluginCacheDirectory, $"{Win32CacheName}.cache");
246+
MoveFile(oldWin32CacheFile, newWin32CacheFile);
247+
var oldUWPCacheFile = Path.Combine(cacheDirectory, $"{UwpCacheName}.cache");
248+
var newUWPCacheFile = Path.Combine(pluginCacheDirectory, $"{UwpCacheName}.cache");
249+
MoveFile(oldUWPCacheFile, newUWPCacheFile);
250+
}
249251

250252
await _win32sLock.WaitAsync();
251253
_win32s = await context.API.LoadCacheBinaryStorageAsync(Win32CacheName, pluginCacheDirectory, new List<Win32>());

0 commit comments

Comments
 (0)