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 SEHTRY2{
46 auto p = SharpKmyBase::StringConv::convert(inPath);
47 auto size = kmyIO::getResourceFileSize(p.c_str());
48 auto buff = gcnew array<byte>(size);
49
50 if (size > 0)
51 {
52 auto* fs = kmyIO::FS::newFS();
53 auto* stream = fs->open(p.c_str(), kmyIO::StreamBase::kREAD_MODE);
54
55 if (stream != nullptr)
56 {
57 byte* tmp;
58
59 TRACK_NEW_ARRAY(tmp, byte, size);
60
61 stream->read(tmp, sizeof(byte), size);
62
63 for (size_t i = 0; i < size; i++)
64 {
65 buff[i] = tmp[i];
66 }
67
68 SAFE_DELETE(stream);
69
70 SAFE_DELETE_ARRAY(tmp);
71 }
72
73 SAFE_DELETE(fs);
74 }
75
76 return buff;
77 }SEHCATCH2;
78 }
79
86 static unsigned char* getCodes(bool flag, int& refCodeCnt)
87 {
88 SEHTRY{
89 return kmyIO::getCodes(flag, refCodeCnt);
90 }SEHCATCH;
91 }
92
99 static bool compress(System::IO::BinaryWriter^ inWriter, System::IO::MemoryStream^ inStream)
100 {
101 SEHTRY{
102 auto srcSize = inStream->Length;
103 byte* srcBuff;
104
105 TRACK_NEW_ARRAY(srcBuff, byte, srcSize);
106
107 for (size_t i = 0; i < srcSize; i++)
108 {
109 srcBuff[i] = (byte)inStream->ReadByte();
110 }
111
112 byte* compressBuff;
113
114 TRACK_NEW_ARRAY(compressBuff, byte, srcSize);
115
116 auto compressSize = (size_t)srcSize;
117
118 auto result = true;
119
120 switch (kmyBase::CompressUtil::compress(srcBuff, inStream->Length, compressBuff, compressSize))
121 {
122 case Z_STREAM_END:
123 case Z_OK:
124 {
125 // 圧縮後の方がサイズが大きくなる場合は無圧縮で格納する
126 auto outSize = min(compressSize, srcSize);
127 auto outBuff = outSize == srcSize ? srcBuff : compressBuff;
128
129 for (size_t i = 0; i < outSize; i++)
130 {
131 inWriter->Write(outBuff[i]);
132 }
133 }
134 break;
135 default:
136 result = false;
137 break;
138 }
139
140 SAFE_DELETE_ARRAY(srcBuff);
141 SAFE_DELETE_ARRAY(compressBuff);
142
143 return result;
144 }SEHCATCH;
145 }
146 };
147}
static std::string convert(System::String^ s)
Definition: SharpKmyCore.cpp:36
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:99
static unsigned char * getCodes(bool flag, int &refCodeCnt)
スクランブルコードの取得
Definition: FSEx.h:86
Definition: FSEx.h:4