OpenFunscripter / OFS

A tool to create funscripts
GNU General Public License v3.0
90 stars 39 forks source link

Feature request: try to use video in project directory if original path not found #14

Closed trassshhub closed 2 years ago

trassshhub commented 2 years ago

I understand that the media path in the project is saved in absolute path, so that if the project file is moved it can still open the video. However when the project file and media file is moved together, OFS will not be able to find the path. As the project file is default to save in the same directory as the media file, can OFS try to find the media file in the project directory and use it instead?

I tried to modify the OpenFuncripter::initProject() but my c++ is quite rusty so I will just put it below instead of a PR.

void OpenFunscripter::initProject() noexcept
{
    OFS_PROFILE(__FUNCTION__);
    if (LoadedProject->Loaded) {
        if (LoadedProject->ProjectSettings.NudgeMetadata) {
            ShowMetadataEditor = settings->data().show_meta_on_new;
            LoadedProject->ProjectSettings.NudgeMetadata = false;
        }

        if (Util::FileExists(LoadedProject->MediaPath)) {
            player->openVideo(LoadedProject->MediaPath);
        }
        else {
            auto mediaName = Util::PathFromString(LoadedProject->MediaPath).filename();
            auto projectDir = Util::PathFromString(LoadedProject->LastPath).parent_path();
            auto testPath = (projectDir / mediaName).u8string();
            if (Util::FileExists(testPath)) {
                Util::YesNoCancelDialog("Failed to find video.",
                    "The original video was not found.\n"
                    "Use video found in project directory?",
                    [this, testPath](Util::YesNoCancel result) {
                        if (result == Util::YesNoCancel::Yes) {
                            player->openVideo(testPath);
                            LoadedProject->MediaPath = testPath;
                        }
                        else if (result == Util::YesNoCancel::No) {
                            pickDifferentMedia();
                        }
                    });
            }
            else {
                Util::MessageBoxAlert("Failed to find video.",
                    "The Video was not found.\n"
                    "Please pick the correct video.");
                pickDifferentMedia();
            }
        }
    }
    updateTitle();

    auto lastPath = Util::PathFromString(LoadedProject->LastPath);
    lastPath.replace_filename("");
    lastPath /= "";
    settings->data().last_path = lastPath.u8string();
    settings->saveSettings();

    lastBackup = std::chrono::steady_clock::now();
}
OpenFunscripter commented 2 years ago

Same as this https://github.com/OpenFunscripter/OFS/issues/15#issuecomment-1026773556

OpenFunscripter commented 2 years ago

So I just took this but removed the Yes/No/Cancel dialog. Didn't see anything wrong with it.