Skip to content

Commit

Permalink
updater, windows: add stable & preview channels
Browse files Browse the repository at this point in the history
  • Loading branch information
blueminder committed Apr 6, 2023
1 parent 1d684a2 commit fcd32f4
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 18 deletions.
1 change: 1 addition & 0 deletions core/cfg/option.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ Option<bool> BufferAutoResume("BufferAutoResume", true, "dojo");
Option<bool> RecordOnFirstInput("RecordOnFirstInput", false, "dojo");
Option<bool> ForceRealBios("ForceRealBios", false, "dojo");
Option<bool> OutputStreamTxt("OutputStreamTxt", false, "dojo");
OptionString UpdateChannel("UpdateChannel", "stable", "dojo");

Option<int> EnableMouseCaptureToggle ("EnableMouseCaptureToggle", false, "input");
Option<bool> EnableDiagonalCorrection ("EnableDiagonalCorrection", true, "input");
Expand Down
1 change: 1 addition & 0 deletions core/cfg/option.h
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,7 @@ extern Option<bool> BufferAutoResume;
extern Option<bool> RecordOnFirstInput;
extern Option<bool> ForceRealBios;
extern Option<bool> OutputStreamTxt;
extern OptionString UpdateChannel;

extern Option<bool> EnableDiagonalCorrection;

Expand Down
40 changes: 33 additions & 7 deletions core/dojo/DojoFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,14 +543,18 @@ size_t writeFunction(void *ptr, size_t size, size_t nmemb, std::string* data) {
return size * nmemb;
}

