Created
August 9, 2018 06:16
-
-
Save teionn/b0454beead30177300bd954b8326a498 to your computer and use it in GitHub Desktop.
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
# -*- coding: utf-8 -*- | |
#コーディング: utf-8 | |
#------------------------------------------------------------------------------ | |
import struct | |
import sys | |
import re | |
import os | |
#------------------------------------------------------------------------------ | |
""" | |
import analyzeMayaVersion;reload(analyzeMayaVersion) | |
analyzeMayaVersion.mayaVersion(_path="") | |
""" | |
#https://fujishinko.exblog.jp/8346612/ | |
def to_string(value): | |
result = "" | |
carry = "" | |
for i in range(0,len(value),2): | |
v = value[i:i+2] | |
if len(carry) != 0: | |
v = carry + v | |
carry = "" | |
result += struct.pack(">H",int(v,16)) | |
else: | |
if int(v,16) < 128: | |
result += struct.pack("B",int(v,16)) | |
else: | |
carry = v | |
return result | |
def analize(_file,_max=1024): | |
f = open(_file,'rb') | |
bit_pos = 0 | |
start_pos = 16 | |
analize_data = "" | |
for line in f: | |
for s in line: | |
if _max <= bit_pos: | |
f.close() | |
return analize_data | |
bit = struct.unpack('B',s)[0] | |
hex = "%02X" % bit | |
if bit_pos == 1: | |
start_pos = int(hex, 16) | |
if start_pos <= bit_pos: | |
analize_data += hex | |
bit_pos += 1 | |
f.close() | |
return analize_data | |
#------------------------------------------------------------------------------ | |
def searchBinaryVersion(_path=""): | |
#f = open(r"X:\user\maya\data\testScripts\unknownPlugin\test.mb",'rb') | |
_text=to_string(analize(_path,_max=1024)) | |
_text = "".join([x for x in _text if re.match(r"\w",x)]) | |
_mayaVer=re.search(r"productMaya\d{4}FINF",_text).group() | |
if _mayaVer: | |
return re.search(r"\d{4}",_mayaVer).group() | |
else: | |
return None | |
def searchAsciiVersion(_path=""): | |
_file=open(_path,"r") | |
_read="".join(_file.readlines()) | |
_verInfo="".join([x for x in _read[:1024].split("\n") if "fileInfo" in x and "version" in x ]) | |
return re.search(r"\d{4}",_verInfo).group() | |
#------------------------------------------------------------------------------ | |
def mayaVersion(_path=""): | |
_ext = os.path.splitext(_path)[-1] | |
if ".mb" == _ext: | |
return searchBinaryVersion(_path) | |
elif ".ma" == _ext: | |
return searchAsciiVersion(_path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment