Rev 5276 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5276 | ZblCoder | 1 | #include "kosSyst.h" |
2 | #include "kosFile.h" |
||
3 | //#include "string.h" |
||
4 | |||
5 | CKosFile::CKosFile(char *fileName) |
||
6 | { |
||
7 | // |
||
5331 | ZblCoder | 8 | //rtlDebugOutString(fileName); |
5276 | ZblCoder | 9 | this->fileInfo.bufferPtr = new Byte[FILE_BUFFER_SIZE]; |
10 | // |
||
11 | this->filePointer = 0; |
||
12 | this->bufferPointer = 0; |
||
13 | this->validBuffer = false; |
||
14 | // |
||
15 | strcpy( this->fileInfo.fileURL, fileName ); |
||
16 | } |
||
17 | |||
18 | |||
19 | CKosFile::~CKosFile(void) |
||
20 | { |
||
21 | // |
||
22 | delete this->fileInfo.bufferPtr; |
||
23 | } |
||
24 | |||
25 | void CKosFile::ValidateBuffer() |
||
26 | { |
||
27 | // |
||
28 | if ( this->validBuffer ) |
||
29 | { |
||
30 | // |
||
31 | if ( this->filePointer < this->bufferPointer |
||
32 | || this->filePointer >= (this->bufferPointer + FILE_BUFFER_SIZE) ) |
||
33 | { |
||
34 | // |
||
35 | this->validBuffer = false; |
||
36 | } |
||
37 | } |
||
38 | } |
||
39 | |||
40 | |||
41 | void CKosFile::UpdateBuffer(void) |
||
42 | { |
||
43 | // |
||
44 | if ( ! this->validBuffer ) |
||
45 | { |
||
46 | // |
||
47 | this->fileInfo.OffsetLow = this->filePointer / OS_BLOCK_SIZE; |
||
48 | this->fileInfo.OffsetHigh = 0; |
||
49 | // |
||
50 | this->bufferPointer = this->fileInfo.OffsetLow * OS_BLOCK_SIZE; |
||
51 | // |
||
52 | this->fileInfo.dataCount = FILE_BUFFER_BLOCKS; |
||
53 | // |
||
54 | this->fileInfo.rwMode = 0; |
||
55 | // |
||
56 | Dword rr = kos_FileSystemAccess( &(this->fileInfo) ); |
||
57 | this->validBuffer = ( rr == 0 ); |
||
58 | } |
||
59 | } |
||
60 | |||
61 | |||
62 | int CKosFile::Seek(int seekFrom, int seekStep) |
||
63 | { |
||
64 | // |
||
65 | switch ( seekFrom ) |
||
66 | { |
||
67 | // |
||
68 | case SEEK_SET: |
||
69 | // |
||
70 | this->filePointer = seekStep; |
||
71 | break; |
||
72 | // |
||
73 | case SEEK_CUR: |
||
74 | // |
||
75 | this->filePointer += seekStep; |
||
76 | break; |
||
77 | } |
||
78 | // |
||
79 | this->ValidateBuffer(); |
||
80 | // |
||
81 | return this->filePointer; |
||
82 | } |
||
83 | |||
84 | |||
85 | int CKosFile::Read(Byte *targetPtr, int readCount) |
||
86 | { |
||
87 | int bufferLeast, result; |
||
88 | |||
89 | // |
||
90 | result = 0; |
||
91 | // |
||
92 | do |
||
93 | { |
||
94 | // |
||
95 | this->UpdateBuffer(); |
||
96 | // |
||
97 | if ( ! this->validBuffer ) return result; |
||
98 | // |
||
99 | bufferLeast = FILE_BUFFER_SIZE - (this->filePointer - this->bufferPointer); |
||
100 | // |
||
101 | if ( bufferLeast > readCount ) bufferLeast = readCount; |
||
102 | // |
||
103 | if ( bufferLeast ) |
||
104 | { |
||
105 | // |
||
106 | memcpy( |
||
107 | targetPtr, |
||
108 | this->fileInfo.bufferPtr + (this->filePointer - this->bufferPointer), |
||
109 | bufferLeast |
||
110 | ); |
||
111 | // |
||
112 | targetPtr += bufferLeast; |
||
113 | readCount -= bufferLeast; |
||
114 | this->filePointer += bufferLeast; |
||
115 | // |
||
116 | result += bufferLeast; |
||
117 | } |
||
118 | // |
||
119 | this->ValidateBuffer(); |
||
120 | } |
||
121 | while ( readCount > 0 ); |
||
122 | // |
||
123 | return result; |
||
124 | } |
||
125 | |||
126 | |||
127 | int CKosFile::Write(Byte *sourcePtr, int writeCount) |
||
128 | { |
||
129 | return 0; |
||
130 | } |
||
131 | |||
132 | void CKosFile::LoadTex(Byte *targetPtr, Byte Size, int width, int height) |
||
133 | { |
||
134 | this->Read(targetPtr, width * height * Size); |
||
135 | }> |
||
136 |