diff options
| author | Jasper St. Pierre <jstpierre@mecheye.net> | 2013-08-11 11:58:32 -0400 |
|---|---|---|
| committer | Jasper St. Pierre <jstpierre@mecheye.net> | 2013-08-11 11:58:54 -0400 |
| commit | b4ebeb05ff61dc6a865ea332d62a605f4079ff0a (patch) | |
| tree | bf2e07c24c0b00fdb4d80fa4e9fb6fcc376f5166 /Data/User/GameConfig | |
| parent | e5f4586356cc6182d4dfa14cc3f45f69df8d4956 (diff) | |
Move the new CleanFiles Python script to Tools/
So it won't be shipped to users. Also, fix it up so that it finds
the ini files regardless of where it is.
Diffstat (limited to 'Data/User/GameConfig')
| -rw-r--r-- | Data/User/GameConfig/CleanFiles.py | 112 |
1 files changed, 0 insertions, 112 deletions
diff --git a/Data/User/GameConfig/CleanFiles.py b/Data/User/GameConfig/CleanFiles.py deleted file mode 100644 index fa4532396d..0000000000 --- a/Data/User/GameConfig/CleanFiles.py +++ /dev/null @@ -1,112 +0,0 @@ - -import chardet -import codecs -import os -import glob - -standard_sections = [ - "Core", - "EmuState", - "OnLoad", - "OnFrame", - "ActionReplay", - "Video", - "Video_Settings", - "Video_Enhancements", - "Video_Hacks", - "Speedhacks", -] - -standard_comments = { - "Core": "Values set here will override the main dolphin settings.", - "EmuState": "The Emulation State. 1 is worst, 5 is best, 0 is not set.", - "OnLoad": "Add memory patches to be loaded once on boot here.", - "OnFrame": "Add memory patches to be applied every frame here.", - "ActionReplay": "Add action replay cheats here.", - "Video": "", - "Video_Settings": "", - "Video_Enhancements": "", - "Video_Hacks": "", - "Speedhacks": "", -} - -def normalize_comment(line): - line = line.strip().lstrip('#').lstrip() - if line: - return "# %s" % (line,) - else: - return "" - -def normalize_ini_file(in_, out): - sections = {} - current_section = None - toplevel_comment = "" - wants_comment = False - - for line in in_: - line = line.strip() - - # strip utf8 bom - line = line.lstrip(u'\ufeff') - - if line.startswith('#'): - line = normalize_comment(line) - if current_section is None: - toplevel_comment += line - continue - - if line.startswith('['): - end = line.find(']') - section_name = line[1:end] - if section_name not in standard_sections: - continue - current_section = [] - sections[section_name] = current_section - wants_comment = False - continue - - if current_section is None and line: - raise ValueError("invalid junk") - - if current_section is None: - continue - - if line.startswith('#') and not wants_comment: - continue - - current_section.append(line) - if line: - wants_comment = True - - out.write(toplevel_comment.strip() + "\n\n") - - for section in standard_sections: - lines = '\n'.join(sections.get(section, "")).strip() - comments = standard_comments[section] - - if not lines and not comments: - continue - - out.write("[%s]\n" % (section,)) - if comments: - out.write("# %s\n" % (comments,)) - if lines: - out.write(lines) - out.write('\n') - out.write('\n') - -def main(): - for name in glob.glob("??????.ini"): - in__name = name - out_name = name + '.new' - - in_str = open(in__name, 'r').read() - encoding = chardet.detect(in_str) - - in_ = codecs.open(in__name, 'r', encoding['encoding']) - out = codecs.open(out_name, 'w', 'utf8') - normalize_ini_file(in_, out) - os.rename(out_name, in__name) - -if __name__ == "__main__": - main() |
