forked from SteamDatabase/Protobufs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
to_java.ps1
57 lines (41 loc) · 1.75 KB
/
to_java.ps1
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
# YOU NEED TO WRITE IN POWERSHELL WINDOW CODE DOWN BELOW:
# Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
$SRC_DIR = (Resolve-Path .\).Path
$OUT_DIR = "output"
$JavaPackage = "in.dragonbra.javasteam.protobufs"
$protoc = "protoc\bin\protoc.exe"
Remove-Item -Path $OUT_DIR -Recurse -Force -Confirm:$false
New-Item -ItemType Directory -path $OUT_DIR
$OUT_DIR_PACKaGE = $OUT_DIR + "\" + $JavaPackage.replace('.','\')
$games = @("artifact", "csgo", "dota2", "steam", "tf2", "underlords", "webui")
For ($i=0; $i -lt $games.Length; $i++)
{
if (Test-Path -Path $games[$i])
{
$game = $games[$i]
"------------------------------------------------"
"Compiling " + $game + "..."
$out_dir_game = $OUT_DIR_PACKaGE + "\" + $game
New-Item -ItemType Directory -path $out_dir_game
Get-ChildItem -Path $game -Filter *.proto -Recurse -File -Name| ForEach-Object {
$file = $_
$fileName = [System.IO.Path]::GetFileName($file)
$fullpath = $game + "\" + $file
& $protoc --proto_path=. --java_out=$out_dir_game $fullpath
}
}
}
"------------------------------------------------"
"Fixing java files..."
Get-ChildItem -Path $OUT_DIR -Filter *.java -Recurse -File -Name| ForEach-Object {
$file = $_
$fileName = [System.IO.Path]::GetFileName($file)
$game = $file.replace(($JavaPackage.replace('.','\')),'')
$game = $game.replace(("\" + $fileName),'')
$game = $game.replace(("\"),'')
$content = (Get-Content -path ($OUT_DIR + "\" + $file))
$contentNew = "package " + $JavaPackage + "." + $game + ";`n"
Set-Content ($OUT_DIR + "\" + $file) -value $contentNew, $content
}
"------------------------------------------------"
"All done!"