Skip to content

Commit

Permalink
vita3k: refactor app path, support other app partitions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zangetsu38 committed Nov 4, 2024
1 parent 527eb4e commit f77659f
Show file tree
Hide file tree
Showing 44 changed files with 569 additions and 314 deletions.
6 changes: 4 additions & 2 deletions vita3k/compat/src/compat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,10 @@ bool load_app_compat_db(GuiState &gui, EmuEnvState &emuenv) {
}

// Update compatibility status of all user apps
for (auto &app : gui.app_selector.user_apps)
app.compat = gui.compat.app_compat_db.contains(app.title_id) ? gui.compat.app_compat_db[app.title_id].state : CompatibilityState::UNKNOWN;
for (auto &apps : gui.app_selector.vita_apps) {
for (auto &app : apps.second)
app.compat = gui.compat.app_compat_db.contains(app.title_id) ? gui.compat.app_compat_db[app.title_id].state : CompatibilityState::UNKNOWN;
}

return !gui.compat.app_compat_db.empty();
}
Expand Down
2 changes: 2 additions & 0 deletions vita3k/config/include/config/state.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ struct Config : YamlLoader {
fullscreen = rhs.fullscreen;
console = rhs.console;
app_args = rhs.app_args;
app_device = rhs.app_device;
load_app_list = rhs.load_app_list;
self_path = rhs.self_path;
}
Expand All @@ -101,6 +102,7 @@ struct Config : YamlLoader {
// Setting not present in the YAML file
fs::path config_path = {};
std::string app_args;
std::string app_device;
std::string self_path;
bool overwrite_config = true;
bool load_config = false;
Expand Down
19 changes: 17 additions & 2 deletions vita3k/config/src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,14 @@ ExitCode init_config(Config &cfg, int argc, char **argv, const Root &root_paths)
->default_val(false)->group("Input");
input->add_option("--app-args,-Z", command_line.app_args, "Argument for app, use ', ' to separate arguments.")
->default_str("")->group("Input");
input->add_option("--app-device,-D", command_line.app_device, "App device")
->default_val("ux0")->group("Input");
input->add_option("--load-app-list,-a", command_line.load_app_list, "Starts the emulator with load app list.")
->default_val(false)->group("Input");
input->add_option("--self,-S", command_line.self_path, "Path to the self to run inside Title ID")
->default_str("eboot.bin")->group("Input");
input->add_option("--installed-path,-r", command_line.run_app_path, "Path to the installed app to run")
->default_str({})->check(CLI::IsMember(get_file_set(cfg.get_pref_path() / "ux0/app")))->group("Input");
->default_str({})->group("Input");
input->add_option("--recompile-shader,-s", command_line.recompile_shader_path, "Recompile the given PS Vita shader (GXP format) to SPIR_V / GLSL and quit")
->default_str({})->group("Input");
input->add_option("--deleted-id,-d", command_line.delete_title_id, "Title ID of installed app to delete")
Expand Down Expand Up @@ -208,7 +210,20 @@ ExitCode init_config(Config &cfg, int argc, char **argv, const Root &root_paths)
std::cout << window_title << std::endl;
return QuitRequested;
}

