Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
FavoritesFile.cs
Go to the documentation of this file.
1using System;
3using System.Text;
4using Newtonsoft.Json;
5using Terraria.UI;
7
8namespace Terraria.IO;
9
10public class FavoritesFile
11{
12 public readonly string Path;
13
14 public readonly bool IsCloudSave;
15
17
19
20 public FavoritesFile(string path, bool isCloud)
21 {
22 Path = path;
24 }
25
27 {
28 if (!_data.ContainsKey(fileData.Type))
29 {
31 }
32 _data[fileData.Type][fileData.GetFileName()] = fileData.IsFavorite;
33 Save();
34 }
35
37 {
38 if (_data.ContainsKey(fileData.Type))
39 {
40 _data[fileData.Type].Remove(fileData.GetFileName());
41 Save();
42 }
43 }
44
46 {
47 if (!_data.ContainsKey(fileData.Type))
48 {
49 return false;
50 }
51 string fileName = fileData.GetFileName();
53 {
54 return value;
55 }
56 return false;
57 }
58
59 public void Save()
60 {
61 try
62 {
63 string s = JsonConvert.SerializeObject((object)_data, (Formatting)1);
64 byte[] bytes = _ourEncoder.GetBytes(s);
66 }
67 catch (Exception exception)
68 {
70 throw;
71 }
72 }
73
74 public void Load()
75 {
77 {
78 _data.Clear();
79 return;
80 }
81 try
82 {
84 string @string;
85 try
86 {
87 @string = _ourEncoder.GetString(bytes);
88 }
89 catch
90 {
91 @string = Encoding.ASCII.GetString(bytes);
92 }
94 if (_data == null)
95 {
97 }
98 }
99 catch (Exception)
100 {
101 Console.WriteLine("Unable to load favorites.json file ({0} : {1})", Path, IsCloudSave ? "Cloud Save" : "Local Save");
102 }
103 }
104}
bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
bool ICollection< KeyValuePair< TKey, TValue > >. Remove(KeyValuePair< TKey, TValue > keyValuePair)
void Add(TKey key, TValue value)
static void WriteLine()
Definition Console.cs:733
static Encoding ASCII
Definition Encoding.cs:511
unsafe override string GetString(byte[] bytes, int index, int count)
unsafe override int GetBytes(string s, int charIndex, int charCount, byte[] bytes, int byteIndex)
Dictionary< string, Dictionary< string, bool > > _data
FavoritesFile(string path, bool isCloud)
void SaveFavorite(FileData fileData)
bool IsFavorite(FileData fileData)
void ClearEntry(FileData fileData)
static void ShowFileSavingFailError(Exception exception, string filePath)
static bool Exists(string path, bool cloud)
static byte[] ReadAllBytes(string path, bool cloud)
static void WriteAllBytes(string path, byte[] data, bool cloud)