Mercurial > projects > hoofbaby
annotate deps/Platinum/ThirdParty/Neptune/Source/System/PSP/NptPSPFile.cpp @ 0:3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
author | fraserofthenight |
---|---|
date | Mon, 06 Jul 2009 08:06:28 -0700 |
parents | |
children |
rev | line source |
---|---|
0
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
1 /***************************************************************** |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
2 | |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
3 | Neptune - File Byte Stream :: Standard C Implementation |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
4 | |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
5 | (c) 2001-2003 Gilles Boccon-Gibod |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
6 | Author: Gilles Boccon-Gibod (bok@bok.net) |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
7 | |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
8 ****************************************************************/ |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
9 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
10 /*---------------------------------------------------------------------- |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
11 | includes |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
12 +---------------------------------------------------------------------*/ |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
13 #include <stdio.h> |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
14 #include <string.h> |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
15 #include <malloc.h> |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
16 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
17 #include <kernel.h> |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
18 #include <psptypes.h> |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
19 #include <psperror.h> |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
20 #include <mediaman.h> |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
21 #include <umderror.h> |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
22 #include <fatms.h> |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
23 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
24 #include "NptFile.h" |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
25 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
26 /*---------------------------------------------------------------------- |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
27 | NPT_PSPFileWrapper |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
28 +---------------------------------------------------------------------*/ |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
29 class NPT_PSPFileWrapper |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
30 { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
31 public: |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
32 // constructors and destructor |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
33 NPT_PSPFileWrapper(SceUID file) : m_File(file) {} |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
34 ~NPT_PSPFileWrapper() { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
35 if (m_File >= 0) { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
36 sceIoClose(m_File); |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
37 } |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
38 } |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
39 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
40 // methods |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
41 SceUID GetFile() { return m_File; } |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
42 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
43 private: |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
44 // members |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
45 SceUID m_File; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
46 }; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
47 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
48 typedef NPT_Reference<NPT_PSPFileWrapper> NPT_PSPFileReference; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
49 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
50 /*---------------------------------------------------------------------- |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
51 | NPT_PSPFileStream |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
52 +---------------------------------------------------------------------*/ |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
53 class NPT_PSPFileStream |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
54 { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
55 public: |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
56 // constructors and destructor |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
57 NPT_PSPFileStream(NPT_PSPFileReference file) : |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
58 m_FileReference(file), m_Position(0) {} |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
59 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
60 // NPT_FileInterface methods |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
61 NPT_Result Seek(NPT_Offset offset); |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
62 NPT_Result Tell(NPT_Offset& offset); |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
63 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
64 protected: |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
65 // constructors and destructors |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
66 virtual ~NPT_PSPFileStream() {} |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
67 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
68 // members |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
69 NPT_PSPFileReference m_FileReference; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
70 SceOff m_Position; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
71 }; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
72 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
73 /*---------------------------------------------------------------------- |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
74 | NPT_PSPFileStream::Seek |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
75 +---------------------------------------------------------------------*/ |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
76 NPT_Result |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
77 NPT_PSPFileStream::Seek(NPT_Offset offset) |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
78 { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
79 SceOff result; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
80 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
81 result = sceIoLseek(m_FileReference->GetFile(), offset, SEEK_SET); |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
82 if (result >= 0) { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
83 m_Position = offset; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
84 return NPT_SUCCESS; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
85 } else { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
86 return NPT_FAILURE; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
87 } |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
88 } |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
89 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
90 /*---------------------------------------------------------------------- |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
91 | NPT_PSPFileStream::Tell |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
92 +---------------------------------------------------------------------*/ |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
93 NPT_Result |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
94 NPT_PSPFileStream::Tell(NPT_Offset& offset) |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
95 { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
96 offset = m_Position; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
97 return NPT_SUCCESS; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
98 } |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
99 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
100 /*---------------------------------------------------------------------- |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
101 | NPT_PSPFileInputStream |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
102 +---------------------------------------------------------------------*/ |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
103 class NPT_PSPFileInputStream : public NPT_InputStream, |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
104 private NPT_PSPFileStream |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
105 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
106 { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
107 public: |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
108 // constructors and destructor |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
109 NPT_PSPFileInputStream(NPT_PSPFileReference& file, NPT_Size size) : |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
110 NPT_PSPFileStream(file), m_Size(size) {} |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
111 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
112 // NPT_InputStream methods |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
113 NPT_Result Read(void* buffer, |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
114 NPT_Size bytes_to_read, |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
115 NPT_Size* bytes_read); |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
116 NPT_Result Seek(NPT_Offset offset) { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
117 return NPT_PSPFileStream::Seek(offset); |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
118 } |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
119 NPT_Result Tell(NPT_Offset& offset) { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
120 return NPT_PSPFileStream::Tell(offset); |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
121 } |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
122 NPT_Result GetSize(NPT_Size& size); |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
123 NPT_Result GetAvailable(NPT_Size& available); |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
124 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
125 private: |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
126 // members |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
127 NPT_Size m_Size; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
128 }; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
129 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
130 /*---------------------------------------------------------------------- |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
131 | NPT_PSPFileInputStream::Read |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
132 +---------------------------------------------------------------------*/ |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
133 NPT_Result |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
134 NPT_PSPFileInputStream::Read(void* buffer, |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
135 NPT_Size bytes_to_read, |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
136 NPT_Size* bytes_read) |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
137 { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
138 size_t nb_read; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
139 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
140 if (buffer == NULL) { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
141 return NPT_ERROR_INVALID_PARAMETERS; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
142 } |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
143 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
144 nb_read = sceIoRead(m_FileReference->GetFile(), (SceChar8*)buffer, bytes_to_read); |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
145 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
146 if (nb_read > 0) { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
147 if (bytes_read) *bytes_read = (NPT_Size)nb_read; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
148 m_Position += nb_read; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
149 return NPT_SUCCESS; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
150 } else { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
151 if (bytes_read) *bytes_read = 0; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
152 return NPT_ERROR_EOS; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
153 } |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
154 } |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
155 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
156 /*---------------------------------------------------------------------- |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
157 | NPT_PSPFileInputStream::GetSize |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
158 +---------------------------------------------------------------------*/ |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
159 NPT_Result |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
160 NPT_PSPFileInputStream::GetSize(NPT_Size& size) |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
161 { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
162 size = m_Size; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
163 return NPT_SUCCESS; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
164 } |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
165 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
166 /*---------------------------------------------------------------------- |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
167 | NPT_PSPFileInputStream::GetAvailable |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
168 +---------------------------------------------------------------------*/ |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
169 NPT_Result |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
170 NPT_PSPFileInputStream::GetAvailable(NPT_Size& available) |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
171 { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
172 long offset = m_Position; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
173 if (offset >= 0 && (NPT_Size)offset <= m_Size) { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
174 available = m_Size = offset; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
175 return NPT_SUCCESS; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
176 } else { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
177 available = 0; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
178 return NPT_FAILURE; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
179 } |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
180 } |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
181 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
182 /*---------------------------------------------------------------------- |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
183 | NPT_PSPFileOutputStream |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
184 +---------------------------------------------------------------------*/ |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
185 class NPT_PSPFileOutputStream : public NPT_OutputStream, |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
186 private NPT_PSPFileStream |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
187 { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
188 public: |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
189 // constructors and destructor |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
190 NPT_PSPFileOutputStream(NPT_PSPFileReference& file) : |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
191 NPT_PSPFileStream(file) {} |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
192 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
193 // NPT_InputStream methods |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
194 NPT_Result Write(const void* buffer, |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
195 NPT_Size bytes_to_write, |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
196 NPT_Size* bytes_written); |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
197 NPT_Result Seek(NPT_Offset offset) { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
198 return NPT_PSPFileStream::Seek(offset); |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
199 } |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
200 NPT_Result Tell(NPT_Offset& offset) { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
201 return NPT_PSPFileStream::Tell(offset); |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
202 } |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
203 }; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
204 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
205 /*---------------------------------------------------------------------- |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
206 | NPT_PSPFileOutputStream::Write |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
207 +---------------------------------------------------------------------*/ |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
208 NPT_Result |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
209 NPT_PSPFileOutputStream::Write(const void* buffer, |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
210 NPT_Size bytes_to_write, |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
211 NPT_Size* bytes_written) |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
212 { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
213 size_t nb_written; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
214 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
215 nb_written = sceIoWrite(m_FileReference->GetFile(), (SceChar8*)buffer, bytes_to_write); |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
216 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
217 if (nb_written > 0) { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
218 if (bytes_written) *bytes_written = (NPT_Size)nb_written; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
219 m_Position += nb_written; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
220 return NPT_SUCCESS; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
221 } else { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
222 if (bytes_written) *bytes_written = 0; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
223 return NPT_ERROR_WRITE_FAILED; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
224 } |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
225 } |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
226 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
227 /*---------------------------------------------------------------------- |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
228 | NPT_PSPFile |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
229 +---------------------------------------------------------------------*/ |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
230 class NPT_PSPFile: public NPT_FileInterface |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
231 { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
232 public: |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
233 // constructors and destructor |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
234 NPT_PSPFile(const char* name); |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
235 ~NPT_PSPFile(); |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
236 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
237 // NPT_FileInterface methods |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
238 NPT_Result Open(OpenMode mode); |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
239 NPT_Result Close(); |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
240 NPT_Result GetSize(NPT_Size& size); |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
241 NPT_Result GetInputStream(NPT_InputStreamReference& stream); |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
242 NPT_Result GetOutputStream(NPT_OutputStreamReference& stream); |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
243 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
244 private: |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
245 // members |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
246 NPT_String m_Name; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
247 OpenMode m_Mode; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
248 NPT_PSPFileReference m_FileReference; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
249 NPT_Size m_Size; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
250 }; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
251 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
252 /*---------------------------------------------------------------------- |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
253 | NPT_PSPFile::NPT_PSPFile |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
254 +---------------------------------------------------------------------*/ |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
255 NPT_PSPFile::NPT_PSPFile(const char* name) : |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
256 m_Name(name), |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
257 m_Mode(0), |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
258 m_Size(0) |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
259 { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
260 } |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
261 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
262 /*---------------------------------------------------------------------- |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
263 | NPT_PSPFile::~NPT_PSPFile |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
264 +---------------------------------------------------------------------*/ |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
265 NPT_PSPFile::~NPT_PSPFile() |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
266 { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
267 Close(); |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
268 } |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
269 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
270 /*---------------------------------------------------------------------- |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
271 | NPT_PSPFile::Open |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
272 +---------------------------------------------------------------------*/ |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
273 NPT_Result |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
274 NPT_PSPFile::Open(NPT_File::OpenMode mode) |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
275 { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
276 SceUID file = -1; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
277 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
278 // check if we're already open |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
279 if (!m_FileReference.IsNull()) { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
280 return NPT_ERROR_FILE_ALREADY_OPEN; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
281 } |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
282 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
283 // store the mode |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
284 m_Mode = mode; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
285 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
286 // check for special names |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
287 const char* name = (const char*)m_Name; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
288 int flags = 0; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
289 SceMode perms = 0; // files opened/created on the PSP require certain permissions |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
290 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
291 /* compute mode */ |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
292 if (mode & NPT_FILE_BYTE_STREAM_MODE_WRITE) { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
293 perms = 0777; // since we're possibly creating a file, give it full permissions |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
294 if (mode & NPT_FILE_BYTE_STREAM_MODE_CREATE) { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
295 if (mode & NPT_FILE_BYTE_STREAM_MODE_TRUNCATE) { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
296 /* write, read, create, truncate */ |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
297 flags = SCE_O_RDWR | SCE_O_CREAT | SCE_O_TRUNC; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
298 } else { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
299 /* write, read, create */ |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
300 flags = SCE_O_RDWR | SCE_O_CREAT | SCE_O_APPEND; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
301 } |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
302 } else { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
303 if (mode & NPT_FILE_BYTE_STREAM_MODE_TRUNCATE) { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
304 /* write, read, truncate */ |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
305 flags = SCE_O_RDWR | SCE_O_CREAT | SCE_O_TRUNC; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
306 } else { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
307 /* write, read */ |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
308 flags = SCE_O_RDWR; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
309 } |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
310 } |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
311 } else { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
312 /* read only */ |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
313 flags = SCE_O_RDONLY; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
314 } |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
315 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
316 // open the file |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
317 file = sceIoOpen(name, flags, perms); |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
318 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
319 // test the result of the open |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
320 if (file < 0) { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
321 if (file == (SceUID)SCE_ERROR_ERRNO_ENOENT ) { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
322 return NPT_ERROR_NO_SUCH_FILE; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
323 } else if (file == (SceUID)SCE_ERROR_ERRNO_EACCESS ) { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
324 return NPT_ERROR_PERMISSION_DENIED; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
325 } else { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
326 return NPT_FAILURE; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
327 } |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
328 } else { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
329 // get the size |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
330 SceOff off; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
331 off = sceIoLseek(file, 0, SCE_SEEK_END); |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
332 if (off >= 0) { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
333 m_Size = off; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
334 sceIoLseek(file, 0, SCE_SEEK_SET); |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
335 } |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
336 } |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
337 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
338 // create a reference to the FILE object |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
339 m_FileReference = new NPT_PSPileWrapper(file); |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
340 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
341 return NPT_SUCCESS; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
342 } |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
343 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
344 /*---------------------------------------------------------------------- |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
345 | NPT_PSPile::Close |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
346 +---------------------------------------------------------------------*/ |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
347 NPT_Result |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
348 NPT_PSPile::Close() |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
349 { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
350 // release the file reference |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
351 m_FileReference = NULL; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
352 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
353 // reset the mode |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
354 m_Mode = 0; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
355 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
356 return NPT_SUCCESS; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
357 } |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
358 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
359 /*---------------------------------------------------------------------- |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
360 | NPT_PSPile::GetSize |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
361 +---------------------------------------------------------------------*/ |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
362 NPT_Result |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
363 NPT_PSPile::GetSize(NPT_Size& size) |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
364 { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
365 // default value |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
366 size = 0; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
367 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
368 // check that the file is open |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
369 if (m_FileReference.IsNull()) return NPT_ERROR_FILE_NOT_OPEN; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
370 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
371 // return the size |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
372 size = m_Size; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
373 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
374 return NPT_SUCCESS; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
375 } |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
376 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
377 /*---------------------------------------------------------------------- |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
378 | NPT_PSPile::GetInputStream |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
379 +---------------------------------------------------------------------*/ |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
380 NPT_Result |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
381 NPT_PSPile::GetInputStream(NPT_InputStreamReference& stream) |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
382 { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
383 // default value |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
384 stream = NULL; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
385 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
386 // check that the file is open |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
387 if (m_FileReference.IsNull()) return NPT_ERROR_FILE_NOT_OPEN; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
388 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
389 // check that the mode is compatible |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
390 if (!(m_Mode & NPT_FILE_OPEN_MODE_READ)) { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
391 return NPT_ERROR_FILE_NOT_READABLE; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
392 } |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
393 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
394 // create a stream |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
395 stream = new NPT_PSPileInputStream(m_FileReference, m_Size); |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
396 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
397 return NPT_SUCCESS; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
398 } |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
399 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
400 /*---------------------------------------------------------------------- |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
401 | NPT_PSPile::GetOutputStream |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
402 +---------------------------------------------------------------------*/ |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
403 NPT_Result |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
404 NPT_PSPile::GetOutputStream(NPT_OutputStreamReference& stream) |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
405 { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
406 // default value |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
407 stream = NULL; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
408 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
409 // check that the file is open |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
410 if (m_FileReference.IsNull()) return NPT_ERROR_FILE_NOT_OPEN; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
411 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
412 // check that the mode is compatible |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
413 if (!(m_Mode & NPT_FILE_OPEN_MODE_WRITE)) { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
414 return NPT_ERROR_FILE_NOT_WRITABLE; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
415 } |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
416 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
417 // create a stream |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
418 stream = new NPT_PSPileOutputStream(m_FileReference); |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
419 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
420 return NPT_SUCCESS; |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
421 } |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
422 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
423 /*---------------------------------------------------------------------- |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
424 | NPT_File::NPT_File |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
425 +---------------------------------------------------------------------*/ |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
426 NPT_File::NPT_File(const char* name) |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
427 { |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
428 m_Delegate = new NPT_PSPile(name); |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
429 } |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
430 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
431 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
432 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
433 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
434 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
435 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
436 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
437 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
438 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
439 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
440 |
3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
fraserofthenight
parents:
diff
changeset
|
441 |