-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdate.ps1
More file actions
159 lines (115 loc) · 6.24 KB
/
Update.ps1
File metadata and controls
159 lines (115 loc) · 6.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#Luis Cuesta.2019..
#if you dont want new files to be download set download to $false
clear
$download=$true
$modLoaderAllowed='1' #List of allowed modLoader values, empty value is allowed too.
$api='https://addons-ecs.forgesvc.net/api/v2/addon/'
#$api='https://curse.nikky.moe/api/addon/'
$ids=get-content .\ids.txt
$version=$ids[0].Split(";")[1]
# PowerShell v2
$executionPath = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition
$modPath = $executionPath.Substring(0, $executionPath.LastIndexOf('\'))
$localFiles = Get-ChildItem -Path $modPath -Name '*.jar' -File
$path = $modPath+"\New"
If(!(test-path $path))
{
New-Item -ItemType Directory -Force -Path $path
}
$clientWeb = New-Object System.Net.WebClient
#https://twitchappapi.docs.apiary.io/#/reference/0/get-multiple-addons/get-multiple-addons/
#get all the addons
$modIdArray=@()
foreach ($linea in $ids){
$fields=$linea.Split(";")
$modId=$fields[0].ToString()
if ($modId.Substring(0,1) -ne "#"){
$modIdArray+=$modId
}
}
[string]$modIdArrayString="["+($modIdArray -join ",") +"]"
#$modIdArrayString="[72210]"
$response=Invoke-WebRequest -UseBasicParsing $api -ContentType "application/json" -Method POST -Body ($modIdArrayString)|ConvertFrom-Json
$addons=@()
$addons=$response|Select-Object *
foreach ($linea in $ids){
$fields=$linea.Split(";")
$modId=$fields[0].ToString()
$modName=$fields[1]
$modFileType=$fields[2]
$modVersion=''
$modVersion=$fields[3]
if ([string]::IsNullOrEmpty($modFileType)){
$modFileType='1'
} #si no se fuerza un tipo ponemos 1
$progressPreference = 'silentlyContinue'
if($modId.Substring(0,1) -ne "#"){
$last =$null
$last = $addons |Where-Object {$_.id -eq $modId}
$tversion=$version
if($modVersion -gt '') {
$tversion=$modVersion
}
$list=$null
$idList=$null
if($last -ne $null){
$list= $last|select -expand gameVersionLatestFiles |Select gameVersion,projectFileID,projectFileName,fileType,modLoader | where {($_.gameVersion -eq $tversion) -and ($_.fileType -ne 'ALPHA') -and ((-not $_.modLoader) -or ($modLoaderAllowed -contains $_.modLoader))}
#quitamos los mods forge
}
# if ($list.modLoader -contains '1') {
# $list=$list | where {($_.modLoader -eq '1')}
# }
if ($list.fileType -contains $modFileType) {
$list=$list | where {($_.fileType -eq $modFileType)}
}else{
if ($list.fileType -contains '2') {
$list=$list | where {($_.fileType -eq '2')}
}
}
if ($list -ne $null) {
$list=$list[0] #cogemos solo uno si hay varios.
}
$idList=$null
$idList=$list.projectFileID
$newfilename=$list.projectFileName
Write-Host $modName ":" $list.fileType ":" $modId ":" $tversion ":" $newfilename
if ($idList -eq $null) {
Write-Host "File not found" -ForegroundColor red
}
if($idList -ne $null){
if($modName.Substring(0,1) -eq "["){
$modName="\"+$modName}
$expresion='^'+$modName
$localFile =($localFiles -match $expresion)
$fileExists = ($localFiles -contains $newfilename)
#ijf only there are a localfile -match devuelve false , not empty,
$empty=([string]::IsNullOrEmpty($localFile) -or (-Not $localFile ))
#if (-not $fileExists -or $empty ){
if (-not $fileExists){
#Solo recuperamos datos del archivo si es necesario porque no coincide
$requestfile= $api+$modId+'/file/'+$idList
$file=""
$file= Invoke-WebRequest $requestfile|ConvertFrom-Json |select fileName,downloadURL
Write-Host "--------------" $newfilename "<->" $localFile
if($file.fileName -eq ""){Write-Host "Fallo recuperando archivo"}
else {
#Write-Host $file.downloadURL
if ($download){
$rutaNuevo=$modPath+"\"+"New\"+$newfilename
$yaExiste=(Test-Path $rutaNuevo -PathType Leaf)
if(-not $yaExiste ){
if (-not($empty)){
$localFilePath= $modPath+"\"+$localFile
$newName="__"+$localFile
Rename-Item -Path $localFilePath -NewName $newName
}
$clientWeb.DownloadFile($file.downloadURL, $modPath+"\"+"New\"+$newfilename)
}
}
}
}
}else {
Write-Host $modName " Not Found"
}
}
}