Advertisement
littlebelialskey

WIP_getLastLogsOnly_1.5.1.4.ps1

Aug 16th, 2024
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PowerShell 7.48 KB | Source Code | 0 0
  1. <# -------- GO getLastLogsOnly for Shtivi's  RDR2 mods  --------
  2.     1.1 : Contracts + curDate dans le filename
  3.     1.2 : OK pour Bounties, BUGS : filename est juste ".log"
  4.     1.3 : retour au dir ou le script a ete lance
  5.     1.4.0 : [WIP] Ajoute params
  6.     1.4.1 : supprime $input_targetModDirPath inutile
  7.     1.4.2 : variabilise args0
  8.     1.4.3 : list allowed params OK
  9.     1.5.0 : PEC allowed params list true
  10.     1.5.1.0 : remplace $input_targetModDirPath par input_targetDirPath BUG : isAllowed ne marche pu (OK FIX)
  11.  ---------- WIP [OK]
  12.     1.5.1.1 : messageerreur si !allowedparam
  13.     1.5.1.2 :  BUG : rien ne marche sauf input vide, FIX : BUG : maintenant tout passe
  14.     1.5.1.3 : essaye de fix le BUG maintenant tout passe (BUG : input dir :  rrr allowed  : True) SAUF VOID
  15.     1.5.1.4 : essaye de fix le BUG maintenant tout passe (BUG : input dir :  rrr allowed  : True) SAUF VOID
  16.         ---> FIX ERROR toujours TRUE sauf VOID  : $input_params = $args : $paramIsAllowed = $input_modName -in $input_params ----> $paramIsAllowed = $input_modName -in $allowedParams
  17.         + renomme $input_targetModDirPath en input_modName (SAUF ou c'est effectivement un PATH)
  18.         + ajoute USAGE : <nom du script + nouvelle function getCurrentScriptFilename(){ return Split-Path $PSCommandPath -Leaf }
  19.  
  20.  
  21.  
  22.     BUG : Get-content : Cannot find path 'D:\SCRIPTS_TRUCS\POWERSHELL\RDR2\Log.log' because it does not exist.
  23.         At D:\SCRIPTS_TRUCS\POWERSHELL\RDR2\script_getLastLogsOnly_1.5.1.4.ps1:191 char:1
  24.         + Get-content -tail $latestLogLinesLength .\Log.log > $outputFilename
  25.     ---> NEED fullpath du fichier de Log.log
  26.  
  27.  
  28.  
  29. <#  ==========================================   ___    ___    _  _    ___   _____   ___    ___    _  _   ___  ========================================== #>
  30. <#  ==========================================  | __|  / _ \  | \| |  / __| |_   _| |_ _|  / _ \  | \| | / __| ========================================== #>
  31. <#  ==========================================  | _|  | (_) | | .` | | (__    | |    | |  | (_) | | .` | \__ \ ================small===================== #>
  32. <#  ==========================================  |_|    \___/  |_|\_|  \___|   |_|   |___|  \___/  |_|\_| |___/ ========================================== #>
  33. <#  ==========================================                                                                 ========================================== #>
  34.  
  35. function getCurrentScriptFilename(){
  36.     return Split-Path $PSCommandPath -Leaf
  37. }
  38.  
  39. <#  ==========================================  ___   _  _   ___   _____   ========================================== #>
  40. <#  ========================================== |_ _| | \| | |_ _| |_   _|  ========================================== #>
  41. <#  ==========================================  | |  | .` |  | |    | |    ====small================================= #>
  42. <#  ========================================== |___| |_|\_| |___|   |_|    ========================================== #>
  43. <#  ==========================================                             ========================================== #>
  44.  
  45.  
  46.  
  47. $currentScriptName = Split-Path $PSCommandPath -Leaf
  48. Write-Host "Executing script :" $currentScriptName
  49.  
  50. $currentScriptName2 = getCurrentScriptFilename
  51. Write-Host "Executing script :$currentScriptName2"
  52.  
  53. # $currentScriptName3 = $MyInvocation.ScriptName -Leaf
  54. # Write-Host "Executing script : $currentScriptName3"
  55.  
  56.  
  57. # $currentScriptName3 = $MyInvocation.MyCommand.Name
  58. # Write-Host "Executing script : $currentScriptName4"
  59.  
  60.  
  61. Write-Host "[1]SCRIPT = " $currentScriptName    -back black
  62. Write-Host [2]SCRIPT =" $currentScriptName"     -back black
  63. Write-Host [3]SCRIPT ="$currentScriptName"      -back black
  64. Write-Host [4]SCRIPT ="$currentScriptName"      -back black
  65. Write-Host "[5]SCRIPT=$currentScriptName"       -back black
  66.  
  67. $baseDir = get-location
  68.  
  69. $input_params = $args
  70. $nb_inputParams = $args.Length
  71.  
  72.  
  73. $input_modName = $args[0]
  74.  
  75. $allowedParams=@(
  76.     $void
  77.     , "bounties"
  78.     , "b"
  79.     , "contracts"
  80.     , "c"
  81.     , "stagecoaches"
  82.     , "s"
  83. )
  84.  
  85.  
  86. Write-Host " ------- "
  87. Write-Host "  $nb_inputParams params inputted : "  -no
  88. Write-Host $input_params
  89.  
  90. if($nb_inputParams -gt 1){
  91.     Write-Host -fore DarkRed "Input error : max 1 param accepted"
  92.     # Write-Host -fore DarkGreen "USAGE : ./script_getLastLogsOnly_X.Y.ps1 [param]"
  93.     Write-Host -fore DarkGreen "USAGE : .\$currentScriptName [option]"
  94.     break
  95. }
  96.  
  97.  
  98. Write-Host "PARAM 1:"$input_modName
  99. Write-Host "Liste params PEC :"$allowedParams
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106. $paramIsAllowed = $input_modName -in $allowedParams
  107. Write-Host "Input param '"$input_modName"'"
  108.  
  109.  
  110. if($paramIsAllowed){
  111.     Write-Host "Param '"$input_modName"' allowed ? (= in allowed params list) : " $paramIsAllowed -fore green
  112. }
  113. else{
  114.     Write-Host "Param '"$input_modName"' allowed ? (= in allowed params list) : " $paramIsAllowed -fore red
  115. }  
  116.  
  117. # Write-Host "input dir : " $input_modName allowed " : " -fore Yellow -no
  118. # write-host -fore Red $paramIsAllowed
  119. # $input_modName = ""
  120.  
  121. # if($input_params.Length -gt 1){
  122.     # Write-Host -fore red "Too many params, just 1 allowed."
  123.     # Write-Host -fore Green "USAGE : ./script_getLastLogsOnly_X.Y.ps1 [param]"
  124.     # break
  125.     # } elseif ($paramIsAllowed){
  126.         # fais rien, j'ai pas reussi a faire une negation if false
  127.     # } else { <# $param Is NOT allowed #>
  128.     # Write-host -fore red "Invalid param : " $input_modName Write-Host -fore Yellow "Accepted parameters : " -no
  129.     # foreach ($okParam in $allowedParams){ if($okParam.Length -eq 0){ Write-Host -fore Yellow `n " - <VOID> `t`t [DEFAULT ---> Bounties dir] `t`t (0)" -no
  130.         # } else{ Write-Host -fore Yellow `n " - " $okParam `t`t "("$okParam.Length")" -no  }
  131.     # }
  132.     # break
  133. # }
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140. <#  ==========================================   ___    ___   ___   ___   ___   _____   ========================================== #>
  141. <#  ==========================================  / __|  / __| | _ \ |_ _| | _ \ |_   _|  ==small=================================== #>
  142. <#  ==========================================  \__ \ | (__  |   /  | |  |  _/   | |    ========================================== #>
  143. <#  ==========================================  |___/  \___| |_|_\ |___| |_|     |_|    ========================================== #>
  144. <#  ==========================================                                          ========================================== #>
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153. if($input_modName.Length -eq 0 -or $input_modName -eq "bounty"){
  154.     $input_targetModDirPath = "C:\Program Files (x86)\Steam\steamapps\common\Red Dead Redemption 2\BountiesExpansion"
  155. }
  156.  
  157.  
  158. write-Host "taget dir = '"$input_targetModDirPath "'"
  159.  
  160. cd $input_targetModDirPath
  161.  
  162.  
  163. $content = (get-content "Log.log")
  164. $totalNbLignes = $index = $content.Count
  165. $latestLogLinesLength = 0
  166. $logfileDir =  Split-Path -Path (Get-Location) -Leaf
  167. $curDate = Get-Date -Format "yyyyMMdd"
  168.  
  169.  
  170. $outputFilename = $logfileDir + "_" + $curDate + "_lastLog.log"
  171. Write-Host "filename = $outputFilename"
  172.  
  173. while($index--){
  174.     if($content[$index] -match "^.*Shtivi.*$"){
  175.         break
  176.     }
  177. }
  178.  
  179. $latestLogLinesLength = $totalNbLignes - $index
  180.  
  181.  
  182.  
  183.  
  184. Get-content -tail $latestLogLinesLength .\Log.log > $outputFilename
  185. Start notepad++ $outputFilename
  186.  
  187. cd $baseDir
  188.  
  189. <# -------- END -------- #>
  190.  
  191. <# meeeeh #>
  192. <# $verbose=false #>
  193. <# if($verbose) { Write-Host -fore Cyan "index = $index" -nonewline } #>
  194. <#  if($verbose){ Write-Host [$index] -Nonewline } #>
  195. <#      if($verbose){ Write-Host -foregroundColor Yellow "[$index]" } #>
  196. <#      if($verbose) { Write-Host "wewewew" -Nonewline } #>
  197. <# Write-Host -fore red "Le dernier log commence ligne [$index] et s arrete a [$totalNbLignes]" #>
  198.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement