comparison deps/Platinum/ThirdParty/Neptune/Source/System/PSP/NptPSPDirectory.cpp @ 0:3425707ddbf6

Initial import (hopefully this mercurial stuff works...)
author fraserofthenight
date Mon, 06 Jul 2009 08:06:28 -0700
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:3425707ddbf6
1 /*****************************************************************
2 |
3 | Neptune - Directory :: PSP Implementation
4 |
5 | Copyright (c) 2004-2008, Plutinosoft, LLC.
6 | Author: Sylvain Rebaud (sylvain@plutinosoft.com)
7 |
8 ****************************************************************/
9
10 /*----------------------------------------------------------------------
11 | includes
12 +---------------------------------------------------------------------*/
13 #include <stdio.h>
14
15 #include <kernel.h>
16 #include <psptypes.h>
17 #include <psperror.h>
18
19 #include "NptConfig.h"
20 #include "NptTypes.h"
21 #include "NptDirectory.h"
22 #include "NptDebug.h"
23 #include "NptResults.h"
24
25 /*----------------------------------------------------------------------
26 | NPT_PSPDirectoryEntry
27 +---------------------------------------------------------------------*/
28 class NPT_PSPDirectoryEntry : public NPT_DirectoryEntryInterface
29 {
30 public:
31 // methods
32 NPT_PSPDirectoryEntry(const char* path);
33 virtual ~NPT_PSPDirectoryEntry();
34
35 // NPT_DirectoryInterface methods
36 virtual NPT_Result GetType(NPT_DirectoryEntryType& type);
37 virtual NPT_Result GetSize(NPT_Size& size);
38
39 private:
40 // members
41 NPT_StringObject m_Path;
42 };
43
44 /*----------------------------------------------------------------------
45 | NPT_PSPDirectoryEntry::NPT_PSPDirectoryEntry
46 +---------------------------------------------------------------------*/
47 NPT_PSPDirectoryEntry::NPT_PSPDirectoryEntry(const char* path) :
48 m_Path(path)
49 {
50 }
51
52 /*----------------------------------------------------------------------
53 | NPT_PSPDirectoryEntry::~NPT_PSPDirectoryEntry
54 +---------------------------------------------------------------------*/
55 NPT_PSPDirectoryEntry::~NPT_PSPDirectoryEntry()
56 {
57 }
58
59 /*----------------------------------------------------------------------
60 | NPT_PSPDirectoryEntry::GetType
61 +---------------------------------------------------------------------*/
62 NPT_Result
63 NPT_PSPDirectoryEntry::GetType(NPT_DirectoryEntryType& type)
64 {
65 //// converts from Utf8 ?
66 //DWORD fa = GetFileAttributes(m_Path);
67 //if (fa == 0xFFFFFFFF) {
68 // return NPT_FAILURE;
69 //}
70
71 //if ((fa & FILE_ATTRIBUTE_DIRECTORY) == 0) {
72 // type = NPT_FILE_TYPE;
73 //} else {
74 // type = NPT_DIRECTORY_TYPE;
75 //}
76
77 return NPT_SUCCESS;
78 }
79
80 /*----------------------------------------------------------------------
81 | NPT_PSPDirectoryEntry::GetSize
82 +---------------------------------------------------------------------*/
83 NPT_Result
84 NPT_PSPDirectoryEntry::GetSize(NPT_Size& size)
85 {
86 //WIN32_FIND_DATA filedata;
87
88 //// converts to Utf8?
89 //HANDLE sizeHandle = FindFirstFile(m_Path, &filedata);
90 //if (sizeHandle == INVALID_HANDLE_VALUE) {
91 // FindClose(sizeHandle);
92 // return NPT_FAILURE;
93 //}
94
95 //size = filedata.nFileSizeLow;
96 //FindClose(sizeHandle);
97 return NPT_SUCCESS;
98 }
99
100 /*----------------------------------------------------------------------
101 | NPT_DirectoryEntry::NPT_DirectoryEntry
102 +---------------------------------------------------------------------*/
103 NPT_DirectoryEntry::NPT_DirectoryEntry(const char* path)
104 {
105 m_Delegate = new NPT_PSPDirectoryEntry(path);
106 }
107
108 /*----------------------------------------------------------------------
109 | NPT_PSPDirectory
110 +---------------------------------------------------------------------*/
111 class NPT_PSPDirectory : public NPT_DirectoryInterface
112 {
113 public:
114 // methods
115 NPT_PSPDirectory(const char* path);
116 virtual ~NPT_PSPDirectory();
117
118 // NPT_DirectoryInterface methods
119 virtual NPT_Result GetNextEntry(NPT_StringObject& name, NPT_Size* size = NULL, NPT_DirectoryEntryType* type = NULL);
120
121 private:
122 // members
123 NPT_StringObject m_Path;
124 };
125
126 /*----------------------------------------------------------------------
127 | NPT_PSPDirectory::NPT_PSPDirectory
128 +---------------------------------------------------------------------*/
129 NPT_PSPDirectory::NPT_PSPDirectory(const char* path) :
130 m_Path(path)
131 {
132 if (!m_Path.EndsWith(NPT_WIN32_DIR_DELIMITER_STR)) {
133 if (!m_Path.EndsWith(NPT_UNIX_DIR_DELIMITER_STR)) {
134 m_Path += NPT_UNIX_DIR_DELIMITER_STR;
135 }
136 }
137
138 m_Path += "*.*";
139 }
140
141 /*----------------------------------------------------------------------
142 | NPT_PSPDirectory::~NPT_PSPDirectory
143 +---------------------------------------------------------------------*/
144 NPT_PSPDirectory::~NPT_PSPDirectory()
145 {
146 //if (m_SearchHandle != NULL) {
147 // FindClose(m_SearchHandle);
148 //}
149 }
150
151 /*----------------------------------------------------------------------
152 | NPT_PSPDirectory::GetNextEntry
153 +---------------------------------------------------------------------*/
154 NPT_Result
155 NPT_PSPDirectory::GetNextEntry(NPT_StringObject& name, NPT_Size* size, NPT_DirectoryEntryType* type)
156 {
157 //WIN32_FIND_DATA filedata;
158
159 //if (m_SearchHandle == NULL) {
160 // m_SearchHandle = FindFirstFile(m_Path, &filedata);
161 // if (m_SearchHandle == INVALID_HANDLE_VALUE) {
162 // m_SearchHandle = NULL;
163 // return NPT_FAILURE;
164 // }
165 //} else {
166 // if (FindNextFile(m_SearchHandle, &filedata) == 0) {
167 // return NPT_FAILURE;
168 // }
169 //}
170
171 //// need to convert to Utf8 ?
172 //name = filedata.cFileName;
173
174 //if (size) {
175 // *size = filedata.nFileSizeLow;
176 //}
177
178 //if (type) {
179 // *type = (filedata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? NPT_DIRECTORY_TYPE : NPT_FILE_TYPE;
180 //}
181
182 return NPT_SUCCESS;
183 }
184
185 /*----------------------------------------------------------------------
186 | NPT_Directory::NPT_Directory
187 +---------------------------------------------------------------------*/
188 NPT_Directory::NPT_Directory(const char* path)
189 {
190 m_Delegate = new NPT_PSPDirectory(path);
191 }
192
193
194
195
196
197
198
199