~haowenl/vorg-windows

cb8437b7c7164588870c0094d502f1352eb3cd0a — Haowen Liu 11 months ago 0ba2075
Add simple repo validation to manage page
M libvorg => libvorg +1 -1
@@ 1,1 1,1 @@
Subproject commit 3d23fa175ac871f820b4a90d72e027d9c310bc5a
Subproject commit b2dced63b67d236068e73bc3a9584b04b6588262

M vorg-windows/App.xaml.cpp => vorg-windows/App.xaml.cpp +65 -0
@@ 237,6 237,66 @@ Windows::Foundation::Collections::IVector<Windows::Foundation::IInspectable> App
    return result;
}

hstring App::ValidateRepoData(int maxLines) const
{
    auto result = mRepo->validateRepoData();
    if (std::get<0>(result).empty() && std::get<1>(result).empty() && std::get<2>(result).empty())
    {
        return L"";
    }
    else
    {
        int lineCount = 0;
        hstring msg;
        if (!std::get<0>(result).empty())
        {
            msg = msg + L"Files in store but not DB:\n";
            lineCount += 1;
            for (auto &hash : std::get<0>(result))
            {
                msg = msg + to_hstring(hash) + L"\n";
                lineCount += 1;
                if (lineCount >= maxLines)
                {
                    msg = msg + L"...";
                    return msg;
                }
            }
        }
        if (!std::get<1>(result).empty())
        {
            msg = msg + L"Files in DB but not store:\n";
            lineCount += 1;
            for (auto &hash : std::get<1>(result))
            {
                msg = msg + to_hstring(hash) + L"\n";
                lineCount += 1;
                if (lineCount >= maxLines)
                {
                    msg = msg + L"...";
                    return msg;
                }
            }
        }
        if (!std::get<2>(result).empty())
        {
            msg = msg + L"Inconsistent files:\n";
            lineCount += 1;
            for (auto &hash : std::get<2>(result))
            {
                msg = msg + to_hstring(hash) + L"\n";
                lineCount += 1;
                if (lineCount >= maxLines)
                {
                    msg = msg + L"...";
                    return msg;
                }
            }
        }
        return msg;
    }
}

hstring App::GetVorgError() const
{
    if (mRepo == nullptr)


@@ 247,6 307,11 @@ hstring App::GetVorgError() const
    return to_hstring(errorUTF8);
}

void App::ShowErrorDialog(const hstring &title, const hstring &content)
{
    mWindow.ShowErrorDialog(title, content);
}

std::vector<std::string> App::WinrtToStdVector(
    const Windows::Foundation::Collections::IObservableVector<hstring> &input)
{

M vorg-windows/App.xaml.h => vorg-windows/App.xaml.h +3 -1
@@ 36,12 36,14 @@ struct App : AppT<App>
    Windows::Foundation::Collections::IVector<Windows::Foundation::IInspectable> CompleteActors(
        const hstring &actor) const;
    Windows::Foundation::Collections::IVector<Windows::Foundation::IInspectable> CompleteTags(const hstring &tag) const;
    hstring ValidateRepoData(int maxLines) const;

    // Error handling
    hstring GetVorgError() const;
    void ShowErrorDialog(const hstring &title, const hstring &content);

    // Members
    Microsoft::UI::Xaml::Window mWindow{nullptr};
    vorg_windows::MainWindow mWindow{nullptr};

  private:
    std::unique_ptr<Vorg::VorgRepo> mRepo;

M vorg-windows/BrowseDetailPage.xaml.cpp => vorg-windows/BrowseDetailPage.xaml.cpp +1 -5
@@ 112,11 112,7 @@ fire_and_forget BrowseDetailPage::OpenButton_Click(const Windows::Foundation::II
    }
    else
    {
        vorg_windows::ErrorContentDialog dialog;
        dialog.Title(box_value(L"Error opening file"));
        dialog.Content(box_value(L"This should not happen. Please file a bug report."));
        dialog.XamlRoot(XamlRoot());
        co_await dialog.ShowAsync();
        mApp->ShowErrorDialog(L"Error opening file", L"This should not happen. Please file a bug report.");
    }
}


