diff options
author | Andrei Karas <akaras@inbox.ru> | 2014-10-31 01:08:46 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2014-10-31 12:19:12 +0300 |
commit | 746192af34a65504cb86a4eca068a8f0fbb361f5 (patch) | |
tree | 12d399627720f7fc72e66deb64bac7ef0d9eb71e /hercules/code/fileutils.py | |
parent | 63f135d8af2a81a78626d6229d077e3f91a35288 (diff) | |
download | evol-tools-746192af34a65504cb86a4eca068a8f0fbb361f5.tar.gz evol-tools-746192af34a65504cb86a4eca068a8f0fbb361f5.tar.bz2 evol-tools-746192af34a65504cb86a4eca068a8f0fbb361f5.tar.xz evol-tools-746192af34a65504cb86a4eca068a8f0fbb361f5.zip |
hercules: split implimentation to many files.
Diffstat (limited to 'hercules/code/fileutils.py')
-rw-r--r-- | hercules/code/fileutils.py | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/hercules/code/fileutils.py b/hercules/code/fileutils.py new file mode 100644 index 0000000..150cb8c --- /dev/null +++ b/hercules/code/fileutils.py @@ -0,0 +1,62 @@ +# -*- coding: utf8 -*- +# +# Copyright (C) 2014 Evol Online +# Author: Andrei Karas (4144) + +import array +import os +import struct +import shutil + +def readInt32(f): + data = f.read(4) + arr = array.array("I") + arr.fromstring(data) + return arr[0] + +def readInt16(f): + data = f.read(2) + arr = array.array("H") + arr.fromstring(data) + return arr[0] + +def readMapName(f): + data = f.read(12) + data = str(data) + while data[-1] == '\x00': + data = data[:-1] + return data + +def readData(f, sz): + return f.read(sz) + +def readFile(path): + with open(path, "r") as f: + return f.read() + +def writeInt32(f, i): + f.write(struct.pack("I", i)) + +def writeInt16(f, i): + f.write(struct.pack("H", i)) + +def writeMapName(f, name): + if len(name) > 12: + name = name[:12] + while len(name) < 12: + name = name + '\x00' + f.write(struct.pack("12s", name)) + +def writeData(f, data): + f.write(data) + +def copyFile(src, dst, name): + shutil.copyfile(src + name, dst + name) + +def saveFile(fileName, data): + with open(fileName, "w") as w: + w.write(data) + +def makeDir(path): + if not os.path.exists(path): + os.makedirs(path) |