import sys
try:
    # py2exe 0.6.4 introduced a replacement modulefinder.
    # This means we have to add package paths there, not to the built-in
    # one.  If this new modulefinder gets integrated into Python, then
    # we might be able to revert this some day.
    # if this doesn't work, try import modulefinder
    try:
        import py2exe.mf as modulefinder
    except ImportError:
        import modulefinder
    import win32com
    for p in win32com.__path__[1:]:
        modulefinder.AddPackagePath("win32com", p)
    for extra in ["win32com.shell"]: #,"win32com.mapi"
        __import__(extra)
        m = sys.modules[extra]
        for p in m.__path__[1:]:
            modulefinder.AddPackagePath(extra, p)
except ImportError:
    # no build path setup, no worries.
    pass

from distutils.core import setup
import py2exe
from glob import glob
msvcrt = [("Microsoft.VC90.CRT", glob(r'vc-redist\*.*'))]

languages = ['de','fr']
locale_support = [("locale",[r"locale\protext.pot"])]
for lang in languages:
    locale_support.append((r"locale\%s\LC_MESSAGES"%lang,glob(r"locale\%s\LC_MESSAGES\protext.*"%lang)))

setup(
    windows=[
        {'script':'protext-setup.py','dest_base':'Setup','icon_resources':[(0,'icons\\tex.ico')], 'uac_info':'asInvoker'},
        #{'script':'protext-setup.py', 'dest_base':'protext-setup-as-admin (Win7 or Vista)', 'icon_resources':[(0,'tex.ico')], 'uac_info':'requireAdministrator'}
    ],
    zipfile='lib/modules.zip',
    data_files=msvcrt+locale_support+['protext.ini',('lib',['SumatraPDF.exe']),('icons',['icons\\tex.ico'])],
    options={'py2exe':{'bundle_files':2, 'dll_excludes':['powrprof.dll']}}
)
