using System; using System.IO; using DB; using Newtonsoft.Json; using Newtonsoft.Json.Linq; namespace WeldingCommon.Settings { // 레시피별 Laser 방향(Front/Down) 발진 차단 체크값. // 활성 레시피 폴더의 Recipe_Laser_Interlock.json 에 저장/로드한다. // 경로 소스는 FieldHelper.json 과 동일한 DB.Dao.SystemRecipe.WorkRecipeFile 을 사용해 // 같은 레시피 폴더에 떨어지도록 보장한다. public class RecipeLaserInterlock { public bool Front { get; set; } // json 1=true(차단) / 0=false public bool Down { get; set; } private const string FileName = "Recipe_Laser_Interlock.json"; private const string WrapperKey = "Laser Interlock"; // 활성 레시피 폴더의 Recipe_Laser_Interlock.json 전체 경로. // (FieldHelper.json 과 동일 소스/폴더. 파일명만 치환) public static string GetActiveFilePath() { string recipeFile = DB.Dao.SystemRecipe.WorkRecipeFile; if (string.IsNullOrEmpty(recipeFile)) { return null; } return recipeFile.Replace(Path.GetFileName(recipeFile), FileName); } // 파일이 없거나 파싱 실패 시 기본값(Front=false, Down=false) = 차단 없음. public static RecipeLaserInterlock Load() { var result = new RecipeLaserInterlock(); try { string path = GetActiveFilePath(); if (string.IsNullOrEmpty(path) || !File.Exists(path)) { return result; } var root = JObject.Parse(File.ReadAllText(path)); var node = root[WrapperKey]; if (node != null) { result.Front = (node["Front"]?.Value() ?? 0) == 1; result.Down = (node["Down"]?.Value() ?? 0) == 1; } } catch { // 손상/파싱 실패 → 기본값(차단 없음) 반환 } return result; } public static void Save(RecipeLaserInterlock value) { string path = GetActiveFilePath(); if (string.IsNullOrEmpty(path)) { return; } var root = new JObject { [WrapperKey] = new JObject { ["Front"] = value.Front ? 1 : 0, ["Down"] = value.Down ? 1 : 0, } }; File.WriteAllText(path, root.ToString(Formatting.Indented)); } } }