o
    :Ѹe                     @   s   d Z ddlZddlZddlZddlmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ ddlmZ dd	lmZ ddlZdd
lmZmZmZ ddlmZmZmZmZ G dd deZG dd deZdS )z#
Implements the bdist_msi command.
    N)Command)remove_tree)get_python_version)StrictVersion)DistutilsOptionError)get_platform)log)schemasequencetext)	DirectoryFeatureDialogadd_datac                   @   sF   e Zd ZdZdd Zdd Zddd	ZdddZdddZdd Z	dS )PyDialogzDialog class with a fixed layout: controls at the top, then a ruler,
    then a list of buttons: back, next, cancel. Optionally a bitmap at the
    left.c                 O   s@   t j| g|R   | jd }d| d }| dd|| jd dS )zbDialog(database, name, x, y, w, h, attributes, title, first,
        default, cancel, bitmap=true)$      iH  
BottomLiner   N)r   __init__hlinew)selfargskwrulerbmwidth r   o/var/www/html/openvpn-purple/vpn-purple/lib/python3.10/site-packages/setuptools/_distutils/command/bdist_msi.pyr      s   
zPyDialog.__init__c              
   C   s   |  ddddddd|  dS )	z,Set the title text of the dialog at the top.Title   
   @  <     z{\VerdanaBold10}%sN)r   )r   titler   r   r   r%   %   s   zPyDialog.titleBack   c              
   C   ,   |rd}nd}|  |d| jd dd|||S )zAdd a back button with a given title, the tab-next button,
        its name in the Control table, possibly initially disabled.

        Return the button, so that events can be associated   r'         8      
pushbuttonr   r   r%   nextnameactiveflagsr   r   r   back,      zPyDialog.backCancelc              
   C   r(   )zAdd a cancel button with a given title, the tab-next button,
        its name in the Control table, possibly initially disabled.

        Return the button, so that events can be associatedr)   r'   i0  r+   r,   r-   r.   r0   r   r   r   cancel7   r6   zPyDialog.cancelNextc              
   C   r(   )zAdd a Next button with a given title, the tab-next button,
        its name in the Control table, possibly initially disabled.

        Return the button, so that events can be associatedr)   r'      r+   r,   r-   r.   r0   r   r   r   r1   B   r6   zPyDialog.nextc              
   C   s,   |  |t| j| d | jd ddd||S )zAdd a button with a given title, the tab-next button,
        its name in the Control table, giving its x position; the
        y-position is aligned with the other buttons.

        Return the button, so that events can be associated   r+   r,   r-   r)   )r/   intr   r   )r   r2   r%   r1   xposr   r   r   xbuttonM   s   ,zPyDialog.xbuttonN)r&   r'   )r7   r'   )r9   r'   )
__name__
__module____qualname____doc__r   r%   r5   r8   r1   r>   r   r   r   r   r      s    



r   c                
       s   e Zd ZdZdddde  fdddd	d
