+
    Ki,  c                   s    R t ^ RIt^ RIHt ^ RIHt ^ RIHt ^ RIH	t	H
t
Ht ^ RIHt ^ RIHt ^ RIHt ^ R	IHt ^ R
IHt ^ RIHt  ! R R4      tR# )zManipulates installer filesN)gettext)Optional)urlparse)get_url_cache_pathhas_valid_custom_cache_pathsave_to_cache)DownloadProgressBox)ScriptingError)system)
Downloader)logger)gtk_safe_urlsc                   s  a  ] tR t^t o RtR tR t]R 4       tR t	]R 4       t
R t]R 4       t]V 3R	 lR
 l4       t]R 4       t]R 4       t]P                   R 4       t]R 4       tR t]R 4       tR tR t]R 4       t]R 4       tR t]R 4       t]R 4       t]R 4       tR tR t]R 4       t]R 4       tR t R t!R t"]V 3R  lR! l4       t#]V 3R" lR# l4       t$R$ t%]R% 4       t&R& t'R' t(R(t)V t*R)# )*InstallerFilez@Representation of a file in the `files` sections of an installerc                s    Wn         VP                  R R4      V n        W0n        RV n        RV n        \        V P                  \        4      '       d#   V P                  P                  R4      V n	        R# RV n	        R# )Z-_N
downloader)
	game_slugZreplaceid
_file_meta_dest_file_override_dest_file_found
isinstancedictget_downloader)selfr   Zfile_idZ	file_metas   &&&&D/usr/lib/python3.14/site-packages/lutris/installer/installer_file.py__init__ZInstallerFile.__init__   s^    "//#s+##'  $doot,,#22<@D#D    c                s   V P                   p\        V\        4      '       d   VP                  4       p\	        V P
                  V P                  V4      pV P                  Vn        V P                  Vn        V P                  Vn	        V# )z<Copies this file object, so the copy can be modified safely.)
r   r   r   copyr   r   r   r   r   r   )r   r   file   &  r   r   ZInstallerFile.copy   si    __
j$''#*JT^^TWWjA#'#;#;  $ 5 5++r   c                s6   R p\        V P                  \        4      '       dK   RV P                  9  d&   \        \	        R4      V P
                  ,          4      hV P                  R,          pMV P                  pVP                  R4      '       d
   RV,           # V# ) urlz!missing field `url` for file `%s`/zfile://)r   r   r   r   r   r   
startswith)r   Z_url   & r   r    ZInstallerFile.url+   st    doot,,DOO+$Q'J%Kdgg%UVV??5)D??D??3t##r   c                sr    \        V P                  \        4      '       d   WP                  R&   R# Wn        R# )z$Change the internal value of the URLr    N)r   r   r   )r   r       &&r   set_urlZInstallerFile.set_url8   s$    doot,,%(OOE"!Or   c                sh   \        V P                  \        4      '       dJ   R V P                  9  d&   \        \	        R4      V P
                  ,          4      hV P                  R ,          # V P                  P                  R4      '       dT   V P                  4       '       d<   \        P                  P                  V P                  4      '       d   V P                  # R# V P                  P                  R4      '       d   V P                  # \        P                  P                  V P                  4      # )filenamez%missing field `filename` in file `%s`N/Ar   $STEAM)r   r   r   r   r   r   r"   uses_pga_cacheospathisdir_cache_pathcached_filenamer    Zbasenamer      &r   r&   ZInstallerFile.filename?   s    doot,,0$Q'N%ORVRYRY%YZZ??:..??%%e,,""$$t7G7G)H)H+++88x((88Oww00r   c                s    \        V P                  \        4      '       d&   V P                  P                  R 4      ;'       g    . # . # )Zalternate_filenamesr   r   r   r   r/   r0   r   get_alternate_filenamesZ%InstallerFile.get_alternate_filenamesM   s6    doot,,??&&'<=CCC	r   c                |    \        V P                  \        4      '       d   V P                  P                  R 4      # R# )refererNr1   r/   r0   r   r4   ZInstallerFile.refererR   s-    doot,,??&&y11 -r   c                0   < V ^8  d   QhRS[ S[,          /# i   Zreturn)r   r	   format__classdict__   "r   __annotate__InstallerFile.__annotate__X   s        HZ0  r   c                s|    \        V P                  4      '       d   V P                  V 4      V n        V P                  # N)Zcallabler   r/   r0   r   r   ZInstallerFile.downloaderW   s2    D$$%%#//5Dr   c                r3   )checksumNr1   r/   r0   r   r>   ZInstallerFile.checksum^   s-    doot,,??&&z22 -r   c                s   a  V 3R  lpS P                   '       d   S P                   # S P                  '       g   V! 4       S n        S P                  # )c                  s@  < SP                  4        FV  p \        P                  P                  SP                  V 4      p\        P                  P                  V4      '       g   KT  Vu # 	  \        P                  P                  SP                  SP                  4      # r=   )r2   r*   r+   Zjoinr-   Zisfiler&   )Zalt_nameZalt_pathr   s     r   find_dest_fileZ/InstallerFile.dest_file.<locals>.find_dest_filee   si     88:77<<(8(8(C77>>(++#O ;
 77<< 0 0$--@@r   )r   r   )r   r?   s   f r   	dest_fileInstallerFile.dest_filec   sF    	A ###+++$$$$2$4D!$$$r   c                s    Wn         R # r=   )r   )r   Zvaluer$   r   r@   rA   u   s    #( r   c                s(    V P                   R,           # )z\This is the actual path to download to; this file is renamed to the
