Skip to content
This repository has been archived by the owner on Apr 5, 2021. It is now read-only.

Commit

Permalink
Fix update checking (#43)
Browse files Browse the repository at this point in the history
* Add banner/icon build artifacts to .gitignore

* Use new citro3d functions

* Rework update checking
  • Loading branch information
Coder-256 authored and RocketRobz committed Mar 2, 2019
1 parent 7ad6ba6 commit 881a330
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 59 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Expand Up @@ -13,4 +13,8 @@ build/*
*.DS_Store

# VS Code files
.vscode/*
.vscode/*

# Build artifacts
app/banner.bin
app/icon.bin
Binary file removed app/banner.bin
Binary file not shown.
Binary file removed app/icon.bin
Binary file not shown.
140 changes: 109 additions & 31 deletions source/download.cpp
Expand Up @@ -20,6 +20,13 @@ static size_t result_sz = 0;
static size_t result_written = 0;
std::vector<std::string> _topText;
std::string jsonName;
CIniFile versionsFile("sdmc:/_nds/TWiLightMenu/extras/updater/currentVersionsV2.ini");
std::string latestMenuReleaseCache = "";
std::string latestMenuNightlyCache = "";
std::string latestBootstrapReleaseCache = "";
std::string latestBootstrapNightlyCache = "";
std::string latestUpdaterReleaseCache = "";
std::string latestUpdaterNightlyCache = "";

extern void displayBottomMsg(const char* text);

Expand Down Expand Up @@ -601,6 +608,91 @@ void drawMessageText(int position)
pp2d_end_draw();
}

std::string latestMenuRelease(void) {
if (latestMenuReleaseCache == "")
latestMenuReleaseCache = getLatestRelease("RocketRobz/TWiLightMenu", "tag_name");
return latestMenuReleaseCache;
}

std::string latestMenuNightly(void) {
if (latestMenuNightlyCache == "")
latestMenuNightlyCache = getLatestCommit("RocketRobz/TWiLightMenu", "sha").substr(0,7);
return latestMenuNightlyCache;
}

std::string latestBootstrapRelease(void) {
if (latestBootstrapReleaseCache == "")
latestBootstrapReleaseCache = getLatestRelease("ahezard/nds-bootstrap", "tag_name");
return latestBootstrapReleaseCache;
}

std::string latestBootstrapNightly(void) {
if (latestBootstrapNightlyCache == "")
latestBootstrapNightlyCache = getLatestCommit("ahezard/nds-bootstrap", "sha").substr(0,7);
return latestBootstrapNightlyCache;
}

std::string latestUpdaterRelease(void) {
if (latestUpdaterReleaseCache == "")
latestUpdaterReleaseCache = getLatestRelease("RocketRobz/TWiLightMenu-Updater", "tag_name");
return latestUpdaterReleaseCache;
}

std::string latestUpdaterNightly(void) {
if (latestUpdaterNightlyCache == "")
latestUpdaterNightlyCache = getLatestCommit("RocketRobz/TWiLightMenu-Updater", "sha").substr(0,7);
return latestUpdaterNightlyCache;
}

void saveUpdateData(void) {
versionsFile.SaveIniFile("sdmc:/_nds/TWiLightMenu/extras/updater/currentVersionsV2.ini");
}

std::string getInstalledVersion(std::string component) {
return versionsFile.GetString(component, "VERSION", "");
}

std::string getInstalledChannel(std::string component) {
return versionsFile.GetString(component, "CHANNEL", "");
}

void setInstalledVersion(std::string component, std::string version) {
versionsFile.SetString(component, "VERSION", version);
}

void setInstalledChannel(std::string component, std::string channel) {
versionsFile.SetString(component, "CHANNEL", channel);
}

void checkForUpdates() {
// First remove the old versions file
unlink("sdmc:/_nds/TWiLightMenu/extras/updater/currentVersions.ini");

std::string menuChannel = getInstalledChannel("TWILIGHTMENU");
std::string menuVersion = getInstalledVersion("TWILIGHTMENU");
std::string updaterChannel = getInstalledChannel("TWILIGHTMENU-UPDATER");
std::string updaterVersion = getInstalledVersion("TWILIGHTMENU-UPDATER");
std::string bootstrapRelease = getInstalledVersion("NDS-BOOTSTRAP-RELEASE");
std::string boostrapNightly = getInstalledVersion("NDS-BOOTSTRAP-NIGHTLY");

if (menuChannel == "release")
updateAvailable[0] = menuVersion != latestMenuRelease();
else if (menuChannel == "nightly")
updateAvailable[1] = menuVersion != latestMenuNightly();
else
updateAvailable[0] = updateAvailable[1] = true;

updateAvailable[2] = bootstrapRelease != latestBootstrapRelease();
updateAvailable[3] = boostrapNightly != latestBootstrapNightly();

if (updaterChannel == "release")
updateAvailable[4] = updaterVersion != latestUpdaterRelease();
else if (updaterChannel == "nightly")
updateAvailable[5] = updaterVersion != latestUpdaterNightly();
else
updateAvailable[4] = updateAvailable[5] = true;
}

void updateBootstrap(bool nightly) {
if(nightly) {
displayBottomMsg("Downloading nds-bootstrap...\n"
Expand All @@ -616,10 +708,8 @@ void updateBootstrap(bool nightly) {

deleteFile("sdmc:/nds-bootstrap-nightly.7z");

std::string latestNightly = getLatestCommit("ahezard/nds-bootstrap", "sha").substr(0,7);
CIniFile ini("sdmc:/_nds/TWiLightMenu/extras/updater/currentVersions.ini");
ini.SetString("NDS-BOOTSTRAP", "NIGHTLY", latestNightly);
ini.SaveIniFile("sdmc:/_nds/TWiLightMenu/extras/updater/currentVersions.ini");
setInstalledVersion("NDS-BOOTSTRAP-NIGHTLY", latestBootstrapNightly());
saveUpdateData();
updateAvailable[3] = false;
} else {
displayBottomMsg("Downloading nds-bootstrap...\n"
Expand All @@ -635,10 +725,8 @@ void updateBootstrap(bool nightly) {

deleteFile("sdmc:/nds-bootstrap-release.zip");

std::string latestVersion = getLatestRelease("ahezard/nds-bootstrap", "tag_name");
CIniFile ini("sdmc:/_nds/TWiLightMenu/extras/updater/currentVersions.ini");
ini.SetString("NDS-BOOTSTRAP", "RELEASE", latestVersion);
ini.SaveIniFile("sdmc:/_nds/TWiLightMenu/extras/updater/currentVersions.ini");
setInstalledVersion("NDS-BOOTSTRAP-RELEASE", latestBootstrapRelease());
saveUpdateData();
updateAvailable[2] = false;
}
doneMsg();
Expand Down Expand Up @@ -667,13 +755,9 @@ void updateTWiLight(bool nightly) {
deleteFile("sdmc:/TWiLight Menu.cia");
deleteFile("sdmc:/TWiLight Menu - Game booter.cia");

std::string latestNightly = getLatestCommit("RocketRobz/TWiLightMenu", "sha").substr(0,7);
std::string latestVersion = getLatestRelease("RocketRobz/TWiLightMenu", "tag_name");
CIniFile ini("sdmc:/_nds/TWiLightMenu/extras/updater/currentVersions.ini");
ini.SetString("TWILIGHTMENU", "NIGHTLY", latestNightly);
ini.SetString("TWILIGHTMENU", "RELEASE", latestVersion);
ini.SaveIniFile("sdmc:/_nds/TWiLightMenu/extras/updater/currentVersions.ini");
updateAvailable[0] = false;
setInstalledChannel("TWILIGHTMENU", "nightly");
setInstalledVersion("TWILIGHTMENU", latestMenuNightly());
saveUpdateData();
updateAvailable[1] = false;
} else {
displayBottomMsg("Downloading TWiLight Menu++...\n"
Expand All @@ -698,10 +782,9 @@ void updateTWiLight(bool nightly) {
deleteFile("sdmc:/TWiLight Menu.cia");
deleteFile("sdmc:/TWiLight Menu - Game booter.cia");

std::string latestVersion = getLatestRelease("RocketRobz/TWiLightMenu", "tag_name");
CIniFile ini("sdmc:/_nds/TWiLightMenu/extras/updater/currentVersions.ini");
ini.SetString("TWILIGHTMENU", "RELEASE", latestVersion);
ini.SaveIniFile("sdmc:/_nds/TWiLightMenu/extras/updater/currentVersions.ini");
setInstalledChannel("TWILIGHTMENU", "release");
setInstalledVersion("TWILIGHTMENU", latestMenuRelease());
saveUpdateData();
updateAvailable[0] = false;
}
doneMsg();
Expand All @@ -723,13 +806,9 @@ void updateSelf(bool nightly) {

deleteFile("sdmc:/TWiLightMenu-Updater-nightly.cia");

std::string latestNightly = getLatestCommit("RocketRobz/TWiLightMenu-Updater", "sha").substr(0,7);
std::string latestVersion = getLatestRelease("RocketRobz/TWiLightMenu-Updater", "tag_name");
CIniFile ini("sdmc:/_nds/TWiLightMenu/extras/updater/currentVersions.ini");
ini.SetString("TWILIGHTMENU-UPDATER", "NIGHTLY", latestNightly);
ini.SetString("TWILIGHTMENU-UPDATER", "RELEASE", latestVersion);
ini.SaveIniFile("sdmc:/_nds/TWiLightMenu/extras/updater/currentVersions.ini");
updateAvailable[4] = false;
setInstalledChannel("TWILIGHTMENU-UPDATER", "nightly");
setInstalledVersion("TWILIGHTMENU-UPDATER", latestUpdaterNightly());
saveUpdateData();
updateAvailable[5] = false;
} else {
displayBottomMsg("Downloading TWiLight Menu++ Updater...\n"
Expand All @@ -746,11 +825,10 @@ void updateSelf(bool nightly) {

deleteFile("sdmc:/TWiLightMenu-Updater-release.cia");

std::string latestVersion = getLatestRelease("RocketRobz/TWiLightMenu", "tag_name");
CIniFile ini("sdmc:/_nds/TWiLightMenu/extras/updater/currentVersions.ini");
ini.SetString("TWILIGHTMENU", "RELEASE", latestVersion);
ini.SaveIniFile("sdmc:/_nds/TWiLightMenu/extras/updater/currentVersions.ini");
updateAvailable[0] = false;
setInstalledChannel("TWILIGHTMENU-UPDATER", "release");
setInstalledVersion("TWILIGHTMENU-UPDATER", latestUpdaterRelease());
saveUpdateData();
updateAvailable[4] = false;
}
doneMsg();
}
Expand Down
5 changes: 5 additions & 0 deletions source/download.hpp
Expand Up @@ -71,6 +71,11 @@ void setMessageText(const std::string &text);
*/
void drawMessageText(int position);

/**
* Check for updates.
*/
void checkForUpdates(void);

/**
* Update nds-bootstrap to the latest build.
*/
Expand Down
18 changes: 0 additions & 18 deletions source/main.cpp
Expand Up @@ -121,24 +121,6 @@ void displayBottomMsg(const char* text) {
pp2d_end_draw();
}

void checkForUpdates(void) {
CIniFile ini("sdmc:/_nds/TWiLightMenu/extras/updater/currentVersions.ini");
if(ini.GetString("TWILIGHTMENU", "RELEASE", "") != getLatestRelease("RocketRobz/TWiLightMenu", "tag_name"))
updateAvailable[0] = true;
if(ini.GetString("TWILIGHTMENU", "NIGHTLY", "") != getLatestCommit("RocketRobz/TWiLightMenu", "sha").substr(0,7))
updateAvailable[1] = true;

if(ini.GetString("NDS-BOOTSTRAP", "RELEASE", "") != getLatestRelease("ahezard/nds-bootstrap", "tag_name"))
updateAvailable[2] = true;
if(ini.GetString("NDS-BOOTSTRAP", "NIGHTLY", "") != getLatestCommit("ahezard/nds-bootstrap", "sha").substr(0,7))
updateAvailable[3] = true;

if(ini.GetString("TWILIGHTMENU-UPDATER", "RELEASE", "") != getLatestRelease("RocketRobz/TWiLightMenu-Updater", "tag_name"))
updateAvailable[4] = true;
if(ini.GetString("TWILIGHTMENU-UPDATER", "NIGHTLY", "") != getLatestCommit("RocketRobz/TWiLightMenu-Updater", "sha").substr(0,7))
updateAvailable[5] = true;
}

// Version numbers.
char launcher_vertext[13];

Expand Down
21 changes: 12 additions & 9 deletions source/pp2d/pp2d.c
Expand Up @@ -114,7 +114,8 @@ void pp2d_draw_rectangle(int x, int y, int width, int height, u32 color)
{
C3D_TexEnv* env = C3D_GetTexEnv(0);
C3D_TexEnvSrc(env, C3D_Both, GPU_CONSTANT, GPU_CONSTANT, 0);
C3D_TexEnvOp(env, C3D_Both, 0, 0, 0);
C3D_TexEnvOpRgb(env, 0, 0, 0);
C3D_TexEnvOpAlpha(env, 0, 0, 0);
C3D_TexEnvFunc(env, C3D_RGB, GPU_INTERPOLATE);
C3D_TexEnvColor(env, color);

Expand Down Expand Up @@ -332,15 +333,15 @@ Result pp2d_init(void)
C3D_Init(C3D_DEFAULT_CMDBUF_SIZE);

topLeft = C3D_RenderTargetCreate(SCREEN_HEIGHT, TOP_WIDTH, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8);
C3D_RenderTargetSetClear(topLeft, C3D_CLEAR_ALL, BACKGROUND_COLOR, 0);
C3D_RenderTargetClear(topLeft, C3D_CLEAR_ALL, BACKGROUND_COLOR, 0);
C3D_RenderTargetSetOutput(topLeft, GFX_TOP, GFX_LEFT, DISPLAY_TRANSFER_FLAGS);

topRight = C3D_RenderTargetCreate(SCREEN_HEIGHT, TOP_WIDTH, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8);
C3D_RenderTargetSetClear(topRight, C3D_CLEAR_ALL, BACKGROUND_COLOR, 0);
C3D_RenderTargetClear(topRight, C3D_CLEAR_ALL, BACKGROUND_COLOR, 0);
C3D_RenderTargetSetOutput(topRight, GFX_TOP, GFX_RIGHT, DISPLAY_TRANSFER_FLAGS);

bot = C3D_RenderTargetCreate(SCREEN_HEIGHT, BOTTOM_WIDTH, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8);
C3D_RenderTargetSetClear(bot, C3D_CLEAR_ALL, BACKGROUND_COLOR, 0);
C3D_RenderTargetClear(bot, C3D_CLEAR_ALL, BACKGROUND_COLOR, 0);
C3D_RenderTargetSetOutput(bot, GFX_BOTTOM, GFX_LEFT, DISPLAY_TRANSFER_FLAGS);

res = fontEnsureMapped();
Expand Down Expand Up @@ -649,12 +650,12 @@ void pp2d_set_screen_color(gfxScreen_t target, u32 color)
{
if (target == GFX_TOP)
{
C3D_RenderTargetSetClear(topLeft, C3D_CLEAR_ALL, color, 0);
C3D_RenderTargetSetClear(topRight, C3D_CLEAR_ALL, color, 0);
C3D_RenderTargetClear(topLeft, C3D_CLEAR_ALL, color, 0);
C3D_RenderTargetClear(topRight, C3D_CLEAR_ALL, color, 0);
}
else
{
C3D_RenderTargetSetClear(bot, C3D_CLEAR_ALL, color, 0);
C3D_RenderTargetClear(bot, C3D_CLEAR_ALL, color, 0);
}
}

Expand All @@ -669,7 +670,8 @@ static void pp2d_set_text_color(u32 color)
C3D_TexEnv* env = C3D_GetTexEnv(0);
C3D_TexEnvSrc(env, C3D_RGB, GPU_CONSTANT, 0, 0);
C3D_TexEnvSrc(env, C3D_Alpha, GPU_TEXTURE0, GPU_CONSTANT, 0);
C3D_TexEnvOp(env, C3D_Both, 0, 0, 0);
C3D_TexEnvOpRgb(env, 0, 0, 0);
C3D_TexEnvOpAlpha(env, 0, 0, 0);
C3D_TexEnvFunc(env, C3D_RGB, GPU_REPLACE);
C3D_TexEnvFunc(env, C3D_Alpha, GPU_MODULATE);
C3D_TexEnvColor(env, color);
Expand Down Expand Up @@ -818,7 +820,8 @@ void pp2d_texture_draw(void)
C3D_TexBind(0, &textures[id].tex);
C3D_TexEnv* env = C3D_GetTexEnv(0);
C3D_TexEnvSrc(env, C3D_Both, GPU_TEXTURE0, GPU_CONSTANT, 0);
C3D_TexEnvOp(env, C3D_Both, 0, 0, 0);
C3D_TexEnvOpRgb(env, 0, 0, 0);
C3D_TexEnvOpAlpha(env, 0, 0, 0);
C3D_TexEnvFunc(env, C3D_Both, GPU_MODULATE);
C3D_TexEnvColor(env, textureData.color);

Expand Down

0 comments on commit 881a330

Please sign in to comment.