From bf95f56a1cd05147ff8d2830731d7a65e7165c15 Mon Sep 17 00:00:00 2001 From: igor725 Date: Thu, 25 Apr 2024 16:47:48 +0300 Subject: [PATCH] Initial commit --- docs/json/logging.json | 4 ++ misc/discordNotify/main.js | 70 +++++++++++++++---------------- modules/libSceNpWebApi2/entry.cpp | 4 ++ modules/libScePad/entry.cpp | 1 + tools/config_emu/config_emu.cpp | 16 ++++++- tools/logging/logging.cpp | 21 +++++++++- 6 files changed, 77 insertions(+), 39 deletions(-) diff --git a/docs/json/logging.json b/docs/json/logging.json index d5a5305..193f1fe 100644 --- a/docs/json/logging.json +++ b/docs/json/logging.json @@ -23,6 +23,10 @@ "description": "Verbosity level of logger.\nPossible values:\n0 - Trace\n1 - Debug\n2 - Warning\n3 - Error\n4 - Critical\n5 - None", "minimum": 0, "maximum": 5 + }, + "_customVerb": { + "type": "object", + "description": "Custom verbosity level for each module." } }, "required": [ diff --git a/misc/discordNotify/main.js b/misc/discordNotify/main.js index c00acef..c5f9f8c 100644 --- a/misc/discordNotify/main.js +++ b/misc/discordNotify/main.js @@ -7,35 +7,35 @@ const maxMessageSize = 2000; const delay = (ms) => new Promise((resolve) => setTimeout(() => resolve(), ms)); -const fetchRetry = ({url, fetchOpts = {}, retryDelay = 5000, retries = 5}) => new Promise((resolve, reject) => { +const fetchRetry = ({ url, fetchOpts = {}, retryDelay = 5000, retries = 5 }) => new Promise((resolve, reject) => { const wrap = (n) => { fetch(url, fetchOpts) - .then(async (res) => { - if (res.ok) { - const rateRemain = res.headers.get('X-RateLimit-Remaining'); - const rateReset = res.headers.get('X-RateLimit-Reset-After'); - if (rateRemain !== null) { - if (parseInt(rateRemain) === 1) - await delay((rateReset ? parseInt(rateReset) : 1) * 1500); // Hold on there, cowboy + .then(async (res) => { + if (res.ok) { + const rateRemain = res.headers.get('X-RateLimit-Remaining'); + const rateReset = res.headers.get('X-RateLimit-Reset-After'); + if (rateRemain !== null) { + if (parseInt(rateRemain) === 1) + await delay((rateReset ? parseInt(rateReset) : 1) * 1500); // Hold on there, cowboy + } + return resolve(res); } - return resolve(res); - } - if (n === 0) return reject(`Failed after ${retries} retries.`); - if (res.status !== 429) return reject(res); - const jdata = res.json(); - if (typeof jdata.retry_after === 'number') { - await delay(jdata.retry_after * 1000); - wrap(--n); - } - }) - .catch(async (err) => { - if (n > 0) { - await delay(retryDelay); - wrap(--n); - } else { - reject(`Failed after ${retries} retries.`); - } - }); + if (n === 0) return reject(`Failed after ${retries} retries.`); + if (res.status !== 429) return reject(res); + const jdata = res.json(); + if (typeof jdata.retry_after === 'number') { + await delay(jdata.retry_after * 1000); + wrap(--n); + } + }) + .catch(async (err) => { + if (n > 0) { + await delay(retryDelay); + wrap(--n); + } else { + reject(`Failed after ${retries} retries.`); + } + }); }; wrap(retries); @@ -110,20 +110,20 @@ const guessCategory = (labels) => { }; const catOpts = { - bugfixes: {display: 'Bugfixes 🪳'}, - stubs: {display: 'Stubbed functions 🆒'}, - impls: {display: 'Implementations 🥳'}, - general: {display: 'General ✅'}, - ench: {display: 'Enhancements 🧙'}, - contrib: {display: 'Authors 🧑‍💻️', splitter: ', '}, + bugfixes: { display: 'Bugfixes 🪳' }, + stubs: { display: 'Stubbed functions 🆒' }, + impls: { display: 'Implementations 🥳' }, + general: { display: 'General ✅' }, + ench: { display: 'Enhancements 🧙' }, + contrib: { display: 'Authors 🧑‍💻️', splitter: ', ' }, }; -octokit.repos.listReleases({repo: r_name, owner: r_owner, per_page: 2, page: 1}).then(({data}) => { +octokit.repos.listReleases({ repo: r_name, owner: r_owner, per_page: 2, page: 1 }).then(({ data }) => { const lastRelease = data[0], prevRelease = data[1]; return new Promise((resolve, reject) => { const readPRs = async (pagenum, list = null, retries = 0) => { - const out = list ?? {general: [], bugfixes: [], stubs: [], impls: [], ench: [], contrib: []}; + const out = list ?? { general: [], bugfixes: [], stubs: [], impls: [], ench: [], contrib: [] }; const handled_contribs = {}; const query = []; @@ -131,7 +131,7 @@ octokit.repos.listReleases({repo: r_name, owner: r_owner, per_page: 2, page: 1}) query.push('is:pr is:closed base:features sort:author-date-asc'); query.push(`merged:${prevRelease.created_at}..${lastRelease.created_at}`); - return octokit.search.issuesAndPullRequests({q: query.join(' '), per_page: 100, page: pagenum}).then(({data}) => { + return octokit.search.issuesAndPullRequests({ q: query.join(' '), per_page: 100, page: pagenum }).then(({ data }) => { data.items.forEach((pr) => { const msg = `* PR #${pr.number}: ${pr.title}`; if (!handled_contribs[pr.user.login]) { diff --git a/modules/libSceNpWebApi2/entry.cpp b/modules/libSceNpWebApi2/entry.cpp index b4fea4a..05a46a3 100644 --- a/modules/libSceNpWebApi2/entry.cpp +++ b/modules/libSceNpWebApi2/entry.cpp @@ -24,4 +24,8 @@ EXPORT SYSV_ABI int32_t sceNpWebApi2AddHttpRequestHeader() { EXPORT SYSV_ABI int32_t sceNpWebApi2SendRequest() { return Ok; } + +EXPORT SYSV_ABI int32_t sceNpWebApi2CreateUserContext() { + return Ok; +} } diff --git a/modules/libScePad/entry.cpp b/modules/libScePad/entry.cpp index cc298e6..ad130b9 100644 --- a/modules/libScePad/entry.cpp +++ b/modules/libScePad/entry.cpp @@ -80,6 +80,7 @@ EXPORT const char* MODULE_NAME = "libScePad"; EXPORT SYSV_ABI int scePadInit(void) { LOG_USE_MODULE(libScePad); + LOG_TRACE(L"scePadInit()"); (void)getData(); return Ok; } diff --git a/tools/config_emu/config_emu.cpp b/tools/config_emu/config_emu.cpp index e0ca1c1..c928d80 100644 --- a/tools/config_emu/config_emu.cpp +++ b/tools/config_emu/config_emu.cpp @@ -142,6 +142,13 @@ Config::Config() { for (auto& [dkey, dval]: def.items()) { json& cval = getVal(obj, dkey); + if (dkey.starts_with("_")) { // Temporary (probably) workaround to stop fixing underscore objects + if (cval.is_null()) { + missing = true; + cval = dval; + } + continue; + } if ((cval.is_null() && !dval.is_null()) || !isJsonTypesSimilar(cval, dval)) { cval = dval; @@ -171,6 +178,9 @@ Config::Config() { bool unused = false; for (auto& [ckey, cval]: obj.items()) { + if (ckey.starts_with("_")) { // Temporary (probably) workaround to stop removing underscore objects + continue; + } json& dval = getVal(def, ckey); if (dval.is_null()) { @@ -221,8 +231,10 @@ Config::Config() { }; } - m_logging._future = std::async(std::launch::async | std::launch::deferred, load, &m_logging, - json({{"$schema", "./.schemas/logging.json"}, {"sink", "FileBin"}, {"verbosity", 1}}), ConfigModFlag::LOGGING); + m_logging._future = + std::async(std::launch::async | std::launch::deferred, load, &m_logging, + json({{"$schema", "./.schemas/logging.json"}, {"sink", "FileBin"}, {"verbosity", 1}, {"_customVerb", json(json::value_t::object)}}), + ConfigModFlag::LOGGING); m_graphics._future = std::async( std::launch::async | std::launch::deferred, load, &m_graphics, diff --git a/tools/logging/logging.cpp b/tools/logging/logging.cpp index 14eb52d..ad162f9 100644 --- a/tools/logging/logging.cpp +++ b/tools/logging/logging.cpp @@ -34,7 +34,7 @@ std::mutex& getMutex() { return mMutex; } -const wchar_t* getParams(std::wstring& params) { +const wchar_t* getParams(std::wstring_view name, std::wstring& params) { auto [lock, jData] = accessConfig()->accessModule(ConfigModFlag::LOGGING); auto readParam = [¶ms](json* field, json::value_t jsontype, const wchar_t* p7param) -> bool { @@ -79,12 +79,29 @@ void* __registerLoggingModule(std::wstring_view name) { interested in is the trace. */ std::wstring params = L"/P7.Pool=1024 /P7.Files=0 /P7.Roll=5hr"; - *getClient() = P7_Create_Client(getParams(params)); + *getClient() = P7_Create_Client(getParams(name, params)); *trace = P7_Create_Trace(*getClient(), __APPNAME); } } + + auto getCustomVerb = [](std::wstring_view name) -> int32_t { + int32_t vlevel; + std::string sname(name.begin(), name.end()); + auto [lock, jData] = accessConfig()->accessModule(ConfigModFlag::LOGGING); + + auto& modver = (*jData)["_customVerb"][sname]; + if (modver.is_number_integer()) { + printf("Custom verbosity set for: %ls\n", name.data()); + return modver.get_to(vlevel); + } + + return -1; + }; + IP7_Trace::hModule pModule; (*trace)->Register_Module(name.data(), &pModule); + auto lvl = getCustomVerb(name); + if (lvl != -1) (*trace)->Set_Verbosity(pModule, (eP7Trace_Level)lvl); return pModule; }