コード例 #1
0
ファイル: Library.cs プロジェクト: solwllms/CI536
        public static void LoadLibrary()
        {
            // make sure the file tree exists
            string libraryPath = UserConfig.GetValue(CONFIG_FILE, "libary_path", defaultPath);

            Directory.CreateDirectory(Path.GetDirectoryName(libraryPath));

            using (StreamReader reader = new StreamReader(File.Open(libraryPath, FileMode.OpenOrCreate)))
            {
                string content = reader.ReadToEnd();
                collection = JsonConvert.DeserializeObject <Dictionary <string, GameEntry> >(content);

                if (collection == null)
                {
                    collection = new Dictionary <string, GameEntry>();
                }
            }

            // load recent
            recent = new FixedList <string>(MAX_RECENT);
            if (UserConfig.HasProperty(CONFIG_FILE, "recent"))
            {
                foreach (var entry in UserConfig.GetValue <JArray>(CONFIG_FILE, "recent"))
                {
                    recent.Add(entry.ToString());
                }
            }
            else
            {
                UserConfig.SetValue(CONFIG_FILE, "recent", recent.ToArray());
            }
        }
コード例 #2
0
ファイル: MainWindow.xaml.cs プロジェクト: solwllms/CI536
        public MainWindow()
        {
            showHidden = UserConfig.GetValue(CONFIG_FILE, "show-hidden", false);
            InitializeComponent();

            gamesEntries = new List <GameListEntry>();

            instance = this;

            ShowHome();
            RefreshGamesList();
        }
コード例 #3
0
ファイル: Library.cs プロジェクト: solwllms/CI536
        public static void SaveChanges()
        {
            if (collection == null)
            {
                return;
            }

            OnSaveChanges?.Invoke();

            string libraryPath = UserConfig.GetValue(CONFIG_FILE, "libary_path", defaultPath);

            JsonSerializerSettings settings = new JsonSerializerSettings();

            settings.NullValueHandling = NullValueHandling.Ignore;
            settings.ContractResolver  = new CamelCasePropertyNamesContractResolver();
            string json = JsonConvert.SerializeObject(collection, Formatting.Indented, settings);

            File.WriteAllText(libraryPath, json);

            UserConfig.SetValue(CONFIG_FILE, "recent", recent.ToArray());
        }