bool FilesPageHandler::listDirectory(Common::String path, Common::String &content, const Common::String &itemTemplate) { if (path == "" || path == "/") { if (ConfMan.hasKey("rootpath", "cloud")) addItem(content, itemTemplate, IT_DIRECTORY, "/root/", _("File system root")); addItem(content, itemTemplate, IT_DIRECTORY, "/saves/", _("Saved games")); return true; } if (HandlerUtils::hasForbiddenCombinations(path)) return false; Common::String prefixToRemove = "", prefixToAdd = ""; if (!transformPath(path, prefixToRemove, prefixToAdd)) return false; Common::FSNode node = Common::FSNode(path); if (path == "/") node = node.getParent(); // absolute root if (!HandlerUtils::permittedPath(node.getPath())) return false; if (!node.isDirectory()) return false; // list directory Common::FSList _nodeContent; if (!node.getChildren(_nodeContent, Common::FSNode::kListAll, false)) // do not show hidden files _nodeContent.clear(); else Common::sort(_nodeContent.begin(), _nodeContent.end()); // add parent directory link { Common::String filePath = path; if (filePath.hasPrefix(prefixToRemove)) filePath.erase(0, prefixToRemove.size()); if (filePath == "" || filePath == "/" || filePath == "\\") filePath = "/"; else filePath = parentPath(prefixToAdd + filePath); addItem(content, itemTemplate, IT_PARENT_DIRECTORY, filePath, _("Parent directory")); } // fill the content for (Common::FSList::iterator i = _nodeContent.begin(); i != _nodeContent.end(); ++i) { Common::String name = i->getDisplayName(); if (i->isDirectory()) name += "/"; Common::String filePath = i->getPath(); if (filePath.hasPrefix(prefixToRemove)) filePath.erase(0, prefixToRemove.size()); filePath = prefixToAdd + filePath; addItem(content, itemTemplate, detectType(i->isDirectory(), name), filePath, name); } return true; }
void ThemeEngine::listUsableThemes(const Common::FSNode &node, Common::List<ThemeDescriptor> &list, int depth) { if (!node.exists() || !node.isReadable() || !node.isDirectory()) return; ThemeDescriptor td; // Check whether we point to a valid theme directory. if (themeConfigUsable(node, td.name)) { td.filename = node.getPath(); td.id = node.getName(); list.push_back(td); // A theme directory should never contain any other themes // thus we just return to the caller here. return; } Common::FSList fileList; // Check all files. We need this to find all themes inside ZIP archives. if (!node.getChildren(fileList, Common::FSNode::kListFilesOnly)) return; for (Common::FSList::iterator i = fileList.begin(); i != fileList.end(); ++i) { // We will only process zip files for now if (!i->getPath().matchString("*.zip", true)) continue; td.name.clear(); if (themeConfigUsable(*i, td.name)) { td.filename = i->getPath(); td.id = i->getName(); // If the name of the node object also contains // the ".zip" suffix, we will strip it. if (td.id.matchString("*.zip", true)) { for (int j = 0; j < 4; ++j) td.id.deleteLastChar(); } list.push_back(td); } } fileList.clear(); // Check if we exceeded the given recursion depth if (depth - 1 == -1) return; // As next step we will search all subdirectories if (!node.getChildren(fileList, Common::FSNode::kListDirectoriesOnly)) return; for (Common::FSList::iterator i = fileList.begin(); i != fileList.end(); ++i) listUsableThemes(*i, list, depth == -1 ? - 1 : depth - 1); }
bool BaseFileManager::registerPackages() { debugC(kWintermuteDebugFileAccess | kWintermuteDebugLog, "Scanning packages"); // Register without using SearchMan, as otherwise the FSNode-based lookup in openPackage will fail // and that has to be like that to support the detection-scheme. Common::FSList files; for (Common::FSList::iterator it = _packagePaths.begin(); it != _packagePaths.end(); ++it) { debugC(kWintermuteDebugFileAccess, "Should register folder: %s %s", (*it).getPath().c_str(), (*it).getName().c_str()); if (!(*it).getChildren(files, Common::FSNode::kListFilesOnly)) { warning("getChildren() failed for path: %s", (*it).getDisplayName().c_str()); } for (Common::FSList::iterator fileIt = files.begin(); fileIt != files.end(); ++fileIt) { if (!fileIt->getName().hasSuffix(".dcp")) { continue; } // Avoid registering all the language files // TODO: Select based on the gameDesc. if (_language != Common::UNK_LANG && fileIt->getParent().getName() == "language") { Common::String parentName = fileIt->getParent().getName(); Common::String dcpName = fileIt->getName(); if (_language == Common::EN_ANY && fileIt->getName() != "english.dcp") { continue; } else if (_language == Common::CZ_CZE && fileIt->getName() != "czech.dcp") { continue; } else if (_language == Common::IT_ITA && fileIt->getName() != "italian.dcp") { continue; } else if (_language == Common::PL_POL && fileIt->getName() != "polish.dcp") { continue; } else if (_language == Common::RU_RUS && fileIt->getName() != "russian.dcp") { continue; } } debugC(kWintermuteDebugFileAccess, "Registering %s %s", (*fileIt).getPath().c_str(), (*fileIt).getName().c_str()); registerPackage((*fileIt)); } } // debugC(kWintermuteDebugFileAccess | kWintermuteDebugLog, " Registered %d files in %d package(s)", _files.size(), _packages.size()); return STATUS_OK; }
void BrowserDialog::updateListing() { // Update the path display _currentPath->setLabel(_node.getPath()); // We memorize the last visited path. ConfMan.set("browser_lastpath", _node.getPath()); // Read in the data from the file system if (!_node.getChildren(_nodeContent, Common::FSNode::kListAll, _showHidden)) _nodeContent.clear(); else Common::sort(_nodeContent.begin(), _nodeContent.end()); // Populate the ListWidget ListWidget::StringArray list; ListWidget::ColorList colors; for (Common::FSList::iterator i = _nodeContent.begin(); i != _nodeContent.end(); ++i) { if (i->isDirectory()) list.push_back(i->getDisplayName() + "/"); else list.push_back(i->getDisplayName()); if (_isDirBrowser) { if (i->isDirectory()) colors.push_back(ThemeEngine::kFontColorNormal); else colors.push_back(ThemeEngine::kFontColorAlternate); } } if (_isDirBrowser) _fileList->setList(list, &colors); else _fileList->setList(list); _fileList->scrollTo(0); // Finally, redraw draw(); }
bool DownloadDialog::selectDirectories() { if (Networking::Connection::isLimited()) { MessageDialog alert(_("It looks like your connection is limited. " "Do you really want to download files with it?"), _("Yes"), _("No")); if (alert.runModal() != GUI::kMessageOK) return false; } //first user should select remote directory to download if (_remoteBrowser->runModal() <= 0) return false; Cloud::StorageFile remoteDirectory = _remoteBrowser->getResult(); //now user should select local directory to download into if (_browser->runModal() <= 0) return false; Common::FSNode dir(_browser->getResult()); Common::FSList files; if (!dir.getChildren(files, Common::FSNode::kListAll)) { MessageDialog alert(_("ScummVM couldn't open the specified directory!")); alert.runModal(); return false; } //check that there is no file with the remote directory's name in the local one for (Common::FSList::iterator i = files.begin(); i != files.end(); ++i) { if (i->getName().equalsIgnoreCase(remoteDirectory.name())) { //if there is, ask user whether it's OK if (!i->isDirectory()) { GUI::MessageDialog alert(_("Cannot create a directory to download - the specified directory has a file with the same name."), _("OK")); alert.runModal(); return false; } GUI::MessageDialog alert( Common::String::format(_("The \"%s\" already exists in the specified directory.\nDo you really want to download files into that directory?"), remoteDirectory.name().c_str()), _("Yes"), _("No") ); if (alert.runModal() != GUI::kMessageOK) return false; break; } } //make a local path Common::String localPath = dir.getPath(); //simple heuristic to determine which path separator to use if (localPath.size() && localPath.lastChar() != '/' && localPath.lastChar() != '\\') { int backslashes = 0; for (uint32 i = 0; i < localPath.size(); ++i) if (localPath[i] == '/') --backslashes; else if (localPath[i] == '\\') ++backslashes; if (backslashes > 0) localPath += '\\' + remoteDirectory.name(); else localPath += '/' + remoteDirectory.name(); } else { localPath += remoteDirectory.name(); } CloudMan.startDownload(remoteDirectory.path(), localPath); CloudMan.setDownloadTarget(this); _localDirectory = localPath; return true; }