M vorg-windows/ImportSelectionPage.xaml.cpp => vorg-windows/ImportSelectionPage.xaml.cpp +2 -10
@@ 39,11 39,7 @@ fire_and_forget ImportSelectionPage::ImportFileButton_Click(Windows::Foundation:
        if (!mApp->SetImportFile(file.Path()))
        {
            // Show dialog with error
            vorg_windows::ErrorContentDialog dialog;
            dialog.Title(box_value(L"Error importing file"));
            dialog.Content(box_value(mApp->GetVorgError()));
            dialog.XamlRoot(XamlRoot());
            co_await dialog.ShowAsync();
            mApp->ShowErrorDialog(L"Error importing file", mApp->GetVorgError());
        }
        else
        {


@@ 74,11 70,7 @@ fire_and_forget ImportSelectionPage::ImportFolderButton_Click(Windows::Foundatio
        if (!mApp->SetImportFolder(folder.Path()))
        {
            // Show dialog with error
            vorg_windows::ErrorContentDialog dialog;
            dialog.Title(box_value(L"Error importing folder"));
            dialog.Content(box_value(mApp->GetVorgError()));
            dialog.XamlRoot(XamlRoot());
            co_await dialog.ShowAsync();
            mApp->ShowErrorDialog(L"Error importing folder", mApp->GetVorgError());
        }
        else
        {

M vorg-windows/LandingPage.xaml.cpp => vorg-windows/LandingPage.xaml.cpp +1 -7
@@ 5,8 5,6 @@
#include "LandingPage.g.cpp"
#endif

#include "ErrorContentDialog.xaml.h"

using namespace winrt;
using namespace Microsoft::UI::Xaml;



@@ 60,11 58,7 @@ fire_and_forget LandingPage::launchFileChooser()
        if (!mApp->OpenRepo(folder.Path()))
        {
            // Show dialog with error
            vorg_windows::ErrorContentDialog dialog;
            dialog.Title(box_value(L"Error opening Vorg repository"));
            dialog.Content(box_value(mApp->GetVorgError()));
            dialog.XamlRoot(XamlRoot());
            co_await dialog.ShowAsync();
            mApp->ShowErrorDialog(L"Error opening Vorg repository", mApp->GetVorgError());
        }
        else
        {

M vorg-windows/MainWindow.idl => vorg-windows/MainWindow.idl +2 -3
@@ 1,10 1,9 @@
// Copyright (c) Microsoft Corporation and Contributors.
// Licensed under the MIT License.

namespace vorg_windows
{
[default_interface] runtimeclass MainWindow : Microsoft.UI.Xaml.Window
{
    MainWindow();

    void ShowErrorDialog(String title, String content);
}
} // namespace vorg_windows

M vorg-windows/MainWindow.xaml.cpp => vorg-windows/MainWindow.xaml.cpp +9 -0
@@ 110,6 110,15 @@ void MainWindow::BrowsePage_VideoModified(const vorg_windows::BrowsePage &, cons
    mApp->PopulateGalleryData(mGalleryData);
}

fire_and_forget MainWindow::ShowErrorDialog(const hstring &title, const hstring &content)
{
    vorg_windows::ErrorContentDialog dialog;
    dialog.Title(box_value(title));
    dialog.Content(box_value(content));
    dialog.XamlRoot(ContentFrame().XamlRoot());
    co_await dialog.ShowAsync();
}

void MainWindow::PageCleanup()
{
    {

M vorg-windows/MainWindow.xaml.h => vorg-windows/MainWindow.xaml.h +3 -0
@@ 23,6 23,9 @@ struct MainWindow : MainWindowT<MainWindow>

    void BrowsePage_VideoModified(const vorg_windows::BrowsePage &, const Windows::Foundation::IInspectable &);

    // Methods
    fire_and_forget ShowErrorDialog(const hstring &title, const hstring &content);

  private:
    // Members
    event_token mOpenRepoEventToken;

M vorg-windows/ManagePage.idl => vorg-windows/ManagePage.idl +0 -1
@@ 6,6 6,5 @@ namespace vorg_windows
[default_interface] runtimeclass ManagePage : Microsoft.UI.Xaml.Controls.Page
{
    ManagePage();
    Int32 MyProperty;
}
} // namespace vorg_windows

M vorg-windows/ManagePage.xaml => vorg-windows/ManagePage.xaml +1 -1
@@ 15,6 15,6 @@
        HorizontalAlignment="Center"
        VerticalAlignment="Center"
        Orientation="Horizontal">
        <Button x:Name="myButton" Click="myButton_Click">Click Me</Button>
        <Button x:Name="ValidateButton" Click="ValidateButton_Click">Validate repo data</Button>
    </StackPanel>
</Page>

M vorg-windows/ManagePage.xaml.cpp => vorg-windows/ManagePage.xaml.cpp +13 -11
@@ 19,20 19,22 @@ namespace winrt::vorg_windows::implementation
ManagePage::ManagePage()
{
    InitializeComponent();
}

int32_t ManagePage::MyProperty()
{
    throw hresult_not_implemented();
}

void ManagePage::MyProperty(int32_t /* value */)
{
    throw hresult_not_implemented();
    // Initialize app ptr
    mApp.copy_from(get_self<vorg_windows::implementation::App>(
        Application::Current().as<default_interface<vorg_windows::implementation::App>>()));
}

void ManagePage::myButton_Click(IInspectable const &, RoutedEventArgs const &)
void ManagePage::ValidateButton_Click(IInspectable const &, RoutedEventArgs const &)
{
    myButton().Content(box_value(L"Clicked"));
    hstring msg = mApp->ValidateRepoData(10);
    if (msg.empty())
    {
        mApp->ShowErrorDialog(L"Repository is valid!", L"");
    }
    else
    {
        mApp->ShowErrorDialog(L"Repository is corrupted", msg);
    }
}
} // namespace winrt::vorg_windows::implementation

M vorg-windows/ManagePage.xaml.h => vorg-windows/ManagePage.xaml.h +7 -4
@@ 5,17 5,20 @@

#include "ManagePage.g.h"

#include "App.xaml.h"

namespace winrt::vorg_windows::implementation
{
struct ManagePage : ManagePageT<ManagePage>
{
    ManagePage();

    int32_t MyProperty();
    void MyProperty(int32_t value);
    void ValidateButton_Click(Windows::Foundation::IInspectable const &sender,
                              Microsoft::UI::Xaml::RoutedEventArgs const &args);

    void myButton_Click(Windows::Foundation::IInspectable const &sender,
                        Microsoft::UI::Xaml::RoutedEventArgs const &args);
  private:
    // App ptr
    com_ptr<vorg_windows::implementation::App> mApp{nullptr};
};
} // namespace winrt::vorg_windows::implementation