Last active
December 14, 2023 08:17
-
-
Save eliemichel/0b5eb59a2622596070c9c225bb7a27ab to your computer and use it in GitHub Desktop.
Extract the items contained in a Marmoset Viewer's .mview archive file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import struct | |
import os | |
# Parameter | |
archive = "vivfox.mview" | |
def readCString(f): | |
"""This is the most naive implementation possible, don't use in prod""" | |
str = "" | |
c = f.read(1) | |
while c != '\0': | |
str += c | |
c = f.read(1) | |
return str | |
def getFileSize(f): | |
pos = f.tell() | |
f.seek(0, 2) | |
end = f.tell() | |
f.seek(pos, 0) | |
return end | |
# Create the output directory | |
directory = os.path.splitext(archive)[0] | |
if not os.path.exists(directory): | |
os.makedirs(directory) | |
with open(archive, 'rb') as f: | |
end = getFileSize(f) | |
while True: | |
name = readCString(f) | |
mime = readCString(f) | |
compressed, size, rawSize = struct.unpack("III", f.read(3*4)) | |
if compressed: | |
name += ".compressed" | |
name = os.path.join(directory, name) | |
print(name) | |
with open(name, 'wb') as outf: | |
outf.write(f.read(size)) | |
if f.tell() >= end: | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment