MCPcopy Create free account
hub / github.com/MayaPosch/NymphCast / GetFiles

Method GetFiles

src/server/angelscript/add_on/scriptfile/scriptfilesystem.cpp:125–193  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

123}
124
125CScriptArray *CScriptFileSystem::GetFiles() const
126{
127 // Obtain a pointer to the engine
128 asIScriptContext *ctx = asGetActiveContext();
129 asIScriptEngine *engine = ctx->GetEngine();
130
131 // TODO: This should only be done once
132 // TODO: This assumes that CScriptArray was already registered
133 asITypeInfo *arrayType = engine->GetTypeInfoByDecl("array<string>");
134
135 // Create the array object
136 CScriptArray *array = CScriptArray::Create(arrayType);
137
138#if defined(_WIN32)
139 // Windows uses UTF16 so it is necessary to convert the string
140 wchar_t bufUTF16[10000];
141 string searchPattern = currentPath + "/*";
142 MultiByteToWideChar(CP_UTF8, 0, searchPattern.c_str(), -1, bufUTF16, 10000);
143
144 WIN32_FIND_DATAW ffd;
145 HANDLE hFind = FindFirstFileW(bufUTF16, &ffd);
146 if( INVALID_HANDLE_VALUE == hFind )
147 return array;
148
149 do
150 {
151 // Skip directories
152 if( (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) )
153 continue;
154
155 // Convert the file name back to UTF8
156 char bufUTF8[10000];
157 WideCharToMultiByte(CP_UTF8, 0, ffd.cFileName, -1, bufUTF8, 10000, 0, 0);
158
159 // Add the file to the array
160 array->Resize(array->GetSize()+1);
161 ((string*)(array->At(array->GetSize()-1)))->assign(bufUTF8);
162 }
163 while( FindNextFileW(hFind, &ffd) != 0 );
164
165 FindClose(hFind);
166#else
167 dirent *ent = 0;
168 DIR *dir = opendir(currentPath.c_str());
169 while( (ent = readdir(dir)) != NULL )
170 {
171 const string filename = ent->d_name;
172
173 // Skip . and ..
174 if( filename[0] == '.' )
175 continue;
176
177 // Skip sub directories
178 const string fullname = currentPath + "/" + filename;
179 struct stat st;
180 if( stat(fullname.c_str(), &st) == -1 )
181 continue;
182 if( (st.st_mode & S_IFDIR) != 0 )

Callers

nothing calls this directly

Calls 8

statClass · 0.85
c_strMethod · 0.80
assignMethod · 0.80
GetEngineMethod · 0.45
GetTypeInfoByDeclMethod · 0.45
ResizeMethod · 0.45
GetSizeMethod · 0.45
AtMethod · 0.45

Tested by

no test coverage detected