if (command_line.run_app_path.has_value()) {
const std::string app_path = command_line.run_app_path.value();
std::set<std::string> exist_apps = get_file_set(fs::path(cfg.pref_path) / command_line.app_device / "app");
if (exist_apps.find(app_path) == exist_apps.end()) {
std::cout << "--installed-path: " << app_path << " no in {";
for (auto &app : exist_apps) {
std::cout << app;
if (app != *exist_apps.rbegin())
std::cout << ", ";
}
std::cout << "}" << std::endl;
return InitConfigFailed;
}
}
if (command_line.recompile_shader_path.has_value()) {
cfg.recompile_shader_path = std::move(command_line.recompile_shader_path);
return QuitRequested;
Expand Down
1 change: 1 addition & 0 deletions vita3k/emuenv/include/emuenv/state.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ struct EmuEnvState {
fs::path static_assets_path{};
fs::path shared_path{};
bool load_exec{};
std::string load_app_device{};
std::string load_app_path{};
std::string load_exec_argv{};
std::string load_exec_path{};
Expand Down
7 changes: 4 additions & 3 deletions vita3k/gui/include/gui/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void browse_live_area_apps_list(GuiState &gui, EmuEnvState &emuenv, const uint32
void browse_pages_manual(GuiState &gui, EmuEnvState &emuenv, const uint32_t button);
void browse_save_data_dialog(GuiState &gui, EmuEnvState &emuenv, const uint32_t button);
void browse_users_management(GuiState &gui, EmuEnvState &emuenv, const uint32_t button);
void close_and_run_new_app(GuiState &gui, EmuEnvState &emuenv, const std::string &app_path);
void close_and_run_new_app(EmuEnvState &emuenv, const std::string &app_path);
void close_live_area_app(GuiState &gui, EmuEnvState &emuenv, const std::string &app_path);
void close_system_app(GuiState &gui, EmuEnvState &emuenv);
void delete_app(GuiState &gui, EmuEnvState &emuenv, const std::string &app_path);
Expand Down Expand Up @@ -69,12 +69,13 @@ std::string get_sys_lang_name(uint32_t lang_id);
void init(GuiState &gui, EmuEnvState &emuenv);
void init_app_background(GuiState &gui, EmuEnvState &emuenv, const std::string &app_path);
void init_app_icon(GuiState &gui, EmuEnvState &emuenv, const std::string &app_path);
void init_apps_icon(GuiState &gui, EmuEnvState &emuenv, const std::vector<gui::App> &app_list);
void init_apps_icon(GuiState &gui, EmuEnvState &emuenv, const std::vector<gui::App> &apps_list);
bool init_bgm(EmuEnvState &emuenv, const std::pair<std::string, std::string> path_bgm);
void init_bgm_player(const float vol);
void init_config(GuiState &gui, EmuEnvState &emuenv, const std::string &app_path);
void init_content_manager(GuiState &gui, EmuEnvState &emuenv);
vfs::FileBuffer init_default_icon(GuiState &gui, EmuEnvState &emuenv);
void init_fw_apps(GuiState &gui, EmuEnvState &emuenv);
void init_home(GuiState &gui, EmuEnvState &emuenv);
void init_live_area(GuiState &gui, EmuEnvState &emuenv, const std::string &app_path);
bool init_manual(GuiState &gui, EmuEnvState &emuenv, const std::string &app_path);
Expand All @@ -85,11 +86,11 @@ void init_last_time_apps(GuiState &gui, EmuEnvState &emuenv);
void init_trophy_collection(GuiState &gui, EmuEnvState &emuenv);
void init_user(GuiState &gui, EmuEnvState &emuenv, const std::string &user_id);
void init_user_app(GuiState &gui, EmuEnvState &emuenv, const std::string &app_path);
void init_user_apps(GuiState &gui, EmuEnvState &emuenv);
bool init_user_background(GuiState &gui, EmuEnvState &emuenv, const std::string &background_path);
bool init_user_backgrounds(GuiState &gui, EmuEnvState &emuenv);
void init_user_management(GuiState &gui, EmuEnvState &emuenv);
bool init_user_start_background(GuiState &gui, const std::string &image_path);
void init_vita_apps(GuiState &gui, EmuEnvState &emuenv);
void load_and_update_compat_user_apps(GuiState &gui, EmuEnvState &emuenv);
void open_live_area(GuiState &gui, EmuEnvState &emuenv, const std::string &app_path);
void open_manual(GuiState &gui, EmuEnvState &emuenv, const std::string &app_path);
Expand Down
8 changes: 4 additions & 4 deletions vita3k/gui/include/gui/state.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ struct IconAsyncLoader {
};

struct AppsSelector {
std::vector<App> sys_apps;
std::vector<App> user_apps;
std::vector<App> emu_apps;
std::map<std::string, std::vector<App>> vita_apps;
uint32_t apps_cache_lang;
AppInfo app_info;
std::optional<IconAsyncLoader> icon_async_loader;
std::map<std::string, ImGui_Texture> sys_apps_icon;
std::map<std::string, ImGui_Texture> user_apps_icon;
std::map<std::string, ImGui_Texture> emu_apps_icon;
std::map<std::string, ImGui_Texture> vita_apps_icon;
bool is_app_list_sorted{ false };
std::map<SortType, SortState> app_list_sorted;
};
Expand Down
30 changes: 18 additions & 12 deletions vita3k/gui/src/app_context_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@

#include <config/state.h>
#include <config/version.h>

#include <dialog/state.h>
#include <gui/functions.h>

#include <include/cpu.h>
#include <include/environment.h>

#include <io/functions.h>
#include <io/state.h>

#include <renderer/state.h>

#include <util/log.h>
Expand Down Expand Up @@ -97,7 +102,7 @@ static bool get_update_history(GuiState &gui, EmuEnvState &emuenv, const std::st

std::vector<TimeApp>::iterator get_time_app_index(GuiState &gui, EmuEnvState &emuenv, const std::string &app) {
const auto time_app_index = std::find_if(gui.time_apps[emuenv.io.user_id].begin(), gui.time_apps[emuenv.io.user_id].end(), [&](const TimeApp &t) {
return t.app == app;
return t.app == fs::path(app).stem().string();
});

return time_app_index;
Expand Down Expand Up @@ -205,7 +210,7 @@ void update_last_time_app_used(GuiState &gui, EmuEnvState &emuenv, const std::st
if (time_app_index != gui.time_apps[emuenv.io.user_id].end())
time_app_index->last_time_used = std::time(nullptr);
else
gui.time_apps[emuenv.io.user_id].push_back({ app, std::time(nullptr), 0 });
gui.time_apps[emuenv.io.user_id].push_back({ fs::path(app).stem().string(), std::time(nullptr), 0 });

get_app_index(gui, app)->last_time = std::time(nullptr);
if (gui.users[emuenv.io.user_id].sort_apps_type == LAST_TIME)
Expand All @@ -216,11 +221,12 @@ void update_last_time_app_used(GuiState &gui, EmuEnvState &emuenv, const std::st

void delete_app(GuiState &gui, EmuEnvState &emuenv, const std::string &app_path) {
const auto APP_INDEX = get_app_index(gui, app_path);
const auto &APP = fs::path(app_path).stem().string();
const auto &title_id = APP_INDEX->title_id;
try {
fs::remove_all(emuenv.pref_path / "ux0/app" / app_path);
fs::remove_all(emuenv.pref_path / "ux0/app" / APP);

const auto CUSTOM_CONFIG_PATH{ emuenv.config_path / "config" / fmt::format("config_{}.xml", app_path) };
const auto CUSTOM_CONFIG_PATH{ emuenv.config_path / "config" / fmt::format("config_{}.xml", APP) };
if (fs::exists(CUSTOM_CONFIG_PATH))
fs::remove_all(CUSTOM_CONFIG_PATH);
const auto ADDCONT_PATH{ emuenv.pref_path / "ux0/addcont" / APP_INDEX->addcont };
Expand Down Expand Up @@ -251,9 +257,9 @@ void delete_app(GuiState &gui, EmuEnvState &emuenv, const std::string &app_path)
if (fs::exists(IMPORT_TEXTURES_PATH))
fs::remove_all(IMPORT_TEXTURES_PATH);

if (gui.app_selector.user_apps_icon.contains(app_path)) {
gui.app_selector.user_apps_icon[app_path] = {};
gui.app_selector.user_apps_icon.erase(app_path);
if (gui.app_selector.vita_apps_icon.contains(app_path)) {
gui.app_selector.vita_apps_icon[app_path] = {};
gui.app_selector.vita_apps_icon.erase(app_path);
}

const auto time_app_index = get_time_app_index(gui, emuenv, app_path);
Expand All @@ -267,7 +273,7 @@ void delete_app(GuiState &gui, EmuEnvState &emuenv, const std::string &app_path)

LOG_INFO("Application successfully deleted '{} [{}]'.", title_id, APP_INDEX->title);

gui.app_selector.user_apps.erase(gui.app_selector.user_apps.begin() + (APP_INDEX - &gui.app_selector.user_apps[0]));
gui.app_selector.vita_apps["ux0"].erase(gui.app_selector.vita_apps["ux0"].begin() + (APP_INDEX - gui.app_selector.vita_apps["ux0"].data()));

save_apps_cache(gui, emuenv);
} catch (std::exception &e) {
Expand Down Expand Up @@ -299,8 +305,8 @@ void draw_app_context_menu(GuiState &gui, EmuEnvState &emuenv, const std::string
const auto APP_INDEX = get_app_index(gui, app_path);
const auto &title_id = APP_INDEX->title_id;

const auto APP_PATH{ emuenv.pref_path / "ux0/app" / app_path };
const auto CUSTOM_CONFIG_PATH{ emuenv.config_path / "config" / fmt::format("config_{}.xml", app_path) };
const auto APP_PATH{ emuenv.pref_path / convert_path(app_path) };
const auto CUSTOM_CONFIG_PATH{ emuenv.config_path / "config" / fmt::format("config_{}.xml", fs::path(app_path).stem().string()) };
const auto ADDCONT_PATH{ emuenv.pref_path / "ux0/addcont" / APP_INDEX->addcont };
const auto LICENSE_PATH{ emuenv.pref_path / "ux0/license" / title_id };
const auto MANUAL_PATH{ APP_PATH / "sce_sys/manual" };
Expand Down Expand Up @@ -571,11 +577,11 @@ void draw_app_context_menu(GuiState &gui, EmuEnvState &emuenv, const std::string
} else {
// Delete Data
const auto ICON_MARGIN = 24.f * SCALE.y;
if (gui.app_selector.user_apps_icon.contains(title_id)) {
if (gui.app_selector.vita_apps_icon.contains(title_id)) {
ImGui::SetCursorPos(ImVec2((WINDOW_SIZE.x / 2.f) - (PUPOP_ICON_SIZE.x / 2.f), ICON_MARGIN));
const auto POS_MIN = ImGui::GetCursorScreenPos();
const ImVec2 POS_MAX(POS_MIN.x + PUPOP_ICON_SIZE.x, POS_MIN.y + PUPOP_ICON_SIZE.y);
ImGui::GetWindowDrawList()->AddImageRounded(gui.app_selector.user_apps_icon[title_id], POS_MIN, POS_MAX, ImVec2(0, 0), ImVec2(1, 1), IM_COL32_WHITE, PUPOP_ICON_SIZE.x * SCALE.x, ImDrawFlags_RoundCornersAll);
ImGui::GetWindowDrawList()->AddImageRounded(gui.app_selector.vita_apps_icon[title_id], POS_MIN, POS_MAX, ImVec2(0, 0), ImVec2(1, 1), IM_COL32_WHITE, PUPOP_ICON_SIZE.x * SCALE.x, ImDrawFlags_RoundCornersAll);
}
ImGui::SetWindowFontScale(1.6f * RES_SCALE.x);
ImGui::SetCursorPos(ImVec2((WINDOW_SIZE.x / 2.f) - (ImGui::CalcTextSize(APP_INDEX->stitle.c_str()).x / 2.f), ICON_MARGIN + PUPOP_ICON_SIZE.y + (4.f * SCALE.y)));
Expand Down
2 changes: 1 addition & 1 deletion vita3k/gui/src/common_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static void draw_ime_dialog(EmuEnvState &emuenv, DialogState &common_dialog, flo
}
ImGui::SameLine();
auto &common = common_dialog.lang.common;
if (ImGui::Button(common["submit"].c_str()) || ImGui::IsKeyPressed(static_cast<ImGuiKey>(emuenv.cfg.keyboard_button_cross))) {
if (ImGui::Button(common["submit"].c_str())) {
common_dialog.ime.status = SCE_IME_DIALOG_BUTTON_ENTER;
common_dialog.status = SCE_COMMON_DIALOG_STATUS_FINISHED;
common_dialog.result = SCE_COMMON_DIALOG_RESULT_OK;
Expand Down
2 changes: 1 addition & 1 deletion vita3k/gui/src/compile_shaders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void draw_pre_compiling_shaders_progress(GuiState &gui, EmuEnvState &emuenv, con
ImGui::SetWindowFontScale(1.1f * RES_SCALE.x);

// Check if icon exist
if (gui.app_selector.user_apps_icon.contains(emuenv.io.app_path)) {
if (gui.app_selector.vita_apps_icon.contains(emuenv.io.app_path)) {
ImGui::SetCursorPos(ImVec2(54.f * SCALE.x, 32.f * SCALE.y));
ImGui::Image(get_app_icon(gui, emuenv.io.app_path)->second, ICON_SIZE_SCALE);
}
Expand Down
Loading

0 comments on commit f77659f

Please sign in to comment.