dest_file when complete.z.tmpr@   r/   r0   r   download_fileZInstallerFile.download_filey   s     ~~&&r   c                s    Wn         R# )z3Called by the UI when the user selects a file path.NrB   )r   Znew_dest_filer$   r   override_dest_fileZ InstallerFile.override_dest_file   s    &r   c                s,    \        V P                  4      # r=   )Zboolr   r/   r0   r   is_dest_file_overriddenZ%InstallerFile.is_dest_file_overridden   s    D,,--r   c                s2    V P                   V P                  /# r=   )r   r@   r/   r0   r   get_dest_files_by_idZ"InstallerFile.get_dest_files_by_id   s    ((r   c                s<    V P                   : R V P                  : 2# )r!   )r   r   r/   r0   r   __str__ZInstallerFile.__str__   s    ..$''22r   c                s    R# )zGProvides a small bit of additional descriptive texts to show in the UI.N r/   r0   r   auxiliary_infoZInstallerFile.auxiliary_info   s     r   c                s    V P                   P                  R4      '       dI   V P                   P                  R^4      p\        V4      ^8X  d
   V^,          # RV P                  ,          # V P                   # )z'Return the url in human-readable formatr'   :zPlease select file '%s')r    r"   splitZlenr   )r   Zpartsr#   r   	human_urlZInstallerFile.human_url   sY     88u%%HHNN3*E5zQQx,tww66xxr   c                s:   V P                   pVP                  R4      '       d=   \        V4      p\        R4      P	                  V P
                  VP                  R7      pM2VP                  R4      '       d   VR,          P                  R4      pMTp\        V4      # )z1Return a human readable label for installer fileshttpz{file} on {host})r   Zhostr'   :i   NNrJ   )	r    r"   r   r   r8   r&   ZnetlocZlstripr   )r   r    ZparsedZlabels   &   r   	get_labelZInstallerFile.get_label   sw    hh>>&!!c]F()00dmm&--0XE^^E""GNN3'EEU##r   c                sh    \         P                  ! V P                  4      pV'       d
   V^ ,          # R# )z7Return the filename of the first file in the cache pathr   )r*   Zlistdirr-   )r   Zcache_filesr#   r   r.   ZInstallerFile.cached_filename   s(     jj!1!12q>!r   c                s   V P                   P                  R4      '       d   R# V P                  '       d   R# V P                   P                  R4      '       d   R# V P                  4       '       d   R# \	        RV P                   ,          4      h)zReturn file provider usedr(   steampgar'   userdownloadzUnsupported provider for %s)r    r"   	is_cachedis_downloadable
ValueErrorr/   r0   r   default_providerZInstallerFile.default_provider   sg     88x((>>>88u%%!!6ABBr   c                sv   \        4       pV P                  P                  R4      '       d   VP                  R4       V P                  '       d   VP                  R4       V P                  P                  R4      '       d   VP                  R4       V P                  4       '       d   VP                  R4       V# )zReturn all supported providersr(   rO   rP   r'   rQ   rR   )Zsetr    r"   ZaddrS   rT   )r   Z
_providersr#   r   	providersZInstallerFile.providers   s     U
88x((NN7#>>>NN5!88u%%NN6"!!NN:&r   c                s8    V P                   P                  R4      # )zJReturn True if the file can be downloaded (even from the local filesystem))rM   r   )r    r"   r/   r0   r   rT   ZInstallerFile.is_downloadable   s    xx""#344r   c                s\    V P                   P                  R4      '       d   R# \        4       # )zTDetermines whether the installer files are stored in a PGA cache

Returns:
    bool
r'   F)r    r"   r   r/   r0   r   r)   ZInstallerFile.uses_pga_cache   s%     88u%%*,,r   c                s"    V P                  4       # )zSReturns true if this file can be transferred to the cache, if
the user provides it.)r)   r/   r0   r   is_user_pga_caching_allowedZ)InstallerFile.is_user_pga_caching_allowed   s     ""$$r   c                sX    \        V P                  V P                  V P                  4      # )zIReturn the directory used as a cache for the duration of the installation)r   r    r   r   r/   r0   r   r-   ZInstallerFile._cache_path   s     "$((DGGT^^DDr   c                s    V P                   '       g0   \        V P                  V P                  V P                  RR7       R# R# )zPrepare the file for download. If we've not been redirected to an existing file,
anwe will create directories to contain the cached file.T)prepareN)rE   r   r    r   r   r/   r0   r   rY   ZInstallerFile.prepare   s/     +++txx$..$O ,r   c                s    \        V P                  V P                  V P                  V P                  V P
                  R 7      # ))r    ZdestZtempr4   r   )r   r    r@   rC   r4   r   r/   r0   r   create_download_progress_boxZ*InstallerFile.create_download_progress_box   s6    "t~~D4F4FPTP\P\imixix
 	
