
    8fO                         d dl Z d dlZd dlZd dlmZmZmZ d dlmZm	Z	 d dl
mZmZ d dlZ G d de      Z G d de      Z G d	 d
e      Z G d dej$                        Zd Zy)    N)QCoreApplication	qCritical	QFileInfo)QIconQFileSystemModel)QFileDialogQMessageBoxc                       e Zd Z	 y)FNISMissingExceptionN__name__
__module____qualname__     \C:\Program Files (x86)/Steam/steamapps/common/Skyrim Special Edition/MO2/plugins\FNISTool.pyr   r      s    @r   r   c                       e Zd Z	 y)FNISInactiveExceptionNr   r   r   r   r   r      s    Lr   r   c                       e Zd Z	 y) UnknownOutputPreferenceExceptionNr   r   r   r   r   r   !   s    Qr   r   c                        e Zd Z f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d Zd Zed        Z xZS )FNISToolc                 F    t         t        |           d | _        d | _        y N)superr   __init___FNISTool__organizer_FNISTool__parentWidget)self	__class__s    r   r   zFNISTool.__init__'   s     h&("r   c                     || _         t        j                  dk  rZt        | j	                  d             t        j                  | j                  | j	                  d      | j	                  d             yy)N)   r   zZFNISTool plugin requires a Python 3 interpreter, but is running on a Python 2 interpreter.zIncompatible Python version.zThis version of the FNIS Integration plugin requires a Python 3 interpreter, but Mod Organizer has provided a Python 2 interpreter. You should check for an updated version, including in the Mod Organizer 2 Development Discord Server.FT)r   sysversion_infor   trr	   criticalr   )r   	organizers     r   initzFNISTool.init,   sj    $f$dggz{|  !4!4dgg>\6]_c_f_f  hS  `T  Ur   c                      yNzFNIS Integration Toolr   r   s    r   namezFNISTool.name4   s    &r   c                 $    | j                  d      S r*   r%   r+   s    r   localizedNamezFNISTool.localizedName7   s    ww.//r   c                      y)NAnyOldName3r   r+   s    r   authorzFNISTool.author:   s    r   c                 $    | j                  d      S NzERuns GenerateFNISforUsers.exe so the game can load custom animations.r.   r+   s    r   descriptionzFNISTool.description=       ww^__r   c                 2    t        j                  dddd      S )N      r   )mobaseVersionInfor+   s    r   versionzFNISTool.version@   s    !!!Q1--r   c                 F    t         j                  j                  h d      gS )N>   	Skyrim VRSkyrim Special EditionSkyrim)r:   PluginRequirementFactorygameDependencyr+   s    r   requirementszFNISTool.requirementsC   s%    ++:: < 
 	
r   c                    t        j                  d| j                  d      d      t        j                  d| j                  d      d      t        j                  d| j                  d      d      t        j                  d	| j                  d
      d      t        j                  d| j                  d      d      t        j                  d| j                  d      d      gS )N	fnis-pathz Path to GenerateFNISforUsers.exe output-to-modz9Whether or not to direct the FNIS output to a mod folder.Toutput-pathz:When output-to-mod is enabled, the path to the mod to use.initialisedzCSettings have been initialised.  Set to False to reinitialise them.Foutput-logs-to-modz;Whether or not to direct any new FNIS logs to a mod folder.output-logs-pathz?When output-logs-to-mod is enabled, the path to the mod to use.)r:   PluginSettingr%   r+   s    r   settingszFNISTool.settingsL   s      dgg6X.Y[]^  $'':u2vx|}  8t0uwyz  8}0~  AF  G  !5tww?|7}  @D  E  !3TWW=~5  BD  E 	r   c                 $    | j                  d      S )NzFNIS/Run FNISr.   r+   s    r   displayNamezFNISTool.displayNameV   s    ww''r   c                 $    | j                  d      S r4   r.   r+   s    r   tooltipzFNISTool.tooltipY   r6   r   c                 n   | j                   j                  | j                         d      }t        j                  j                  |      rbt        |      }t               }|j                  |j	                                |j                  |j                  |j                                     S t        d      S )NrE   zplugins/FNIS.ico)r   pluginSettingr,   ospathexistsr   r   setRootPathfileIconindexfilePathr   )r   fnisPathfinmodels       r   iconzFNISTool.icon\   s    ##11$))+{K77>>(#H%C$&Echhj)>>%++clln"=>> +,,r   c                     || _         y r   )r   )r   widgets     r   setParentWidgetzFNISTool.setParentWidgeth   s
    $r   c                 	   g }d}d }d}t        | j                  j                  | j                         d            s| j                  j	                  | j                         dd       | j                  j	                  | j                         dd       | j                  j	                  | j                         dd       | j                  j	                  | j                         dd       | j                  j	                  | j                         dd       	 | j                         }|rG	 | j                         }|j                  d|z   dz          t        j                  |      j                  }|j                  d       |rC	 | j                         }|r0	 | j!                         }t        j                  |      j                  }	 | j#                         }| j                  j	                  | j                         dd       |rV| j                  j)                         j+                  |d       r*| j                  j)                         j+                  |d       | j                  j-                  |||t        |             }| j                  j/                  |      \  }	}
