Improve deprecation (adding some books that changed other the years)

Orionik [08-02-22 - 16:56]
Improve deprecation (adding some books that changed other the years)
Fix a crash when trying to read a book that the current character didn't know
Filename
Deprecation.lua
Librarian.lua
lang/en.lua
lang/fr.lua
diff --git a/Deprecation.lua b/Deprecation.lua
index 1a75a46..c2cfad3 100644
--- a/Deprecation.lua
+++ b/Deprecation.lua
@@ -148,6 +148,122 @@ function Librarian:GetBookIdWithTitle(title)
         return 3162
     elseif title == "The Year 2920, Vol. 28" then
         return 2945
+    elseif title == "Shrine of Mother Morrowind" then
+        return 4495
+    elseif title == "My Dearest Love" then
+        return 4115
+    elseif title == "Crafting Motif 69: Dead-Water Chest Pieces" then
+        return 5335
+    elseif title == "Crafting Motif 16: Glass Style" then
+        return 3174
+    elseif title == "Bravil,  Part 1" then
+        return 792
+    elseif title == "Tharayyas' Journal, Entry 10" then
+        return 1399
+    elseif title == "The True Nature of Orcs (Banned Ed.)" then
+        return 13
+    elseif title == "Guild Memo on Soul Trapping" then
+        return 240
+    elseif title == "Crafting Motif 15: Dwemer Chests" then -- Crafting Motif 15: Dwemer Chests Pieces
+        return 2861
+    elseif title == "Crafting Motif 15: Dwemer" then
+        return 2856
+    elseif title == "Crafting Motif 16: Glass Style" then
+        return 3174
+    elseif title == "Crafting Motif 37: Ebony Style" then
+        return 3592
+
+    elseif title == "Crafting Motif 51: Redoran Axes" then -- Crafting Motif 52
+        return 4649
+    elseif title == "Crafting Motif 51: Redoran Belts" then
+        return 4650
+    elseif title == "Crafting Motif 51: Redoran Boots" then
+        return 4651
+    elseif title == "Crafting Motif 51: Redoran Bows" then
+        return 4652
+    elseif title == "Crafting Motif 51: Redoran Chests" then
+        return 4653
+    elseif title == "Crafting Motif 51: Redoran Daggers" then
+        return 4654
+    elseif title == "Crafting Motif 51: Redoran Gloves" then
+        return 4655
+    elseif title == "Crafting Motif 51: Redoran Helmets" then
+        return 4656
+    elseif title == "Crafting Motif 51: Redoran Legs" then
+        return 4657
+    elseif title == "Crafting Motif 51: Redoran Maces" then
+        return 4658
+    elseif title == "Crafting Motif 51: Redoran Shields" then
+        return 4659
+    elseif title == "Crafting Motif 51: Redoran Shoulders" then
+        return 4660
+    elseif title == "Crafting Motif 51: Redoran Staves" then
+        return 4661
+    elseif title == "Crafting Motif 51: Redoran Swords" then
+        return 4662
+
+    elseif title == "Crafting Motif 52: Hlaalu Axes" then -- Crafting Motif 51
+        return 4633
+    elseif title == "Crafting Motif 52: Hlaalu Belts" then
+        return 4634
+    elseif title == "Crafting Motif 52: Hlaalu Boots" then
+        return 4635
+    elseif title == "Crafting Motif 52: Hlaalu Bows" then
+        return 4636
+    elseif title == "Crafting Motif 52: Hlaalu Chests" then
+        return 4637
+    elseif title == "Crafting Motif 52: Hlaalu Daggers" then
+        return 4638
+    elseif title == "Crafting Motif 52: Hlaalu Gloves" then
+        return 4639
+    elseif title == "Crafting Motif 52: Hlaalu Helmets" then
+        return 4640
+    elseif title == "Crafting Motif 52: Hlaalu Legs" then
+        return 4641
+    elseif title == "Crafting Motif 52: Hlaalu Maces" then
+        return 4642
+    elseif title == "Crafting Motif 52: Hlaalu Shields" then
+        return 4643
+    elseif title == "Crafting Motif 52: Hlaalu Shoulders" then
+        return 4644
+    elseif title == "Crafting Motif 52: Hlaalu Staves" then
+        return 4645
+    elseif title == "Crafting Motif 52: Hlaalu Swords" then
+        return 4646
+
+    elseif title == "Crafting Motif 56: Apostle Chest Pieces" then
+        return 4748
+    elseif title == "Crafting Motif 56: Apostle Shoulder Armor" then
+        return 4755
+
+    elseif title == "Crafting Motif 56: Ebonshadow Axes" then -- Crafting Motif 57
+        return 4774
+    elseif title == "Crafting Motif 56: Ebonshadow Belts" then
+        return 4775
+    elseif title == "Crafting Motif 56: Ebonshadow Boots" then
+        return 4776
+    elseif title == "Crafting Motif 56: Ebonshadow Bows" then
+        return 4777
+    elseif title == "Crafting Motif 56: Ebonshadow Chests" then
+        return 4778
+    elseif title == "Crafting Motif 56: Ebonshadow Daggers" then
+        return 4779
+    elseif title == "Crafting Motif 56: Ebonshadow Gloves" then
+        return 4780
+    elseif title == "Crafting Motif 56: Ebonshadow Helmets" then
+        return 4781
+    elseif title == "Crafting Motif 56: Ebonshadow Leg Greaves" then
+        return 4782
+    elseif title == "Crafting Motif 56: Ebonshadow Maces" then
+        return 4783
+    elseif title == "Crafting Motif 56: Ebonshadow Shields" then
+        return 4784
+    elseif title == "Crafting Motif 56: Ebonshadow Shoulders" then
+        return 4785
+    elseif title == "Crafting Motif 56: Ebonshadow Staves" then
+        return 4786
+    elseif title == "Crafting Motif 56: Ebonshadow Swords" then
+        return 4787
     end

     if not self.globalSavedVars.failedDeprecation then
