Skip to content

Commit

Permalink
Auto update (#61)
Browse files Browse the repository at this point in the history
* WIP: auto update

* Using sce mutex insted of std mutex

* Make network thread safe

* Fix re-entrant mutex usage in activity

* Reworked font

- Added methods to draw fonts and clip to rectangle.
- vita2d draws fonts relative to their baseline
  => added methods to compensate

* Improved mutex logging

* Update check + dialog

* Version creation tool fixed to use little endian

* Fix broken log function name format

Didn't handle functions correctly that returned std::*

* Fixed nan progress when downloading things

* Adding updater app

* Rename src/updater.* -> src/update.*

* DialogView: refactor macros to cpp + focus on up/down

* Lock PS and power buttons in updater app

* Update thread opens dialog on error (instead of crashing)

* Rename update thread Updater->Update

* Fix "have to close vhbb" popup when staring updater app

* Show plain background while updating

* Minor improvments in CMakeList

* adding compiled release files

* Fix version comparison only woriking on big endian

* Remove debug logging

* Start working threads (icon fetch etc) after update check is done

* Refactor std::string in macros to c-style strings

* Use shared_ptr for DialogViewResult + code style

* Only link debugnet in updater if enabled

* Add missing newlines

* Using YAML to store latest version + download url

* Make updater log to file

* Copy updater from resources instead of embedding it

* Improve misc code style

* Add fixme about merging the duplicate debug log sources together

* updater: fix style issues

* Remove unused Font::Draw()

* Rename Font::DrawFromBaseline to Font::Draw

* Update version YAML URL
  • Loading branch information
robsdedude authored and devnoname120 committed Jun 16, 2019
1 parent e88ee5a commit 356b65c
Show file tree
Hide file tree
Showing 50 changed files with 2,067 additions and 464 deletions.
402 changes: 225 additions & 177 deletions CMakeLists.txt

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions assets/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/updater/
Binary file added assets/spr/img_dialog_msg_bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/spr/img_dialog_msg_btn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/spr/img_dialog_msg_btn_active.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/spr/img_dialog_msg_btn_focus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/spr/img_updater_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions release/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!*
2 changes: 2 additions & 0 deletions release/version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
version: "00.83"
url: "https://github.com/devnoname120/vhbb/releases/download/0.83/VitaHBBrowser.vpk"
12 changes: 6 additions & 6 deletions src/Views/HomebrewView/homebrewView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,21 @@ HomebrewView::HomebrewView(Homebrew hb) :
img_preview_btn_download(Texture(&_binary_assets_spr_img_preview_btn_download_png_start)),
img_preview_btn_open(Texture(&_binary_assets_spr_img_preview_btn_open_png_start)),
hb_(hb),
img_icon(Texture(ICONS_FOLDER + "/" + hb.icon))
img_icon(Texture(std::string(ICONS_FOLDER "/") + hb.icon))
{
// FIXME Support more than 1 screenshot
if (!hb_.screenshots.empty()) {
std::string path = hb_.screenshots.at(0);
std::size_t found = path.find_last_of('/');
std::string filename = path.substr(found+1);

sceIoMkdir(SCREENSHOTS_FOLDER.c_str(), 0777);
sceIoMkdir(SCREENSHOTS_FOLDER, 0777);

try {
Network::get_instance()->Download(SERVER_BASE_URL + path, SCREENSHOTS_FOLDER + "/" + filename);
Network::get_instance()->Download(std::string(SERVER_BASE_URL) + path, std::string(SCREENSHOTS_FOLDER "/") + filename);
// FIXME Should give false to Texture() so as not to cache but for some reason the destructor is called and so the vita2d resource is freed (cf ~Texture())
screenshots.emplace_back(SCREENSHOTS_FOLDER + "/" + filename, false);
sceIoRemove((SCREENSHOTS_FOLDER + "/" + filename).c_str());
screenshots.emplace_back(std::string(SCREENSHOTS_FOLDER "/") + filename, false);
sceIoRemove((std::string(SCREENSHOTS_FOLDER "/") + filename).c_str());
} catch (const std::exception &ex) {
log_printf(DBG_ERROR, "Cannot download screenshot %s", path.c_str());
}
Expand Down Expand Up @@ -138,7 +138,7 @@ int HomebrewView::Display()
sb.Display();

img_preview_infobg.Draw(Point(HB_X, HB_Y + 300));

font_40.Draw(Point(HB_X + 225, HB_Y + 88), hb_.name, COLOR_WHITE);
font_25.Draw(Point(HB_X + 225, HB_Y + 115), hb_.author, COLOR_AQUA);
font_25.Draw(Point(HB_X + 225, HB_Y + 144), hb_.version, COLOR_WHITE);
Expand Down
37 changes: 19 additions & 18 deletions src/Views/IMEView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@

#include <utility>

#include <utility>

#include <utility>

#include "IMEView.h"


IMEView::IMEView() {
log_printf(DBG_DEBUG, "IMEView::IMEView()");
auto sce_common_dialog_config_param = SceCommonDialogConfigParam{};
sceCommonDialogSetConfigParam(&sce_common_dialog_config_param);
commonDialogSetConfig();
// FIXME HACK: when IMEView is passed to Activity::AddView() it's destroyed once the activity is closed
// Keeping an internal shared_ptr of itself makes sure that it's never destroyed
me_ptr = std::shared_ptr<IMEView>(this);
Expand All @@ -37,6 +32,12 @@ void IMEView::closeIMEView() {
void IMEView::prepare(std::shared_ptr<IMEViewResult> result, std::string title, std::string initialText,
SceUInt32 maxInputLength) {
log_printf(DBG_DEBUG, "Created IMEView \"%s\"", title.c_str());
if (_status == COMMON_DIALOG_STATUS_RUNNING) {
log_printf(DBG_WARNING, "Canceling current IMEView");
sceImeDialogTerm();
if (_result)
_result->status = COMMON_DIALOG_STATUS_CANCELED;
}
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> converter;
_title = converter.from_bytes(title);
_result = result;
Expand Down Expand Up @@ -89,37 +90,37 @@ int IMEView::Display() {
"https://github.com/vitasdk/vita-headers/blob/master/include/psp2/common_dialog.h",
res);
if (_result)
_result->status = IMEVIEW_STATUS_CANCELED;
_result->status = COMMON_DIALOG_STATUS_CANCELED;
request_destroy = true;
sceImeDialogTerm();
}
return 0;
}

auto new_status = (IMEViewStatus)sceImeDialogGetStatus();
auto new_status = (CommonDialogStatus)sceImeDialogGetStatus();
if (_status != new_status)
switch (new_status) {
case IMEVIEW_STATUS_NONE:
log_printf(DBG_DEBUG, "IMEView status \"IMEVIEW_STATUS_NONE\"");
case COMMON_DIALOG_STATUS_NONE:
log_printf(DBG_DEBUG, "IMEView status \"COMMON_DIALOG_STATUS_NONE\"");
break;
case IMEVIEW_STATUS_RUNNING:
log_printf(DBG_DEBUG, "IMEView status \"IMEVIEW_STATUS_RUNNING\"");
case COMMON_DIALOG_STATUS_RUNNING:
log_printf(DBG_DEBUG, "IMEView status \"COMMON_DIALOG_STATUS_RUNNING\"");
break;
case IMEVIEW_STATUS_FINISHED:
log_printf(DBG_DEBUG, "IMEView status \"IMEVIEW_STATUS_FINISHED\"");
case COMMON_DIALOG_STATUS_FINISHED:
log_printf(DBG_DEBUG, "IMEView status \"COMMON_DIALOG_STATUS_FINISHED\"");
break;
case IMEVIEW_STATUS_CANCELED:
log_printf(DBG_DEBUG, "IMEView status \"IMEVIEW_STATUS_CANCELED\"");
case COMMON_DIALOG_STATUS_CANCELED:
log_printf(DBG_DEBUG, "IMEView status \"COMMON_DIALOG_STATUS_CANCELED\"");
break;
}
_status = new_status;

if (_status == IMEVIEW_STATUS_FINISHED) {
if (_status == COMMON_DIALOG_STATUS_FINISHED) {
SceImeDialogResult result={};
sceImeDialogGetResult(&result);

if (result.button == SCE_IME_DIALOG_BUTTON_CLOSE)
_status = IMEVIEW_STATUS_CANCELED;
_status = COMMON_DIALOG_STATUS_CANCELED;
else {
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> converter;
_input_text_buffer_utf8 = converter.to_bytes((char16_t*)_input_text_buffer_utf16);
Expand Down
20 changes: 7 additions & 13 deletions src/Views/IMEView.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,15 @@
#include <codecvt>
#include <sys/socket.h>

#include <global_include.h>
#include <singleton.h>
#include <Views/View.h>
#include <activity.h>
#include "../global_include.h"
#include "commonDialog.h"
#include "../singleton.h"
#include "View.h"
#include "activity.h"


enum IMEViewStatus {
IMEVIEW_STATUS_NONE = SCE_COMMON_DIALOG_STATUS_NONE,
IMEVIEW_STATUS_RUNNING = SCE_COMMON_DIALOG_STATUS_RUNNING,
IMEVIEW_STATUS_FINISHED = SCE_COMMON_DIALOG_STATUS_FINISHED,
IMEVIEW_STATUS_CANCELED
};

struct IMEViewResult {
IMEViewStatus status = IMEVIEW_STATUS_NONE;
CommonDialogStatus status = COMMON_DIALOG_STATUS_NONE;
std::string userText = "";
};

Expand Down Expand Up @@ -48,7 +42,7 @@ class IMEView : Singleton<IMEView>, public View {
SceUInt32 _maxTextLength;
SceWChar16 *_input_text_buffer_utf16 = nullptr;
std::string _input_text_buffer_utf8;
IMEViewStatus _status = IMEVIEW_STATUS_NONE;
CommonDialogStatus _status = COMMON_DIALOG_STATUS_NONE;
std::shared_ptr<IMEViewResult> _result;
bool shown_dialog = false;
};
2 changes: 1 addition & 1 deletion src/Views/ListView/listItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ListItem::ListItem(Homebrew hb) :
font_32(Font(std::string(FONT_DIR "segoeui.ttf"), 32)),
img_itm_panel(Texture(&_binary_assets_spr_img_itm_panel_png_start)),
img_itm_panel_highlight(Texture(&_binary_assets_spr_img_itm_panel_highlight_png_start)),
img_icon_(Texture(ICONS_FOLDER + "/" + hb.icon)),
img_icon_(Texture(std::string(ICONS_FOLDER "/") + hb.icon)),
img_itm_label_game(Texture(&_binary_assets_spr_img_itm_label_game_png_start)),
img_itm_label_port(Texture(&_binary_assets_spr_img_itm_label_port_png_start)),
img_itm_label_emu(Texture(&_binary_assets_spr_img_itm_label_emu_png_start)),
Expand Down
8 changes: 4 additions & 4 deletions src/Views/ListView/searchView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ void SearchView::startSearch() {

void SearchView::SignalSelected() {
log_printf(DBG_DEBUG, "SearchView::SignalSelected");
if (_ime_search_view_result->status != IMEVIEW_STATUS_RUNNING)
if (_ime_search_view_result->status != COMMON_DIALOG_STATUS_RUNNING)
startSearch();
}

Expand All @@ -19,11 +19,11 @@ void SearchView::SignalDeselected() {
}

bool SearchView::IsReadyToShow() {
return _ime_search_view_result->status == IMEVIEW_STATUS_FINISHED;
return _ime_search_view_result->status == COMMON_DIALOG_STATUS_FINISHED;
}

int SearchView::Display() {
if (_ime_search_view_result->status == IMEVIEW_STATUS_FINISHED) {
if (_ime_search_view_result->status == COMMON_DIALOG_STATUS_FINISHED) {
log_printf(DBG_DEBUG, "Processing finished search dialog: \"%s\"", _ime_search_view_result->userText.c_str());
if (lastQuery != _ime_search_view_result->userText) {
auto db = Database::get_instance();
Expand All @@ -37,7 +37,7 @@ int SearchView::Display() {
} else {
log_printf(DBG_DEBUG, "Ignore search: same filter as before");
}
_ime_search_view_result->status = IMEVIEW_STATUS_NONE;
_ime_search_view_result->status = COMMON_DIALOG_STATUS_NONE;
}
return ListView::Display();
}
19 changes: 14 additions & 5 deletions src/Views/ProgressView/progressView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,21 @@ extern unsigned char _binary_assets_spr_img_dialog_btn_png_start;


ProgressView::ProgressView(InfoProgress progress, Homebrew hb) :
progress_(std::move(progress)),
hb_(std::move(hb)),
ProgressView(std::move(progress), hb.name, std::string(ICONS_FOLDER "/") + hb.icon)
{
}

ProgressView::ProgressView(InfoProgress progress, std::string hb_name, std::string icon_path) :
ProgressView(std::move(progress), std::move(hb_name), Texture(icon_path))
{
}
ProgressView::ProgressView(InfoProgress progress, std::string hb_name, Texture icon_texture) :
hb_name(std::move(hb_name)),
progress_(std::move(progress)),
font_24(Font(std::string(FONT_DIR "segoeui.ttf"), 24)),
//thid_(thid),
img_icon(Texture(ICONS_FOLDER + "/" + hb_.icon)),
img_dialog_progress_bg(Texture(&_binary_assets_spr_img_dialog_progress_bg_png_start)),
img_icon(icon_texture),
img_dialog_progress_bg(Texture(&_binary_assets_spr_img_dialog_progress_bg_png_start)),
img_dialog_progress_bar(Texture(&_binary_assets_spr_img_dialog_progress_bar_png_start)),
img_dialog_progress_bar_glow(Texture(&_binary_assets_spr_img_dialog_progress_bar_glow_png_start)),
img_dialog_btn(Texture(&_binary_assets_spr_img_dialog_btn_png_start))
Expand All @@ -40,7 +49,7 @@ int ProgressView::Display()
// Background
img_dialog_progress_bg.Draw(Point(PROGRESS_VIEW_X, PROGRESS_VIEW_Y));
// Name
font_24.Draw(Point(PROGRESS_VIEW_X + 197, PROGRESS_VIEW_Y + 53), hb_.name);
font_24.Draw(Point(PROGRESS_VIEW_X + 197, PROGRESS_VIEW_Y + 53), hb_name);
// Message
font_24.Draw(Point(PROGRESS_VIEW_X + 197, PROGRESS_VIEW_Y + 117), progress_.message());
// Progress bar
Expand Down
5 changes: 4 additions & 1 deletion src/Views/ProgressView/progressView.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,19 @@
class ProgressView: public View {
public:
ProgressView(InfoProgress progress, Homebrew hb);
ProgressView(InfoProgress progress, std::string hb_name, std::string icon_path);
ProgressView(InfoProgress progress, std::string hb_name, Texture icon_texture);

int HandleInput(int focus, const Input& input) override;
int Display() override;
// Wait in millisecond
void Finish(unsigned int wait = 300);

std::string hb_name;
private:
uint32_t finish_tick = 0;

InfoProgress progress_;
Homebrew hb_;

Font font_24;
Texture img_icon;
Expand Down
20 changes: 20 additions & 0 deletions src/Views/commonDialog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# pragma once

#include "../global_include.h"

enum CommonDialogStatus {
COMMON_DIALOG_STATUS_NONE = SCE_COMMON_DIALOG_STATUS_NONE,
COMMON_DIALOG_STATUS_RUNNING = SCE_COMMON_DIALOG_STATUS_RUNNING,
COMMON_DIALOG_STATUS_FINISHED = SCE_COMMON_DIALOG_STATUS_FINISHED,
COMMON_DIALOG_STATUS_CANCELED
};

inline void commonDialogSetConfig() {
SceCommonDialogConfigParam sce_common_dialog_config_param;
sceCommonDialogConfigParamInit(&sce_common_dialog_config_param);
sce_common_dialog_config_param.language = SCE_SYSTEM_PARAM_LANG_ENGLISH_US;
sce_common_dialog_config_param.enterButtonAssign = SCE_SYSTEM_PARAM_ENTER_BUTTON_CROSS;
int res = sceCommonDialogSetConfigParam(&sce_common_dialog_config_param);
if (res)
log_printf(DBG_ERROR, "sceCommonDialogSetConfigParam failed: %0.8x", res);
};
Loading

0 comments on commit 356b65c

Please sign in to comment.