|r| j                  j)                         j+                  |d       | j                  j1                  | j                  j3                  |             r5| j                  j1                  | j                  j3                  |             y y y # t        $ rB t        j                  | j                  | j                  d	      | j                  d
             Y y w xY w# t        $ rB t        j                  | j                  | j                  d      | j                  d             Y y w xY w# t        $ rB t        j                  | j                  | j                  d	      | j                  d
             Y y w xY w# t        $ rB t        j                  | j                  | j                  d      | j                  d             Y y w xY w# t$        $ rB t        j                  | j                  | j                  d      | j                  d             Y y t&        $ r Y y w xY w)NTrF   rI   rE   rH   rG   rK   rJ   zOutput preference not setzLWhether or not to output to a mod was not specified. The tool will now exit.zRedirectFiles=""zOutput mod not setz?The mod to output to was not specified. The tool will now exit.zInstantExecute=1zFNIS path not specifiedzNThe path to GenerateFNISforUsers.exe wasn't specified. The tool will now exit.F)forcedCustomOverwriteignoreCustomOverwrite)boolr   rS   r,   setPluginSetting_FNISTool__getRedirectOutputr   r	   r&   r   r%   _FNISTool__getOutputPathappendpathlibPath_FNISTool__getRedirectLogs_FNISTool__getLogOutputPath_FNISTool__getFNISPathr   r   modList	setActivestartApplicationwaitForApplicationmodDataChangedgetMod)r   argsredirectOutputoutputModNamelogOutputModName
