Cartographer_Data = {}

local Cartographer_Data = Cartographer_Data
local _G = getfenv(0)

local treasure_icon = {}

local RegisterNotesDatabaseOLD = Cartographer_Notes.RegisterNotesDatabase
function RegisterNotesDatabaseNEW(Cartographer_Notes, name, db, ...)
	local cd_db = Cartographer_Data[name]
	if cd_db and ( (db.version and tonumber(string.match(db.version, '%d+')) or 0) < tonumber(string.match(cd_db.version, '%d+'))) then
		db = cd_db
		if name == "Treasure" then
			-- Fix Icon's for Treasure
			for k,v in pairs(db) do
				if type(v) == "table" then
					for pos,name in pairs(v) do
						if type(name) == "string" then
							local icon = treasure_icon[name] or Cartographer_Treasure and Cartographer_Treasure:getIcon(name)
							treasure_icon[name] = icon
							v[pos] = { ["title"] = name, ["icon"] = icon }
						end
					end
				end
			end
		end
		Cartographer_Data[name] = nil
		_G["Cartographer_"..name.."DB"] = db
	end
	RegisterNotesDatabaseOLD(Cartographer_Notes, name, db, ...)
end
Cartographer_Notes.RegisterNotesDatabase = RegisterNotesDatabaseNEW