dddg
Zg dZg dZdZ fddZ	dd Z
dd Zdd Zdd Zdd Zdd Zdd  Zd!d" Z  ZS )#	bdist_msiz7create a Microsoft Installer (.msi) binary distribution)z
bdist-dir=Nz1temporary directory for creating the distributionz
plat-name=pz;platform name to embed in generated filenames (default: %s))	keep-tempkzPkeep the pseudo-installation tree around after creating the distribution archive)ztarget-version=Nz6require a specific python version on the target system)no-target-compilecz/do not compile .py to .pyc on the target system)no-target-optimizeoz;do not compile .py to .pyo (optimized) on the target system)z	dist-dir=dz-directory to put final built distributions in)
skip-buildNz2skip rebuilding everything (for testing/debugging))zinstall-script=NzUbasename of installation script to be run after installation or before deinstallation)zpre-install-script=Nz{Fully qualified filename of a script to be run before any files are installed.  This script need not be in the distribution)rE   rG   rI   rL   )z2.0z2.1z2.2z2.3z2.4z2.5z2.6z2.7z2.8z2.9z3.0z3.1z3.2z3.3z3.4z3.5z3.6z3.7z3.8z3.9Xc                    s$   t  j|i | tdtd d S )NzZbdist_msi command is deprecated since Python 3.9, use bdist_wheel (wheel packages) instead   )superr   warningswarnDeprecationWarning)r   r   r   	__class__r   r   r      s   zbdist_msi.__init__c                 C   sF   d | _ d | _d| _d| _d| _d | _d | _d | _d | _d | _	d | _
d S )Nr   )	bdist_dir	plat_name	keep_tempno_target_compileno_target_optimizetarget_versiondist_dir
skip_buildinstall_scriptpre_install_scriptversions)r   r   r   r   initialize_options   s   
zbdist_msi.initialize_optionsc                 C   s   |  dd | jd u r| dj}tj|d| _t }| js'| j	
 r'|| _| jrD| jg| _| jsC| j	
 rC| j|krCtd|f nt| j| _|  ddd | jrXtd| jrt| j	jD ]}| jtj|krl nq_td| j d | _d S )	Nbdist)r\   r\   msizMtarget version can only be %s, or the '--skip-build' option must be specified)r[   r[   )rV   rV   z5the pre-install-script feature is not yet implementedz(install_script '%s' not found in scripts)set_undefined_optionsrU   get_finalized_command
bdist_baseospathjoinr   rZ   distributionhas_ext_modulesr_   r\   r   listall_versionsr^   r]   scriptsbasenameinstall_script_key)r   re   short_versionscriptr   r   r   finalize_options   sJ   



zbdist_msi.finalize_optionsc                 C   s~  | j s| d | jddd}| j|_| j |_ d|_| d}d|_d|_| j	 rV| j
}|s?| j s6J ddtjd d	  }d
| j|f }| d}tj|jd| |_td| j |  tjdtj| jd |  tjd= | | j | j }| |}tj|}tj|rt| | jj }|j!}	|	s|j"}	|	sd}	|# }
dt$|
j% }| j }| j
rd| j
|f }nd| }t&'|t(|t&) ||	| _*t&+| j*t, d|
fg}|j-p|j.}|r|/d|f |j0r|/d|j0f |rt1| j*d| | 2  | 3  | 4  | 5  | j*6  t7| jdr/d| j
p%d|f}| jj8/| | j9s=t:| j| j;d d S d S )Nbuildinstallr'   )reinit_subcommandsr   install_libz Should have already checked thisz%d.%drN   z.%s-%slibzinstalling to %sPURELIBUNKNOWNz%d.%d.%dzPython %s %sz	Python %sDistVersion
ARPCONTACTARPURLINFOABOUTProperty
dist_filesrC   any)dry_run)<r\   run_commandreinitialize_commandrU   prefixwarn_dircompileoptimizeri   rj   rZ   sysversion_inforV   rd   rf   rg   rh   
build_base	build_libr   infoensure_finalizedinsertrunmkpathr[   get_fullnameget_installer_filenameabspathexistsunlinkmetadataauthor
maintainerget_versionr   versionmsilibinit_databaser	   gen_uuiddb
add_tablesr
   author_emailmaintainer_emailappendurlr   add_find_python	add_filesadd_scriptsadd_uiCommithasattrr~   rW   r   r   )r   rt   rv   rZ   plat_specifierrs   fullnameinstaller_namer   r   r   sversionproduct_namepropsemailtupr   r   r   r      s   









zbdist_msi.runc              
   C   s  | j }td}tj| j}t||d |dd}t|ddddddd}||d	fg}| j	| j
