using System; using System.Collections.Generic; using System.IO; using Newtonsoft.Json; namespace ShadowStream.ObjecktForJason; public class Jason_Writer { private readonly string _folderPath; public Jason_Writer(string folderName = "Temp Data") { _folderPath = Path.Combine(Environment.CurrentDirectory, folderName); if (!Directory.Exists(_folderPath)) Directory.CreateDirectory(_folderPath); } // Save one list of locJason objects to JSON file with given name public async Task SaveList(string listName, List list) { Console.WriteLine($"Saving JSON list '{listName}' with {list.Count} items."); foreach (var item in list) { Console.WriteLine($" - Path: {item.path}, Type: {item.type}, ImageData length: {(item.imageData?.Length ?? 0)}"); } string filePath = Path.Combine(_folderPath, $"{listName}.json"); string jsonString = JsonConvert.SerializeObject(list, Formatting.Indented); await File.WriteAllTextAsync(filePath, jsonString); Console.WriteLine($"Saved JSON to: {filePath}"); } // Load one list of locJason objects from JSON file with given name public List LoadList(string listName) { string filePath = Path.Combine(_folderPath, $"{listName}.json"); if (!File.Exists(filePath)) return new List(); // Return empty list if file doesn't exist string jsonString = File.ReadAllText(filePath); return JsonConvert.DeserializeObject>(jsonString) ?? new List(); } // Check if list file exists public bool ListExists(string listName) { string filePath = Path.Combine(_folderPath, $"{listName}.json"); return File.Exists(filePath); } }