Skip to content

Commit

Permalink
vita: update version in app.db when installing update
Browse files Browse the repository at this point in the history
Closes #14
  • Loading branch information
blastrock committed Jul 16, 2018
1 parent 24f6897 commit 17146cd
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion src/vita.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ extern "C" {
#include "config.hpp"
#include "db.hpp"
#include "http.hpp"
#include "sfo.hpp"

#include <fmt/format.h>

Expand Down Expand Up @@ -749,8 +750,9 @@ void pkgi_install_update(const char* contentid)
{
pkgi_mkdirs("ux0:patch");

const auto titleid = fmt::format("{:.9}", contentid + 7);
const auto src = fmt::format("ux0:pkgi/{}", contentid);
const auto dest = fmt::format("ux0:patch/{:.9}", contentid + 7);
const auto dest = fmt::format("ux0:patch/{}", titleid);

LOGF("deleting previous patch at {}", dest);
pkgi_delete_dir(dest);
Expand All @@ -760,6 +762,48 @@ void pkgi_install_update(const char* contentid)
if (res < 0)
throw formatEx<std::runtime_error>(
"failed to rename: {:#08x}", static_cast<uint32_t>(res));

const auto sfo = pkgi_load(fmt::format("{}/sce_sys/param.sfo", dest));
const auto version = pkgi_sfo_get_string(sfo.data(), sfo.size(), "APP_VER");

LOGF("found version is {}", version);
if (version.empty())
throw std::runtime_error("no version field found in param.sfo");
if (version.size() != 5)
throw formatEx<std::runtime_error>(
"version field of incorrect size: {}", version.size());

SqlitePtr _sqliteDb;
sqlite3* raw_appdb;
SQLITE_CHECK(
sqlite3_open("ur0:shell/db/app.db", &raw_appdb),
"can't open app.db database");
_sqliteDb.reset(raw_appdb);

sqlite3_stmt* stmt;
SQLITE_CHECK(
sqlite3_prepare_v2(
_sqliteDb.get(),
R"(UPDATE tbl_appinfo
SET val = ?
WHERE titleId = ? AND key = 3168212510)",
-1,
&stmt,
nullptr),
"can't prepare version update SQL statement");
BOOST_SCOPE_EXIT_ALL(&)
{
sqlite3_finalize(stmt);
};

sqlite3_bind_text(stmt, 1, version.data(), version.size(), nullptr);
sqlite3_bind_text(stmt, 2, titleid.data(), titleid.size(), nullptr);

const auto err = sqlite3_step(stmt);
if (err != SQLITE_DONE)
throw formatEx<std::runtime_error>(
"can't execute version update SQL statement:\n{}",
sqlite3_errmsg(_sqliteDb.get()));
}

void pkgi_install_pspgame(const char* partition, const char* contentid)
Expand Down

0 comments on commit 17146cd

Please sign in to comment.