
import os
import sys
import codecs



dirs = os.listdir('.')
realdirs = []
stringid = ""


if (len(sys.argv) > 1):
	stringid = sys.argv[1]
else:
	print("\nERROR: Enter a stringid to search for on the command line.")
	exit(0)

print("\nSearching string tables for: " + stringid)


# Get the list of directories with string files in them
for dir in dirs:
	if (os.path.isfile(os.path.join('.', dir, 'strings.dat'))):        
		realdirs.append(dir)
		
		
		
outfile = open("stringid.txt", mode="a", encoding="utf-16-le")		
outfile.write(stringid + "\n\n")		
nFound = 0

for dir in realdirs:
	
	infile = codecs.open(os.path.join('.', dir, 'strings.dat'), mode="r", encoding="utf-16-le");
							  	
	for line in infile:
		if line.startswith(stringid):
			value = line[line.find("=")+1:]
			outfile.write("  " + dir + "\t\t" + value.strip() + "\n")
			nFound += 1


outfile.write("\n\n")
outfile.close()

print("\nFound " + str(nFound) + " instances.")
print("Wrote to file: stringid.txt")





	