Added error handling for shallow repositories to GuiThemeDownloader

Also made some minor layout changes
This commit is contained in:
Leon Styhre 2023-04-01 12:55:58 +02:00
parent 8cdedd945f
commit 56831f1785
2 changed files with 41 additions and 6 deletions

View file

@ -99,7 +99,7 @@ GuiThemeDownloader::GuiThemeDownloader(std::function<void()> updateCallback)
mScreenshot->setLinearInterpolation(true); mScreenshot->setLinearInterpolation(true);
mCenterGrid->setEntry(mScreenshot, glm::ivec2 {1, 3}, false, true, glm::ivec2 {4, 1}); mCenterGrid->setEntry(mScreenshot, glm::ivec2 {1, 3}, false, true, glm::ivec2 {4, 1});
mAuthor = std::make_shared<TextComponent>("", Font::get(FONT_SIZE_MINI, FONT_PATH_LIGHT), mAuthor = std::make_shared<TextComponent>("", Font::get(FONT_SIZE_MINI * 0.9f, FONT_PATH_LIGHT),
0x555555FF, ALIGN_LEFT); 0x555555FF, ALIGN_LEFT);
mCenterGrid->setEntry(mAuthor, glm::ivec2 {1, 4}, false, true, glm::ivec2 {4, 1}, mCenterGrid->setEntry(mAuthor, glm::ivec2 {1, 4}, false, true, glm::ivec2 {4, 1},
GridFlags::BORDER_BOTTOM); GridFlags::BORDER_BOTTOM);
@ -412,6 +412,7 @@ void GuiThemeDownloader::makeInventory()
for (auto& theme : mThemeSets) { for (auto& theme : mThemeSets) {
const std::string path {mThemeDirectory + theme.reponame}; const std::string path {mThemeDirectory + theme.reponame};
theme.invalidRepository = false; theme.invalidRepository = false;
theme.shallowRepository = false;
theme.manuallyDownloaded = false; theme.manuallyDownloaded = false;
theme.hasLocalChanges = false; theme.hasLocalChanges = false;
theme.isCloned = false; theme.isCloned = false;
@ -436,6 +437,12 @@ void GuiThemeDownloader::makeInventory()
continue; continue;
} }
if (git_repository_is_shallow(repository)) {
theme.shallowRepository = true;
git_repository_free(repository);
continue;
}
theme.isCloned = true; theme.isCloned = true;
if (checkLocalChanges(repository)) if (checkLocalChanges(repository))
@ -581,7 +588,7 @@ void GuiThemeDownloader::populateGUI()
themeName.append(" ").append(ViewController::BRANCH_CHAR); themeName.append(" ").append(ViewController::BRANCH_CHAR);
if (theme.isCloned) if (theme.isCloned)
themeName.append(" ").append(ViewController::TICKMARK_CHAR); themeName.append(" ").append(ViewController::TICKMARK_CHAR);
if (theme.manuallyDownloaded || theme.invalidRepository) if (theme.manuallyDownloaded || theme.invalidRepository || theme.shallowRepository)
themeName.append(" ").append(ViewController::CROSSEDCIRCLE_CHAR); themeName.append(" ").append(ViewController::CROSSEDCIRCLE_CHAR);
if (theme.hasLocalChanges) if (theme.hasLocalChanges)
themeName.append(" ").append(ViewController::EXCLAMATION_CHAR); themeName.append(" ").append(ViewController::EXCLAMATION_CHAR);
@ -620,6 +627,29 @@ void GuiThemeDownloader::populateGUI()
0.75f : 0.75f :
0.45f * (1.778f / mRenderer->getScreenAspectRatio())))); 0.45f * (1.778f / mRenderer->getScreenAspectRatio()))));
} }
else if (theme.shallowRepository) {
mWindow->pushGui(new GuiMsgBox(
getHelpStyle(),
"IT SEEMS AS IF THIS IS A SHALLOW REPOSITORY WHICH MEANS THAT IT'S BEEN "
"DOWNLOADED USING SOME OTHER TOOL THAN THIS THEME DOWNLOADER. A FRESH DOWNLOAD "
"IS REQUIRED AND THE OLD THEME DIRECTORY \"" +
theme.reponame + theme.manualExtension + "\" WILL BE RENAMED TO \"" +
theme.reponame + theme.manualExtension + "_DISABLED\"",
"PROCEED",
[this, theme] {
renameDirectory(mThemeDirectory + theme.reponame + theme.manualExtension);
std::promise<bool>().swap(mPromise);
mFuture = mPromise.get_future();
mFetchThread = std::thread(&GuiThemeDownloader::cloneRepository, this,
theme.reponame, theme.url);
mStatusType = StatusType::STATUS_DOWNLOADING;
mStatusText = "DOWNLOADING THEME";
},
"ABORT", [] { return; }, "", nullptr, true, true,
(mRenderer->getIsVerticalOrientation() ?
0.75f :
0.45f * (1.778f / mRenderer->getScreenAspectRatio()))));
}
else if (theme.hasLocalChanges) { else if (theme.hasLocalChanges) {
mWindow->pushGui(new GuiMsgBox( mWindow->pushGui(new GuiMsgBox(
getHelpStyle(), getHelpStyle(),
@ -678,7 +708,8 @@ void GuiThemeDownloader::updateGUI()
themeName.append(" ").append(ViewController::BRANCH_CHAR); themeName.append(" ").append(ViewController::BRANCH_CHAR);
if (mThemeSets[i].isCloned) if (mThemeSets[i].isCloned)
themeName.append(" ").append(ViewController::TICKMARK_CHAR); themeName.append(" ").append(ViewController::TICKMARK_CHAR);
if (mThemeSets[i].manuallyDownloaded || mThemeSets[i].invalidRepository) if (mThemeSets[i].manuallyDownloaded || mThemeSets[i].invalidRepository ||
mThemeSets[i].shallowRepository)
themeName.append(" ").append(ViewController::CROSSEDCIRCLE_CHAR); themeName.append(" ").append(ViewController::CROSSEDCIRCLE_CHAR);
if (mThemeSets[i].hasLocalChanges) if (mThemeSets[i].hasLocalChanges)
themeName.append(" ").append(ViewController::EXCLAMATION_CHAR); themeName.append(" ").append(ViewController::EXCLAMATION_CHAR);
@ -703,6 +734,10 @@ void GuiThemeDownloader::updateInfoPane()
mDownloadStatus->setText(ViewController::CROSSEDCIRCLE_CHAR + " MANUAL DOWNLOAD"); mDownloadStatus->setText(ViewController::CROSSEDCIRCLE_CHAR + " MANUAL DOWNLOAD");
mDownloadStatus->setColor(0x992222FF); mDownloadStatus->setColor(0x992222FF);
} }
else if (mThemeSets[mList->getCursorId()].shallowRepository) {
mDownloadStatus->setText(ViewController::CROSSEDCIRCLE_CHAR + " SHALLOW REPO");
mDownloadStatus->setColor(0x992222FF);
}
else { else {
if (mThemeSets[mList->getCursorId()].newEntry) if (mThemeSets[mList->getCursorId()].newEntry)
mDownloadStatus->setText("NOT INSTALLED (NEW)"); mDownloadStatus->setText("NOT INSTALLED (NEW)");

View file

@ -68,12 +68,14 @@ private:
std::vector<Screenshot> screenshots; std::vector<Screenshot> screenshots;
bool newEntry; bool newEntry;
bool invalidRepository; bool invalidRepository;
bool shallowRepository;
bool manuallyDownloaded; bool manuallyDownloaded;
bool hasLocalChanges; bool hasLocalChanges;
bool isCloned; bool isCloned;
ThemeEntry() ThemeEntry()
: newEntry {false} : newEntry {false}
, invalidRepository {false} , invalidRepository {false}
, shallowRepository {false}
, manuallyDownloaded {false} , manuallyDownloaded {false}
, hasLocalChanges {false} , hasLocalChanges {false}
, isCloned {false} , isCloned {false}
@ -121,11 +123,9 @@ private:
enum class RepositoryError { enum class RepositoryError {
NO_REPO_ERROR, NO_REPO_ERROR,
MANUALLY_DOWNLOADED,
NOT_A_REPOSITORY, NOT_A_REPOSITORY,
INVALID_ORIGIN, INVALID_ORIGIN,
HAS_DIVERGED, HAS_DIVERGED
HAS_LOCAL_CHANGES
}; };
RepositoryError mRepositoryError; RepositoryError mRepositoryError;