# ========= CONFIG ========= $SevenZip = "C:\Program Files\7-Zip\7z.exe" if (-not (Test-Path $SevenZip)) { Write-Host "KHONG TIM THAY 7z.exe" Read-Host exit } # ========= LIST JAR (KHONG BAO GOM SO.JAR) ========= $baseJars = Get-ChildItem *.jar | Where-Object { $_.BaseName -notmatch '^\d+$' } if ($baseJars.Count -eq 0) { Write-Host "KHONG CO FILE JAR NAO" Read-Host exit } Write-Host "==== DANH SACH FILE JAR (KHONG BAO GOM SO.JAR) ====" for ($i = 0; $i -lt $baseJars.Count; $i++) { Write-Host "$($i+1). $($baseJars[$i].Name)" } $choice = Read-Host "Chon so file JAR goc" if ($choice -notmatch '^\d+$' -or $choice -lt 1 -or $choice -gt $baseJars.Count) { Write-Host "Lua chon khong hop le" Read-Host exit } $baseJar = $baseJars[$choice - 1].FullName Write-Host "`nFile goc: $($baseJars[$choice - 1].Name)`n" # ========= TIM SO LON NHAT ========= $max = 0 Get-ChildItem *.jar | ForEach-Object { if ($_.BaseName -match '^\d+$') { $num = [int]$_.BaseName if ($num -gt $max) { $max = $num } } } Write-Host "So lon nhat hien co: $max`n" $count = Read-Host "Nhap so file can tao THEM" if ($count -notmatch '^\d+$') { Write-Host "So luong khong hop le" Read-Host exit } $start = $max + 1 $end = $max + [int]$count Write-Host "`nDang tao file tu $start.jar den $end.jar`n" # ========= TAO FILE + SUA MANIFEST ========= for ($i = $start; $i -le $end; $i++) { Write-Host "Tao $i.jar" Copy-Item $baseJar "$i.jar" -Force Write-Host "Dang xu ly manifest $i.jar" & $SevenZip x "$i.jar" "META-INF\MANIFEST.MF" -y | Out-Null if (Test-Path "META-INF\MANIFEST.MF") { #$content = Get-Content "META-INF\MANIFEST.MF" -Raw # Doc manifest theo dong $lines = Get-Content "META-INF\MANIFEST.MF" # Lay ten goc tu MIDlet-Name $baseName = $null foreach ($line in $lines) { if ($line -match '^MIDlet-Name:\s*(.+)$') { $baseName = $Matches[1].Trim() break } } if ($baseName) { for ($iLine = 0; $iLine -lt $lines.Count; $iLine++) { # Replace TAT CA Avatar LAPRO thanh Avatar LAPRO $lines[$iLine] = $lines[$iLine] -replace [regex]::Escape($baseName), "$baseName $i" } # Ghi lai, GIU NGUYEN XUONG DONG Set-Content "META-INF\MANIFEST.MF" $lines } #Set-Content "META-INF\MANIFEST.MF" $content -NoNewline & $SevenZip u "$i.jar" "META-INF\MANIFEST.MF" | Out-Null Remove-Item META-INF -Recurse -Force } } Write-Host "DONE" Read-Host