gui: refactor open path.

- fix open folder when using space.
This commit is contained in:
Zangetsu38 2021-07-29 20:30:45 +02:00 committed by Nicolas Jallamion
parent 96d5dba963
commit 0058459cea
8 changed files with 43 additions and 119 deletions

View File

@ -71,6 +71,7 @@ void init_user(GuiState &gui, HostState &host, const std::string &user_id);
void init_user_app(GuiState &gui, HostState &host, const std::string &app_path);
bool init_user_background(GuiState &gui, HostState &host, const std::string &user_id, const std::string &background_path);
bool init_user_start_background(GuiState &gui, const std::string &image_path);
void open_path(const std::string &path);
void open_trophy_unlocked(GuiState &gui, HostState &host, const std::string &np_com_id, const std::string &trophy_id);
void open_user(GuiState &gui, HostState &host);
void pre_load_app(GuiState &gui, HostState &host, bool live_area, const std::string &app_path);

View File

@ -21,18 +21,8 @@
#include <config/version.h>
#include <sstream>
namespace gui {
#ifdef _WIN32
static const char OS_PREFIX[] = "start ";
#elif __APPLE__
static const char OS_PREFIX[] = "open ";
#else
static const char OS_PREFIX[] = "xdg-open ";
#endif
void draw_about_dialog(GuiState &gui, HostState &host) {
ImGui::SetNextWindowPos(ImVec2(ImGui::GetIO().DisplaySize.x / 2.f, ImGui::GetIO().DisplaySize.y / 2.f), ImGuiCond_Always, ImVec2(0.5f, 0.5f));
ImGui::Begin("About", &gui.help_menu.about_dialog, ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_AlwaysAutoResize);
@ -49,29 +39,18 @@ void draw_about_dialog(GuiState &gui, HostState &host) {
ImGui::Text("If you'd like to show your support to the project, you can donate to our Patreon:");
std::ostringstream link;
if (ImGui::Button("patreon.com/vita3k")) {
std::string patreon_url = "https://patreon.com/vita3k";
link << OS_PREFIX << patreon_url;
system(link.str().c_str());
}
if (ImGui::Button("Patreon"))
open_path("https://patreon.com/vita3k");
ImGui::Text("Or if you're interested in contributing, check out our Github:");
if (ImGui::Button("github.com/vita3k/vita3k")) {
std::string github_url = "https://github.com/vita3k/vita3k";
link << OS_PREFIX << github_url;
system(link.str().c_str());
}
if (ImGui::Button("Github"))
open_path("https://github.com/vita3k/vita3k");
ImGui::Text("Visit our website for more info:");
if (ImGui::Button("vita3k.org")) {
std::string website_url = "https://vita3k.org";
link << OS_PREFIX << website_url;
system(link.str().c_str());
}
if (ImGui::Button("vita3k.org"))
open_path("https://vita3k.org");
ImGui::End();
}

View File

@ -23,7 +23,6 @@
#include <util/safe_time.h>
#include <pugixml.hpp>
#include <sstream>
namespace gui {
@ -74,14 +73,6 @@ static bool get_update_history(GuiState &gui, HostState &host, const std::string
return !update_history_infos.empty();
}
#ifdef _WIN32
static const char OS_PREFIX[] = "start \"Vita3K\" ";
#elif __APPLE__
static const char OS_PREFIX[] = "open ";
#else
static const char OS_PREFIX[] = "xdg-open ";
#endif
static std::vector<TimeApp>::iterator get_time_app_index(GuiState &gui, HostState &host, const std::string &app) {
const auto time_app_index = std::find_if(gui.time_apps[host.io.user_id].begin(), gui.time_apps[host.io.user_id].end(), [&](const TimeApp &t) {
return t.app == app;
@ -230,6 +221,18 @@ void delete_app(GuiState &gui, HostState &host, const std::string &app_path) {
}
}
void open_path(const std::string &path) {
#ifdef _WIN32
static const char OS_PREFIX[] = "start \"Vita3K\" ";
#elif __APPLE__
static const char OS_PREFIX[] = "open ";
#else
static const char OS_PREFIX[] = "xdg-open ";
#endif
system((OS_PREFIX + ("\"" + path + "\"")).c_str());
}
static std::string context_dialog;
static auto information = false;
@ -260,7 +263,7 @@ void draw_app_context_menu(GuiState &gui, HostState &host, const std::string &ap
if (title_id.find("NPXS") == std::string::npos) {
if (ImGui::MenuItem("Check App Compatibility")) {
const std::string compat_url = title_id.find("PCS") != std::string::npos ? "https://vita3k.org/compatibility?g=" + title_id : "https://github.com/Vita3K/homebrew-compatibility/issues?q=" + APP_INDEX->title;
system((OS_PREFIX + compat_url).c_str());
open_path(compat_url);
}
if (ImGui::BeginMenu("Copy App Info")) {
if (ImGui::MenuItem("ID and Name")) {
@ -294,20 +297,20 @@ void draw_app_context_menu(GuiState &gui, HostState &host, const std::string &ap
}
if (ImGui::BeginMenu("Open Folder")) {
if (ImGui::MenuItem("Application"))
system((OS_PREFIX + ("\"" + APP_PATH.string() + "\"")).c_str());
open_path(APP_PATH.string());
if (fs::exists(DLC_PATH) && ImGui::MenuItem("Dlc"))
system((OS_PREFIX + DLC_PATH.string()).c_str());
open_path(DLC_PATH.string());
if (fs::exists(LICENSE_PATH) && ImGui::MenuItem("License"))
system((OS_PREFIX + LICENSE_PATH.string()).c_str());
open_path(LICENSE_PATH.string());
if (fs::exists(SAVE_DATA_PATH) && ImGui::MenuItem("Save Data"))
system((OS_PREFIX + SAVE_DATA_PATH.string()).c_str());
open_path(SAVE_DATA_PATH.string());
if (ImGui::MenuItem("Shader Cache")) {
if (!fs::exists(SHADER_CACHE_PATH))
fs::create_directories(SHADER_CACHE_PATH);
system((OS_PREFIX + SHADER_CACHE_PATH.string()).c_str());
open_path(SHADER_CACHE_PATH.string());
}
if (fs::exists(SHADER_LOG_PATH) && ImGui::MenuItem("Shader Log"))
system((OS_PREFIX + SHADER_LOG_PATH.string()).c_str());
open_path(SHADER_LOG_PATH.string());
ImGui::EndMenu();
}
if (!host.cfg.show_live_area_screen && ImGui::MenuItem("Live Area", nullptr, &gui.live_area.live_area_screen))

View File

@ -29,7 +29,6 @@
#include <pugixml.hpp>
#include <chrono>
#include <sstream>
#include <stb_image.h>
namespace gui {
@ -362,14 +361,6 @@ bool get_sys_apps_state(GuiState &gui) {
return !gui.live_area.content_manager && !gui.live_area.settings && !gui.live_area.trophy_collection && !gui.live_area.manual && !gui.live_area.user_management;
}
#ifdef _WIN32
static const char OS_PREFIX[] = "start ";
#elif __APPLE__
static const char OS_PREFIX[] = "open ";
#else
static const char OS_PREFIX[] = "xdg-open ";
#endif
struct FRAME {
std::string id;
std::string multi;
@ -1018,7 +1009,7 @@ void draw_live_area_screen(GuiState &gui, HostState &host) {
ImGui::SetCursorPos(pos_frame);
ImGui::PushID(frame.id.c_str());
if (ImGui::Selectable("##target_link", false, ImGuiSelectableFlags_None, scal_size_frame))
system((OS_PREFIX + target[app_path][frame.id]).c_str());
open_path(target[app_path][frame.id]);
ImGui::PopID();
}
@ -1291,7 +1282,7 @@ void draw_live_area_screen(GuiState &gui, HostState &host) {
if (ImGui::Selectable("##Search", ImGuiSelectableFlags_None, false, widget_scal_size)) {
auto search_url = "http://www.google.com/search?q=" + get_app_index(gui, app_path)->title;
std::replace(search_url.begin(), search_url.end(), ' ', '+');
system((OS_PREFIX + search_url).c_str());
open_path(search_url);
}
if (fs::exists(manual_path) && !fs::is_empty(manual_path)) {

View File

@ -21,23 +21,14 @@
#include "private.h"
#ifdef _WIN32
static const char OS_PREFIX[] = "start ";
#elif __APPLE__
static const char OS_PREFIX[] = "open ";
#else
static const char OS_PREFIX[] = "xdg-open ";
#endif
namespace gui {
static void draw_file_menu(GuiState &gui, HostState &host) {
auto lang = gui.lang.main_menubar;
const auto is_lang = !lang.empty();
if (ImGui::BeginMenu(is_lang ? lang["file"].c_str() : "File")) {
if (ImGui::MenuItem(is_lang ? lang["open_pref_path"].c_str() : "Open Pref Path")) {
system((OS_PREFIX + string_utils::wide_to_utf(host.pref_path)).c_str());
}
if (ImGui::MenuItem(is_lang ? lang["open_pref_path"].c_str() : "Open Pref Path"))
open_path(string_utils::wide_to_utf(host.pref_path));
ImGui::Separator();
ImGui::MenuItem(is_lang ? lang["install_firmware"].c_str() : "Install Firmware", nullptr, &gui.file_menu.firmware_install_dialog);
ImGui::MenuItem(is_lang ? lang["install_pkg"].c_str() : "Install .pkg", nullptr, &gui.file_menu.pkg_install_dialog);

View File

@ -40,14 +40,6 @@
namespace gui {
#ifdef _WIN32
static const char OS_PREFIX[] = "start ";
#elif __APPLE__
static const char OS_PREFIX[] = "open ";
#else
static const char OS_PREFIX[] = "xdg-open ";
#endif
static Config::CurrentConfig config;
static void get_modules_list(GuiState &gui, HostState &host) {
@ -275,7 +267,6 @@ void draw_settings_dialog(GuiState &gui, HostState &host) {
ImGui::Separator();
ImGui::SetWindowFontScale(1.f);
ImGui::BeginTabBar("SettingsTabBar", ImGuiTabBarFlags_None);
std::ostringstream link;
// Core
if (ImGui::BeginTabItem("Core")) {
@ -333,11 +324,8 @@ void draw_settings_dialog(GuiState &gui, HostState &host) {
ImGui::SameLine();
} else {
ImGui::TextColored(GUI_COLOR_TEXT, "No modules present.\nPlease download and install the last firmware.");
if (ImGui::Button("Download Firmware")) {
std::string firmware_url = "https://www.playstation.com/en-us/support/hardware/psvita/system-software/";
link << OS_PREFIX << firmware_url;
system(link.str().c_str());
}
if (ImGui::Button("Download Firmware"))
open_path("https://www.playstation.com/en-us/support/hardware/psvita/system-software/");
}
if (ImGui::Button("Refresh list"))
get_modules_list(gui, host);
@ -519,10 +507,8 @@ void draw_settings_dialog(GuiState &gui, HostState &host) {
ImGui::SetTooltip("Check this box to enable font support for Korean and Traditional Chinese.\nEnabling this will use more memory and will require you to restart the emulator.");
} else {
ImGui::TextColored(GUI_COLOR_TEXT, "No firmware font package present.\nPlease download and install it.");
if (ImGui::Button("Download firmware font package")) {
link << OS_PREFIX << "https://bit.ly/2P2rb0r";
system(link.str().c_str());
}
if (ImGui::Button("Download firmware font package"))
open_path("https://bit.ly/2P2rb0r");
if (ImGui::IsItemHovered())
ImGui::SetTooltip("Firmware font package is mandatory for some applications and also for asian region font support in gui.\nIt is also generally recommended for gui");
}

View File

@ -211,14 +211,6 @@ void clear_temp(GuiState &gui) {
user_id.clear();
}
#ifdef _WIN32
static const char OS_PREFIX[] = "start ";
#elif __APPLE__
static const char OS_PREFIX[] = "open ";
#else
static const char OS_PREFIX[] = "xdg-open ";
#endif
void draw_user_management(GuiState &gui, HostState &host) {
const auto display_size = ImGui::GetIO().DisplaySize;
const auto RES_SCALE = ImVec2(display_size.x / host.res_width_dpi_scale, display_size.y / host.res_height_dpi_scale);
@ -335,7 +327,7 @@ void draw_user_management(GuiState &gui, HostState &host) {
ImGui::PopStyleColor();
if (ImGui::BeginPopupContextItem("##user_context_menu")) {
if (ImGui::MenuItem("Open User Folder"))
system((OS_PREFIX + (user_path / user.first).string()).c_str());
open_path((user_path / user.first).string());
ImGui::EndPopup();
}
ImGui::PopID();

View File

@ -21,20 +21,9 @@
#include "private.h"
#include <sstream>
namespace gui {
#ifdef _WIN32
static const char OS_PREFIX[] = "start ";
#elif __APPLE__
static const char OS_PREFIX[] = "open ";
#else
static const char OS_PREFIX[] = "xdg-open ";
#endif
void draw_welcome_dialog(GuiState &gui, HostState &host) {
std::ostringstream link;
ImGui::SetNextWindowPos(ImVec2(ImGui::GetIO().DisplaySize.x / 2.f, ImGui::GetIO().DisplaySize.y / 2.f), ImGuiCond_Always, ImVec2(0.5f, 0.5f));
ImGui::PushStyleColor(ImGuiCol_Text, GUI_COLOR_TEXT_MENUBAR);
ImGui::Begin("Welcome to Vita3K", &gui.help_menu.welcome_dialog, ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_AlwaysAutoResize);
@ -50,19 +39,15 @@ void draw_welcome_dialog(GuiState &gui, HostState &host) {
ImGui::TextColored(GUI_COLOR_TEXT, "\nA comprehensive guide on how to set-up Vita3K can be found on the");
ImGui::SameLine();
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 9.f);
if (ImGui::Button("Quickstart")) {
link << OS_PREFIX << "https://vita3k.org/quickstart.html";
system(link.str().c_str());
}
if (ImGui::Button("Quickstart"))
open_path("https://vita3k.org/quickstart.html");
ImGui::SameLine();
ImGui::TextColored(GUI_COLOR_TEXT, "page.");
ImGui::TextColored(GUI_COLOR_TEXT, "Consult the Commercial game");
ImGui::SameLine();
ImGui::SetCursorPosY(ImGui::GetCursorPosY() - 4.f);
if (ImGui::Button("compatibility")) {
link << OS_PREFIX << "https://vita3k.org/compatibility.html";
system(link.str().c_str());
}
if (ImGui::Button("compatibility"))
open_path("https://vita3k.org/compatibility.html");
ImGui::SameLine();
ImGui::TextColored(GUI_COLOR_TEXT, "list and the Homebrew compatibility list to see what runs.");
ImGui::Spacing();
@ -70,17 +55,13 @@ void draw_welcome_dialog(GuiState &gui, HostState &host) {
ImGui::TextColored(GUI_COLOR_TEXT, "\nAdditional support can be found in the #help channel of the");
ImGui::SameLine();
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 9.f);
if (ImGui::Button("Discord")) {
link << OS_PREFIX << "https://discord.gg/6aGwQzh";
system(link.str().c_str());
}
if (ImGui::Button("Discord"))
open_path("https://discord.gg/6aGwQzh");
ImGui::TextColored(GUI_COLOR_TEXT, "Support us on");
ImGui::SameLine();
ImGui::SetCursorPosY(ImGui::GetCursorPosY() - 4.f);
if (ImGui::Button("Patreon")) {
link << OS_PREFIX << "https://patreon.com/vita3k";
system(link.str().c_str());
}
if (ImGui::Button("Patreon"))
open_path("https://patreon.com/vita3k");
ImGui::Spacing();
ImGui::TextColored(GUI_COLOR_TEXT, "Vita3K does not condone piracy. You must dump your own games.");
ImGui::Spacing();