/trunk/TipTop/libs/LibSharedMedia-3.0
--[[ |
Name: LibSharedMedia-3.0 |
Revision: $Revision: 91 $ |
Revision: $Revision: 113 $ |
Author: Elkano (elkano@gmx.de) |
Inspired By: SurfaceLib by Haste/Otravi (troeks@gmail.com) |
Website: http://www.wowace.com/projects/libsharedmedia-3-0/ |
License: LGPL v2.1 |
]] |
local MAJOR, MINOR = "LibSharedMedia-3.0", 6010002 -- 6.1.0 v2 / increase manually on changes |
local MAJOR, MINOR = "LibSharedMedia-3.0", 8020002 -- 8.2.0 v2 / increase manually on changes |
local lib = LibStub:NewLibrary(MAJOR, MINOR) |
if not lib then return end |
local type = _G.type |
local band = _G.bit.band |
local table_insert = _G.table.insert |
local table_sort = _G.table.sort |
local RESTRICTED_FILE_ACCESS = not not C_RaidLocks -- starting with 8.2, some rules for file access have changed; classic still uses the old way |
local locale = GetLocale() |
local locale_is_western |
local LOCALE_MASK = 0 |
lib.MediaTable.statusbar["Blizzard"] = [[Interface\TargetingFrame\UI-StatusBar]] |
lib.MediaTable.statusbar["Blizzard Character Skills Bar"] = [[Interface\PaperDollInfoFrame\UI-Character-Skills-Bar]] |
lib.MediaTable.statusbar["Blizzard Raid Bar"] = [[Interface\RaidFrame\Raid-Bar-Hp-Fill]] |
lib.MediaTable.statusbar["Solid"] = [[Interface\Buttons\WHITE8X8]] |
lib.DefaultMedia.statusbar = "Blizzard" |
-- SOUND |
if not lib.MediaTable.sound then lib.MediaTable.sound = {} end |
lib.MediaTable.sound["None"] = [[Interface\Quiet.ogg]] -- Relies on the fact that PlaySound[File] doesn't error on non-existing input. |
lib.MediaTable.sound["None"] = RESTRICTED_FILE_ACCESS and 1 or [[Interface\Quiet.ogg]] -- Relies on the fact that PlaySound[File] doesn't error on these values. |
lib.DefaultMedia.sound = "None" |
local function rebuildMediaList(mediatype) |
error(MAJOR..":Register(mediatype, key, data, langmask) - key must be string, got "..type(key)) |
end |
mediatype = mediatype:lower() |
if mediatype == lib.MediaType.FONT and ((langmask and band(langmask, LOCALE_MASK) == 0) or not (langmask or locale_is_western)) then return false end |
if mediatype == lib.MediaType.SOUND and type(data) == "string" then |
if mediatype == lib.MediaType.FONT and ((langmask and band(langmask, LOCALE_MASK) == 0) or not (langmask or locale_is_western)) then |
-- ignore fonts that aren't flagged as supporting local glyphs on non-western clients |
return false |
end |
if type(data) == "string" and (mediatype == lib.MediaType.BACKGROUND or mediatype == lib.MediaType.BORDER or mediatype == lib.MediaType.STATUSBAR or mediatype == lib.MediaType.SOUND) then |
local path = data:lower() |
-- Only ogg and mp3 are valid sounds. |
if not path:find(".ogg", nil, true) and not path:find(".mp3", nil, true) then |
if RESTRICTED_FILE_ACCESS and not path:find("^interface") then |
-- files accessed via path only allowed from interface folder |
return false |
end |
if mediatype == lib.MediaType.SOUND and not (path:find(".ogg", nil, true) or not path:find(".mp3", nil, true)) then |
-- Only ogg and mp3 are valid sounds. |
return false |
end |
end |
if not mediaTable[mediatype] then mediaTable[mediatype] = {} end |
local mtable = mediaTable[mediatype] |
if mtable[key] then return false end |
mtable[key] = data |
rebuildMediaList(mediatype) |
self.callbacks:Fire("LibSharedMedia_Registered", mediatype, key) |