mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-11 19:54:03 +00:00
CLOUD: Add icons in "/files" list
This commit is contained in:
parent
626d85ea49
commit
06ccfd4b9a
@ -17,12 +17,14 @@ def buildArchive(archiveName):
|
||||
print ("Building '" + archiveName + "' archive:")
|
||||
os.chdir(archiveName)
|
||||
|
||||
filenames = os.listdir('.')
|
||||
filenames.sort()
|
||||
for filename in filenames:
|
||||
if os.path.isfile(filename) and filename.endswith(ARCHIVE_FILE_EXTENSIONS):
|
||||
zf.write(filename, './' + filename)
|
||||
print (" Adding file: " + filename)
|
||||
directories = ['.', './icons']
|
||||
for d in directories:
|
||||
filenames = os.listdir(d)
|
||||
filenames.sort()
|
||||
for filename in filenames:
|
||||
if os.path.isfile(d + '/' + filename) and filename.endswith(ARCHIVE_FILE_EXTENSIONS):
|
||||
zf.write(d + '/' + filename, d + '/' + filename)
|
||||
print (" Adding file: " + d + '/' + filename)
|
||||
|
||||
os.chdir('../')
|
||||
|
||||
|
@ -68,7 +68,7 @@ void FilesPageHandler::handle(Client &client) {
|
||||
"<table>{content}</table>" \
|
||||
"</body>" \
|
||||
"</html>";
|
||||
Common::String itemTemplate = "<tr><td><a href=\"{link}\">{name}</a></td><td>{size}</td></tr>\n"; //TODO: load this template too?
|
||||
Common::String itemTemplate = "<tr><td><img src=\"icons/{icon}\"/></td><td><a href=\"{link}\">{name}</a></td><td>{size}</td></tr>\n"; //TODO: load this template too?
|
||||
|
||||
// load stylish response page from the archive
|
||||
Common::SeekableReadStream *const stream = HandlerUtils::getArchiveFile(FILES_PAGE_NAME);
|
||||
@ -99,8 +99,8 @@ void FilesPageHandler::handle(Client &client) {
|
||||
|
||||
bool FilesPageHandler::listDirectory(Common::String path, Common::String &content, const Common::String &itemTemplate) {
|
||||
if (path == "" || path == "/") {
|
||||
addItem(content, itemTemplate, true, "/root/", _("File system root"));
|
||||
addItem(content, itemTemplate, true, "/saves/", _("Saved games"));
|
||||
addItem(content, itemTemplate, IT_DIRECTORY, "/root/", _("File system root"));
|
||||
addItem(content, itemTemplate, IT_DIRECTORY, "/saves/", _("Saved games"));
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -127,7 +127,7 @@ bool FilesPageHandler::listDirectory(Common::String path, Common::String &conten
|
||||
filePath = "/";
|
||||
else
|
||||
filePath = parentPath(prefixToAdd + filePath);
|
||||
addItem(content, itemTemplate, true, filePath, _("Parent directory"));
|
||||
addItem(content, itemTemplate, IT_PARENT_DIRECTORY, filePath, _("Parent directory"));
|
||||
}
|
||||
|
||||
// fill the content
|
||||
@ -140,14 +140,32 @@ bool FilesPageHandler::listDirectory(Common::String path, Common::String &conten
|
||||
filePath.erase(0, prefixToRemove.size());
|
||||
filePath = prefixToAdd + filePath;
|
||||
|
||||
addItem(content, itemTemplate, i->isDirectory(), filePath, name);
|
||||
addItem(content, itemTemplate, detectType(i->isDirectory(), name), filePath, name);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void FilesPageHandler::addItem(Common::String &content, const Common::String &itemTemplate, bool isDirectory, Common::String path, Common::String name, Common::String size) {
|
||||
Common::String item = itemTemplate;
|
||||
FilesPageHandler::ItemType FilesPageHandler::detectType(bool isDirectory, const Common::String &name) const {
|
||||
if (isDirectory) return IT_DIRECTORY;
|
||||
if (name.hasSuffix(".txt")) return IT_TXT;
|
||||
if (name.hasSuffix(".zip")) return IT_ZIP;
|
||||
if (name.hasSuffix(".7z")) return IT_7Z;
|
||||
return IT_UNKNOWN;
|
||||
}
|
||||
|
||||
void FilesPageHandler::addItem(Common::String &content, const Common::String &itemTemplate, ItemType itemType, Common::String path, Common::String name, Common::String size) {
|
||||
Common::String item = itemTemplate, icon;
|
||||
bool isDirectory = (itemType == IT_DIRECTORY || itemType == IT_PARENT_DIRECTORY);
|
||||
switch (itemType) {
|
||||
case IT_DIRECTORY: icon = "dir.png"; break;
|
||||
case IT_PARENT_DIRECTORY: icon = "up.png"; break;
|
||||
case IT_TXT: icon = "txt.png"; break;
|
||||
case IT_ZIP: icon = "zip.png"; break;
|
||||
case IT_7Z: icon = "7z.png"; break;
|
||||
default: icon = "unk.png";
|
||||
}
|
||||
replace(item, "{icon}", icon);
|
||||
replace(item, "{link}", (isDirectory ? "files?path=" : "download?path=") + LocalWebserver::urlEncodeQueryParameterValue(path));
|
||||
replace(item, "{name}", name);
|
||||
replace(item, "{size}", size);
|
||||
|
@ -28,6 +28,15 @@
|
||||
namespace Networking {
|
||||
|
||||
class FilesPageHandler: public FilesBaseHandler {
|
||||
enum ItemType {
|
||||
IT_DIRECTORY,
|
||||
IT_PARENT_DIRECTORY,
|
||||
IT_TXT,
|
||||
IT_ZIP,
|
||||
IT_7Z,
|
||||
IT_UNKNOWN
|
||||
};
|
||||
|
||||
void handle(Client &client);
|
||||
|
||||
/**
|
||||
@ -37,8 +46,11 @@ class FilesPageHandler: public FilesBaseHandler {
|
||||
*/
|
||||
bool listDirectory(Common::String path, Common::String &content, const Common::String &itemTemplate);
|
||||
|
||||
/** Helper method for detecting items' type. */
|
||||
ItemType detectType(bool isDirectory, const Common::String &name) const;
|
||||
|
||||
/** Helper method for adding items into the files list. */
|
||||
void addItem(Common::String &content, const Common::String &itemTemplate, bool isDirectory, Common::String path, Common::String name, Common::String size = "");
|
||||
void addItem(Common::String &content, const Common::String &itemTemplate, ItemType itemType, Common::String path, Common::String name, Common::String size = "");
|
||||
|
||||
public:
|
||||
FilesPageHandler();
|
||||
|
Binary file not shown.
BIN
backends/networking/wwwroot/icons/7z.png
Normal file
BIN
backends/networking/wwwroot/icons/7z.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 166 B |
BIN
backends/networking/wwwroot/icons/dir.png
Normal file
BIN
backends/networking/wwwroot/icons/dir.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 150 B |
BIN
backends/networking/wwwroot/icons/txt.png
Normal file
BIN
backends/networking/wwwroot/icons/txt.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 156 B |
BIN
backends/networking/wwwroot/icons/unk.png
Normal file
BIN
backends/networking/wwwroot/icons/unk.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 142 B |
BIN
backends/networking/wwwroot/icons/up.png
Normal file
BIN
backends/networking/wwwroot/icons/up.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 161 B |
BIN
backends/networking/wwwroot/icons/zip.png
Normal file
BIN
backends/networking/wwwroot/icons/zip.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 183 B |
@ -85,4 +85,6 @@ html {
|
||||
.modal input[type="submit"]:hover {
|
||||
background: #F3F3F3;
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
|
||||
td img { vertical-align: middle; height: 20px; }
|
Loading…
Reference in New Issue
Block a user