neogeographica / singleplayer_scripts

Linux desktop and browser integration for SP Quake.
3 stars 0 forks source link

add "magic" for x-bsp-map.xml #28

Closed neogeographica closed 1 year ago

neogeographica commented 2 years ago

We can distinguish between Quake bsp maps and other "bsp" kinds of files, and avoid all the documented qualifiers about whether the .bsp association already has a type associated.

See https://specifications.freedesktop.org/shared-mime-info-spec/shared-mime-info-spec-latest.html for the docs and https://github.com/TrenchBroom/TrenchBroom/blob/master/app/resources/linux/trenchbroom.xml for an example.

In the case of Quake bsp maps we want to detect BSP (BSP29), BSP2 (BSP29a), and maybe even 2PSB and Quake64. Cf. Mod_LoadBrushModel in Quakespasm engines like https://github.com/andrei-drexler/ironwail/blob/e585ce9b8e52fe02ca723686e4d7cadb7669f4b3/Quake/gl_model.c#L2254

neogeographica commented 1 year ago

Welp, hmm.

This seems like it would do the trick:

<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
  <mime-type type="application/x-bsp-map">
    <glob pattern="*.bsp"/>
    <magic priority="60">
      <match offset="0" type="little32" value="29"/>
      <match offset="0" type="string" value="BSP2"/>
      <match offset="0" type="string" value="2PSB"/>
      <match offset="0" type="string" value=" 46Q"/>
    </magic>
    <comment>BSP map</comment>
  </mime-type>
</mime-info>

But even after I install that and update the MIME database, the system still sees any old .bsp file as x-bsp-map type, even if it's just e.g. a text file that I renamed.

neogeographica commented 1 year ago

Oh wait yeah. I guess it's matching on glob or magic, not glob AND magic.

Maybe just remove the glob at this point.