@@ -222,6 +338,14 @@ function Librarian:UpdateSavedVariables()
                     book.showTitle = nil
                 else
                     book.bookId = self:GetBookIdWithTitle(book.title)
+
+                    local categoryIndex, collectionIndex, bookIndex = GetLoreBookIndicesFromBookId(book.bookId)
+                    if categoryIndex and collectionIndex and bookIndex then -- the deprecation found a valid book, so we can erase the content of this one as well
+                        book.title = nil
+                        book.body = nil
+                        book.medium = nil
+                        book.showTitle = nil
+                    end
                 end
                 book.wordCount = nil -- it will be computed when building the list (it will allow to switch language and this will still be acurate)
             end
@@ -276,6 +400,11 @@ function Librarian:UpdateSavedVariables()
                 characterBook.title = nil
             else
                 characterBook.bookId = self:GetBookIdWithTitle(characterBook.title)
+
+                local categoryIndex, collectionIndex, bookIndex = GetLoreBookIndicesFromBookId(characterBook.bookId)
+                if categoryIndex and collectionIndex and bookIndex then -- the deprecation found a valid book, so we can erase the content of this one as well
+                    characterBook.title = nil
+                end
             end
         end
     end
diff --git a/Librarian.lua b/Librarian.lua
index 3131422..8e8ed75 100644
--- a/Librarian.lua
+++ b/Librarian.lua
@@ -717,7 +717,13 @@ function Librarian:ReadBook(data)

     if data.categoryIndex and data.collectionIndex and data.bookIndex then
         local body, medium, showTitle = ReadLoreBook(data.categoryIndex, data.collectionIndex, data.bookIndex)
-        LORE_READER:SetupBook(data.title, body, medium, showTitle)
+        if medium ~= 0 then
+            LORE_READER:SetupBook(data.title, body, medium, showTitle)
+        else
+            d(GetString(LIBRARIAN_COULD_NOT_READ))
+            PlaySound(SOUNDS.GENERAL_ALERT_ERROR)
+            return
+        end
     else
         LORE_READER:SetupBook(data.title, data.body, data.medium, data.showTitle)
     end
diff --git a/lang/en.lua b/lang/en.lua
index 160e8ea..87bd1aa 100644
--- a/lang/en.lua
+++ b/lang/en.lua
@@ -24,6 +24,7 @@ local strings = {
     LIBRARIAN_GO_TO_CATEGORY = "Go to Category",
     LIBRARIAN_RELOAD_REMINDER = "ReloadUI suggested to update Librarian database.",
     LIBRARIAN_BACKUP_REMINDER = "Remember to backup your Librarian SavedVariables regularly.  Look up Librarian on ESOUI for instructions.",
+    LIBRARIAN_COULD_NOT_READ = "The current character doesn't know this book, you can't read it",

     -- Settings
     LIBRARIAN_SETTINGS_DISPLAY_NAME = "Librarian Book Manager",
diff --git a/lang/fr.lua b/lang/fr.lua
index 58bd7e4..3e0113d 100644
--- a/lang/fr.lua
+++ b/lang/fr.lua
@@ -21,6 +21,7 @@ SafeAddString(LIBRARIAN_NO_CATEGORY,								"Pas de catégorie", 1)
 SafeAddString(LIBRARIAN_GO_TO_CATEGORY,								"Ouvrir la catégorie", 1)
 SafeAddString(LIBRARIAN_RELOAD_REMINDER,							"ReloadUI conseillé pour mettre à jour les données de Librarian.", 1)
 SafeAddString(LIBRARIAN_BACKUP_REMINDER,							"Pensez à sauvegader les SaveVariables de Librarian régulièrement. Cherchez 'Librarian' sur ESOUI pour plus d'explications (en anglais).", 1)
+SafeAddString(LIBRARIAN_COULD_NOT_READ,							    "Ce personnage ne connait pas ce livre, impossible de le lire.", 1)

 SafeAddString(LIBRARIAN_SETTINGS_DISPLAY_NAME,						"Librarian (Gestionaire de livres)", 1)
 SafeAddString(LIBRARIAN_SETTINGS_TIME,								"Format d'heure", 1)