MCPcopy Create free account
hub / github.com/MonaSolutions/MonaServer / WriteDirectoryEntries

Method WriteDirectoryEntries

MonaCore/sources/HTTP/HTTP.cpp:300–342  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

298
299
300bool HTTP::WriteDirectoryEntries(Exception& ex, BinaryWriter& writer, const string& serverAddress, const std::string& fullPath, const std::string& path, SortField sortField, SortOrder sortOrder) {
301
302 vector<File*> files;
303 FileSystem::ForEach forEach([&files](const string& path, UInt16 level){
304 files.emplace_back(new File(path));
305 });
306 FileSystem::ListFiles(ex, fullPath, forEach);
307 if (ex)
308 return false;
309
310 char sort[] = "D";
311 if (sortOrder==SORT_DESC)
312 sort[0] = 'A';
313
314 // Write column names
315 // Name Modified Size
316 writer.write(EXPAND("<html><head><title>Index of "))
317 .write(path).write(EXPAND("/</title><style>th {text-align: center;}</style></head><body><h1>Index of "))
318 .write(path).write(EXPAND("/</h1><pre><table cellpadding=\"0\"><tr><th><a href=\"?N="))
319 .write(sort).write(EXPAND("\">Name</a></th><th><a href=\"?M="))
320 .write(sort).write(EXPAND("\">Modified</a></th><th><a href=\"?S="))
321 .write(sort).write(EXPAND("\">Size</a></th></tr><tr><td colspan=\"3\"><hr></td></tr>"));
322
323 // Write first entry - link to a parent directory
324 if(!path.empty())
325 writer.write(EXPAND("<tr><td><a href=\"http://"))
326 .write(serverAddress).write(path)
327 .write(EXPAND("/..\">Parent directory</a></td><td>&nbsp;-</td><td>&nbsp;&nbsp;-</td></tr>\n"));
328
329 // Sort entries
330 EntriesComparator comparator(sortField,sortOrder);
331 std::sort(files.begin(), files.end(), comparator);
332
333 // Write entries
334 for (const File* pFile : files) {
335 WriteDirectoryEntry(writer, serverAddress, path, *pFile);
336 delete pFile;
337 }
338
339 // Write footer
340 writer.write(EXPAND("</table></body></html>"));
341 return true;
342}
343
344void HTTP::WriteDirectoryEntry(BinaryWriter& writer,const string& serverAddress,const string& path,const File& entry) {
345 string size,date;

Callers

nothing calls this directly

Calls 4

writeMethod · 0.45
emptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected