-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathNew-ModZip.ps1
57 lines (45 loc) · 2.18 KB
/
New-ModZip.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
$srcPath = $PSScriptRoot
$dstPath = $PSScriptRoot
$dstFilename = "FS22_VehicleExplorer.zip"
$tmpPath = Join-Path $env:TMP "TmpZip"
$ignorelist = get-content (Join-Path $srcPath ".gitignore")
$ignorelist += "/New-ModZip.ps1"
$ignorelist += "/textures/png"
$ignoreList += "/screenshots"
$ignoreList += "/README.md"
$ignoreList = ($ignorelist | ?{ -not [string]::IsNullOrEmpty($_) })
if($srcPath.Length -gt 0 -and $dstPath.Length -gt 0)
{
Remove-Item (Join-Path $dstPath $dstFilename) -Force
[array]$allFiles = Get-ChildItem -Path $srcPath -Exclude {.gitignore} -Recurse -Attributes !Directory
[array]$allFolders = Get-ChildItem -Path $srcPath -Exclude {.gitignore} -Recurse -Attributes Directory
New-Item -ItemType Directory -Path $tmpPath -Force
foreach($f in $allFolders)
{
if( -not $ignorelist.contains($f.FullName.ToString().Replace("$srcPath", "").Replace("\","/")) )
{
New-Item -ItemType Directory -Path $f.FullName.ToString().Replace($srcPath, $tmpPath)
}
}
foreach($f in $allFiles)
{
if( -not $ignorelist.contains($f.DirectoryName.ToString().Replace("$srcPath", "").Replace("\","/")) )
{
if( -not $ignorelist.contains($f.FullName.ToString().Replace("$srcPath", "").Replace("\","/")) )
{
#$F.FullName
#$f.FullName.ToString().Replace("$srcPath", "").Replace("\","/")
Copy-Item $f.FullName -Destination $f.FullName.ToString().Replace($srcPath, $tmpPath) -Force
}
}
}
##Compress-Archive -Path (Join-Path $tmpPath "\*") -DestinationPath (Join-Path $dstPath $dstFilename)
# For some reason neither PS nor the .NET libraries create an archive suitable for FS19. the translations folder is included, but not used by the Giants engine
# Switching to a quick and dirty Winrar solution for now
$binary = "C:\Program Files\winrar\WinRAR.exe"
$folder = Join-Path $tmpPath "\*"
$file = Join-Path $dstPath $dstFilename
$rarargs = @("a", "-afzip -ep1 -r", "`"$file`"", "`"$($folder)`"" )
Start-Process -FilePath $binary -ArgumentList $rarargs -Wait
Remove-Item -Path $tmpPath -Recurse -Force
}