Logo
FSEx.h
1#pragma once
2
3namespace SharpKmyIO
4{
5#define Z_OK 0
6#define Z_STREAM_END 1
7#define Z_NEED_DICT 2
8#define Z_ERRNO (-1)
9#define Z_STREAM_ERROR (-2)
10#define Z_DATA_ERROR (-3)
11#define Z_MEM_ERROR (-4)
12#define Z_BUF_ERROR (-5)
13#define Z_VERSION_ERROR (-6)
14
15 public ref class FSEx
16 {
17 public:
23 static bool initializeResourceFileInfo(System::String^ inPath)
24 {
25 return kmyIO::initializeResourceFileInfo(SharpKmyBase::StringConv::convert(inPath).c_str());
26 }
27
33 static bool existsResourceFile(System::String^ inPath)
34 {
35 return kmyIO::existsResourceFile(SharpKmyBase::StringConv::convert(inPath).c_str());
36 }
37
43 static array<byte>^ readResourceFileAllBytes(System::String^ inPath)
44 {
45 auto p = SharpKmyBase::StringConv::convert(inPath);
46 auto size = kmyIO::getResourceFileSize(p.c_str());
47 auto buff = gcnew array<byte>(size);
48
49 if (size > 0)
50 {
51 auto* fs = kmyIO::FS::newFS();
52 auto* stream = fs->open(p.c_str(), kmyIO::StreamBase::kREAD_MODE);
53
54 if (stream != nullptr)
55 {
56 byte* tmp;
57
58 TRACK_NEW_ARRAY(tmp, byte, size);
59
60 stream->read(tmp, sizeof(byte), size);
61
62 for (size_t i = 0; i < size; i++)
63 {
64 buff[i] = tmp[i];
65 }
66
67 SAFE_DELETE(stream);
68
69 SAFE_DELETE_ARRAY(tmp);
70 }
71
72 SAFE_DELETE(fs);
73 }
74
75 return buff;
76 }
77
84 static unsigned char* getCodes(bool flag, int& refCodeCnt)
85 {
86 return kmyIO::getCodes(flag, refCodeCnt);
87 }
88
95 static bool compress(System::IO::BinaryWriter^ inWriter, System::IO::MemoryStream^ inStream)
96 {
97 auto srcSize = inStream->Length;
98 byte* srcBuff;
99
100 TRACK_NEW_ARRAY(srcBuff, byte, srcSize);
101
102 for (size_t i = 0; i < srcSize; i++)
103 {
104 srcBuff[i] = (byte)inStream->ReadByte();
105 }
106
107 byte* compressBuff;
108
109 TRACK_NEW_ARRAY(compressBuff, byte, srcSize);
110
111 auto compressSize = (size_t)srcSize;
112
113 auto result = true;
114
115 switch (kmyBase::CompressUtil::compress(srcBuff, inStream->Length, compressBuff, compressSize))
116 {
117 case Z_STREAM_END:
118 case Z_OK:
119 {
120 // 圧縮後の方がサイズが大きくなる場合は無圧縮で格納する
121 auto outSize = min(compressSize, srcSize);
122 auto outBuff = outSize == srcSize ? srcBuff : compressBuff;
123
124 for (size_t i = 0; i < outSize; i++)
125 {
126 inWriter->Write(outBuff[i]);
127 }
128 }
129 break;
130 default:
131 result = false;
132 break;
133 }
134
135 SAFE_DELETE_ARRAY(srcBuff);
136 SAFE_DELETE_ARRAY(compressBuff);
137
138 return result;
139 }
140 };
141}
static std::string convert(System::String^ s)
Definition: SharpKmyCore.h:33
Definition: FSEx.h:16
static bool initializeResourceFileInfo(System::String^ inPath)
リソースファイルの管理情報の初期化
Definition: FSEx.h:23
static array< byte > readResourceFileAllBytes(System::String^ inPath)
リソースファイルの全バイナリの取得
Definition: FSEx.h:43
static bool existsResourceFile(System::String^ inPath)
リソースファイルの存在確認
Definition: FSEx.h:33
static bool compress(System::IO::BinaryWriter^ inWriter, System::IO::MemoryStream^ inStream)
圧縮処理
Definition: FSEx.h:95
static unsigned char * getCodes(bool flag, int &refCodeCnt)
スクランブルコードの取得
Definition: FSEx.h:84
Definition: FSEx.h:4