# Copyright AllSeen Alliance. All rights reserved.
#
#    Permission to use, copy, modify, and/or distribute this software for any
#    purpose with or without fee is hereby granted, provided that the above
#    copyright notice and this permission notice appear in all copies.
#
#    THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
#    WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
#    MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
#    ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
#    WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
#    ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
#    OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
# 
import os
Import('env')

cwd = os.getcwd()

msiDestination = '../../build/Win7'
msiSource='./release/AllJoynWinInstaller.msi'

# Always rebuild the MSI so that multiple builds of debug, release, CPU can be made and
# a new MSI is made after each one. 
if os.path.exists(msiSource):
    os.remove(msiSource)

programFiles=''

if os.environ.has_key('ProgramFiles(x86)'):
    programFiles=os.environ['ProgramFiles(x86)']
elif os.environ.has_key('ProgramFiles'):
    programFiles=os.environ['ProgramFiles']
else:
    print 'Program files directory not found.'
    Exit(1)

if env.has_key('MSVC_VERSION'):
    msvcVer = env['MSVC_VERSION']
else:
    print 'Visual Studio version not found.'
    Exit(1)

devEnv = '"' + programFiles + '\Microsoft Visual Studio ' + msvcVer + '\Common7\IDE\devenv.exe"' 
cmd = cwd + '\MakeAjSdkMsi.cmd ' + cwd + ' ' + devEnv

Msi = env.Command(msiSource, Dir('$DISTDIR'), cmd)
installedMsi = env.Install(msiDestination, Msi)

Return ('installedMsi')
