-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
OriginalImageDataFile.cs
74 lines (66 loc) · 2.41 KB
/
OriginalImageDataFile.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System;
using System.Collections.Generic;
using Playnite.SDK.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HtmlExporterPlugin
{
class OriginalImageDataFile
{
public class ImageDataFileModel
{
public Dictionary<string, OriginalGameImageData> OriginalImageDataDict { get; set; } = new Dictionary<string, OriginalGameImageData>();
public string ImageOptionsString { get; set; } = String.Empty;
public string ExportPath { get; set; } = String.Empty;
}
private ImageDataFileModel Data = new ImageDataFileModel();
public bool LoadFromFile(string filename)
{
if (File.Exists(filename))
{
Data = Serialization.FromJsonFile<ImageDataFileModel>(filename);
return true;
}
else
{
return false;
}
}
public void Clear()
{
Data.OriginalImageDataDict.Clear();
}
public OriginalGameImageData GetOriginalGameImageData(string GameId)
{
if (Data.OriginalImageDataDict.ContainsKey(GameId))
{
return Data.OriginalImageDataDict[GameId];
}
else
{
return new OriginalGameImageData();
}
}
public bool SameSettingsUsed (HtmlExporterPluginSettings SettingsUsed)
{
return SettingsUsed.OutputFolder.Equals(Data.ExportPath) && SettingsUsed.ConvertImageOptions.GetUniqueString().Equals(Data.ImageOptionsString);
}
public void SetOriginalGameImageData(string GameId, OriginalGameImageData GameImageData)
{
Data.OriginalImageDataDict[GameId] = GameImageData;
}
public void SaveToFile(string filename, HtmlExporterPluginSettings SettingsUsed)
{
Data.ImageOptionsString = SettingsUsed.ConvertImageOptions.GetUniqueString();
Data.ExportPath = SettingsUsed.OutputFolder;
Directory.CreateDirectory(Path.GetDirectoryName(filename));
var fileMode = File.Exists(filename) ? FileMode.Truncate : FileMode.CreateNew;
using (FileStream fs = File.Open(filename, fileMode, FileAccess.Write, FileShare.None))
{
Serialization.ToJsonStream(Data, fs, true);
}
}
}
}