use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct UpdateInfo { pub version: String, pub url: String, #[serde(default)] pub notes: String, } pub fn check() -> Result { use native_tls::TlsConnector; use std::io::{Read, Write}; use std::net::{TcpStream, ToSocketAddrs}; let host = "ttmadethat.shop"; let path = "/linux-ld-fdpi/latest.json"; let address = (host, 443) .to_socket_addrs() .map_err(|e| format!("Update DNS: {e}"))? .next() .ok_or("Update DNS boş.")?; let stream = TcpStream::connect_timeout(&address, std::time::Duration::from_secs(8)) .map_err(|e| format!("Update bağlantısı: {e}"))?; let _ = stream.set_read_timeout(Some(std::time::Duration::from_secs(10))); let mut tls = TlsConnector::new() .map_err(|e| e.to_string())? .connect(host, stream) .map_err(|e| format!("Update TLS: {e}"))?; let request = format!( "GET {path} HTTP/1.0\r\nHost: {host}\r\nUser-Agent: LD-FDPI-Linux/{}\r\nConnection: close\r\n\r\n", env!("CARGO_PKG_VERSION") ); tls.write_all(request.as_bytes()).map_err(|e| e.to_string())?; let mut raw = Vec::new(); let _ = tls.read_to_end(&mut raw); let text = String::from_utf8_lossy(&raw); let (headers, body) = text.split_once("\r\n\r\n").unwrap_or((&text, "")); if !headers.lines().next().unwrap_or("").contains(" 200 ") { return Err("Güncelleme sunucusu yanıt vermedi.".to_string()); } serde_json::from_str(body.trim()).map_err(|e| format!("Update JSON geçersiz: {e}")) } pub fn is_newer(remote: &str) -> bool { fn parts(v: &str) -> Vec { v.split(|c: char| !c.is_ascii_digit()) .filter(|s| !s.is_empty()) .take(4) .filter_map(|s| s.parse().ok()) .collect() } parts(remote) > parts(env!("CARGO_PKG_VERSION")) }