- Add Support for Downloading Data/Files, do Api Requests
- Refactor Tasks System
  - Now uses std::thread
- The Net  Functions Will Break IDBN server for now
This commit is contained in:
2024-05-22 22:16:40 +02:00
parent a0923acec7
commit 6d7781b209
9 changed files with 415 additions and 39 deletions

View File

@ -25,6 +25,7 @@
#include <renderd7/Hid.hpp>
#include <renderd7/Image.hpp>
#include <renderd7/Message.hpp>
#include <renderd7/Net.hpp>
#include <renderd7/Overlays.hpp>
#include <renderd7/StealConsole.hpp>
#include <renderd7/Timer.hpp>

60
include/renderd7/Net.hpp Normal file
View File

@ -0,0 +1,60 @@
/**
* This file is part of RenderD7
* Copyright (C) 2021-2024 NPI-D7, tobid7
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <renderd7/external/json.hpp>
#include <string>
namespace RenderD7 {
namespace Net {
// Define List of Errors
enum Error_ {
Error_None, // Function Executed Successfully
Error_Memory, // Memory Allocation Error
Error_Write, // Unable to Write File
Error_StatusCode, // Error with Status Code
Error_Git, // Git Error
Error_CtrStatus, // 3ds Result Code
Error_Curl, // Curl Error
Error_Busy, // Another Download Taskl is already running
Error_Invalid, // Invalid Json struct
Error_NoWifi, // Console not connected to wifi
};
// Set an typedefine for Error code
using Error = unsigned long long;
// Extract Error_ from Error code
inline Error_ ErrorCode(Error err) {
return static_cast<Error_>(static_cast<unsigned int>(err & 0xffffffff));
}
// Extract Http Status code, Curl Error Code or Ctr Result Code
inline int StatusCode(Error err) {
Error_ c = ErrorCode(err);
if (c != Error_StatusCode && c != Error_CtrStatus && c != Error_Curl)
return 0;
return static_cast<unsigned int>(err >> 32);
}
Error Download(const std::string& url, std::string& data);
Error Download2File(const std::string& url, const std::string& path);
Error GitDownloadRelease(const std::string& url, const std::string& asset_name,
const std::string& path, bool prerelease = false);
Error JsonApiRequest(const std::string& api_url, nlohmann::json& res);
unsigned long long GetProgressCurrent();
unsigned long long GetProgressTotal();
} // namespace Net
} // namespace RenderD7

View File

@ -17,14 +17,15 @@
*/
#pragma once
#include <3ds.h>
#include <functional>
namespace RenderD7 {
namespace Tasks {
/// @brief Push A Task
/// @param entrypoint Function of Your Task
void create(ThreadFunc entrypoint);
/// @param fun Function of Your Task
/// @return index
int Create(std::function<void()> fun);
/// @brief Destroy all Tasks
void destroy(void);
void DestroyAll();
} // namespace Tasks
} // namespace RenderD7

View File

@ -17,6 +17,7 @@
*/
#pragma once
#include <renderd7/Net.hpp>
#include <renderd7/external/json.hpp>
#include <renderd7/global_db.hpp>
#include <renderd7/renderd7.hpp>
@ -72,4 +73,8 @@ extern bool rd7i_fade_exit;
extern bool rd7i_fade_scene_wait;
extern bool rd7i_idb_running;
extern bool rd7i_graphics_on;
extern bool rd7i_amdt;
extern bool rd7i_amdt;
extern void* rd7i_soc_buf;
RenderD7::Net::Error rd7i_soc_init();
void rd7i_soc_deinit();