ES-DE/es-app/src/guis/GuiThemeDownloader.h

131 lines
3.6 KiB
C
Raw Normal View History

2023-02-13 19:38:23 +00:00
// SPDX-License-Identifier: MIT
//
// EmulationStation Desktop Edition
// GuiThemeDownloader.h
//
// Theme downloader.
//
#ifndef ES_APP_GUIS_GUI_THEME_DOWNLOADER_H
#define ES_APP_GUIS_GUI_THEME_DOWNLOADER_H
#include "GuiComponent.h"
#include "components/BusyComponent.h"
#include "components/ButtonComponent.h"
2023-02-13 19:38:23 +00:00
#include "components/ComponentGrid.h"
#include "components/ComponentList.h"
2023-02-13 19:38:23 +00:00
#include "components/NinePatchComponent.h"
#include "components/TextComponent.h"
#include "renderers/Renderer.h"
#include "views/ViewController.h"
#include <git2/clone.h>
#include <git2/errors.h>
#include <git2/global.h>
#include <git2/merge.h>
#include <git2/reset.h>
#include <git2/revparse.h>
#include <git2/status.h>
#include <git2/version.h>
#include <atomic>
#include <future>
#include <thread>
2023-02-13 19:38:23 +00:00
class GuiThemeDownloader : public GuiComponent
{
public:
GuiThemeDownloader();
~GuiThemeDownloader();
2023-02-13 19:38:23 +00:00
void update(int deltaTime) override;
void render(const glm::mat4& parentTrans) override;
2023-02-13 19:38:23 +00:00
void onSizeChanged() override;
bool input(InputConfig* config, Input input) override;
std::vector<HelpPrompt> getHelpPrompts() override;
HelpStyle getHelpStyle() override { return ViewController::getInstance()->getViewHelpStyle(); }
private:
struct Screenshot {
std::string image;
std::string caption;
};
struct ThemeEntry {
std::string name;
std::string reponame;
std::string url;
std::string manualExtension;
std::vector<std::string> variants;
std::vector<std::string> colorSchemes;
std::vector<std::string> aspectRatios;
std::vector<std::string> transitions;
std::vector<Screenshot> screenshots;
bool invalidRepository;
bool manuallyDownloaded;
bool hasLocalChanges;
bool isCloned;
ThemeEntry()
: invalidRepository {false}
, manuallyDownloaded {false}
, hasLocalChanges {false}
, isCloned {false}
{
}
};
bool fetchThemesList();
bool fetchRepository(const std::string& repositoryName,
const std::string& url,
bool allowReset = false);
bool cloneRepository(const std::string& repositoryName, const std::string& url);
bool checkLocalChanges(git_repository* repository, bool hasFetched = false);
void resetRepository(git_repository* repository);
void makeInventory();
bool renameDirectory(const std::string& path);
void parseThemesList();
void populateGUI();
void updateGUI();
2023-02-13 19:38:23 +00:00
Renderer* mRenderer;
NinePatchComponent mBackground;
ComponentGrid mGrid;
std::shared_ptr<ComponentList> mList;
std::shared_ptr<ComponentGrid> mButtons;
BusyComponent mBusyAnim;
2023-02-13 19:38:23 +00:00
struct ThemeGUIEntry {
std::shared_ptr<TextComponent> themeName;
};
std::vector<ThemeGUIEntry> mThemeGUIEntries;
enum class RepositoryError {
2023-03-26 18:49:44 +00:00
NO_REPO_ERROR,
MANUALLY_DOWNLOADED,
NOT_A_REPOSITORY,
INVALID_ORIGIN,
HAS_DIVERGED,
HAS_LOCAL_CHANGES
};
RepositoryError mRepositoryError;
std::string mErrorMessage;
std::thread mFetchThread;
std::promise<bool> mPromise;
std::future<bool> mFuture;
std::atomic<bool> mFetching;
std::atomic<bool> mLatestThemesList;
static inline std::atomic<float> mReceivedObjectsProgress {0.0f};
static inline std::atomic<float> mResolveDeltaProgress {0.0f};
2023-02-13 19:38:23 +00:00
std::shared_ptr<TextComponent> mTitle;
std::vector<ThemeEntry> mThemeSets;
};
#endif // ES_APP_GUIS_GUI_THEME_DOWNLOADER_H