using System; using System.Collections; using System.Collections.Generic; using System.IO; using UnityEngine; using Newtonsoft.Json; using Newtonsoft.Json.Linq; namespace QuestAppLauncher { /// /// Root config object /// [Serializable] public class Config { // Supported category mode public const string Category_Off = "off"; public const string Category_Top = "top"; public const string Category_Left = "left"; public const string Category_Right = "right"; // Download repos public const string DownloadRepo_Type_GitHub = "github"; public const string DownloadRepo_Default = @"tverona1/QuestAppLauncher_Assets/releases/latest"; /// /// Grid size /// [Serializable] public class GridSize { public int rows = 3; public int cols = 3; } /// /// Download repo type /// [Serializable] public class DownloadRepo { public string repoUri; public string type; } // Grid size, specified as cols x rows public GridSize gridSize = new GridSize(); // Whether to show 2D apps public bool show2D = false; // Auto Category: Apps are automatically categorized into 3 tabs - Quest, Go/GearVr, 2D public string autoCategory = Category_Top; // Custom Category: Apps are categorized according to appnames.txt file public string customCategory = Category_Right; // Whether to auto-download updates public bool autoUpdate = false; // Github download repos public List downloadRepos = new List() { new DownloadRepo { repoUri = DownloadRepo_Default, type = DownloadRepo_Type_GitHub } }; } /// /// Class responsible for loading / saving config into a config.json file. /// public class ConfigPersistence { // File name of app name overrides const string ConfigFileName = "config.json"; /// /// Load config from file /// /// /// Config object static public Config LoadConfig() { var configFilePath = Path.Combine(UnityEngine.Application.persistentDataPath, ConfigFileName); if (File.Exists(configFilePath)) { Debug.Log("Found config file: " + configFilePath); var jsonConfig = File.ReadAllText(configFilePath); try { return JsonConvert.DeserializeObject(jsonConfig); } catch (Exception e) { Debug.Log(string.Format("Failed to read config: {0}", e.Message)); } } else { Debug.Log("Did not find config file: " + configFilePath); } // Return default config return new Config(); } /// /// Save config to a file /// /// static public void SaveConfig(Config config) { var configFilePath = Path.Combine(UnityEngine.Application.persistentDataPath, ConfigFileName); Debug.Log("Saving config file: " + configFilePath); try { File.WriteAllText(configFilePath, JsonConvert.SerializeObject(config, Formatting.Indented)); } catch (Exception e) { Debug.Log(string.Format("Failed to write config: {0}", e.Message)); } } } }