std::tuple<std::string, std::string> DojoFile::GetLatestDownloadUrl()
std::tuple<std::string, std::string> DojoFile::GetLatestDownloadUrl(std::string channel)
{
status_text = "Checking For Updates";

std::string tag_name = "";
std::string download_url = "";

std::string latest_url = "https://api.github.com/repos/blueminder/flycast-dojo/releases/latest";
std::string latest_url;
if (channel == "stable")
latest_url = "https://api.github.com/repos/blueminder/flycast-dojo/releases/latest";
else if (channel == "preview")
latest_url = "https://api.github.com/repos/blueminder/flycast-dojo/releases";

#ifndef ANDROID
auto curl = curl_easy_init();
Expand All @@ -576,13 +580,35 @@ std::tuple<std::string, std::string> DojoFile::GetLatestDownloadUrl()
if (!body.empty())
{
nlohmann::json j = nlohmann::json::parse(body);
tag_name = j["tag_name"].get<std::string>();
for (nlohmann::json::iterator it = j["assets"].begin(); it != j["assets"].end(); ++it)
if (channel == "stable")
{
if ((*it)["name"].get<std::string>().rfind("flycast-dojo", 0) == 0 &&
(*it)["content_type"] == "application/x-zip-compressed")
tag_name = j["tag_name"].get<std::string>();
for (nlohmann::json::iterator it = j["assets"].begin(); it != j["assets"].end(); ++it)
{
download_url = (*it)["browser_download_url"].get<std::string>();
if ((*it)["name"].get<std::string>().rfind("flycast-dojo", 0) == 0 &&
(*it)["content_type"] == "application/x-zip-compressed")
{
download_url = (*it)["browser_download_url"].get<std::string>();
}
}
}
else if (channel == "preview")
{
for (int i = 0; i < j.size(); i++)
{
if (!j[i]["prerelease"].get<bool>())
continue;

tag_name = j[i]["tag_name"].get<std::string>();
for (nlohmann::json::iterator it = j[i]["assets"].begin(); it != j[i]["assets"].end(); ++it)
{
if ((*it)["name"].get<std::string>().rfind("flycast-dojo", 0) == 0 &&
(*it)["content_type"] == "application/x-zip-compressed")
{
download_url = (*it)["browser_download_url"].get<std::string>();
}
}
break;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/dojo/DojoFile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class DojoFile
void CopyNewFlycast(std::string new_root);
void ValidateAndCopyMem(std::string rom_path);
void ValidateAndCopyVmu();
std::tuple<std::string, std::string> GetLatestDownloadUrl();
std::tuple<std::string, std::string> GetLatestDownloadUrl(std::string channel = "stable");

std::string DownloadFile(std::string download_url, std::string dest_folder);
std::string DownloadFile(std::string download_url, std::string dest_folder, size_t download_size);
Expand Down
11 changes: 9 additions & 2 deletions core/rend/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3121,14 +3121,21 @@ static void gui_display_content()
ImGui::SameLine(ImGui::GetContentRegionAvail().x - ImGui::CalcTextSize((std::string(GIT_VERSION) + std::string(" (?)")).data()).x - ImGui::GetStyle().FramePadding.x * 2.0f /*+ ImGui::GetStyle().ItemSpacing.x*/);

#ifdef _WIN32
if (config::UpdateChannel.get() != "stable")
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.0f, 0.5f, 0.2f, 1.0f));
if (ImGui::Button(GIT_VERSION))
{
dojo_file.tag_download = dojo_file.GetLatestDownloadUrl();
dojo_file.tag_download = dojo_file.GetLatestDownloadUrl(config::UpdateChannel);
ImGui::OpenPopup("Update?");
}
if (config::UpdateChannel.get() != "stable")
ImGui::PopStyleColor(1);

ImGui::SameLine();
ShowHelpMarker("Current Flycast Dojo version. Click to check for new updates.");
std::string current_channel = config::UpdateChannel.get();
current_channel[0] = toupper(current_channel[0]);
std::string update_desc = "Current Flycast Dojo version. Click to check for new updates. (" + current_channel + " Channel)";
ShowHelpMarker(update_desc.c_str());

dojo_gui.update_action();
#else
Expand Down
56 changes: 48 additions & 8 deletions core/rend/gui_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,20 +427,60 @@ void GuiSettings::settings_body_about(ImVec2 normal_padding)
header("Flycast Dojo");
{
ImGui::Text("Version: %s", GIT_VERSION);
ImGui::Text("Git Hash: %s", GIT_HASH);
ImGui::Text("Build Date: %s", BUILD_DATE);
}
ImGui::Spacing();
#ifdef _WIN32
ImGui::SameLine();
if (ImGui::Button("Update"))
header("Update");
{
static int channel_current_idx = 0;
const char* channels[] = { "Stable", "Preview" };

update_channel = config::UpdateChannel.get();
if (update_channel == "stable")
channel_current_idx = 0;
else if (update_channel == "preview")
channel_current_idx = 1;

if(ImGui::Combo("Update Channel", &channel_current_idx, channels, IM_ARRAYSIZE(channels)))
{
latest = "";
update_channel = channels[channel_current_idx];
update_channel[0] = tolower(update_channel[0]);

config::UpdateChannel = update_channel;
}

if (ImGui::Button("Check for Latest Version"))
{
dojo_file.tag_download = dojo_file.GetLatestDownloadUrl(update_channel);
latest = std::get<0>(dojo_file.tag_download);
}

if (latest.size() > 0)
{
dojo_file.tag_download = dojo_file.GetLatestDownloadUrl();
ImGui::OpenPopup("Update?");
ImGui::Text("Latest %s Release: %s", channels[channel_current_idx], latest.c_str());

char buffer[40] = { 0 };
snprintf(buffer, 40, "%s", GIT_VERSION);
if(strcmp(buffer, latest.c_str()) != 0)
{
if (ImGui::Button("Update##btn"))
{
dojo_file.tag_download = dojo_file.GetLatestDownloadUrl(update_channel);
ImGui::OpenPopup("Update?");
}
}
else
{
ImGui::TextColored(ImVec4(0, 128, 0, 1), "You are already on the latest version.");
}
}

dojo_gui.update_action();
#endif
ImGui::Text("Git Hash: %s", GIT_HASH);
ImGui::Text("Build Date: %s", BUILD_DATE);
}
ImGui::Spacing();
#endif
header("Platform");
{
ImGui::Text("CPU: %s",
Expand Down
3 changes: 3 additions & 0 deletions core/rend/gui_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ class GuiSettings
void settings_body_about(ImVec2 normal_padding);
void settings_body_video(ImVec2 normal_padding);
void settings_body_credits(ImVec2 normal_padding);

std::string update_channel = "";
std::string latest = "";
};

0 comments on commit fcd32f4

Please sign in to comment.