-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAssetLoadWindow.cs
More file actions
86 lines (73 loc) · 2.98 KB
/
Copy pathAssetLoadWindow.cs
File metadata and controls
86 lines (73 loc) · 2.98 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
using System;
using System.IO;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CustomStreamMaker
{
public partial class AssetLoadWindow : Form
{
internal Progress<int> progress = new();
public AssetLoadWindow()
{
InitializeComponent();
}
private async void AssetLoadWindow_Load(object sender, EventArgs e)
{
}
public async Task<bool> StartCachingAssets()
{
await LoadAssetsToMemory(progress);
return true;
}
private async Task LoadAssetsToMemory(IProgress<int> progress)
{
CreateNewDirectoryIfNull();
progress.Report(0);
await Task.Run(AssetExtractor.CacheBackgrounds);
progress.Report(50);
await Task.Run(AssetExtractor.CacheSprites);
progress.Report(100);
await Task.Run(AssetExtractor.CacheAudio);
if (!IsAllLoaded())
{
MessageBox.Show("Some assets were either not loaded properly or are missing. Previews of these broken assets are disabled.", "Error");
Properties.Settings.Default.IsAssetsLoaded = false;
}
else Properties.Settings.Default.IsAssetsLoaded = true;
Properties.Settings.Default.Save();
}
internal bool IsAllLoaded()
{
bool isAllCachedToMemory = AssetExtractor.SaveToMemory && (AssetExtractor.CachedBackgrounds.Count == 12 && AssetExtractor.CachedSprites.Count == (352 + 11) && AssetExtractor.CachedMusic.Count == 128);
bool isAllCachedToFiles = !AssetExtractor.SaveToMemory && (Directory.GetFiles(AssetExtractor.BackgroundDirectory).Length == 12 && Directory.GetFiles(AssetExtractor.SpriteDirectory).Length == (352 + 11) && Directory.GetFiles(AssetExtractor.AudioDirectory).Length == 128);
return isAllCachedToMemory || isAllCachedToFiles;
}
private void CreateNewDirectoryIfNull()
{
var dir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\CustomStreamMaker";
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
Directory.CreateDirectory(dir + @"\CachedBackgrounds");
Directory.CreateDirectory(dir + @"\CachedSprites");
Directory.CreateDirectory(dir + @"\CachedAudio");
}
}
private async void AssetLoadWindow_Shown(object sender, EventArgs e)
{
progress = new Progress<int>(value => { AssetToMem_Progress.Value = value; });
await StartCachingAssets();
Close();
Dispose();
}
private void AssetLoadWindow_Enter(object sender, EventArgs e)
{
}
private void AssetLoadWindow_Activated(object sender, EventArgs e)
{
}
private void AssetLoadWindow_Validated(object sender, EventArgs e)
{
}
}
}