Created
July 19, 2018 11:32
-
-
Save spiiin/4166a699be87b591e6718d8a208e3c53 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
#python 2.7 | |
import os, glob, shutil, zipfile, path | |
def applyToAllFilesInFolder ( folder, fileexts, func, *params): | |
"""apply function with params func to all files with extenstions from list fileext in folder | |
example: | |
applyToAllFilesInFolder ("C:", [".txt"], lambda filename:None) | |
""" | |
def visit ( arg, dirname, names ): | |
for name in names: | |
shortName, ext = os.path.splitext(name) | |
if ext.lower() in fileexts: | |
func(os.path.join(dirname, name), *params) | |
os.path.walk( folder, visit, 0) | |
def insertOffsetLine(offsetLine, width, height): | |
lastBracket = offsetLine.rfind(")") | |
return offsetLine[:lastBracket] + ", %d, %d"%(width, height) + offsetLine[lastBracket:] | |
def removeSettingsCode(filename): | |
if filename.lower().find("settings_")==-1: | |
return | |
print filename | |
#lines = [] | |
with open(filename, "rt") as f: | |
lines = f.readlines() | |
ans = [] | |
for i, l in enumerate(lines): | |
if l.find("//css_include settings_") != -1: | |
print l | |
ans.append(l.replace("//css_include settings_", "//css_include ")) | |
else: | |
ans.append(l) | |
with open(filename,"wt") as f: | |
f.writelines(ans) | |
def removeGetScreensWidth(filename): | |
if filename.lower().find("settings_")==-1: | |
return | |
print filename | |
#lines = [] | |
with open(filename, "rt") as f: | |
lines = f.readlines() | |
width = 0 | |
height = 0 | |
found = False | |
offsetLine = "" | |
offsetLineIndex = widthLineIndex = heightLineIndex = -1 | |
for i, l in enumerate(lines): | |
if l.find("int getScreenWidth") != -1: | |
found = True | |
widthLineIndex = i | |
print l, | |
width = int("".join([s for s in l if s.isdigit()])) | |
if l.find("int getScreenHeight") != -1: | |
found = True | |
print l, | |
height = int("".join([s for s in l if s.isdigit()])) | |
heightLineIndex = i | |
if l.find("OffsetRec getScreensOffset") != -1: | |
print l, | |
offsetLine, offsetLineIndex = l, i | |
if found: | |
ans = [] | |
print "Width:%d, Height:%d"%(width, height) | |
print "%d OffsetLine:%s"%(offsetLineIndex, offsetLine) | |
newOffsetLine = insertOffsetLine(offsetLine, width, height) | |
print "New offsetLine:%s"% newOffsetLine | |
for i, l in enumerate(lines): | |
if i == offsetLineIndex: | |
ans.append(newOffsetLine) | |
continue | |
if i != widthLineIndex and i != heightLineIndex: | |
ans.append(l) | |
with open(filename,"wt") as f: | |
f.writelines(ans) | |
def makeWork(): | |
print "Replace strings in all configs" | |
applyToAllFilesInFolder(".", [".cs"], removeSettingsCode) | |
print "DONE!" | |
#----------------------------------------------------------------------- | |
if __name__ == "__main__": | |
makeWork() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment