From fe86e23dead49655301f1608d1e7789b26b66e61 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Mon, 24 Feb 2025 16:11:49 +0800 Subject: [PATCH] Add exception handles --- Plugins/Flow.Launcher.Plugin.Program/Main.cs | 34 ++++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Program/Main.cs b/Plugins/Flow.Launcher.Plugin.Program/Main.cs index 6e1cdffb5..3be23214c 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Program/Main.cs @@ -193,26 +193,46 @@ namespace Flow.Launcher.Plugin.Program { Helper.ValidateDirectory(Context.CurrentPluginMetadata.PluginCacheDirectoryPath); - static bool MoveFile(string sourcePath, string destinationPath) + static void MoveFile(string sourcePath, string destinationPath) { if (!File.Exists(sourcePath)) { - return false; + return; } if (File.Exists(destinationPath)) { - File.Delete(sourcePath); - return false; + try + { + File.Delete(sourcePath); + } + catch (Exception) + { + // Ignore, we will handle next time we start the plugin + } + return; } var destinationDirectory = Path.GetDirectoryName(destinationPath); if (!Directory.Exists(destinationDirectory) && (!string.IsNullOrEmpty(destinationDirectory))) { - Directory.CreateDirectory(destinationDirectory); + try + { + Directory.CreateDirectory(destinationDirectory); + } + catch (Exception) + { + // Ignore, we will handle next time we start the plugin + } + } + try + { + File.Move(sourcePath, destinationPath); + } + catch (Exception) + { + // Ignore, we will handle next time we start the plugin } - File.Move(sourcePath, destinationPath); - return true; } // Move old cache files to the new cache directory