コード例 #1
0
DataPromisePtr DirectorySharingPromise::data (const Path & subPath, const String & user) const {
	if (sf::checkDangerousPath(subPath.toString())) {
		Log (LogWarning) << LOGID << subPath << " looks dangerous, rejecting" << std::endl;
	}
	
	if (user.empty()){
		// Check if it is a directory
		DataPromisePtr tryDirectory = directoryListing (subPath);
		if (tryDirectory) return tryDirectory;

	
		// It must be a file
		return subFile (subPath);
	}
	if (user == "list"){
		return directoryListing (subPath);
	}
	if (user == "file"){
		return subFile (subPath);
	}
	if (user == "glob") {
		return DataPromisePtr (new GlobPromise (mGlobber, osPath (subPath)));
	}
	// unknown user flag
	Log (LogWarning) << LOGID << "Unknown user flag: " << user << std::endl;
	return DataPromisePtr ();
}
コード例 #2
0
void readInFile(std::string* &subsystems) {

	/* Read in the file. */
	std::ifstream subFile("../files/subsystems.fln");

	/* Verify that the file is open. */
	if(subFile.is_open()) {
		
		/* Create an array to hold the file's contents (for simplicity we know there are 6 lines). */
		subsystems = new std::string[6];
		
		/* Read in each line from the file. */
		std::string line;
		int index = 0;
		while(getline(subFile, line)) {
			
			/* Store each line in the array. */
			subsystems[index] = line;
			index++;
		}

	/* Set the pointer to NULL if we couldn't open the file. */
	} else {
		subsystems = NULL;
	}
}
コード例 #3
0
ファイル: FBReader.cpp プロジェクト: Dzha/FBReader
bool FBReader::createBook(const ZLFile &bookFile, shared_ptr<Book> &book) {
	shared_ptr<FormatPlugin> plugin =
		PluginCollection::Instance().plugin(bookFile, false);
	if (!plugin.isNull()) {
		std::string error = plugin->tryOpen(bookFile);
		if (!error.empty()) {
			ZLResourceKey boxKey("openBookErrorBox");
			ZLDialogManager::Instance().errorBox(
				boxKey,
				ZLStringUtil::printf(ZLDialogManager::dialogMessage(boxKey), error)
			);
		} else {
			book = BooksDBUtil::getBook(bookFile.path());
			if (!book.isNull()) {
				BooksDB::Instance().insertIntoBookList(*book);
			}
		}
		return true;
	}

	if (!bookFile.isArchive()) {
		return false;
	}

	std::queue<std::string> archiveNames;
	archiveNames.push(bookFile.path());

	std::vector<std::string> items;

	while (!archiveNames.empty()) {
		shared_ptr<ZLDir> archiveDir = ZLFile(archiveNames.front()).directory();
		archiveNames.pop();
		if (archiveDir.isNull()) {
			continue;
		}
		archiveDir->collectFiles(items, true);
		for (std::vector<std::string>::const_iterator it = items.begin(); it != items.end(); ++it) {
			const std::string itemName = archiveDir->itemPath(*it);
			ZLFile subFile(itemName);
			if (subFile.isArchive()) {
				archiveNames.push(itemName);
			} else if (createBook(subFile, book)) {
				return true;
			}
		}
		items.clear();
	}

	return false;
}
コード例 #4
0
ファイル: FBReader.cpp プロジェクト: mhuber/fbreader
bool FBReader::createDescription(const std::string& fileName, BookDescriptionPtr &description) {
	ZLFile bookFile = ZLFile(fileName);

	FormatPlugin *plugin = PluginCollection::instance().plugin(ZLFile(fileName), false);
	if (plugin != 0) {
		std::string error = plugin->tryOpen(fileName);
		if (!error.empty()) {
			ZLResourceKey boxKey("openBookErrorBox");
			ZLDialogManager::instance().errorBox(
				boxKey,
				ZLStringUtil::printf(ZLDialogManager::dialogMessage(boxKey), error)
			);
		} else {
			BookList().addFileName(bookFile.path());
			description = BookDescription::getDescription(bookFile.path());
		}
		return true;
	}

	if (!bookFile.isArchive()) {
		return false;
	}

	std::queue<std::string> archiveNames;
	archiveNames.push(bookFile.path());

	std::vector<std::string> items;

	while (!archiveNames.empty()) {
		shared_ptr<ZLDir> archiveDir = ZLFile(archiveNames.front()).directory();
		archiveNames.pop();
		if (archiveDir.isNull()) {
			continue;
		}
		archiveDir->collectFiles(items, true);
		for (std::vector<std::string>::const_iterator it = items.begin(); it != items.end(); ++it) {
			const std::string itemName = archiveDir->itemPath(*it);
			ZLFile subFile(itemName);
			if (subFile.isArchive()) {
				archiveNames.push(itemName);
			} else if (createDescription(itemName, description)) {
				return true;
			}
		}
		items.clear();
	}

	return 0;
}
コード例 #5
0
ファイル: BooksUtil.cpp プロジェクト: TeamWew/harbour-books
shared_ptr<Book> BooksUtil::bookFromFile(std::string aPath)
{
    shared_ptr<Book> book;
    const ZLFile file(aPath);
    PluginCollection& plugins = PluginCollection::Instance();
    shared_ptr<FormatPlugin> plugin = plugins.plugin(file, false);
    if (!plugin.isNull()) {
        std::string error = plugin->tryOpen(file);
        if (error.empty()) {
            book = Book::loadFromFile(file);
        } else {
            HWARN(error.c_str());
        }
    } else if (file.isArchive()) {
        std::queue<std::string> archiveNames;
        std::vector<std::string> items;
        archiveNames.push(aPath);
        while (!archiveNames.empty() && book.isNull()) {
            shared_ptr<ZLDir> dir = ZLFile(archiveNames.front()).directory();
            archiveNames.pop();
            if (!dir.isNull()) {
                dir->collectFiles(items, true);
                for (std::vector<std::string>::const_iterator it = items.begin();
                     book.isNull() && it != items.end(); ++it) {
                    const std::string itemName = dir->itemPath(*it);
                    ZLFile subFile(itemName);
                    if (subFile.isArchive()) {
                        archiveNames.push(itemName);
                    } else {
                        book = Book::loadFromFile(subFile);
                    }
                }
                items.clear();
            }
        }
    }
    return book;
}
コード例 #6
0
bool FBReader::createBook(const std::string& fileName, shared_ptr<Book> &book) {
    ZLFile bookFile = ZLFile(fileName);

    // PB: return if physical file doesnt exists
    if (!bookFile.exists())
        return false;
    // PB

    shared_ptr<FormatPlugin> plugin =
        PluginCollection::Instance().plugin(ZLFile(fileName), false);
    if (!plugin.isNull()) {
        std::string error = plugin->tryOpen(fileName);
        if (!error.empty()) {
            ZLResourceKey boxKey("openBookErrorBox");
            ZLDialogManager::Instance().errorBox(
                boxKey,
                ZLStringUtil::printf(ZLDialogManager::dialogMessage(boxKey), error)
            );
        } else {
            // PB: we dont like to load the book from the DB, just from file
            book = Book::loadFromFile(fileName /*bookFile.physicalFilePath()*/, FBReader::EncodingOverride);

            if (FBReader::LanguageOverride != "" && !book.isNull())
                book->setLanguage(FBReader::LanguageOverride);


            //book = BooksDBUtil::getBook(bookFile.path());
            //if (!book.isNull()) {
            //	BooksDB::Instance().insertIntoBookList(*book);
            //}
            // PB
        }
        return true;
    }

    if (!bookFile.isArchive()) {
        return false;
    }

    std::queue<std::string> archiveNames;
    archiveNames.push(bookFile.path());

    std::vector<std::string> items;

    while (!archiveNames.empty()) {
        shared_ptr<ZLDir> archiveDir = ZLFile(archiveNames.front()).directory();
        archiveNames.pop();
        if (archiveDir.isNull()) {
            continue;
        }
        archiveDir->collectFiles(items, true);
        for (std::vector<std::string>::const_iterator it = items.begin(); it != items.end(); ++it) {
            const std::string itemName = archiveDir->itemPath(*it);
            ZLFile subFile(itemName);
            if (subFile.isArchive()) {
                archiveNames.push(itemName);
            } else if (createBook(itemName, book)) {
                return true;
            }
        }
        items.clear();
    }

    return false;
}