ó
2…6ic           @   sÍ   d  d l  Z  d  d l Z d  d l Z d  d l Z d  d l Z d  d l m Z m Z d  d l	 Z	 e j
 ƒ  Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ e a e a e j ƒ  Z d „  Z d „  Z d	 „  Z d S(
   iÿÿÿÿN(   t
   clear_slott   safe_renamet   FileLocationc           B   sž   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s=   
    A location that saves files to a directory on disk.
    c         C   sË   | |  _  y t j |  j  ƒ Wn n XyW t j j |  j  d ƒ } t | d ƒ  } | j d ƒ Wd  QXt j | ƒ t |  _	 Wn t
 |  _	 n Xi  |  _ t j j |  j  d ƒ |  _ d |  _ d  |  _ d  S(   Ns   text.txtt   ws   Test.t
   persistenti    (   t	   directoryt   ost   makedirst   patht   joint   opent   writet   unlinkt   Truet   activet   Falset   mtimesR   t   persistent_mtimet   Nonet   persistent_data(   t   selfR   t   fnt   f(    (    sa   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\savelocation.pyt   __init__-   s"    			c         C   s)   t  j j |  j t j j | t j ƒ ƒ S(   s8   
        Given a slot name, returns a filename.
        (   R   R   R	   R   t   renpyt   exportst   fsencodet   savegame_suffix(   R   t   slotname(    (    sa   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\savelocation.pyt   filenameO   s    c   
   	   C   s¸  |  j  s d St Ÿ|  j } i  } t j } t | ƒ } xp t j |  j ƒ D]\ } | j	 | ƒ sf qK n  | |  } y, t j
 j t j
 j |  j | ƒ ƒ | | <WqK qK XqK W| |  _ x? | j ƒ  D]1 \ } } | j | d ƒ | k rÁ t | ƒ qÁ qÁ Wx' | D] } | | k rý t | ƒ qý qý Wx‹ |  j d |  j g D]s } t j
 j | ƒ r7t j
 j | ƒ } | |  j k rªt j j | ƒ }	 |	 d k	 r§| |  _ |	 |  _ Pq§qªq7q7WWd QXd S(   s;   
        Scan for files that are added or removed.
        Ns   .new(   R   t	   disk_lockR   R   R   t   lenR   t   listdirR   t   endswithR   t   getmtimeR	   t	   iteritemst   getR   R    R   t   existsR   t   loadR   (
   R   t
   old_mtimest
   new_mtimest   suffixt
   suffix_lenR   R   t   mtimet   pfnt   data(    (    sa   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\savelocation.pyt   scanV   s>    			,			c         C   s7   |  j  | ƒ } t  | j | ƒ Wd QX|  j ƒ  d S(   s4   
        Saves the save record in slotname.
        N(   R   R   t
   write_fileR.   (   R   R   t   recordR   (    (    sa   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\savelocation.pyt   save†   s    c         C   s   t  |  j ƒ S(   sa   
        Returns a list of all slots with savefiles in them, in arbitrary
        order.
        (   t   listR   (   R   (    (    sa   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\savelocation.pyR2   ’   s    c         C   s   |  j  j | d ƒ S(   s…   
        For a slot, returns the time the object was saved in that
        slot.

        Returns None if the slot is empty.
        N(   R   R$   R   (   R   R   (    (    sa   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\savelocation.pyR+   š   s    c         C   s¸   t  ¬ y% |  j | ƒ } t j | d ƒ } Wn d SXzi y& | j d ƒ } t j | ƒ } | SWn n Xy' | j d ƒ j d ƒ } i | d 6SWn n Xi  SWd | j	 ƒ  XWd QXd S(   sa   
        Returns the JSON data for slotname.

        Returns None if the slot is empty.
        t   rt   jsont
   extra_infos   utf-8t
   _save_nameN(
   R   R   t   zipfilet   ZipFileR   t   readR4   t   loadst   decodet   close(   R   R   R   t   zfR-   R5   (    (    sa   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\savelocation.pyR4   ¤   s(    c         C   sá   t  Õ |  j | ƒ } | d k r& d Sy% |  j | ƒ } t j | d ƒ } Wn d SXy t } | j d ƒ Wn t } | j d ƒ n X| j	 ƒ  | r¸ t
 j j j | d | ƒ } n t
 j j j | d | ƒ } | SWd QXd S(   s{   
        Returns a displayable that show the screenshot for this slot.

        Returns None if the slot is empty.
        R3   s   screenshot.tgas   screenshot.pngN(   R   R+   R   R   R7   R8   R   t   getinfoR   R<   R   t   displayt   imt   ZipFileImage(   R   R   R+   R   R=   t   pngt
   screenshot(    (    sa   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\savelocation.pyRC   Ç   s(    
c         C   sO   t  C |  j | ƒ } t j | d ƒ } | j d ƒ } | j ƒ  | SWd QXd S(   si   
        Returns the log component of the file found in `slotname`, so it
        can be loaded.
        R3   t   logN(   R   R   R7   R8   R9   R<   (   R   R   R   R=   t   rv(    (    sa   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\savelocation.pyR&   ë   s    
c         C   sL   t  @ |  j | ƒ } t j j | ƒ r8 t j | ƒ n  |  j ƒ  Wd QXd S(   s/   
        Deletes the file in slotname.
        N(   R   R   R   R   R%   R   R.   (   R   R   R   (    (    sa   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\savelocation.pyR   û   s
    c         C   s   t  u |  j | ƒ } |  j | ƒ } t j j | ƒ s; d St j j | ƒ r] t j | ƒ n  t j | | ƒ |  j ƒ  Wd QXd S(   s3   
        If old exists, renames it to new.
        N(   R   R   R   R   R%   R   t   renameR.   (   R   t   oldt   new(    (    sa   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\savelocation.pyRF     s    c         C   s_   t  S |  j | ƒ } |  j | ƒ } t j j | ƒ s; d St j | | ƒ |  j ƒ  Wd QXd S(   s9   
        Copies `old` to `new`, if `old` exists.
        N(   R   R   R   R   R%   t   shutilt   copyfileR.   (   R   RG   RH   (    (    sa   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\savelocation.pyt   copy  s    c         C   s$   |  j  r |  j |  j  f g Sg  Sd S(   s½   
        Returns a list of (mtime, persistent) tuples loaded from the
        persistent file. This should return quickly, with the actual
        load occuring in the scan thread.
        N(   R   R   (   R   (    (    sa   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\savelocation.pyt   load_persistent,  s    	c      
   C   sz   t  n |  j s d S|  j } | d } | d } t | d ƒ  } | j | ƒ Wd QXt | | ƒ t | | ƒ Wd QXd S(   sƒ   
        Saves `data` as the persistent data. Data is a binary string giving
        the persistent data in python format.
        Ns   .tmps   .newt   wb(   R   R   R   R
   R   R   (   R   R-   R   t   fn_tmpt   fn_newR   (    (    sa   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\savelocation.pyt   save_persistent8  s    		

c         C   s/   |  j  s d  Sy t j |  j ƒ Wn n Xd  S(   N(   R   R   R   R   (   R   (    (    sa   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\savelocation.pyt   unlink_persistentM  s    	c         C   s#   t  | t ƒ s t S|  j | j k S(   N(   t
   isinstanceR   R   R   (   R   t   other(    (    sa   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\savelocation.pyt   __eq__W  s    (   t   __name__t
   __module__t   __doc__R   R   R.   R1   R2   R+   R4   RC   R&   R   RF   RK   RL   RP   RQ   RT   (    (    (    sa   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\savelocation.pyR   (   s"   	"		0			
	#	$							
t   MultiLocationc           B   s°   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   sš   
    A location that saves in multiple places. When loading or otherwise
    accessing a file, it loads the newest file found for the given slotname.
    c         C   s   g  |  _  d  S(   N(   t	   locations(   R   (    (    sa   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\savelocation.pyR   d  s    c         C   s#   g  |  j  D] } | j r
 | ^ q
 S(   N(   RY   R   (   R   t   i(    (    sa   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\savelocation.pyt   active_locationsg  s    c         C   s]   d } d } xJ |  j D]? } | j s+ q n  | j | ƒ } | | k r | } | } q q W| S(   s€   
        Returns the location containing the slotname with the newest
        mtime. Returns None of the slot is empty.
        iÿÿÿÿN(   R   RY   R   R+   (   R   R   R+   t   locationt   lt
   slot_mtime(    (    sa   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\savelocation.pyt   newestj  s    	c         C   s'   | |  j  k r d S|  j  j | ƒ d S(   s&   
        Adds a new location.
        N(   RY   t   append(   R   R\   (    (    sa   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\savelocation.pyt   add  s    c         C   sL   t  } x* |  j ƒ  D] } | j | | ƒ t } q W| sH t d ƒ ‚ n  d  S(   Ns$   Not saved - no valid save locations.(   R   R[   R1   R   t	   Exception(   R   R   R0   t   savedR]   (    (    sa   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\savelocation.pyR1   ‰  s    
c         C   s=   t  ƒ  } x' |  j ƒ  D] } | j | j ƒ  ƒ q Wt | ƒ S(   N(   t   setR[   t   updateR2   (   R   RE   R]   (    (    sa   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\savelocation.pyR2   ”  s    	c         C   s,   |  j  | ƒ } | d  k r d  S| j | ƒ S(   N(   R_   R   R+   (   R   R   R]   (    (    sa   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\savelocation.pyR+   œ  s    c         C   s,   |  j  | ƒ } | d  k r d  S| j | ƒ S(   N(   R_   R   R4   (   R   R   R]   (    (    sa   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\savelocation.pyR4   ¤  s    c         C   s,   |  j  | ƒ } | d  k r d  S| j | ƒ S(   N(   R_   R   RC   (   R   R   R]   (    (    sa   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\savelocation.pyRC   ¬  s    c         C   s   |  j  | ƒ } | j | ƒ S(   N(   R_   R&   (   R   R   R]   (    (    sa   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\savelocation.pyR&   ´  s    c         C   s(   x! |  j  ƒ  D] } | j | ƒ q Wd  S(   N(   R[   R   (   R   R   R]   (    (    sa   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\savelocation.pyR   ¸  s    c         C   s+   x$ |  j  ƒ  D] } | j | | ƒ q Wd  S(   N(   R[   RF   (   R   RG   RH   R]   (    (    sa   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\savelocation.pyRF   ¼  s    c         C   s+   x$ |  j  ƒ  D] } | j | | ƒ q Wd  S(   N(   R[   RK   (   R   RG   RH   R]   (    (    sa   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\savelocation.pyRK   À  s    c         C   s4   g  } x' |  j  ƒ  D] } | j | j ƒ  ƒ q W| S(   N(   R[   t   extendRL   (   R   RE   R]   (    (    sa   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\savelocation.pyRL   Ä  s    c         C   s(   x! |  j  ƒ  D] } | j | ƒ q Wd  S(   N(   R[   RP   (   R   R-   R]   (    (    sa   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\savelocation.pyRP   Ì  s    c         C   s%   x |  j  ƒ  D] } | j ƒ  q Wd  S(   N(   R[   RQ   (   R   R]   (    (    sa   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\savelocation.pyRQ   Ñ  s    c         C   s"   x |  j  D] } | j ƒ  q
 Wd  S(   N(   RY   R.   (   R   R]   (    (    sa   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\savelocation.pyR.   Ö  s    c         C   s#   t  | t ƒ s t S|  j | j k S(   N(   RR   RX   R   RY   (   R   RS   (    (    sa   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\savelocation.pyRT   Ý  s    (   RU   RV   RW   R   R[   R_   Ra   R1   R2   R+   R4   RC   R&   R   RF   RK   RL   RP   RQ   R.   RT   (    (    (    sa   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\savelocation.pyRX   ^  s&   				
													c           C   sO   t  a xB t sJ y t j j j ƒ  Wn n Xt  t j d ƒ Wd  QXq	 Wd  S(   Ng      @(   R   t   quit_scan_threadR   t   loadsaveR\   R.   t   scan_thread_conditiont   wait(    (    (    sa   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\savelocation.pyt   run_scan_threadî  s    	c           C   s+   t   t a t  j ƒ  Wd  QXt j ƒ  d  S(   N(   Ri   R   Rg   t	   notifyAllt   scan_threadR	   (    (    (    sa   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\savelocation.pyt   quitþ  s    c          C   s   t  ƒ  }  |  j t t j j ƒ ƒ t j rg t j rg t j	 j
 t j j d ƒ } |  j t | ƒ ƒ n  |  j ƒ  |  t j _ t j d t ƒ a t j ƒ  d  S(   Nt   savest   target(   RX   Ra   R   R   t   configt   savedirt   mobilet   macappR   R   R	   t   gamedirR.   Rh   R\   t	   threadingt   ThreadRk   Rm   t   start(   R\   R   (    (    sa   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\savelocation.pyt   init  s    	
(   R   R7   R4   t   renpy.displayR   Rv   t   renpy.loadsaveR    R   RI   t   RLockR   t   objectR   RX   R   Rm   R   Rg   t	   ConditionRi   Rk   Rn   Ry   (    (    (    sa   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\savelocation.pyt   <module>   s    ÿ 7‡		