g D ]:}d| }d|  }	}
d}|| j
u rHd
}d}nd| }d}t||	||d||d}t||||||
}||||f q0|  i }|D ]\}}}|g}|r| }t|jD ]m}tj|j|}tj|rd|||f }|| }
t|||||
|}|| q|js||j|d ||vr|| }||< || jkr| jrtd| d| | _q|| }t| j d|| |j|d |jfg q|s}|  qs|| d S )N	distfiles	TARGETDIR	SourceDirPython
Everythingr   r'   )	directory zPython from another locationrN   zPython %s from registryz%s|%szMultiple files with name %sz[#%s]DuplicateFile)r   r   CABrf   rg   r   rU   r   r   r_   other_versionr   r   poplistdirabsoluterh   isdir
make_short	componentstart_componentlogicaladd_filer]   ro   r   r   commit)r   r   cabrootdirrootfitemsr   targetr2   defaultdescr%   leveldirseenfeaturetodofileafileshortnewdirkeyr   r   r   r     sf   





zbdist_msi.add_filesc                 C   s  d}| j D ]}d| }d| }d| }d| }d| }d| }d| }	d	| }
d
| }d| }tjr5d}nd}t| jd|d|d|f|d|d|fg t| jd||f||fg t| jd|d|d| d f|	d|d| d f|
d|d| d fg t| jd|||f|	||d f|
d|d fg t| jd|||f|	||d f|
d|d fg t| jdd| dd| fg |d7 }|dk sJ qdS )as  Adds code to the installer to compute the location of Python.

        Properties PYTHON.MACHINE.X.Y and PYTHON.USER.X.Y will be set from the
        registry for each version of Python.

        Properties TARGETDIRX.Y will be set from PYTHON.USER.X.Y if defined,
        else from PYTHON.MACHINE.X.Y.

        Properties PYTHONX.Y will be set to TARGETDIRX.Y\python.exei  z)SOFTWARE\Python\PythonCore\%s\InstallPathzpython.machine.zpython.user.zPYTHON.MACHINE.zPYTHON.USER.PythonFromMachinePythonFromUser	PythonExer   PYTHON   rN   
