From e40c4999b6d18deab2bf98a60cd9cf5d1ac2b198 Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Fri, 26 Apr 2024 10:56:36 +0200 Subject: [PATCH] Improve collection migration maybe. --- .../Collections/Manager/CollectionStorage.cs | 30 +++++++++++++++---- .../Manager/ModCollectionMigration.cs | 2 -- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/Penumbra/Collections/Manager/CollectionStorage.cs b/Penumbra/Collections/Manager/CollectionStorage.cs index 4e2fb7b7..1fe5b227 100644 --- a/Penumbra/Collections/Manager/CollectionStorage.cs +++ b/Penumbra/Collections/Manager/CollectionStorage.cs @@ -184,21 +184,39 @@ public class CollectionStorage : IReadOnlyList, IDisposable { if (version >= 2) { - File.Move(file.FullName, correctName, false); - Penumbra.Messager.NotificationMessage($"Collection {file.Name} does not correspond to {collection.Identifier}, renamed.", - NotificationType.Warning); + try + { + File.Move(file.FullName, correctName, false); + Penumbra.Messager.NotificationMessage( + $"Collection {file.Name} does not correspond to {collection.Identifier}, renamed.", + NotificationType.Warning); + } + catch (Exception ex) + { + Penumbra.Messager.NotificationMessage( + $"Collection {file.Name} does not correspond to {collection.Identifier}, rename failed:\n{ex}", + NotificationType.Warning); + } } else { _saveService.ImmediateSaveSync(new ModCollectionSave(_modStorage, collection)); - File.Delete(file.FullName); - Penumbra.Log.Information($"Migrated collection {name} to Guid {id}."); + try + { + File.Move(file.FullName, file.FullName + ".bak", true); + Penumbra.Log.Information($"Migrated collection {name} to Guid {id} with backup of old file."); + } + catch (Exception ex) + { + Penumbra.Log.Information($"Migrated collection {name} to Guid {id}, rename of old file failed:\n{ex}"); + } } } catch (Exception e) { Penumbra.Messager.NotificationMessage(e, - $"Collection {file.Name} does not correspond to {collection.Identifier}, but could not rename.", NotificationType.Error); + $"Collection {file.Name} does not correspond to {collection.Identifier}, but could not rename.", + NotificationType.Error); } _collections.Add(collection); diff --git a/Penumbra/Collections/Manager/ModCollectionMigration.cs b/Penumbra/Collections/Manager/ModCollectionMigration.cs index 89743aa2..fe61285d 100644 --- a/Penumbra/Collections/Manager/ModCollectionMigration.cs +++ b/Penumbra/Collections/Manager/ModCollectionMigration.cs @@ -1,8 +1,6 @@ -using Penumbra.Mods; using Penumbra.Mods.Manager; using Penumbra.Mods.Settings; using Penumbra.Services; -using Penumbra.Util; namespace Penumbra.Collections.Manager;