public static Cll.JSON.Object InjectFolder(string inputPath, string outputPath) { string[] folders = Directory.GetDirectories(inputPath); string[] files = Directory.GetFiles(inputPath); string validFolderName = ValidFilename(Path.GetFileName(inputPath)); string output = Path.Combine(outputPath, validFolderName); if (!Directory.Exists(output)) { Directory.CreateDirectory(output); } NumericComparer numericComparer = new NumericComparer(); Array.Sort(folders, numericComparer.Compare); Array.Sort(files, numericComparer.Compare); Cll.JSON.Object folderJSON = new Cll.JSON.Object(); folderJSON.AddMember("name", ValidName(Path.GetFileName(inputPath))); folderJSON.AddMember("foldername", ValidName(validFolderName)); Cll.JSON.Array foldersArray = new Cll.JSON.Array(); foreach (string folder in folders) { foldersArray.AddValue(InjectFolder(folder, output)); } Cll.JSON.Array filesArray = new Cll.JSON.Array(); foreach (string file in files) { try { Cll.JSON.Object fileJSON = InjectFile(file, output); if (fileJSON.Count != 0) { filesArray.AddValue(fileJSON); } } catch (Exception e) { Cll.Log.WriteLine(e.ToString()); } } folderJSON.AddMember("folders", foldersArray); folderJSON.AddMember("files", filesArray); return(folderJSON); }
public Cll.JSON.Value GetJSON(int index) { Cll.JSON.Object jsonObj = new Cll.JSON.Object(); Cll.JSON.Array arrayScreens = new Cll.JSON.Array(); Cll.JSON.Array arrayBackgrounds = new Cll.JSON.Array(); if (ScreenUpperTV.Size.Width > 0 && ScreenUpperTV.Size.Height > 0) { arrayScreens.AddValue(ScreenUpperTV.GetJSON()); } if (ScreenLowerTV.Size.Width > 0 && ScreenLowerTV.Size.Height > 0) { arrayScreens.AddValue(ScreenLowerTV.GetJSON()); } if (ScreenUpperGamePad.Size.Width > 0 && ScreenUpperGamePad.Size.Height > 0) { arrayScreens.AddValue(ScreenUpperGamePad.GetJSON()); } if (ScreenLowerGamePad.Size.Width > 0 && ScreenLowerGamePad.Size.Height > 0) { arrayScreens.AddValue(ScreenLowerGamePad.GetJSON()); } if (arrayScreens.Count == 0) { throw new Exception("There must be at least one screen."); } arrayBackgrounds.AddValue(BackgroundTV.GetJSON(index)); arrayBackgrounds.AddValue(BackgroundGamePad.GetJSON(index)); jsonObj.AddMember("pad_rotation", PadRotation); jsonObj.AddMember("drc_rotation", DRCRotation); jsonObj.AddMember("screen", arrayScreens); jsonObj.AddMember("name_string_id", NameID); jsonObj.AddMember("background", arrayBackgrounds); jsonObj.AddMember("buttons_rotation", ButtonsRotation); jsonObj.AddMember("desc_string_id", DescriptionID); return(jsonObj); }
public Cll.JSON.Value GetJSON() { Cll.JSON.Object jsonObj = new Cll.JSON.Object(); Cll.JSON.Object jsonConfiguration = new Cll.JSON.Object(); Cll.JSON.Object jsonLayouts = new Cll.JSON.Object(); Cll.JSON.Array arrayLayout = new Cll.JSON.Array(); Cll.JSON.Array arrayGroups = new Cll.JSON.Array(); Cll.JSON.Object json3DRendering = new Cll.JSON.Object(); Cll.JSON.Object jsonDisplay = new Cll.JSON.Object(); Cll.JSON.Object jsonArguments = new Cll.JSON.Object(); for (int i = 0; i < Layouts.Length; i++) { arrayLayout.AddValue(Layouts[i].GetJSON(i + 1)); } for (int i = 0; i < Groups.Length; i++) { arrayGroups.AddValue(Groups[i]); } jsonLayouts.AddMember("layout", arrayLayout); jsonLayouts.AddMember("groups", arrayGroups); json3DRendering.AddMember("Bilinear", Bilinear); json3DRendering.AddMember("RenderScale", RenderScale); jsonDisplay.AddMember("PixelArtUpscaler", PixelArtUpscaler); jsonDisplay.AddMember("Brightness", Brightness); jsonArguments.AddMember("fold_on_pause", FoldOnPause); jsonArguments.AddMember("fold_on_resume_fade_from_black_duration", FoldOnResumeFadeFromBlackDuration); jsonArguments.AddMember("fold_on_pause_timeout", FoldOnPauseTimeout); jsonConfiguration.AddMember("layouts", jsonLayouts); jsonConfiguration.AddMember("3DRendering", json3DRendering); jsonConfiguration.AddMember("Display", jsonDisplay); jsonConfiguration.AddMember("arguments", jsonArguments); jsonObj.AddMember("configuration", jsonConfiguration); return(jsonObj); }
public Configuration(Cll.JSON.Element json) { Cll.JSON.Object config = (Cll.JSON.Object)json.Value.GetValue("configuration"); Cll.JSON.Array layout = (Cll.JSON.Array)config.GetValue("layouts").GetValue("layout"); Cll.JSON.Array groups = (Cll.JSON.Array)config.GetValue("layouts").GetValue("groups"); Layouts = new Layout[layout.Count]; Groups = new int[groups.Count]; Bilinear = Convert.ToInt32(((Cll.JSON.Number)config.GetValue("3DRendering").GetValue("Bilinear")).Value); RenderScale = Convert.ToInt32(((Cll.JSON.Number)config.GetValue("3DRendering").GetValue("RenderScale")).Value); PixelArtUpscaler = Convert.ToInt32(((Cll.JSON.Number)config.GetValue("Display").GetValue("PixelArtUpscaler")).Value); Brightness = Convert.ToInt32(((Cll.JSON.Number)config.GetValue("Display").GetValue("Brightness")).Value); if (config.Contains("arguments")) { FoldOnPause = ((Cll.JSON.Boolean)config.GetValue("arguments").GetValue("fold_on_pause")).Value; FoldOnResumeFadeFromBlackDuration = Convert.ToInt32(((Cll.JSON.Number)config.GetValue("arguments").GetValue("fold_on_resume_fade_from_black_duration")).Value); FoldOnPauseTimeout = Convert.ToInt32(((Cll.JSON.Number)config.GetValue("arguments").GetValue("fold_on_pause_timeout")).Value); } else { FoldOnPause = false; FoldOnResumeFadeFromBlackDuration = 1000; FoldOnPauseTimeout = 3000; } for (int i = 0; i < Layouts.Length; i++) { Layouts[i] = new Layout((Cll.JSON.Object)layout.GetValue(i)); } for (int i = 0; i < Groups.Length; i++) { Groups[i] = Convert.ToInt32(((Cll.JSON.Number)groups.GetValue(i)).Value); } }
public Layout(Cll.JSON.Object layout) { Cll.JSON.Array screen = (Cll.JSON.Array)layout.GetValue("screen"); Cll.JSON.Array background = (Cll.JSON.Array)layout.GetValue("background"); if (screen.Count < 1 || screen.Count > 4) { throw new Exception("Screens count must be greater than 0 and less than 5."); } if (background.Count != 2) { throw new Exception("Backgrounds count must be equal to 2."); } ScreenStruct[] screens = new ScreenStruct[screen.Count]; BackgroundStruct[] backgrounds = new BackgroundStruct[background.Count]; for (int i = 0; i < screens.Length; i++) { screens[i] = new ScreenStruct((Cll.JSON.Object)screen.GetValue(i)); } if (screens[0].Source == "upper" && screens[0].Target == "tv") { ScreenUpperTV = screens[0]; } else if (screens.Length > 1 && screens[1].Source == "upper" && screens[1].Target == "tv") { ScreenUpperTV = screens[1]; } else if (screens.Length > 2 && screens[2].Source == "upper" && screens[2].Target == "tv") { ScreenUpperTV = screens[2]; } else if (screens.Length > 3 && screens[3].Source == "upper" && screens[3].Target == "tv") { ScreenUpperTV = screens[3]; } else { ScreenUpperTV = new ScreenStruct("upper", "tv", 0, 0, 0, 0); } if (screens[0].Source == "lower" && screens[0].Target == "tv") { ScreenLowerTV = screens[0]; } else if (screens.Length > 1 && screens[1].Source == "lower" && screens[1].Target == "tv") { ScreenLowerTV = screens[1]; } else if (screens.Length > 2 && screens[2].Source == "lower" && screens[2].Target == "tv") { ScreenLowerTV = screens[2]; } else if (screens.Length > 3 && screens[3].Source == "lower" && screens[3].Target == "tv") { ScreenLowerTV = screens[3]; } else { ScreenLowerTV = new ScreenStruct("lower", "tv", 0, 0, 0, 0); } if (screens[0].Source == "upper" && screens[0].Target == "drc") { ScreenUpperGamePad = screens[0]; } else if (screens.Length > 1 && screens[1].Source == "upper" && screens[1].Target == "drc") { ScreenUpperGamePad = screens[1]; } else if (screens.Length > 2 && screens[2].Source == "upper" && screens[2].Target == "drc") { ScreenUpperGamePad = screens[2]; } else if (screens.Length > 3 && screens[3].Source == "upper" && screens[3].Target == "drc") { ScreenUpperGamePad = screens[3]; } else { ScreenUpperGamePad = new ScreenStruct("upper", "drc", 0, 0, 0, 0); } if (screens[0].Source == "lower" && screens[0].Target == "drc") { ScreenLowerGamePad = screens[0]; } else if (screens.Length > 1 && screens[1].Source == "lower" && screens[1].Target == "drc") { ScreenLowerGamePad = screens[1]; } else if (screens.Length > 2 && screens[2].Source == "lower" && screens[2].Target == "drc") { ScreenLowerGamePad = screens[2]; } else if (screens.Length > 3 && screens[3].Source == "lower" && screens[3].Target == "drc") { ScreenLowerGamePad = screens[3]; } else { ScreenLowerGamePad = new ScreenStruct("lower", "drc", 0, 0, 0, 0); } backgrounds[0] = new BackgroundStruct((Cll.JSON.Object)background.GetValue(0)); backgrounds[1] = new BackgroundStruct((Cll.JSON.Object)background.GetValue(1)); if (backgrounds[0].Target == "tv") { BackgroundTV = backgrounds[0]; } else if (backgrounds[1].Target == "tv") { BackgroundTV = backgrounds[1]; } else { BackgroundTV = new BackgroundStruct("tv"); } if (backgrounds[0].Target == "drc") { BackgroundGamePad = backgrounds[0]; } else if (backgrounds[1].Target == "drc") { BackgroundGamePad = backgrounds[1]; } else { BackgroundGamePad = new BackgroundStruct("drc"); } if (layout.Contains("pad_rotation")) { PadRotation = Convert.ToInt32(((Cll.JSON.Number)layout.GetValue("pad_rotation")).Value); } else { PadRotation = 0; } if (layout.Contains("drc_rotation")) { DRCRotation = Convert.ToInt32(((Cll.JSON.Number)layout.GetValue("drc_rotation")).Value); } else { DRCRotation = 0; } if (layout.Contains("buttons_rotation")) { ButtonsRotation = Convert.ToInt32(((Cll.JSON.Number)layout.GetValue("buttons_rotation")).Value); } else { ButtonsRotation = 0; } if (layout.Contains("name_string_id")) { NameID = ((Cll.JSON.String)layout.GetValue("name_string_id")).Value; } else { NameID = ""; } if (layout.Contains("desc_string_id")) { DescriptionID = ((Cll.JSON.String)layout.GetValue("desc_string_id")).Value; } else { DescriptionID = ""; } Name = StringLanguages.Empty; Description = StringLanguages.Empty; }