RegLocatorNr'   	AppSearchCustomActioni3  []z]\python.exeInstallExecuteSequenceInstallUISequence	Conditionr   r   zNOT TARGETDIR   i  )r_   r   Win64r   r   )r   startverinstall_pathmachine_reguser_regmachine_prop	user_propmachine_actionuser_action
exe_actiontarget_dir_propexe_propTyper   r   r   r   K  sb   
zbdist_msi.add_find_pythonc              	   C   s.  | j r5d}| j| jg D ](}d| }d| }t| jd|d|| jfg t| jd|d| |fg |d7 }q| jrtj	| j
d	}t|d
)}|d t| j}||  W d    n1 sbw   Y  W d    n1 sqw   Y  t| jddt|fg t| jddg t| jddg d S d S )Ni  zinstall_script.r   r   2   r   z&Python%s=3r'   zpreinstall.batr   zrem ="""
%1 %0
exit
"""
Binary
PreInstall)r   rN   r   N)r   zNOT Installedi  )r]   r_   r   r   r   ro   r^   rf   rg   rh   rU   openwritereadr   r   )r   r   r   install_actionr   scriptfnr   finr   r   r   r     s>   

	zbdist_msi.add_scriptsc                 C   s
  | j }d }}d}d}d}d}d}d}	t|dg d	 t|d
g d t|dg d t|dtj t|dtj t|d||||||ddd}
|
d |
jdddd |
jdddd |
ddddddd |
ddd dd!dd" |
j	dddd#}|
d$d% t|d&||||||ddd}|d' |jdddd |jdddd |ddddddd( |ddd dd!dd" |j	dddd#}|
d$d% t|d)||||||ddd}|d* |jdddd |jdddd |d+dd,dd!dd" |j	dddd#}|
d$d- t|d.||||d/|d0d0d0d1d2}|d3dd4d5ddd6 |d+d!d7d8d!dd9 |d:d!d;d<ddd= |d>d?d!d@d<dAdBdCd d d  |jd%dDd%d#}|
d$d% |j	dDd0dDd#}|
d$dD |jd0d%d0d#}|
d$d0 t|dEddFd<dGdH|dId d }|dIddJd8dKddL |dMdNdOdPdQddRd 
d$dS |dTdUdOdPdQddVd 
d$dW |dXddOdPdQddYd 
d$dZ |d[d\dOdPdQddd 
d$d] |d^dPdOdPdQddDd 
d$d_ |d`dadOdPdQddbd 
d$dc |dddedOdPdQdd0d 
d$df t|dgddFdhdid|dRdRdR}|d:dKddjdkddl |dVdOdmdndoddVdR}|
d$d% |dRdpdmdndoddRdV}|
d$d- t|dqddFdhdi||d-d-d-}|d:dKddjdkddr |d-dsdmdndodd-d }|
d$d% t|dt||||||ddd}|d+dddduddv |dw |dddxdd!ddy}|dd: |dzdd{ddkdd }|dzd: |jdd dd |j	d|d dd |dd }|
d}dg t|d~||||||d|d|d}|d |dddkdd!dd| j   |jdd dd |	dd}d}|j
dd|d | j| jg D ]}|d7 }|j
dd| d| |d q|j
ddq|d d |j
d$d-|d d |dd}|
d}dg |ddddddNddd dd }|
dd | j}d| }d| }|ddd5dddd}|d| |d| |d| |d| |dddddddd| d d|d }|d| |d| |d| |d| t|d||||||dddd1d2}|d3dd4d5ddd |d+d!d!d8d!dd |d:d!dd<ddd |ddd!dd<ddd dd d  |ddbd d
d$d- t|d||||||dd|d}|d |ddddhddddLd|	}|ddddd!d |ddddd!d |jdd dd |	dd}|
dddd |j
d$d-dd |dd}|
d}dg t|d||||||dddd1d2}|d3d!dd5ddd |d:ddddkdd |ddddd!dd |ddd|d d!ddy}|dd: |ddddNddFdd dd d }|dd |jdd|d1d |j	ddd1d |dd
d}dg t|d||||||d|d|d}|d |dddd<d\ddġ |dddd<ddddLd|	}|dddd5dodʡ |dddd5dod͡ |jdd d1d |	dd}|
dddd |
dddd4 |
ddddB |
ddddա |
ddddء |
ddddڡ |
ddddܡ |
ddddݡ |
d$d-dd! |ddš
d}dg d S )Nr   ir  i,  z[ProductName] Setupr)   r'       r}   ))DefaultUIFontDlgFont8)ErrorDialogErrorDlg)	Progress1Install)	Progress2installs)MaintenanceForm_ActionRepair)
WhichUsersALL	TextStyle))r   Tahoma	   Nr   )DlgFontBold8r
     Nr'   )VerdanaBold10Verdanar!   Nr'   )VerdanaRed9r  r     r   r   ))
PrepareDlgz(Not Privileged or Windows9x or Installed   )WhichUsersDlgz.Privileged and not Windows9x and not Installed   )SelectFeaturesDlgzNot Installedi  )MaintenanceTypeDlgz,Installed AND NOT RESUME AND NOT Preselectedi  )ProgressDlgNi   
ActionTextUIText
FatalErrorFinishz)[ProductName] Installer ended prematurelyz< Backr   )r3   r7   r&   Description1r    F   r"   P   r$   z[ProductName] setup ended prematurely because of an error.  Your system has not been modified.  To install this program at a later time, please run the installation again.Description2      z.Click the Finish button to exit the Installer.)r2   	EndDialogExitUserExitz'[ProductName] Installer was interruptedz[ProductName] setup was interrupted.  Your system has not been modified.  To install this program at a later time, please run the installation again.
ExitDialogz&Completing the [ProductName] InstallerDescription   Return
FilesInUse   RetryF)bitmapr         z{\DlgFontBold8}Files in Use   i  z8Some files that need to be updated are currently in use.Text7   iJ  zThe following applications are using files that need to be updated by this setup. Close these applications and then click Retry to continue the installation or Cancel to exit it.ListListBoxk         FileInUseProcessIgnorer   r!   e   i  	ErrorTextr  0   r   Nx   H   Q      NoErrorNoY   YesErrorYesAAbort
ErrorAbortC*   ErrorCancelIErrorIgnoreO   OkErrorOkR   
ErrorRetry	CancelDlgi  U         z;Are you sure you want to cancel [ProductName] installation?9   r,   r-      WaitForCostingDlgzRPlease wait while the installer finishes determining your disk space requirements.f   r  (   zOPlease wait while the Installer prepares to guide you through the installation.z&Welcome to the [ProductName] Installern   zPondering...
ActionData   r9   SpawnDialogr  zSelect Python InstallationsHintz9Select the Python locations where %s should be installed.zNext >z[TARGETDIR]z[SourceDir])orderingz[TARGETDIR%s]z FEATURE_SELECTED AND &Python%s=3SpawnWaitDialogrN   FeaturesSelectionTreer#   FEATUREPathEditz[FEATURE_SELECTED]1z!FEATURE_SELECTED AND &Python%s<>3Otherz$Provide an alternate Python locationEnableShowDisableHide      r   DiskCostDlgOKz&{\DlgFontBold8}Disk Space RequirementszFThe disk space required for the installation of the selected features.5   a  The highlighted volumes (if any) do not have enough disk space available for the currently selected features.  You can either remove some files from the highlighted volumes, or choose to install less features onto local drive(s), or select different destination drive(s).
VolumeListVolumeCostListd      i  z{120}{70}{70}{70}{70}g      ?r  AdminInstallzGSelect whether to install [ProductName] for all users of this computer.r  r     zInstall for all usersJUSTME   zInstall just for mez
[ALLUSERS]zWhichUsers="ALL"r  z({\DlgFontBold8}[Progress1] [ProductName]#   A   zYPlease wait while the Installer [Progress2] [ProductName]. This may take several minutes.StatusLabelzStatus:ProgressBari  zProgress doneSetProgressProgressr  z)Welcome to the [ProductName] Setup WizardBodyText?   z:Select whether you want to repair or remove [ProductName].RepairRadioGroupl   r  r  r   z&Repair [ProductName]Remover   zRe&move [ProductName]z[REINSTALL]zMaintenanceForm_Action="Repair"z[Progress1]	Repairingz[Progress2]repairs	Reinstallr  z[REMOVE]zMaintenanceForm_Action="Remove"   Removing   removes      z MaintenanceForm_Action<>"Change")r   r   r   r  r  r   r%   r5   r8   r1   eventcontrolr   r/   mappingri   r   r_   r   	conditionr>   
radiogroupadd)r   r   xyr   r   r%   modalmodelesstrack_disk_spacefatalrH   	user_exitexit_dialoginuseerrorr8   costingprepseldlgorderr   r   install_other_conddont_install_other_condcost
whichusersgprogressmaintr   r   r   r     s  	



       




zbdist_msi.add_uic                 C   s<   | j rd|| j| j f }nd|| jf }tj| j|}|S )Nz%s.%s-py%s.msiz	%s.%s.msi)rZ   rV   rf   rg   rh   r[   )r   r   	base_namer   r   r   r   r     s   z bdist_msi.get_installer_filename)r?   r@   rA   descriptionr   user_optionsboolean_optionsrl   r   r   r`   rr   r   r   r   r   r   r   __classcell__r   r   rS   r   rC   U   s>    ([66&  @rC   )rB   rf   r   rP   distutils.corer   distutils.dir_utilr   distutils.sysconfigr   distutils.versionr   distutils.errorsr   distutils.utilr   	distutilsr   r   r	   r
   r   r   r   r   r   r   rC   r   r   r   r   <module>   s    >