$intiFilePath = ".\init.json"

$intiContent = Get-Content $intiFilePath -Raw
$intiObject = ConvertFrom-Json -InputObject $intiContent

$newName = $intiObject.name
$versionParts = $intiObject.version.Split('.')
$newVersion = [int[]]$versionParts
$vers = $intiObject.version

#¸ÄÕâÀï
$folders = @(".\sakura_dress_RP", ".\sakura_dress_BP")
#¸ÄÕâÀï

$versionParts = $intiObject.version.Split('.')
$major = [int]$versionParts[0]
$minor = [int]$versionParts[1]
$patch = [int]$versionParts[2]
$patch++

foreach ($folder in $folders) {
    $manifestPath = Join-Path $folder "manifest.json"

    $manifestContent = Get-Content $manifestPath -Raw
    $manifest = ConvertFrom-Json -InputObject $manifestContent

    $manifest.header.name = "$newName $vers"
    $manifest.header.version = $newVersion
    if ($manifest.modules) {
        foreach ($module in $manifest.modules) {
            if ($module.PSobject.Properties.Name -contains "version") {
                $module.version = $newVersion
            }
        }
    }

    $jsonOutput = ConvertTo-Json $manifest -Depth 10
    $jsonOutput | Set-Content -Path $manifestPath -Encoding utf8NoBOM

    Write-Host "Updated manifest.json in $folder" -ForegroundColor Green
}

Write-Host "All manifest.json files have been updated." -ForegroundColor Green



#¸ÄÕâÀï
7z a -tzip "SakuraDress v$vers.mcaddon" sakura_dress_BP\ sakura_dress_RP\  
mkdir dist
#¸ÄÕâÀï
move "SakuraDress v$vers.mcaddon" .\dist\

$newVersion = "$major.$minor.$patch"

$intiObject.version = $newVersion

$updatedIntiJson = ConvertTo-Json $intiObject -Depth 10
$updatedIntiJson | Set-Content -Path $intiFilePath -Encoding utf8NoBOM