#!/usr/bin/env python3
"""Conservar solo datos propios de un cliente v1; nunca perfiles de la maestra."""
import sys,shutil
from pathlib import Path
def migrar(old,new):
    new=Path(new);marker=new/'.mundogames-pes13-perfil-v2'
    if marker.exists():return 0
    count=0
    if old:
        old=Path(old)
        # La botella wine-tkg de la maestra no satisface estas condiciones.
        if old.name=='PES 2013.pc.wine' and old.parent.name in ['wine-tkg-pes2013-9.21','wine-tkg-pes2013-9.21-compat'] and (old/'.mundogames-pes13-v1').is_file():
            rel=Path('drive_c/users/root/Documents/KONAMI/Pro Evolution Soccer 2013')
            source=old/rel;dest=new/rel
            if old.resolve() not in source.resolve().parents or new.resolve() not in dest.resolve().parents:
                raise RuntimeError('Perfil fuera de la botella: no se modifica')
            if source.is_dir():
                for p in source.rglob('*'):
                    if not p.is_file() or p.is_symlink():continue
                    if p.name!='settings.dat' and not (p.suffix.lower()=='.bin' and 'save' in p.relative_to(source).parts):continue
                    if source.resolve() not in p.resolve().parents:raise RuntimeError('Enlace externo en perfil')
                    target=dest/p.relative_to(source)
                    if target.exists():continue
                    target.parent.mkdir(parents=True,exist_ok=True);shutil.copy2(p,target);count+=1
    marker.write_text('2\n')
    return count
if __name__=='__main__':print('Archivos propios del cliente conservados:',migrar(sys.argv[1],sys.argv[2]))
