Ports "Fix bicon(icon2html) showing full dmis, fix asset cache hashes being incorrect." (#13347)

This commit is contained in:
Letter N
2020-09-06 15:23:28 +08:00
committed by GitHub
parent 8b59b4a80d
commit fd2ec66757
3 changed files with 33 additions and 10 deletions

View File

@@ -71,3 +71,18 @@
/proc/pathflatten(path)
return replacetext(path, "/", "_")
/// Returns the md5 of a file at a given path.
/proc/md5filepath(path)
. = md5(file(path))
/// Save file as an external file then md5 it.
/// Used because md5ing files stored in the rsc sometimes gives incorrect md5 results.
/proc/md5asfile(file)
var/static/notch = 0
// its importaint this code can handle md5filepath sleeping instead of hard blocking, if it's converted to use rust_g.
var/filename = "tmp/md5asfile.[world.realtime].[world.timeofday].[world.time].[world.tick_usage].[notch]"
notch = WRAP(notch+1, 0, 2^15)
fcopy(file, filename)
. = md5filepath(filename)
fdel(filename)

View File

@@ -1126,12 +1126,13 @@ GLOBAL_DATUM_INIT(dummySave, /savefile, new("tmp/dummySave.sav")) //Cache of ico
var/list/partial = splittext(iconData, "{")
return replacetext(copytext_char(partial[2], 3, -5), "\n", "")
/proc/icon2html(thing, target, icon_state, dir, frame = 1, moving = FALSE)
/proc/icon2html(thing, target, icon_state, dir = SOUTH, frame = 1, moving = FALSE, sourceonly = FALSE)
if (!thing)
return
var/key
var/icon/I = thing
if (!target)
return
if (target == world)
@@ -1147,17 +1148,26 @@ GLOBAL_DATUM_INIT(dummySave, /savefile, new("tmp/dummySave.sav")) //Cache of ico
if (!isicon(I))
if (isfile(thing)) //special snowflake
var/name = sanitize_filename("[generate_asset_name(thing)].png")
if(!SSassets.cache[name])
if (!SSassets.cache[name])
SSassets.transport.register_asset(name, thing)
for (var/thing2 in targets)
SSassets.transport.send_assets(thing2, name)
if(sourceonly)
return SSassets.transport.get_asset_url(name)
return "<img class='icon icon-misc' src='[SSassets.transport.get_asset_url(name)]'>"
var/atom/A = thing
if (isnull(dir))
dir = A.dir
I = A.icon
if (isnull(icon_state))
icon_state = A.icon_state
I = A.icon
if (!(icon_state in icon_states(I, 1)))
icon_state = initial(A.icon_state)
if (isnull(dir))
dir = initial(A.dir)
if (isnull(dir))
dir = A.dir
if (ishuman(thing)) // Shitty workaround for a BYOND issue.
var/icon/temp = I
I = icon()

View File

@@ -24,12 +24,10 @@
/datum/asset_cache_item/New(name, file)
if (!isfile(file))
file = fcopy_rsc(file)
hash = md5(file)
hash = md5asfile(file) //icons sent to the rsc sometimes md5 incorrectly
if (!hash)
hash = md5(fcopy_rsc(file))
if (!hash)
CRASH("invalid asset sent to asset cache")
debug_world_log("asset cache unexpected success of second fcopy_rsc")
CRASH("invalid asset sent to asset cache")
src.name = name
var/extstart = findlasttext(name, ".")
if (extstart)