#!/usr/bin/env python import os,sys,string,re def main(): reg_data = r'''REGEDIT4 [HKEY_CLASSES_ROOT\flauxtext] @="flauxtext" [HKEY_CLASSES_ROOT\flauxtext\DefaultIcon] @="''' + os.path.join(os.path.dirname(__file__),'icon.ico') + r'''" [HKEY_CLASSES_ROOT\flauxtext\shell] [HKEY_CLASSES_ROOT\flauxtext\shell\open] @="&flauxtext" [HKEY_CLASSES_ROOT\flauxtext\shell\open\command] @='"''' + sys.executable.lower().replace('python.exe','pythonw.exe') + '" "' + os.path.join(os.path.dirname(__file__),'flauxtext.pyw') + r'''" "%1"' [HKEY_CLASSES_ROOT\.flauxtext] @="flauxtext" ''' old_reg_data = "REGEDIT4\n" #contents of the file that may be used to undo the effects of flauxtext.reg print "depending on what you answer to the following questions, i will create a backup of the pertinent registry settings and write them to 'remove_flauxtext.reg', so anything i do to your registry is as safe as anything on windows can be.\nstill, you can hit 'Control+C' at any time to keep me from touching your registry at all." r = raw_input('would you like to be able to open any file in flauxtext from explorer.exe? [this will add a menuitem to the context menu for every file') while not ('y' in r or 'n' in r) or ('y' in r and 'n' in r): print 'please enter "y" or "n"' r = raw_input('would you like to be able to open any file in flauxtext from within explorer.exe?') if 'y' in r: reg_data += '\n[HKEY_CLASSES_ROOT\\*\\Shell\\flauxtext]\n@="&flauxtext"\n\n[HKEY_CLASSES_ROOT\\*\\Shell\\flauxtext\\command]\n@=\'c:\\windows\\system32\\flauxtext.bat "%1"\' ' r = raw_input('would you like to associate *.txt files with flauxtext? [if you enter "y", double-clicking on a *.txt file in explorer will open that text file in flauxtext.]\n') while not ('y' in r or 'n' in r) or ('y' in r and 'n' in r): print 'please enter "y" or "n"' r = raw_input('would you like to associate *.txt files with flauxtext?') if 'y' in r: reg_data += '\n[HKEY_CLASSES_ROOT\\.txt]\n@="flauxtext"' old_reg_data += '\n[HKEY_CLASSES_ROOT\\.txt]@="' + os.popen('reg query hkcr\\.txt /ve').read().split()[-1] + '"' r = raw_input('would you like to associate *.tex files with flauxtext?\n') while not ('y' in r or 'n' in r) or ('y' in r and 'n' in r): print 'please enter "y" or "n"' r = raw_input('would you like to associate *.txt files with flauxtext?') if 'y' in r: reg_data += '\n[HKEY_CLASSES_ROOT\\.tex]\n@="flauxtext"' old_reg_data += '\n[HKEY_CLASSES_ROOT\\.txt]@="' + os.popen('reg query hkcr\\.tex /ve').read().split()[-1] + '"' r = raw_input('if you would like to associate any other file extensions with flauxtext, enter them now [comma-separated, eg: "py,pyw,reg,htm,html"].\n[just hit enter if you don't want to associate any other extensions with flauxtext.]\n[note that as soon as flauxtext.reg is merged, ".flauxtext" files will be associated with flauxtext, so you don\'t have to enter that here.]\n') for ext in r.split(','): reg_data += '\n[HKEY_CLASSES_ROOT\\.'+ext+']\n@="flauxtext"' old_reg_data += '\n[HKEY_CLASSES_ROOT\\.'+ext+']@="' + os.popen('reg query hkcr\\.'+ext+' /ve').read().split()[-1] + '"' open('flauxtext.reg','w').write(reg_data) open('remove_flauxtext.reg','w').write(old_reg_data) r = raw_input("i have written your choices to flauxtext.reg and your current registry settings to remove_flauxtext.reg.\nwould you like me to try to merge your choices from flauxtext.reg to your registry now? [y|n]\n") if 'y' in r: os.startfile('flauxtext.reg') print "flauxtext.reg is merged into your registry. you can undo this by merging remove_flauxtext.reg" if __name__ == "__main__": if os.name == 'nt': main() else: print 'this script is meant to generate *.reg files on windows NT systems, and is thus useless on yours. feel free to delete it.'