-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFolderResourceManager.cs
44 lines (37 loc) · 1.21 KB
/
FolderResourceManager.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
using System;
using System.Collections.Generic;
using System.IO;
namespace LPC.Spritesheet.ResourceManager
{
public class FolderResourceManager : IResourceManager
{
public const string ImageExtension = "*.png";
private static string _sheetRoot;
public static string SheetRoot
{
get
{
if (string.IsNullOrEmpty(_sheetRoot))
{
_sheetRoot = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\..\..\spritesheets"));
}
return _sheetRoot;
}
}
public Stream GetImageStream(string path)
{
var ms = new MemoryStream();
using (var file = new FileStream(path, FileMode.Open, FileAccess.Read))
{
byte[] bytes = new byte[file.Length];
file.Read(bytes, 0, (int)file.Length);
ms.Write(bytes, 0, (int)file.Length);
}
return ms;
}
public IEnumerable<string> GetSprites(string path, SearchOption option)
{
return Directory.EnumerateFiles(Path.Combine(SheetRoot, path), ImageExtension, option);
}
}
}