
    Ca                     2   % S SK r S SKrS SKJr  S SKJrJrJrJr  SSK	J
r
  Sq\\S'   S\\\4   S	\S
\4S jrS\S
S4S jrS\S\\   S	\S
S4S jrS\S	\S
S4S jrS\\\4   S
\4S jrS\S\\\4   S
S4S jrS\\\4   S
S4S jrSSKJr  S	\S
S4S jrg)    N)Path)AnyIOUnioncast   )log_tracebackT	_COMPRESSpathcompressreturnc                     [        U 5      nU(       a0  UR                  S:X  a  U$ UR                  UR                  S-   5      $ UR                  S:X  a  UR                  S5      $ U$ )Nz.gz )r   suffixwith_suffix)r   r   ps      jZ:\mnt\Skyabridged\SteamLibrary\steamapps\common\Borderlands 2\sdk_mods\SanitySaver\compression_handler.py_convert_pathr      sW    T
A88uH==E!12288u==$$H    c                 p     U R                  5         g ! [         a     g [         a    [        5          g f = f)N)unlinkFileNotFoundErrorOSErrorr	   r   s    r   _delete_single_filer      s/      s    
555datafilec                 j    [         R                  " U U[        (       a  S OSS[        (       a  SOS4S9  g )N   ,:z: )indent
separators)jsondumpr
   )r   r   r   s      r   
_dump_filer&   "   s+    II yta		t4	r   c           	          U(       a  SOSu  p#[         R                  " [        U S5      USS9 n[        [        U S5      USS9 nX%U[        [        [
           U5      0n[        R                  " US   5      n[        XvS   U5        S S S 5        S S S 5        U R                  5         g ! , (       d  f       N'= f! , (       d  f       N0= f! [         a    [        5          g f = f)	N)rtwt)r)   r(   Tutf8encodingFr(   r)   )gzipopenr   r   r   strr$   loadr&   r   r   r	   )r   r   	json_mode	gzip_mode	gzip_file	json_filefile_mapr   s           r   _update_single_file_compressionr6   +   s    /7|\	YY}T40)fMQZmD%0)fMQZ tBsGY7	 yy$04$: N N 	 NM NM  sA   -C B:AB)B:C )
B7	3B::
CC C"!C"c                    [        U [        5      n[        U [        (       + 5      nUR                  5       (       ag  UR                  5       (       a6  UR                  5       R                  UR                  5       R                  :  a  [        U[        5        O[        U5        [        (       a  [        R                  O[        nU" USSS9 n[        R                  " U5      sSSS5        $ ! , (       d  f       g= f)z?Loads json data (which may be compressed) from the given file. r(   r*   r+   N)r   r
   existsstatst_mtimer6   r   r-   r.   r$   r0   )r   correct_fileincorrect_file	open_funcr   s        r   r0   r0   A   s     y1L"4Y7N ##%%""$--0A0A0C0L0LL+L)D/&Y		DI	<	74yy 
8	7	7s   C++
C9c                 8   [         (       a  [        R                  O[        n U" [        U[         5      SSS9 n[	        X[         5        SSS5        [        [        U[         (       + 5      5        g! , (       d  f       N-= f! [
         a    [        5          NFf = f)zKDumps the given json data into the given file, compressing it if required. r)   r*   r+   N)r
   r-   r.   r   r&   r   r	   r   )r   r   r=   r   s       r   r%   r%   V   sl    &Y		DI}T95tfMQUt9- N
 d	M:; NM s.   B A1
B 1
A?;B ?B BBc                 X    [        [        U S5      5        [        [        U S5      5        g)zWDeletes the given file, including a version with incorrect compression (if it exists). TFN)r   r   r   s    r   deleter@   c   s     dD12dE23r   )
_SAVES_DIRc                 j    U q [        R                  " U (       a  SOS5       H  n[        X5        M     g)za
Changes if save files will be compressed, and updates any existing files to the correct format.
z*.jsonz	*.json.gzN)r
   rA   globr6   )r   r   s     r   update_compressionrD   l   s)    
 IH+F'7 Gr   )r-   r$   pathlibr   typingr   r   r   r   helpersr	   r
   bool__annotations__r/   r   r   r&   r6   r0   r%   r@   save_managerrA   rD    r   r   <module>rL      s	      ' ' "	4 c4i( D T d t S 3 4 D $ $ 4 ,uS$Y C *
<s 
<%T	* 
<t 
<4sDy! 4d 4 %8 8$ 8r   