Exemplo n.º 1
0
void LoadSaveGamePreviews(const fs::path& orig_path, const std::string& extension, std::vector<FullPreview>& previews) {
    FullPreview data;
    fs::directory_iterator end_it;

    fs::path path = orig_path;
    // Relative path relative to the save directory
    if (path.is_relative()) {
        path = GetSaveDir() / path;
    }

    if (!fs::exists(path)) {
        ErrorLogger() << "SaveFileListBox::LoadSaveGamePreviews: Save Game directory \"" << path << "\" not found";
        return;
    }
    if (!fs::is_directory(path)) {
        ErrorLogger() << "SaveFileListBox::LoadSaveGamePreviews: Save Game directory \"" << path << "\" was not a directory";
        return;
    }

    for (fs::directory_iterator it(path); it != end_it; ++it) {
        try {
            std::string filename = PathString(it->path().filename());
            if (it->path().filename().extension() == extension & !fs::is_directory(it->path())) {
                if (LoadSaveGamePreviewData(*it, data)) {
                    // Add preview entry to list
                    previews.push_back(data);
                }
            }
        } catch (const std::exception& e) {
            ErrorLogger() << "SaveFileListBox::LoadSaveGamePreviews: Failed loading preview from " << it->path() << " because: " << e.what();
        }
    }
}
Exemplo n.º 2
0
    /// Loads preview data on all save files in a directory specidifed by path.
    /// @param [in] path The path of the directory
    /// @param [out] previews The preview datas indexed by file names
    void LoadSaveGamePreviews ( const fs::path& path, const std::string& extension ) {
        SaveGamePreviewData data;
        fs::directory_iterator end_it;

        if ( !fs::exists ( path ) ) {
            Logger().errorStream() << "SaveFileListBox::LoadSaveGamePreviews: Save Game directory \"" << path << "\" not found";
            return;
        }
        if ( !fs::is_directory ( path ) ) {
            Logger().errorStream() << "SaveFileListBox::LoadSaveGamePreviews: Save Game directory \"" << path << "\" was not a directory";
            return;
        }

        for ( fs::directory_iterator it ( path ); it != end_it; ++it ) {
            try {
                std::string filename = PathString ( it->path().filename() );
                if ( it->path().filename().extension() == extension ) {
                    if ( LoadSaveGamePreviewData ( *it, data ) ) {
                        // Add preview entry to list
                        Insert ( new SaveFileRow ( filename, data ) );
                    }
                }
            } catch ( const std::exception& e ) {
                Logger().errorStream() << "SaveFileListBox::LoadSaveGamePreviews: Failed loading preview from " << it->path() << " because: " << e.what();
            }
        }
    }