# --- 1. TÜRKÇE KARAKTER AYARI ---
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8

# --- 2. AYARLAR VE YOLLAR ---
$ScriptPath = Split-Path -Parent $MyInvocation.MyCommand.Definition
$WallpaperFile = "$ScriptPath\wallpaper.jpg"
$LogoFile = "$ScriptPath\logo.jpg"
$HedefKlasor = "C:\DINOSOFT\RESPOS\Logo"

# --- 3. LOGO KOPYALAMA İŞLEMİ ---
Write-Host "Logo dosyası kopyalanıyor..." -ForegroundColor Cyan

if (Test-Path $LogoFile) {
    # Hedef klasör yoksa oluştur
    if (-not (Test-Path $HedefKlasor)) {
        New-Item -ItemType Directory -Path $HedefKlasor -Force | Out-Null
        Write-Host "Klasör oluşturuldu: $HedefKlasor" -ForegroundColor Yellow
    }
    
    # Dosyayı kopyala (Varsa üzerine yazar)
    Copy-Item -Path $LogoFile -Destination $HedefKlasor -Force
    Write-Host "Logo başarıyla kopyalandı: $HedefKlasor" -ForegroundColor Green
}
else {
    Write-Host "UYARI: logo.jpg dosyası scriptin yanında bulunamadı, kopyalanmadı." -ForegroundColor Magenta
}

# --- 4. C# ENTEGRASYONU (Hızlı Yenileme İçin) ---
$code = @'
using System;
using System.Runtime.InteropServices;

public class SystemChanger {
    public const int SPI_SETDESKWALLPAPER = 0x0014;
    public const int SPIF_UPDATEINIFILE = 0x01;
    public const int SPIF_SENDWININICHANGE = 0x02;
    public const int HWND_BROADCAST = 0xffff;
    public const int WM_SETTINGCHANGE = 0x001A;
    public const int SMTO_ABORTIFHUNG = 0x0002;

    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    public static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni);

    [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
    public static extern IntPtr SendMessageTimeout(IntPtr hWnd, uint Msg, UIntPtr wParam, string lParam, uint fuFlags, uint uTimeout, out UIntPtr lpdwResult);

    public static void SetWallpaper(string path) {
        SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, path, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);
    }

    public static void RefreshSettings() {
        UIntPtr result;
        SendMessageTimeout((IntPtr)HWND_BROADCAST, WM_SETTINGCHANGE, UIntPtr.Zero, "Environment", SMTO_ABORTIFHUNG, 500, out result);
        SendMessageTimeout((IntPtr)HWND_BROADCAST, WM_SETTINGCHANGE, UIntPtr.Zero, "Policy", SMTO_ABORTIFHUNG, 500, out result);
    }
}
'@

Add-Type -TypeDefinition $code -Language CSharp

# --- 5. TEMA DEĞİŞİKLİĞİ ---
Write-Host "Tema ayarları işleniyor..." -ForegroundColor Cyan
try {
    # Uygulamalar AÇIK (1), Sistem KOYU (0)
    Set-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize" -Name "AppsUseLightTheme" -Value 1 -Force
    Set-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize" -Name "SystemUsesLightTheme" -Value 0 -Force
} catch {}

# --- 6. DUVAR KAĞIDI VE BİTİŞ ---
if (Test-Path $WallpaperFile) {
    [SystemChanger]::RefreshSettings()
    [SystemChanger]::SetWallpaper($WallpaperFile)
    [SystemChanger]::RefreshSettings()
    Write-Host "Duvar kağıdı ve tema ayarlandı." -ForegroundColor Green
} else {
    Write-Host "HATA: wallpaper.jpg bulunamadı!" -ForegroundColor Red
}

Write-Host "İşlemler tamamlandı." -ForegroundColor Green
# Pencere hemen kapansın diye bekleme süresi yok