From 5cdc687f6dc74307f22ee734e8c69658882ad2e4 Mon Sep 17 00:00:00 2001 From: "DESKTOP-T0O5CDB\\DESK-555BD" Date: Mon, 4 Nov 2024 09:51:50 -0700 Subject: [PATCH] backup widgets and further enhance the cleanup api method. --- Helper/FileHelper.cs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Helper/FileHelper.cs b/Helper/FileHelper.cs index 313074e..e62aaa2 100644 --- a/Helper/FileHelper.cs +++ b/Helper/FileHelper.cs @@ -104,6 +104,7 @@ namespace CarCareTracker.Helper var documentPath = Path.Combine(tempPath, "documents"); var translationPath = Path.Combine(tempPath, "translations"); var dataPath = Path.Combine(tempPath, StaticHelper.DbName); + var widgetPath = Path.Combine(tempPath, StaticHelper.AdditionalWidgetsPath); var configPath = Path.Combine(tempPath, StaticHelper.UserConfigPath); if (Directory.Exists(imagePath)) { @@ -178,6 +179,10 @@ namespace CarCareTracker.Helper //data path will always exist as it is created on startup if not. File.Move(dataPath, StaticHelper.DbName, true); } + if (File.Exists(widgetPath)) + { + File.Move(widgetPath, StaticHelper.AdditionalWidgetsPath, true); + } if (File.Exists(configPath)) { //check if config folder exists. @@ -227,6 +232,7 @@ namespace CarCareTracker.Helper var documentPath = Path.Combine(_webEnv.WebRootPath, "documents"); var translationPath = Path.Combine(_webEnv.WebRootPath, "translations"); var dataPath = StaticHelper.DbName; + var widgetPath = StaticHelper.AdditionalWidgetsPath; var configPath = StaticHelper.UserConfigPath; if (!Directory.Exists(tempPath)) Directory.CreateDirectory(tempPath); @@ -266,6 +272,12 @@ namespace CarCareTracker.Helper Directory.CreateDirectory(newPath); File.Copy(dataPath, $"{newPath}/{Path.GetFileName(dataPath)}"); } + if (File.Exists(widgetPath)) + { + var newPath = Path.Combine(tempPath, "data"); + Directory.CreateDirectory(newPath); + File.Copy(widgetPath, $"{newPath}/{Path.GetFileName(widgetPath)}"); + } if (File.Exists(configPath)) { var newPath = Path.Combine(tempPath, "config"); @@ -327,12 +339,20 @@ namespace CarCareTracker.Helper var tempPath = GetFullFilePath("temp", false); if (Directory.Exists(tempPath)) { + //delete files var files = Directory.GetFiles(tempPath); foreach (var file in files) { File.Delete(file); filesDeleted++; } + //delete folders + var folders = Directory.GetDirectories(tempPath); + foreach(var folder in folders) + { + Directory.Delete(folder, true); + filesDeleted++; + } } return filesDeleted; }