outputPathredirectLogs
executablehandleresultexitCodes              r   displayzFNISTool.displayk   sS   D$$22499;NO--diik;K--diik="M--diik?DQ--diik;MrR--diik;OQUV	!557N !113
-
:S@A 'Z 8 = = 	&'#557 !%!8!8!:J'.||J'?'D'D$
	++-J 	))$))+}dK$$&00F  ((*445EtL !!22:t[k  HL  M]  H^  D^2  _++>>vF$$&00E++D,<,<,C,CM,RS  //0@0@0G0GHX0YZ  e 0 	  !4!4dgg>Y6Z\`\c\c  es  ]t  u	 4 $$T%8%8$''BV:WY]Y`Y`  bc  Zd  e 4 $$T%8%8$''B]:^`d`g`g  iw  ax  y 8 (()<)<dggFZ>[]a]d]d  fg  ^h  i $ 	  !4!4dgg>W6XZ^ZaZa  cs  [t  u$ 		sf   L7 'AN O /P! Q/ 7ANNAOOAPP!AQ,+Q,/AS9SSc                 .    t        j                  d|      S )Nr   )r   	translate)r   strs     r   r%   zFNISTool.tr   s    ))*c::r   c           	         t        | j                  j                  | j                         d            }t        | j                  j                  | j                         d            }|st	        j
                  | j                  | j                  d      | j                  d      t	        j                  t        j                  j                  t        j                  j                  z  t        j                  j                  z              }|t        j                  j                  k(  rd}n&|t        j                  j                  k(  rd}nt        | j                  j                  | j                         d|       |S )NrG   rI   zOutput to a mod?a  Fore's New Idles in Skyrim can output either to Mod Organizer's VFS (potentially overwriting files from multiple mods) or to a separate mod. Would you like FNIS to output to a separate mod? This setting can be updated in the Plugins tab of the Mod Organizer Settings menu.TFrf   r   rS   r,   r	   questionr   r%   StandardButtonYesNoCancelr   rg   )r   rw   rI   r~   s       r   __getRedirectOutputzFNISTool.__getRedirectOutput   sx   d..<<TYY[/Z[4++99$))+}UV ))$*=*=twwGY?Z\`\c\c  ew  ]x  zE  zT  zT  U`  Uo  Uo  Us  Us  vA  vP  vP  vS  vS  US  Va  Vp  Vp  Vw  Vw  Uw  zx  yF33777!%;55888!& 76--diik?N[r   c           	         t        | j                  j                  | j                         d            }t        | j                  j                  | j                         d            }|st	        j
                  | j                  | j                  d      | j                  d      t	        j                  t        j                  j                  t        j                  j                  z  t        j                  j                  z              }|t        j                  j                  k(  rd}n&|t        j                  j                  k(  rd}nt        | j                  j                  | j                         d|       |S )NrJ   rI   zOutput logs to a mod?zAny new logs generated when running FNIS will end up in Mod Organizer's overwrite folder. Would you like these logs to be output to a separate mod? This setting can be updated in the Plugins tab of the Mod Organizer Settings menu.TFr   )r   r{   rI   r~   s       r   __getRedirectLogszFNISTool.__getRedirectLogs   s{   D,,::499;H\]^4++99$))+}UV ))$*=*=twwG^?_aeahah  jR  bS  U`  Uo  Uo  p{  pJ  pJ  pN  pN  Q\  Qk  Qk  Qn  Qn  pn  q|  qK  qK  qR  qR  pR  US  TF33777#;55888$ 76--diik;OQ]^r   c           	         | j                   j                  | j                         d      }t        j                  |      }| j                         }|j                  j                  |      }|j                         r|sIt        j                  | j                  | j                  d      | j                  d             |j                         r|st        j                  | j                  | j                  d      t        |      t        j                   j"                        }|st$        t        j                  |      }|j                  j                  |      }|s@t        j                  | j                  | j                  d      | j                  d             d}|j'                         D ]  }|j                  dk7  sd} n |st        j(                  | j                  | j                  d	      | j                  d
      t        j*                  t        j*                  j,                  t        j*                  j.                  z              t        j*                  j,                  k(  rnd}|j                         s|s| j                   j1                          | j                   j3                  | j                         d|       |S )NrH   Choose an output modao  Please choose an output mod for Fore's New Idles in Skyrim. This must be a directory in Mod Organizer's mods directory, and you can create one if you do not have one already. This mod will not be available to the VFS when FNIS is run, so do not choose a mod you use for anything else. This setting can be updated in the Plugins tab of the Mod Organizer Settings menu.Not a mod...oThe selected directory is not a Mod Organizer managed mod. Please choose a directory within the mods directory.Tmeta.iniFMod not emptyWThe selected mod already contains files. Are you sure want to use it as the output mod?)r   rS   r,   rk   rl   _FNISTool__getModDirectoryparentsamefileis_dirr	   informationr   r%   r   getExistingDirectoryr   OptionShowDirsOnlyr   iterdirr   r   r   r   refreshModListrg   )r   rU   pathlibPathmodDirectoryisAModemptyitems          r   __getOutputPathzFNISTool.__getOutputPath   s   --diik=Ill4(--/##,,\:!!#6##D$7$7AW9XZ^ZaZa  cT  [U  V!((*&"778K8KTWWUkMlnqr~n  BM  BT  BT  Ba  Ba  b::%ll40$++44\B++D,?,?AXZ^ZaZa  cT  [U  V'//1 DyyJ. % "++D,?,?AY[_[b[b  d}  \~  @K  @Z  @Z  [f  [u  [u  [y  [y  |G  |V  |V  |Y  |Y  [Y  @Z  [  _j  _y  _y  _}  _}  } "'+ "((*&. ++---diik=$Or   c           	         | j                   j                  | j                         d      }t        j                  |      }| j                         }t        j                  | j                               }|j                  j                  |      }|j                  |      }|j                         r|r|rt        j                  | j                  | j                  d      | j                  d             |j                         r|r|r
t        j                  | j                  | j                  d      t!        |      t        j"                  j$                        }|st&        t        j                  |      }|j                  j                  |      }|s@t        j                  | j                  | j                  d      | j                  d             |j                  |      }|rAt        j                  | j                  | j                  d      | j                  d             5d	}|j)                         D ]  }|j                  d
k7  sd} n |st        j*                  | j                  | j                  d      | j                  d      t        j,                  t        j,                  j.                  t        j,                  j0                  z              t        j,                  j.                  k(  rnd}|j                         s|s|r
| j                   j3                          | j                   j5                  | j                         d|       |S )NrK   r   a7  Please choose an output mod for logs for Fore's New Idles in Skyrim. This must be a directory in Mod Organizer's mods directory, must not be the same as the FNIS output mod, and you can create one if you do not have one already. This setting can be updated in the Plugins tab of the Mod Organizer Settings menu.zChoose a log output modr   r   zSame as FNIS outputzTThe selected mod is the same as the FNIS output mod.  Please choose a different mod.Tr   Fr   r   )r   rS   r,   rk   rl   r   ri   r   r   r   r	   r   r   r%   r   r   r   r   r   r   r   r   r   r   r   r   rg   )	r   rU   r   r   fnisOutputPathr   isSameAsFnisOutputr   r   s	            r   __getLogOutputPathzFNISTool.__getLogOutputPath   sC   --diik;MNll4(--/ d&:&:&<=##,,\:(11.A!!#65G##D$7$7AW9XZ^ZaZa  c\  []  ^!((*&<N"778K8KTWWUnMoqt  vB  rC  EP  EW  EW  Ed  Ed  e::%ll40$++44\B++D,?,?AXZ^ZaZa  cT  [U  V%0%9%9.%I"%++D,?,?I^A_aeahah  j@  bA  B'//1 DyyJ. % "++D,?,?AY[_[b[b  d}  \~  @K  @Z  @Z  [f  [u  [u  [y  [y  |G  |V  |V  |Y  |Y  [Y  @Z  [  _j  _y  _y  _}  _}  } "'3 "((*&<N8 ++---diik;MtTr   c           	      
   | j                   j                  | j                         d      }| j                         }t	        j
                  | j                   j                         j                         j                               }t	        j
                  |      }| j                  ||      }|| j                  ||      z  }|j                         r|sEt        j                  | j                  | j                  d      | j                  d             	 t        j                   | j                  | j                  d      t#        |      d      d   }|dk(  rt$        t	        j
                  |      }| j                  ||      }|| j                  ||      z  }|j                         r0|r.| j                   j'                  | j                         d|       |}nAt        j                  | j                  | j                  d	      | j                  d
             | j                  ||      rXd }|j(                  D ]+  }|j*                  j-                  |      s|j                  } n | j                   j/                         j1                  |      t2        j4                  j6                  z  dk(  rt        j8                  | j                  | j                  d      | j                  d      t        j:                  t        j:                  j<                  t        j:                  j>                  z              }|t        j:                  j<                  k(  r,| j                   j/                         jA                  |d       |S tB        |S )NrE   z	Find FNISaj  Fore's New Idles in Skyrim can't be found using the location saved in Mod Organizer's settings. Please find GenerateFNISforUsers.exe in the file picker. FNIS must be visible within the VFS, so choose an installation either within the game's data directory or within a mod folder. This setting can be updated in the Plugins tab of the Mod Organizer Settings menu.TzLocate GenerateFNISforUsers.exezFNIS (GenerateFNISforUsers.exe)r   rF   zNot a compatible location...zFore's New Idles in Skyrim only works when within the VFS, so must be installed to the game's data directory or within a mod folder. Please select a different FNIS installation.zFNIS mod deactivatedznFore's New Idles in Skyrim is installed to an inactive mod. Press OK to activate it or Cancel to quit the tool)"r   rS   r,   r   rk   rl   managedGamedataDirectoryabsolutePath_FNISTool__withinDirectoryis_filer	   r   r   r%   r   getOpenFileNamer   r   rg   parentsr   r   rp   stater:   ModStateactiver   r   Okr   rq   r   )	r   	savedPathr   gameDataDirectoryr   inGoodLocationrU   fnisModNamer~   s	            r   __getFNISPathzFNISTool.__getFNISPath#  sL   $$22499;L	--/#LL)9)9)E)E)G)U)U)W)d)d)fgll9-//\J$00>OPP""$N##D$7$79Mtww  XD  PE  F"2243F3FPqHrtw  yE  uF  Hi  j  kl  m2:..%ll40!%!7!7\!R$"8"8FW"XX&&(^$$55diik;PTU $I++D,?,?IgAhjnjqjq  sf  kg  h  !!+|<K#++ ;;''5"&))K   ((*00=@V@VV[\\$--d.A.A477KaCbdhdkdk  m]  e^  `k  `z  `z  {F  {U  {U  {X  {X  [f  [u  [u  [|  [|  {|  `}  ~[77:::$$,,.88dK  0/r   c                 6    | j                   j                         S r   )r   modsPathr+   s    r   __getModDirectoryzFNISTool.__getModDirectoryK  s    ((**r   c                 L    | j                   D ]  }|j                  |      s y y)NTF)r   r   )	innerPathouterDirrU   s      r   __withinDirectoryzFNISTool.__withinDirectoryN  s+    %% 	D}}X&	 r   )r   r   r   r   r(   r,   r/   r2   r5   r<   rC   rM   rO   rQ   r^   ra   r   r%   rh   rm   ri   rn   ro   r   staticmethodr   __classcell__)r    s   @r   r   r   %   s    #
'0`.
(`
-%H[T;   D'R&P+  r   r   c                      t               S r   )r   r   r   r   createPluginr   U  s
    :r   )rT   rk   r#   PyQt6.QtCorer   r   r   PyQt6.QtGuir   r   PyQt6.QtWidgetsr   r	   r:   	Exceptionr   r   r   IPluginToolr   r   r   r   r   <module>r      s]    
  
 ? ? / 4 	9 		I 		y 	nv!! n`	r   