commit 8f16d171e00fa5730bb6f96aa4d7c17c5eda4372 Author: hOLOlu Date: Fri Nov 14 01:21:50 2025 +0300 first commit diff --git a/BackupFolder.ps1 b/BackupFolder.ps1 new file mode 100644 index 0000000..9ae4b86 --- /dev/null +++ b/BackupFolder.ps1 @@ -0,0 +1,118 @@ +# BackupFolder.ps1 +# Script to backup and compress folders from Windows context menu + +param( + [Parameter(Mandatory=$true)] + [string]$FolderPath +) + +# Function to show message +function Show-Message { + param( + [string]$Message, + [string]$Title = "Klasör Yedekleme", + [int]$Type = 0 # 0=Info, 1=Error, 2=Warning + ) + + switch ($Type) { + 0 { $icon = 64 } # Information + 1 { $icon = 16 } # Error + 2 { $icon = 48 } # Warning + default { $icon = 64 } + } + + [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null + [System.Windows.Forms.MessageBox]::Show($Message, $Title, 0, $icon) | Out-Null +} + +# Check if folder exists +if (-not (Test-Path $FolderPath)) { + Show-Message -Message "Belirtilen klasör mevcut deðil: $FolderPath" -Type 1 + exit 1 +} + +# Get folder name +$FolderName = Split-Path $FolderPath -Leaf + +# Get current date in YYYYMMDD format +$Date = Get-Date -Format "yyyyMMdd" + +# Determine output directory (same as source folder) +$OutputDir = Split-Path $FolderPath -Parent + +# Find existing backups with same name and date to determine next number +$Pattern = "^${FolderName}_${Date}_\d{3}\.(rar|zip)$" +$ExistingBackups = Get-ChildItem -Path $OutputDir -Filter "${FolderName}_${Date}_*" | Where-Object { $_.Name -match $Pattern } + +$NextNumber = 1 +if ($ExistingBackups) { + $Numbers = $ExistingBackups.Name | ForEach-Object { + if ($_ -match "_([0-9]{3})\.(rar|zip)$") { [int]$matches[1] } + } | Sort-Object + if ($Numbers) { + $NextNumber = ($Numbers | Select-Object -Last 1) + 1 + } +} + +$NumberFormatted = "{0:D3}" -f $NextNumber + +# Try WinRAR first +$WinRarPath = "${env:ProgramFiles}\WinRAR\rar.exe" +$UseWinRar = Test-Path $WinRarPath + +# If WinRAR not found, try 7-Zip +$SevenZipPath = "${env:ProgramFiles}\7-Zip\7z.exe" +$UseSevenZip = Test-Path $SevenZipPath + +# If neither found, use PowerShell Compress-Archive +$UsePowerShellArchive = -not ($UseWinRar -or $UseSevenZip) + +# Create backup filename +if ($UseWinRar) { + $OutputFile = Join-Path $OutputDir "${FolderName}_${Date}_${NumberFormatted}.rar" +} else { + $OutputFile = Join-Path $OutputDir "${FolderName}_${Date}_${NumberFormatted}.zip" +} + +try { + if ($UseWinRar) { + # Use WinRAR + # Change to the parent directory and use relative path to avoid full path in archive + Push-Location $OutputDir + try { + $Arguments = "a -r `"$OutputFile`" `".\$FolderName`"" + Start-Process -FilePath $WinRarPath -ArgumentList $Arguments -Wait -NoNewWindow + } + finally { + Pop-Location + } + } + elseif ($UseSevenZip) { + # Use 7-Zip + # Change to the parent directory and use relative path to avoid full path in archive + Push-Location $OutputDir + try { + $Arguments = "a `"$OutputFile`" `".\$FolderName`"" + Start-Process -FilePath $SevenZipPath -ArgumentList $Arguments -Wait -NoNewWindow + } + finally { + Pop-Location + } + } + else { + # Use PowerShell built-in Compress-Archive + # Fix the path issue by changing to the parent directory and using relative path + Push-Location $OutputDir + try { + Compress-Archive -Path ".\$FolderName" -DestinationPath $OutputFile -Force + } + finally { + Pop-Location + } + } + + Show-Message -Message "Yedekleme baþarýyla tamamlandý!`n`nDosya: $OutputFile" +} +catch { + Show-Message -Message "Yedekleme sýrasýnda hata oluþtu:`n$($_.Exception.Message)" -Type 1 +} \ No newline at end of file diff --git a/Install.bat b/Install.bat new file mode 100644 index 0000000..a7b8774 --- /dev/null +++ b/Install.bat @@ -0,0 +1,6 @@ +@echo off +REM Install.bat +REM Klasör yedekleme saÄŸ tık menüsü entegrasyonunu yüklemek için batch dosyası + +powershell.exe -ExecutionPolicy Bypass -File "%~dp0Install.ps1" +pause \ No newline at end of file diff --git a/Install.ps1 b/Install.ps1 new file mode 100644 index 0000000..6b9d59e --- /dev/null +++ b/Install.ps1 @@ -0,0 +1,57 @@ +# Install.ps1 +# Script to install the folder backup context menu integration + +# Check for admin rights +$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) +if (-not $isAdmin) { + Write-Host "Bu komut dosyasý yönetici ayrýcalýklarý gerektirir. Lütfen Yönetici olarak çalýþtýrýn." -ForegroundColor Red + exit 1 +} + +# Get the current script directory +$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition + +# Path to the backup script +$BackupScriptPath = Join-Path $ScriptDir "BackupFolder.ps1" + +# Check if backup script exists +if (-not (Test-Path $BackupScriptPath)) { + Write-Host "Hata: BackupFolder.ps1 dosyasý $ScriptDir dizininde bulunamadý" -ForegroundColor Red + exit 1 +} + +Write-Host "Klasör Yedekleme Sað Týk Menüsü Entegrasyonu Kuruluyor..." -ForegroundColor Green + +# Define registry paths +$FolderContextMenuPath = "Registry::HKEY_CLASSES_ROOT\Directory\shell\BackupFolder" +$BackgroundContextMenuPath = "Registry::HKEY_CLASSES_ROOT\Directory\Background\shell\BackupFolder" + +try { + # Create folder context menu entry + New-Item -Path $FolderContextMenuPath -Force | Out-Null + New-ItemProperty -Path $FolderContextMenuPath -Name "(Default)" -Value "Yedekle ve Sýkýþtýr" -PropertyType String -Force | Out-Null + New-ItemProperty -Path $FolderContextMenuPath -Name "Icon" -Value "powershell.exe" -PropertyType String -Force | Out-Null + + # Create command subkey for folder context menu + $FolderCommandPath = "$FolderContextMenuPath\command" + New-Item -Path $FolderCommandPath -Force | Out-Null + $CommandValue = "powershell.exe -ExecutionPolicy Bypass -File `"$BackupScriptPath`" -FolderPath `"%V`"" + New-ItemProperty -Path $FolderCommandPath -Name "(Default)" -Value $CommandValue -PropertyType String -Force | Out-Null + + # Create background context menu entry + New-Item -Path $BackgroundContextMenuPath -Force | Out-Null + New-ItemProperty -Path $BackgroundContextMenuPath -Name "(Default)" -Value "Yedekle ve Sýkýþtýr" -PropertyType String -Force | Out-Null + New-ItemProperty -Path $BackgroundContextMenuPath -Name "Icon" -Value "powershell.exe" -PropertyType String -Force | Out-Null + + # Create command subkey for background context menu + $BackgroundCommandPath = "$BackgroundContextMenuPath\command" + New-Item -Path $BackgroundCommandPath -Force | Out-Null + $BackgroundCommandValue = "powershell.exe -ExecutionPolicy Bypass -File `"$BackupScriptPath`" -FolderPath `"%V`"" + New-ItemProperty -Path $BackgroundCommandPath -Name "(Default)" -Value $BackgroundCommandValue -PropertyType String -Force | Out-Null + + Write-Host "Kurulum baþarýyla tamamlandý!" -ForegroundColor Green + Write-Host "Artýk klasörler üzerinde veya boþ alanda sað týklayarak yedekleme ve sýkýþtýrma yapabilirsiniz." -ForegroundColor Yellow +} +catch { + Write-Host "Kurulum sýrasýnda hata oluþtu: $($_.Exception.Message)" -ForegroundColor Red +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..1955d0e --- /dev/null +++ b/README.md @@ -0,0 +1,90 @@ +# Klasör Yedekleme Aracı / Folder Backup Tool + +## Türkçe Açıklama + +Bu araç, klasörler için Windows saÄŸ tık menüsüne "Yedekle ve Sıkıştır" seçeneÄŸi ekler. + +### Özellikler + +- Klasörler ve boÅŸ alan için "Yedekle ve Sıkıştır" seçeneÄŸini saÄŸ tık menüsüne ekler +- Zaman damgalı ve numaralandırılmış yedeklemeleri otomatik olarak oluÅŸturur +- WinRAR, 7-Zip veya PowerShell'in yerleÅŸik sıkıştırma özelliÄŸini destekler +- Türkçe karakterleri doÄŸru ÅŸekilde iÅŸler +- Aynı gün içinde yapılan çoklu yedeklemeler için otomatik numaralandırma + +### Kurulum + +1. `Install.bat` dosyasını Yönetici olarak çalıştırın (veya `Install.ps1` dosyasını PowerShell ile) +2. SaÄŸ tık menüsü seçeneÄŸi hemen kullanılabilir olacak + +### Kullanım + +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 +3. Yedekleme, aÅŸağıdaki formatta aynı dizinde oluÅŸturulacak: + `__.rar` (veya WinRAR mevcut deÄŸilse .zip) + +### Kaldırma + +1. `Uninstall.bat` dosyasını Yönetici olarak çalıştırın (veya `Uninstall.ps1` dosyasını PowerShell ile) +2. SaÄŸ tık menüsü seçeneÄŸi kaldırılacak + +### Gereksinimler + +- Windows 10 veya 11 +- PowerShell 5.1 veya sonrası +- İsteÄŸe baÄŸlı: Daha iyi sıkıştırma seçenekleri için WinRAR veya 7-Zip + +## English Description + +# Folder Backup Tool + +This tool adds a "Yedekle ve Sıkıştır" (Backup and Compress) option to the Windows context menu for folders. + +## Features + +- Adds "Yedekle ve Sıkıştır" option to right-click menu for folders and empty space +- Automatically creates compressed backups with timestamp and numbering +- Supports WinRAR, 7-Zip, or PowerShell's built-in compression +- Handles Turkish characters correctly with ANSI encoding +- Automatic numbering for multiple backups in the same day +- All messages and interface elements are available in both Turkish and English + +## Installation + +1. Run `Install.bat` as Administrator (or `Install.ps1` with PowerShell) +2. The context menu option will be available immediately + +## Usage + +1. Right-click on any folder or in empty space in Windows Explorer +2. Select "Yedekle ve Sıkıştır" +3. The backup will be created in the same directory with the format: + `__.rar` (or .zip if WinRAR is not available) + +## Uninstallation + +1. Run `Uninstall.bat` as Administrator (or `Uninstall.ps1` with PowerShell) +2. The context menu option will be removed + +## Requirements + +- Windows 10 or 11 +- PowerShell 5.1 or later +- Optional: WinRAR or 7-Zip for better compression options + +## How It Works + +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 +2. Uses WinRAR, 7-Zip, or PowerShell's Compress-Archive (in order of preference) +3. Creates the backup with the proper naming convention +4. Shows success or error messages in Turkish or English + +## Recent Improvements + +- Fixed Turkish character display issues in context menu by using ANSI encoding +- Updated all messages and interface elements to support both Turkish and English +- Improved file naming consistency with proper variable expansion +- Enhanced path handling to compress only selected folder content without full directory paths +- Added admin rights checking for installation and uninstallation scripts \ No newline at end of file diff --git a/Uninstall.bat b/Uninstall.bat new file mode 100644 index 0000000..4859ff7 --- /dev/null +++ b/Uninstall.bat @@ -0,0 +1,6 @@ +@echo off +REM Uninstall.bat +REM Klasör yedekleme saÄŸ tık menüsü entegrasyonunu kaldırmak için batch dosyası + +powershell.exe -ExecutionPolicy Bypass -File "%~dp0Uninstall.ps1" +pause \ No newline at end of file diff --git a/Uninstall.ps1 b/Uninstall.ps1 new file mode 100644 index 0000000..a1577b0 --- /dev/null +++ b/Uninstall.ps1 @@ -0,0 +1,34 @@ +# Uninstall.ps1 +# Script to uninstall the folder backup context menu integration + +# Check for admin rights +$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) +if (-not $isAdmin) { + Write-Host "Bu komut dosyasý yönetici ayrýcalýklarý gerektirir. Lütfen Yönetici olarak çalýþtýrýn." -ForegroundColor Red + exit 1 +} + +Write-Host "Klasör Yedekleme Sað Týk Menüsü Entegrasyonu Kaldýrýlýyor..." -ForegroundColor Yellow + +# Define registry paths +$FolderContextMenuPath = "Registry::HKEY_CLASSES_ROOT\Directory\shell\BackupFolder" +$BackgroundContextMenuPath = "Registry::HKEY_CLASSES_ROOT\Directory\Background\shell\BackupFolder" + +try { + # Remove folder context menu entry + if (Test-Path $FolderContextMenuPath) { + Remove-Item -Path $FolderContextMenuPath -Recurse -Force + Write-Host "Klasör sað týk menüsü girdisi kaldýrýldý" -ForegroundColor Green + } + + # Remove background context menu entry + if (Test-Path $BackgroundContextMenuPath) { + Remove-Item -Path $BackgroundContextMenuPath -Recurse -Force + Write-Host "Arka plan sað týk menüsü girdisi kaldýrýldý" -ForegroundColor Green + } + + Write-Host "Kaldýrma iþlemi baþarýyla tamamlandý!" -ForegroundColor Green +} +catch { + Write-Host "Kaldýrma iþlemi sýrasýnda hata oluþtu: $($_.Exception.Message)" -ForegroundColor Red +} \ No newline at end of file diff --git a/yapi.md b/yapi.md new file mode 100644 index 0000000..2e4589a --- /dev/null +++ b/yapi.md @@ -0,0 +1,41 @@ +**Görev: Windows SaÄŸ Tık Menüsüne Klasör Yedekleme ÖzelliÄŸi Ekle** + +Windows gezgininde bir klasör üzerindeyken saÄŸ tıkladığımda çıkan menüye "Yedekle ve Sıkıştır" seçeneÄŸi ekleyen bir çözüm geliÅŸtir. + +**Gereksinimler:** + +1. **SaÄŸ Tık Menüsü Entegrasyonu:** + - Windows Registry'ye uygun kayıtları ekleyerek saÄŸ tık menüsünde "Yedekle ve Sıkıştır" seçeneÄŸi oluÅŸtur + - Hem klasörler için hem de boÅŸ alanda saÄŸ tık yapıldığında çalışmalı + +2. **Sıkıştırma İşlemi:** + - Birinci seçenek olarak WinRAR komut satırı (rar.exe) kullan + - İkinci seçenek olarak ücretsiz alternatif: 7-Zip komut satırı (7z.exe) veya PowerShell'in yerleÅŸik Compress-Archive cmdlet'ini kullan + - Sıkıştırma formatı: RAR (WinRAR için) veya ZIP (alternatifler için) + +3. **Dosya Adlandırma:** + - Format: `__.rar` (veya .zip) + - Tarih formatı: `YYYYMMDD` (örnek: 20241114) + - Numara: Aynı klasör için aynı gün içinde yapılan sıkıştırmalarda otomatik artan sıra numarası (001, 002, 003...) + - Örnek çıktı: `MusteriDosyalari_20241114_001.rar` + +4. **Numara Takibi:** + - Aynı klasör adı ve tarih için mevcut yedekleri tara + - En yüksek numarayı bul ve bir sonrakini kullan + - Yedek dosyası kaynak klasörle aynı dizine kaydedilecek + +5. **Hata Yönetimi:** + - WinRAR/7-Zip kurulu deÄŸilse kullanıcıyı bilgilendir + - Sıkıştırma baÅŸarısız olursa hata mesajı göster + - Yedekleme baÅŸarılı olursa bildirim göster + +**Çıktı:** +- 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 +- Kaldırma scripti +- Kullanım talimatları + +**Teknik Notlar:** +- Windows 10/11 uyumlu olmalı +- Yönetici hakları gerektiriyorsa bunu belirt +- Türkçe karakterleri (ÅŸ, ÄŸ, ü, ö, ç, ı) doÄŸru iÅŸlemeli