a
     ñ»j5#  ã                   @  sú   d Z ddlmZ ddlZddlZddlZddlmZ ddlm	Z	m
Z
 ddlmZ G dd	„ d	eƒZedd
�ddœdd„ƒZedd
�ddœdd„ƒZedd
�ddœdd„ƒZedd
�ddœdd„ƒZedd
�ddœdd„ƒZedd
�ddœdd„ƒZd	gZdS )zAndroid.é    )ÚannotationsN)Ú	lru_cache)ÚTYPE_CHECKINGÚcasté   )ÚPlatformDirsABCc                   @  s0  e Zd ZdZeddœdd„ƒZeddœdd„ƒZeddœdd	„ƒZeddœd
d„ƒZeddœdd„ƒZ	eddœdd„ƒZ
eddœdd„ƒZeddœdd„ƒZeddœdd„ƒZeddœdd„ƒZeddœdd„ƒZeddœdd„ƒZeddœdd„ƒZeddœdd„ƒZeddœd d!„ƒZeddœd"d#„ƒZd$S )%ÚAndroida"  
    Follows the guidance `from here <https://android.stackexchange.com/a/216132>`_.

    Makes use of the `appname <platformdirs.api.PlatformDirsABC.appname>`, `version
    <platformdirs.api.PlatformDirsABC.version>`, `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.

    Ústr©Úreturnc                 C  s   |   tdtƒ ƒd¡S )zd:return: data directory tied to the user, e.g. ``/data/user/<userid>/<packagename>/files/<AppName>``r	   Úfiles©Ú_append_app_name_and_versionr   Ú_android_folder©Úself© r   ú:E:\soccer\ml_env\Lib\site-packages\platformdirs/android.pyÚuser_data_dir   s    zAndroid.user_data_dirc                 C  s   | j S )z@:return: data directory shared by users, same as `user_data_dir`©r   r   r   r   r   Úsite_data_dir   s    zAndroid.site_data_dirc                 C  s   |   tdtƒ ƒd¡S )z‡
        :return: config directory tied to the user, e.g.         ``/data/user/<userid>/<packagename>/shared_prefs/<AppName>``
        r	   Zshared_prefsr   r   r   r   r   Úuser_config_dir!   s    zAndroid.user_config_dirc                 C  s   | j S )zH:return: config directory shared by the users, same as `user_config_dir`)r   r   r   r   r   Úsite_config_dir)   s    zAndroid.site_config_dirc                 C  s   |   tdtƒ ƒd¡S )ze:return: cache directory tied to the user, e.g.,``/data/user/<userid>/<packagename>/cache/<AppName>``r	   Úcacher   r   r   r   r   Úuser_cache_dir.   s    zAndroid.user_cache_dirc                 C  s   | j S )zB:return: cache directory shared by users, same as `user_cache_dir`)r   r   r   r   r   Úsite_cache_dir3   s    zAndroid.site_cache_dirc                 C  s   | j S )zB:return: state directory tied to the user, same as `user_data_dir`r   r   r   r   r   Úuser_state_dir8   s    zAndroid.user_state_dirc                 C  s   | j }| jrtj |d¡}|S )zÃ
        :return: log directory tied to the user, same as `user_cache_dir` if not opinionated else ``log`` in it,
          e.g. ``/data/user/<userid>/<packagename>/cache/<AppName>/log``
        Úlog©r   ÚopinionÚosÚpathÚjoin©r   r!   r   r   r   Úuser_log_dir=   s    zAndroid.user_log_dirc                 C  s   t ƒ S )zT:return: documents directory tied to the user e.g. ``/storage/emulated/0/Documents``)Ú_android_documents_folderr   r   r   r   Úuser_documents_dirH   s    zAndroid.user_documents_dirc                 C  s   t ƒ S )zT:return: downloads directory tied to the user e.g. ``/storage/emulated/0/Downloads``)Ú_android_downloads_folderr   r   r   r   Úuser_downloads_dirM   s    zAndroid.user_downloads_dirc                 C  s   t ƒ S )zR:return: pictures directory tied to the user e.g. ``/storage/emulated/0/Pictures``)Ú_android_pictures_folderr   r   r   r   Úuser_pictures_dirR   s    zAndroid.user_pictures_dirc                 C  s   t ƒ S )zS:return: videos directory tied to the user e.g. ``/storage/emulated/0/DCIM/Camera``)Ú_android_videos_folderr   r   r   r   Úuser_videos_dirW   s    zAndroid.user_videos_dirc                 C  s   t ƒ S )zL:return: music directory tied to the user e.g. ``/storage/emulated/0/Music``)Ú_android_music_folderr   r   r   r   Úuser_music_dir\   s    zAndroid.user_music_dirc                 C  s   dS )zP:return: desktop directory tied to the user e.g. ``/storage/emulated/0/Desktop``z/storage/emulated/0/Desktopr   r   r   r   r   Úuser_desktop_dira   s    zAndroid.user_desktop_dirc                 C  s   | j }| jrtj |d¡}|S )zÇ
        :return: runtime directory tied to the user, same as `user_cache_dir` if not opinionated else ``tmp`` in it,
          e.g. ``/data/user/<userid>/<packagename>/cache/<AppName>/tmp``
        Útmpr   r#   r   r   r   Úuser_runtime_dirf   s    zAndroid.user_runtime_dirc                 C  s   | j S )zF:return: runtime directory shared by users, same as `user_runtime_dir`)r1   r   r   r   r   Úsite_runtime_dirq   s    zAndroid.site_runtime_dirN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úpropertyr   r   r   r   r   r   r   r$   r&   r(   r*   r,   r.   r/   r1   r2   r   r   r   r   r      sB   

r   )Úmaxsizez
str | Noner
   c                  C  s  d} t sNz.ddlm} td| ¡ ƒ}| ¡  ¡  ¡ } W n tyL   d} Y n0 | du r–z(ddl	m
} |dƒ}| ¡  ¡  ¡ } W n ty”   d} Y n0 | du rÔt d¡}tjD ] }| |¡r®| d¡d }  qÔq®d} | du �rt d¡}tjD ]"}| |¡rî| d¡d }  �qqîd} | S )	zE:return: base folder for the Android OS or None if it cannot be foundNr   )Ú	mActivityúandroid.content.Context©Ú	autoclassz /data/(data|user/\d+)/(.+)/filesz/filesz7/mnt/expand/[a-fA-F0-9-]{36}/(data|user/\d+)/(.+)/files)r   Úandroidr9   r   ZgetApplicationContextZgetFilesDirZgetParentFileÚgetAbsolutePathÚ	ExceptionÚjniusr<   ÚreÚcompileÚsysr!   ÚmatchÚsplit)Úresultr9   Úcontextr<   Úpatternr!   r   r   r   r   w   s<    








r   r	   c                  C  sL   z0ddl m}  | dƒ}| dƒ}| |j¡ ¡ }W n tyF   d}Y n0 |S )z,:return: documents folder for the Android OSr   r;   r:   úandroid.os.Environmentz/storage/emulated/0/Documents)r@   r<   ÚgetExternalFilesDirZDIRECTORY_DOCUMENTSr>   r?   )r<   rG   ÚenvironmentZdocuments_dirr   r   r   r%   §   s    
r%   c                  C  sL   z0ddl m}  | dƒ}| dƒ}| |j¡ ¡ }W n tyF   d}Y n0 |S )z,:return: downloads folder for the Android OSr   r;   r:   rI   z/storage/emulated/0/Downloads)r@   r<   rJ   ZDIRECTORY_DOWNLOADSr>   r?   )r<   rG   rK   Zdownloads_dirr   r   r   r'   ·   s    
r'   c                  C  sL   z0ddl m}  | dƒ}| dƒ}| |j¡ ¡ }W n tyF   d}Y n0 |S )z+:return: pictures folder for the Android OSr   r;   r:   rI   z/storage/emulated/0/Pictures)r@   r<   rJ   ZDIRECTORY_PICTURESr>   r?   )r<   rG   rK   Zpictures_dirr   r   r   r)   Ç   s    
r)   c                  C  sL   z0ddl m}  | dƒ}| dƒ}| |j¡ ¡ }W n tyF   d}Y n0 |S )z):return: videos folder for the Android OSr   r;   r:   rI   z/storage/emulated/0/DCIM/Camera)r@   r<   rJ   ZDIRECTORY_DCIMr>   r?   )r<   rG   rK   Z
videos_dirr   r   r   r+   ×   s    
r+   c                  C  sL   z0ddl m}  | dƒ}| dƒ}| |j¡ ¡ }W n tyF   d}Y n0 |S )z(:return: music folder for the Android OSr   r;   r:   rI   z/storage/emulated/0/Music)r@   r<   rJ   ZDIRECTORY_MUSICr>   r?   )r<   rG   rK   Z	music_dirr   r   r   r-   ç   s    
r-   )r6   Ú
__future__r   r    rA   rC   Ú	functoolsr   Útypingr   r   Úapir   r   r   r%   r'   r)   r+   r-   Ú__all__r   r   r   r   Ú<module>   s,   i/ÿ