r   c                s   V P                   '       d   V P                  '       g   R#  V P                   P                  R^4      w  r\        P                  ! RYP                  4       \        P                  ! T P                  T4      pYB8w  d1   \	        TP                  4       \        R4      ,           T RT 2R7      hR#   \         d'   p\	        \        R4      T P                   R7      ThRp?ii ; i)zChecks the checksum of `file` and compare it to `value`

Args:
    checksum (str): The checksum to look for (type:hash)
    dest_file (str): The path to the destination file
    dest_file_uri (str): The uri for the destination file
NrJ   z.Invalid checksum, expected format (type:hash) )Zfaulty_datazChecking hash %s for %sz checksum mismatch z != )r>   r@   rK   rU   r   r   r
   Zinfor   Zget_file_checksumZ
capitalize)r   Z	hash_typeZexpected_hashZerrZcalculated_hashs   &    r   
check_hashZInstallerFile.check_hash   s     }}}DNNN	'+}}':':3'B$I 	-y..I 224>>9M+ $$&+@)AAR_Q``detduOv  ,  	 BCQUQ^Q^	s   C   C1!C,,C1c                r5   r6   r   intr7   r:   r   r;   r<   	  s      hsm r   c                    \        V P                  \        4      '       d;   R V P                  9   d*    \        V P                  R ,          4      pV^ 8  d   V#  R# R#   \        \
        3 d     R# i ; i)sizeNr   r   r   r]   rU   Z	TypeError)r   r_   r#   r   r_   ZInstallerFile.size  se    doot,,4??1J4??62319K   	*    $A A21A2c                r5   r6   r\   r7   r:   r   r;   r<     s      HSM r   c                r^   )
total_sizeNr`   )r   rb   r#   r   rb   ZInstallerFile.total_size  sf    doot,,1P !>?
?%% #  	* ra   c                s\    VR9  ;'       g!    \         P                  ! V P                  4      # )z?Is the file already present at the destination (if applicable)?)rQ   rP   )r   path_existsr@   )r   Zproviderr$   r   is_readyZInstallerFile.is_ready  s$    .TT&2D2DT^^2TTr   c                sr    V P                  4       ;'       d!    \        P                  ! V P                  4      # )z-Is the file available in the local PGA cache?)r)   r   rc   r@   r/   r0   r   rS   ZInstallerFile.is_cached"  s*     ""$KK););DNN)KKr   c                sp   V P                   p \        P                  P                  V4      '       g8   \        P
                  ! RV P                   4       \        P                  ! V4       \        T P                  T4       R#   \        \        3 d#   p\        P                  ! RT4        Rp?R# Rp?ii ; i)z!Copy the file into the PGA cache.zCreating cache path %sz Failed to created cache path: %sN)r-   r*   r+   r,   r
   ZdebugZmakedirsZOSErrorZPermissionErrorZerrorr   r@   )r   Z
cache_pathZexr   r   r   ZInstallerFile.save_to_cache'  s     %%
	77==,,5t7G7GHJ'
 	dnnj1	 ) 	LL;R@	s   $B 7B B5B00B5c                sh   V P                  4       '       g   \        P                  ! V P                  4      '       dt   \        P
                  P                  V P                  4      '       d#   \        P                  ! V P                  4       R# \        P                  ! V P                  4       R# R# R# )zFRemove file at already at destination, prior to starting the download.N)	r)   r   rc   r@   r*   r+   r,   Zdelete_folderZremover/   r0   r   remove_previousZInstallerFile.remove_previous5  si    ""$$););DNN)K)K ww}}T^^,,$$T^^4		$..) *L$r   )r   r   r   r   r@   r   r   N)+Z__name__Z
__module__Z__qualname__Z__firstlineno____doc__r   r   Zpropertyr    r%   r&   r2   r4   r   r>   r@   ZsetterrC   rD   rE   rF   rG   rI   rL   rN   r.   rV   rW   rT   r)   rX   r-   rY   rZ   r[   r_   rb   rd   rS   r   re   Z__static_attributes__Z__classdictcell__)r9   s   @r   r   r      s    J	$
 
 
" 1 1
 2 2     3 3 % %" ) ) ' '
' . .)3    
$   
C 
C  5- % %
 E EP

0    U L L2	* 	*r   r   )rf   r*   r    r   Ztypingr   Zurllib.parser   Zlutris.cacher   r   r   Z(lutris.gui.widgets.download_progress_boxr   Zlutris.installer.errorsr   Zlutris.utilr   Zlutris.util.downloaderr	   Zlutris.util.logr
   Zlutris.util.stringsr   r   rH   r   r   <module>rg      s8    ! 	    ! W W H 2  - " -m* m*r   