-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConvertir.ps1
More file actions
91 lines (73 loc) · 3.25 KB
/
Convertir.ps1
File metadata and controls
91 lines (73 loc) · 3.25 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
#Convert a curseforge manifest json to ids txt format
$legibleModFileNames=$true
$executionPath = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition
$localFiles = Get-ChildItem -Path $executionPath -Name '*.json' -File
$path = $executionPath+"\Ids"
If(!(test-path $path))
{
New-Item -ItemType Directory -Force -Path $path
}
function filenameWithoutNumbers{
param( $filename)
$expression="[\d.\[\]\(\)-]+"
$salida=""
$firstMinus=$true
for ($a=0;$a -lt $filename.Length;$a++){
$char=$filename.substring($a, 1)
if ($char -match $expression){
if ($char -eq "-" -and $firstMinus){
$salida=$salida+$char
$firstMinus=$false
}else{
if( $a+1 -lt $filename.Length){
$char=$filename.substring($a+1, 1)
while ($a+1 -lt $filename.Length -and $char -match $expression) {
$a++
if ($a+1 -lt $filename.Length ) {$char=$filename.substring($a+1, 1)}
}
}
if($legibleModFileNames){
if($a+1 -lt $filename.Length)
{$salida=$salida+"("+$expression+")"} #if legible is on try to not concatenate the expression at the end
}else
{$salida=$salida+"("+$expression+")"
if ($a+1 -ge $filename.Length){$salida+=".jar"}
}
}
}else{$salida=$salida+$char}
}
return $salida
}
$api='https://addons-ecs.forgesvc.net/api/v2/addon/'
$clientWeb = New-Object System.Net.WebClient
foreach ($localfile in $localFiles){
$contenido=(get-content $localfile.PSPath)| ConvertFrom-Json
$tipo=$contenido.manifestType
if($tipo -eq 'minecraftModpack'){
$version=$contenido.minecraft.version
$DestFilePath=$path+"\"+$localfile+".txt"
"#version;"+$version| Out-File $DestFilePath
"#Format Id;FileNameRegularexpression;Type;Version" | Out-File $DestFilePath -Append
"#"| Out-File $DestFilePath -Append
$ficheros=$contenido.files
$modIdArray=@()
foreach ($f in $ficheros){
$modId=$f.projectID
$modIdArray+=$modId
$fileId=$f.fileID
$requestfile= $api+$modId+'/file/'+$fileId
#https://addons-ecs.forgesvc.net/api/v2/addon/{addonID}/file/{fileID}
$fileInfo=""
$fileInfo= Invoke-WebRequest $requestfile|ConvertFrom-Json |select fileName,downloadURL
$cadenaNombre=filenameWithoutNumbers($fileInfo.fileName.substring(0,$fileInfo.fileName.Length-4))
Write-Host $modId ":" $fileInfo.fileName
$modId.ToString()+";"+$cadenaNombre| Out-File $DestFilePath -Append
}
<#
[string]$modIdArrayString="["+($modIdArray -join ",") +"]"
$response=Invoke-WebRequest -UseBasicParsing $api -ContentType "application/json" -Method POST -Body ($modIdArrayString)|ConvertFrom-Json
$addons=@()
$addons=$response|Select-Object *
#>
}
}