Ver código fonte

add basic files

rachels 2 anos atrás
commit
5ab47e5d99
2 arquivos alterados com 44 adições e 0 exclusões
  1. BIN
      tools/txt2gam.exe
  2. 44 0
      tools/txtmerge.py

BIN
tools/txt2gam.exe


+ 44 - 0
tools/txtmerge.py

@@ -0,0 +1,44 @@
+#!/usr/bin/env python
+# usage: txtmerge.py <input_dir> <output_file_name> 
+# does the exact opposite of txtsplit.py
+
+import os
+import sys
+import re
+import io 
+import xml.etree.ElementTree as ET
+
+assert len(sys.argv) == 4, "usage:\ntxtmerge.py <input_file_name> <input_dir> <output_file_name>"
+iname = str(sys.argv[1])
+idir = str(sys.argv[2])
+oname = str(sys.argv[3])
+
+# read the project xml file first
+# let's do this later in order to implement directory structure
+tree = ET.parse(iname)
+root = tree.getroot()
+
+ofile = io.open(oname, 'w', encoding='utf-16', newline='\r\n')
+
+for location in root.iter('Location'):
+    iname = location.attrib['name']
+    iname = iname.replace("$","_")
+
+    try:
+        ifile = io.open(os.path.join(idir,iname + '.qsrc'), 'rt', encoding='utf-8')
+        text = ifile.read()
+
+        # make sure there's a line at the end of file
+        # (why wouldn't there be one? WINDOWS!
+        if text[-1] != u'\n':
+            text += u'\n\n'
+
+        ofile.write(text)
+        ifile.close()
+    except IOError:
+        print("WARNING: missing location %s" % iname)
+        pass
+
+ofile.close()
+    
+