Example #1
0
std::unique_ptr<Workspace> JsonImporter::ImportWorkspace(FileManager& fileManager, const filesystem::path& workspaceFile)
{
    auto json = internal::ParseJsonFile(fileManager.GetFileSystem(), workspaceFile);

    if (internal::IsValidWorkspace(json))
    {
        auto workspace = std::make_unique<Workspace>();

        workspace->SetName(json["workspace"]);
        workspace->SetFile(workspaceFile);

        auto& projects = json["projects"];

        if (projects.is_array())
        {
            auto workspacePath = workspaceFile.parent_path();

            for (auto& project : projects)
            {
                workspace->AddProject(ImportProject(fileManager, workspacePath / project));
            }
        }

        return workspace;
    }

    return nullptr;
}
Example #2
0
void MaterialItem::slot_export()
{
    const char* project_path = m_editor_context.m_project.get_path();
    const filesystem::path project_root_path = filesystem::path(project_path).parent_path();
    const filesystem::path file_path = absolute("material.dmt", project_root_path);
    const filesystem::path file_root_path = file_path.parent_path();

    QString filepath =
        get_save_filename(
            0,
            "Export...",
            "Disney Materials (*.dmt)",
            m_editor_context.m_settings,
            SETTINGS_FILE_DIALOG_PROJECTS);

    if (!filepath.isEmpty())
    {
        if (QFileInfo(filepath).suffix().isEmpty())
            filepath += ".dmt";

        filepath = QDir::toNativeSeparators(filepath);

        ParamArray parameters = m_entity->get_parameters();
        parameters.insert("__name", m_entity->get_name());
        parameters.insert("__model", m_entity->get_model());

        SettingsFileWriter writer;
        if (!writer.write(filepath.toStdString().c_str(), parameters))
        {
            show_error_message_box(
                "Exporting Error",
                "Failed to export the Disney Material file " + filepath.toStdString() + ".");
        }
    }
}
void TextureCollectionItem::slot_import_textures()
{
    QFileDialog::Options options;
    QString selected_filter;

    const QStringList filepaths =
        QFileDialog::getOpenFileNames(
            treeWidget(),
            "Import Textures...",
            m_settings.get_path_optional<QString>(LAST_DIRECTORY_SETTINGS_KEY),
            "Texture Files (*.exr);;All Files (*.*)",
            &selected_filter,
            options);

    if (filepaths.empty())
        return;

    const filesystem::path path(
        QDir::toNativeSeparators(filepaths.first()).toStdString());

    m_settings.insert_path(
        LAST_DIRECTORY_SETTINGS_KEY,
        path.parent_path().string());

    for (int i = 0; i < filepaths.size(); ++i)
    {
        const string filepath = QDir::toNativeSeparators(filepaths[i]).toStdString();
        m_project_builder.insert_texture(m_parent, m_parent_item, filepath);
    }
}
Example #4
0
void MainWindow::slot_save_project_as()
{
    assert(m_project_manager.is_project_open());

    QFileDialog::Options options;
    QString selected_filter;

    QString filepath =
        QFileDialog::getSaveFileName(
            this,
            "Save As...",
            m_settings.get_path_optional<QString>(LAST_DIRECTORY_SETTINGS_KEY),
            "Project Files (*.appleseed)",
            &selected_filter,
            options);

    if (!filepath.isEmpty())
    {
        filepath = QDir::toNativeSeparators(filepath);

        const filesystem::path path(filepath.toStdString());

        m_settings.insert_path(
            LAST_DIRECTORY_SETTINGS_KEY,
            path.parent_path().string());

        m_project_manager.save_project_as(filepath.toAscii().constData());

        update_recent_files_menu(filepath);
        update_workspace();
    }
}
Example #5
0
void makePathCompact(const filesystem::path& path, filesystem::path& out_compact)
{
    out_compact.clear();
        
    for(filesystem::path::const_iterator p = path.begin(); p != path.end(); ++p){
        if(*p == ".."){
            out_compact = out_compact.parent_path();
        } else if(*p != "."){
            out_compact /= *p;
        }
    }
}
Example #6
0
void MainWindow::open_project(const QString& filepath)
{
    const filesystem::path path(filepath.toStdString());

    m_settings.insert_path(
        LAST_DIRECTORY_SETTINGS_KEY,
        path.parent_path().string());

    const bool successful =
        m_project_manager.load_project(filepath.toAscii().constData());

    if (successful)
        on_project_change();
    else  show_project_file_loading_failed_message_box(this, filepath);
}
    //! The function stores the specified file in the storage
    void file_collector::store_file(filesystem::path const& src_path)
    {
        // NOTE FOR THE FOLLOWING CODE:
        // Avoid using Boost.Filesystem functions that would call path::codecvt(). store_file() can be called
        // at process termination, and the global codecvt facet can already be destroyed at this point.
        // https://svn.boost.org/trac/boost/ticket/8642

        // Let's construct the new file name
        file_info info;
        info.m_TimeStamp = filesystem::last_write_time(src_path);
        info.m_Size = filesystem::file_size(src_path);

        filesystem::path file_name_path = src_path.filename();
        path_string_type file_name = file_name_path.native();
        info.m_Path = m_StorageDir / file_name_path;

        // Check if the file is already in the target directory
        filesystem::path src_dir = src_path.has_parent_path() ?
                            filesystem::system_complete(src_path.parent_path()) :
                            m_BasePath;
        const bool is_in_target_dir = filesystem::equivalent(src_dir, m_StorageDir);
        if (!is_in_target_dir)
        {
            if (filesystem::exists(info.m_Path))
            {
                // If the file already exists, try to mangle the file name
                // to ensure there's no conflict. I'll need to make this customizable some day.
                file_counter_formatter formatter(file_name.size(), 5);
                unsigned int n = 0;
                do
                {
                    path_string_type alt_file_name = formatter(file_name, n++);
                    info.m_Path = m_StorageDir / filesystem::path(alt_file_name);
                }
                while (filesystem::exists(info.m_Path) && n < (std::numeric_limits< unsigned int >::max)());
            }

            // The directory should have been created in constructor, but just in case it got deleted since then...
            filesystem::create_directories(m_StorageDir);
        }

        BOOST_LOG_EXPR_IF_MT(lock_guard< mutex > lock(m_Mutex);)
Example #8
0
void MainWindow::slot_open_project()
{
    if (!can_close_project())
        return;

    QFileDialog::Options options;
    QString selected_filter;

    QString filepath =
        QFileDialog::getOpenFileName(
            this,
            "Open...",
            m_settings.get_path_optional<QString>(LAST_DIRECTORY_SETTINGS_KEY),
            "Project Files (*.appleseed);;All Files (*.*)",
            &selected_filter,
            options);

    if (!filepath.isEmpty())
    {
        filepath = QDir::toNativeSeparators(filepath);

        const filesystem::path path(filepath.toStdString());

        m_settings.insert_path(
            LAST_DIRECTORY_SETTINGS_KEY,
            path.parent_path().string());

        const bool successful =
            m_project_manager.load_project(filepath.toAscii().constData());

        if (successful)
        {
            on_project_change();
        }
        else
        {
            show_project_file_loading_failed_message_box(this, filepath);
        }
    }
}