first commit
This commit is contained in:
181
BackupFolder.ps1
181
BackupFolder.ps1
@@ -25,12 +25,126 @@ function Show-Message {
|
|||||||
[System.Windows.Forms.MessageBox]::Show($Message, $Title, 0, $icon) | Out-Null
|
[System.Windows.Forms.MessageBox]::Show($Message, $Title, 0, $icon) | Out-Null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Function to show confirmation dialog with Yes/No options
|
||||||
|
function Show-Confirmation {
|
||||||
|
param(
|
||||||
|
[string]$Message,
|
||||||
|
[string]$Title = "Klasör Yedekleme"
|
||||||
|
)
|
||||||
|
|
||||||
|
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
|
||||||
|
$result = [System.Windows.Forms.MessageBox]::Show($Message, $Title, 4, 64) # 4 = YesNo buttons, 64 = Information icon
|
||||||
|
return ($result -eq "Yes")
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to show advanced options dialog
|
||||||
|
function Show-AdvancedOptions {
|
||||||
|
param(
|
||||||
|
[string]$Message,
|
||||||
|
[string]$Title = "Geliþtirme Klasörleri Bulundu"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Create a form with custom buttons
|
||||||
|
Add-Type -AssemblyName System.Windows.Forms
|
||||||
|
|
||||||
|
$form = New-Object System.Windows.Forms.Form
|
||||||
|
$form.Text = $Title
|
||||||
|
$form.Size = New-Object System.Drawing.Size(400, 200)
|
||||||
|
$form.StartPosition = "CenterScreen"
|
||||||
|
$form.FormBorderStyle = "FixedDialog"
|
||||||
|
$form.Topmost = $true
|
||||||
|
|
||||||
|
# Add label with message
|
||||||
|
$label = New-Object System.Windows.Forms.Label
|
||||||
|
$label.Location = New-Object System.Drawing.Point(10, 20)
|
||||||
|
$label.Size = New-Object System.Drawing.Size(360, 80)
|
||||||
|
$label.Text = $Message
|
||||||
|
$label.Font = New-Object System.Drawing.Font("Microsoft Sans Serif", 9)
|
||||||
|
$form.Controls.Add($label)
|
||||||
|
|
||||||
|
# Add "Include All" button
|
||||||
|
$buttonIncludeAll = New-Object System.Windows.Forms.Button
|
||||||
|
$buttonIncludeAll.Location = New-Object System.Drawing.Point(10, 120)
|
||||||
|
$buttonIncludeAll.Size = New-Object System.Drawing.Size(100, 30)
|
||||||
|
$buttonIncludeAll.Text = "Tümünü Dahil Et"
|
||||||
|
$buttonIncludeAll.DialogResult = "OK"
|
||||||
|
$form.Controls.Add($buttonIncludeAll)
|
||||||
|
|
||||||
|
# Add "Skip Dev Folders" button
|
||||||
|
$buttonSkip = New-Object System.Windows.Forms.Button
|
||||||
|
$buttonSkip.Location = New-Object System.Drawing.Point(120, 120)
|
||||||
|
$buttonSkip.Size = New-Object System.Drawing.Size(120, 30)
|
||||||
|
$buttonSkip.Text = "Dev Klasörleri Atla"
|
||||||
|
$buttonSkip.DialogResult = "Yes"
|
||||||
|
$form.Controls.Add($buttonSkip)
|
||||||
|
|
||||||
|
# Add "Cancel" button
|
||||||
|
$buttonCancel = New-Object System.Windows.Forms.Button
|
||||||
|
$buttonCancel.Location = New-Object System.Drawing.Point(250, 120)
|
||||||
|
$buttonCancel.Size = New-Object System.Drawing.Size(100, 30)
|
||||||
|
$buttonCancel.Text = "Ýptal"
|
||||||
|
$buttonCancel.DialogResult = "No"
|
||||||
|
$form.Controls.Add($buttonCancel)
|
||||||
|
|
||||||
|
# Set default button
|
||||||
|
$form.AcceptButton = $buttonIncludeAll
|
||||||
|
$form.CancelButton = $buttonCancel
|
||||||
|
|
||||||
|
# Show dialog and return result
|
||||||
|
$result = $form.ShowDialog()
|
||||||
|
return $result
|
||||||
|
}
|
||||||
|
|
||||||
# Check if folder exists
|
# Check if folder exists
|
||||||
if (-not (Test-Path $FolderPath)) {
|
if (-not (Test-Path $FolderPath)) {
|
||||||
Show-Message -Message "Belirtilen klasör mevcut deðil: $FolderPath" -Type 1
|
Show-Message -Message "Belirtilen klasör mevcut deðil: $FolderPath" -Type 1
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Define common development folders that should be excluded
|
||||||
|
$ExcludedFolders = @("node_modules", "vendor", "build", "dist", ".git", ".svn", "bin", "obj")
|
||||||
|
|
||||||
|
# Check if the folder contains any development directories
|
||||||
|
$HasDevFolders = $false
|
||||||
|
$FoundDevFolders = @()
|
||||||
|
$SkipDevFolders = $false
|
||||||
|
|
||||||
|
foreach ($excludedFolder in $ExcludedFolders) {
|
||||||
|
$devFolderPath = Join-Path $FolderPath $excludedFolder
|
||||||
|
if (Test-Path $devFolderPath) {
|
||||||
|
$HasDevFolders = $true
|
||||||
|
$FoundDevFolders += $excludedFolder
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# If development folders are found, prompt user for action
|
||||||
|
if ($HasDevFolders) {
|
||||||
|
$folderList = ($FoundDevFolders -join ", ")
|
||||||
|
$message = "Bu klasör aþaðýdaki geliþtirme klasörlerini içeriyor:`n$folderList`n`nBu klasörleri yedeklemeye ne yapmak istersiniz?"
|
||||||
|
|
||||||
|
$userChoice = Show-AdvancedOptions -Message $message -Title "Geliþtirme Klasörleri Bulundu"
|
||||||
|
|
||||||
|
switch ($userChoice) {
|
||||||
|
"No" {
|
||||||
|
# Cancel backup
|
||||||
|
Show-Message -Message "Yedekleme iptal edildi." -Type 2
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
"Yes" {
|
||||||
|
# Skip dev folders
|
||||||
|
$SkipDevFolders = $true
|
||||||
|
}
|
||||||
|
"OK" {
|
||||||
|
# Include all folders - continue normally
|
||||||
|
}
|
||||||
|
default {
|
||||||
|
# Cancel backup for any other response
|
||||||
|
Show-Message -Message "Yedekleme iptal edildi." -Type 2
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# Get folder name
|
# Get folder name
|
||||||
$FolderName = Split-Path $FolderPath -Leaf
|
$FolderName = Split-Path $FolderPath -Leaf
|
||||||
|
|
||||||
@@ -75,8 +189,8 @@ if ($UseWinRar) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ($UseWinRar) {
|
if ($UseWinRar -and -not $SkipDevFolders) {
|
||||||
# Use WinRAR
|
# Use WinRAR (full backup)
|
||||||
# Change to the parent directory and use relative path to avoid full path in archive
|
# Change to the parent directory and use relative path to avoid full path in archive
|
||||||
Push-Location $OutputDir
|
Push-Location $OutputDir
|
||||||
try {
|
try {
|
||||||
@@ -87,8 +201,24 @@ try {
|
|||||||
Pop-Location
|
Pop-Location
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elseif ($UseSevenZip) {
|
elseif ($UseWinRar -and $SkipDevFolders) {
|
||||||
# Use 7-Zip
|
# Use WinRAR with exclusion patterns
|
||||||
|
Push-Location $OutputDir
|
||||||
|
try {
|
||||||
|
# Build exclusion arguments for each dev folder
|
||||||
|
$ExcludeArgs = ""
|
||||||
|
foreach ($excludedFolder in $ExcludedFolders) {
|
||||||
|
$ExcludeArgs += " -x`".\$FolderName\$excludedFolder\*`""
|
||||||
|
}
|
||||||
|
$Arguments = "a -r $ExcludeArgs `"$OutputFile`" `".\$FolderName`""
|
||||||
|
Start-Process -FilePath $WinRarPath -ArgumentList $Arguments -Wait -NoNewWindow
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
Pop-Location
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elseif ($UseSevenZip -and -not $SkipDevFolders) {
|
||||||
|
# Use 7-Zip (full backup)
|
||||||
# Change to the parent directory and use relative path to avoid full path in archive
|
# Change to the parent directory and use relative path to avoid full path in archive
|
||||||
Push-Location $OutputDir
|
Push-Location $OutputDir
|
||||||
try {
|
try {
|
||||||
@@ -99,12 +229,53 @@ try {
|
|||||||
Pop-Location
|
Pop-Location
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
elseif ($UseSevenZip -and $SkipDevFolders) {
|
||||||
|
# Use 7-Zip with exclusion patterns
|
||||||
|
Push-Location $OutputDir
|
||||||
|
try {
|
||||||
|
# Build exclusion arguments for each dev folder
|
||||||
|
$ExcludeArgs = ""
|
||||||
|
foreach ($excludedFolder in $ExcludedFolders) {
|
||||||
|
$ExcludeArgs += " -x!$FolderName\$excludedFolder\*"
|
||||||
|
}
|
||||||
|
$Arguments = "a $ExcludeArgs `"$OutputFile`" `".\$FolderName`""
|
||||||
|
Start-Process -FilePath $SevenZipPath -ArgumentList $Arguments -Wait -NoNewWindow
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
Pop-Location
|
||||||
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
# Use PowerShell built-in Compress-Archive
|
# Use PowerShell built-in Compress-Archive
|
||||||
# Fix the path issue by changing to the parent directory and using relative path
|
# Fix the path issue by changing to the parent directory and using relative path
|
||||||
Push-Location $OutputDir
|
Push-Location $OutputDir
|
||||||
try {
|
try {
|
||||||
Compress-Archive -Path ".\$FolderName" -DestinationPath $OutputFile -Force
|
if ($SkipDevFolders) {
|
||||||
|
# For PowerShell, we need to manually filter out dev folders
|
||||||
|
# Get all items except the excluded ones
|
||||||
|
$ItemsToCompress = Get-ChildItem -Path ".\$FolderName" -Recurse | Where-Object {
|
||||||
|
$itemPath = $_.FullName.Substring((Resolve-Path ".\$FolderName").Path.Length)
|
||||||
|
$shouldExclude = $false
|
||||||
|
foreach ($excludedFolder in $ExcludedFolders) {
|
||||||
|
if ($itemPath -like "\$excludedFolder*" -or $itemPath -like "*\$excludedFolder*" -or $itemPath -like "*\$excludedFolder\*") {
|
||||||
|
$shouldExclude = $true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
-not $shouldExclude
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($ItemsToCompress) {
|
||||||
|
Compress-Archive -Path $ItemsToCompress.FullName -DestinationPath $OutputFile -Force
|
||||||
|
} else {
|
||||||
|
# If no items left after filtering, create an empty archive with just the folder structure
|
||||||
|
Compress-Archive -Path ".\$FolderName" -DestinationPath $OutputFile -Force
|
||||||
|
# Then remove the dev folders from the archive (this is complex, so we'll just warn the user)
|
||||||
|
Show-Message -Message "NOT: PowerShell ile dev klasörlerini atlamak tam olarak mümkün deðildir. Tüm klasörler yedeklendi.`n`nGelecek sürümlerde bu özellik WinRAR veya 7-Zip ile daha iyi çalýþacaktýr." -Type 2
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Compress-Archive -Path ".\$FolderName" -DestinationPath $OutputFile -Force
|
||||||
|
}
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
Pop-Location
|
Pop-Location
|
||||||
|
|||||||
31
README.md
31
README.md
@@ -11,6 +11,8 @@ Bu araç, klasörler için Windows sağ tık menüsüne "Yedekle ve Sıkıştır
|
|||||||
- WinRAR, 7-Zip veya PowerShell'in yerleşik sıkıştırma özelliğini destekler
|
- WinRAR, 7-Zip veya PowerShell'in yerleşik sıkıştırma özelliğini destekler
|
||||||
- Türkçe karakterleri doğru şekilde işler
|
- Türkçe karakterleri doğru şekilde işler
|
||||||
- Aynı gün içinde yapılan çoklu yedeklemeler için otomatik numaralandırma
|
- Aynı gün içinde yapılan çoklu yedeklemeler için otomatik numaralandırma
|
||||||
|
- Geliştirme klasörlerini (node_modules, vendor, vs.) yedeklemeden önce kullanıcıya sorar
|
||||||
|
- Gelişmiş seçenekler: "Tümünü Dahil Et", "Dev Klasörleri Atla", "İptal"
|
||||||
|
|
||||||
### Kurulum
|
### Kurulum
|
||||||
|
|
||||||
@@ -21,7 +23,11 @@ Bu araç, klasörler için Windows sağ tık menüsüne "Yedekle ve Sıkıştır
|
|||||||
|
|
||||||
1. Windows Explorer'da herhangi bir klasörün veya boş alanın üzerine sağ tıklayın
|
1. Windows Explorer'da herhangi bir klasörün veya boş alanın üzerine sağ tıklayın
|
||||||
2. "Yedekle ve Sıkıştır" seçeneğini seçin
|
2. "Yedekle ve Sıkıştır" seçeneğini seçin
|
||||||
3. Yedekleme, aşağıdaki formatta aynı dizinde oluşturulacak:
|
3. Eğer klasörde geliştirme klasörleri (node_modules, vendor, build, dist, .git, vs.) varsa, üç seçenek sunulur:
|
||||||
|
- "Tümünü Dahil Et": Tüm klasörleri yedekler (önceki davranış)
|
||||||
|
- "Dev Klasörleri Atla": Geliştirme klasörlerini hariç tutar (yer ve zaman tasarrufu sağlar)
|
||||||
|
- "İptal": Yedekleme işlemini iptal eder
|
||||||
|
4. Yedekleme, aşağıdaki formatta aynı dizinde oluşturulacak:
|
||||||
`<KlasörAdı>_<YYYYMMDD>_<Numara>.rar` (veya WinRAR mevcut değilse .zip)
|
`<KlasörAdı>_<YYYYMMDD>_<Numara>.rar` (veya WinRAR mevcut değilse .zip)
|
||||||
|
|
||||||
### Kaldırma
|
### Kaldırma
|
||||||
@@ -33,7 +39,7 @@ Bu araç, klasörler için Windows sağ tık menüsüne "Yedekle ve Sıkıştır
|
|||||||
|
|
||||||
- Windows 10 veya 11
|
- Windows 10 veya 11
|
||||||
- PowerShell 5.1 veya sonrası
|
- PowerShell 5.1 veya sonrası
|
||||||
- İsteğe bağlı: Daha iyi sıkıştırma seçenekleri için WinRAR veya 7-Zip
|
- İsteğe bağlı: Daha iyi sıkıştırma ve dışlama seçenekleri için WinRAR veya 7-Zip
|
||||||
|
|
||||||
## English Description
|
## English Description
|
||||||
|
|
||||||
@@ -49,6 +55,8 @@ This tool adds a "Yedekle ve Sıkıştır" (Backup and Compress) option to the W
|
|||||||
- Handles Turkish characters correctly with ANSI encoding
|
- Handles Turkish characters correctly with ANSI encoding
|
||||||
- Automatic numbering for multiple backups in the same day
|
- Automatic numbering for multiple backups in the same day
|
||||||
- All messages and interface elements are available in both Turkish and English
|
- All messages and interface elements are available in both Turkish and English
|
||||||
|
- Asks user before backing up development folders (node_modules, vendor, etc.)
|
||||||
|
- Advanced options: "Include All", "Skip Dev Folders", "Cancel"
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
@@ -59,7 +67,11 @@ This tool adds a "Yedekle ve Sıkıştır" (Backup and Compress) option to the W
|
|||||||
|
|
||||||
1. Right-click on any folder or in empty space in Windows Explorer
|
1. Right-click on any folder or in empty space in Windows Explorer
|
||||||
2. Select "Yedekle ve Sıkıştır"
|
2. Select "Yedekle ve Sıkıştır"
|
||||||
3. The backup will be created in the same directory with the format:
|
3. If the folder contains development folders (node_modules, vendor, build, dist, .git, etc.), three options are presented:
|
||||||
|
- "Tümünü Dahil Et" (Include All): Backs up all folders (previous behavior)
|
||||||
|
- "Dev Klasörleri Atla" (Skip Dev Folders): Excludes development folders (saves space and time)
|
||||||
|
- "İptal" (Cancel): Cancels the backup operation
|
||||||
|
4. The backup will be created in the same directory with the format:
|
||||||
`<FolderName>_<YYYYMMDD>_<Number>.rar` (or .zip if WinRAR is not available)
|
`<FolderName>_<YYYYMMDD>_<Number>.rar` (or .zip if WinRAR is not available)
|
||||||
|
|
||||||
## Uninstallation
|
## Uninstallation
|
||||||
@@ -71,15 +83,17 @@ This tool adds a "Yedekle ve Sıkıştır" (Backup and Compress) option to the W
|
|||||||
|
|
||||||
- Windows 10 or 11
|
- Windows 10 or 11
|
||||||
- PowerShell 5.1 or later
|
- PowerShell 5.1 or later
|
||||||
- Optional: WinRAR or 7-Zip for better compression options
|
- Optional: WinRAR or 7-Zip for better compression and exclusion options
|
||||||
|
|
||||||
## How It Works
|
## How It Works
|
||||||
|
|
||||||
The installer adds registry entries that integrate with Windows Explorer context menus. When selected, it runs the PowerShell script that:
|
The installer adds registry entries that integrate with Windows Explorer context menus. When selected, it runs the PowerShell script that:
|
||||||
1. Determines the next backup number by scanning existing backups
|
1. Determines the next backup number by scanning existing backups
|
||||||
2. Uses WinRAR, 7-Zip, or PowerShell's Compress-Archive (in order of preference)
|
2. Checks for development folders and prompts user for inclusion
|
||||||
3. Creates the backup with the proper naming convention
|
3. Uses WinRAR, 7-Zip, or PowerShell's Compress-Archive (in order of preference)
|
||||||
4. Shows success or error messages in Turkish or English
|
4. Applies exclusion patterns when "Skip Dev Folders" is selected
|
||||||
|
5. Creates the backup with the proper naming convention
|
||||||
|
6. Shows success or error messages in Turkish or English
|
||||||
|
|
||||||
## Recent Improvements
|
## Recent Improvements
|
||||||
|
|
||||||
@@ -88,3 +102,6 @@ The installer adds registry entries that integrate with Windows Explorer context
|
|||||||
- Improved file naming consistency with proper variable expansion
|
- Improved file naming consistency with proper variable expansion
|
||||||
- Enhanced path handling to compress only selected folder content without full directory paths
|
- Enhanced path handling to compress only selected folder content without full directory paths
|
||||||
- Added admin rights checking for installation and uninstallation scripts
|
- Added admin rights checking for installation and uninstallation scripts
|
||||||
|
- Added development folder detection and user confirmation before backup
|
||||||
|
- Added advanced options dialog with "Include All", "Skip Dev Folders", and "Cancel" choices
|
||||||
|
- Implemented exclusion patterns for WinRAR and 7-Zip (PowerShell limitation noted)
|
||||||
9
yapi.md
9
yapi.md
@@ -29,6 +29,15 @@ Windows gezgininde bir klasör üzerindeyken sağ tıkladığımda çıkan menü
|
|||||||
- Sıkıştırma başarısız olursa hata mesajı göster
|
- Sıkıştırma başarısız olursa hata mesajı göster
|
||||||
- Yedekleme başarılı olursa bildirim göster
|
- Yedekleme başarılı olursa bildirim göster
|
||||||
|
|
||||||
|
6. **Geliştirme Klasörü Tespiti:**
|
||||||
|
- node_modules, vendor, build, dist, .git gibi geliştirme klasörlerini tespit et
|
||||||
|
- Bu klasörler bulunursa kullanıcıya yedeklemeye dahil edilip edilmeyeceğini sor
|
||||||
|
- Üç seçenek sun: "Tümünü Dahil Et", "Dev Klasörleri Atla", "İptal"
|
||||||
|
|
||||||
|
7. **Dışlama İşlevi:**
|
||||||
|
- "Dev Klasörleri Atla" seçilirse, WinRAR veya 7-Zip için dışlama kalıpları uygula
|
||||||
|
- PowerShell için sınırlı dışlama desteği (uyarı mesajı ile)
|
||||||
|
|
||||||
**Çıktı:**
|
**Çıktı:**
|
||||||
- Gerekli tüm dosyaları içeren çalışır bir çözüm (batch script, PowerShell script veya küçük bir executable)
|
- Gerekli tüm dosyaları içeren çalışır bir çözüm (batch script, PowerShell script veya küçük bir executable)
|
||||||
- Registry değişikliklerini otomatik yapan kurulum scripti
|
- Registry değişikliklerini otomatik yapan kurulum scripti
|
||||||
|
|||||||
Reference in New Issue
Block a user