rewrite everything
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
/********************************************************************************
|
||||
* File: debug_funcs.hpp
|
||||
* Author: ppkantorski
|
||||
* Description:
|
||||
* This header file contains debugging functions for the Ultrahand Overlay project.
|
||||
* These functions allow logging messages with timestamps to a log file.
|
||||
*
|
||||
* For the latest updates and contributions, visit the project's GitHub repository.
|
||||
* (GitHub Repository: https://github.com/ppkantorski/Ultrahand-Overlay)
|
||||
*
|
||||
* Note: Please be aware that this notice cannot be altered or removed. It is a part
|
||||
* of the project's documentation and must remain intact.
|
||||
*
|
||||
* Licensed under both GPLv2 and CC-BY-4.0
|
||||
* Copyright (c) 2024 ppkantorski
|
||||
********************************************************************************/
|
||||
|
||||
#pragma once
|
||||
#ifndef DEBUG_FUNCS_HPP
|
||||
#define DEBUG_FUNCS_HPP
|
||||
|
||||
#if !USING_FSTREAM_DIRECTIVE // For not using fstream (needs implementing)
|
||||
#include <stdio.h>
|
||||
#else
|
||||
#include <fstream>
|
||||
#endif
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <ctime>
|
||||
|
||||
namespace ult {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
|
||||
// Specify the log file path
|
||||
extern const std::string defaultLogFilePath;
|
||||
|
||||
extern std::string logFilePath; // Declare logFilePath as extern
|
||||
extern bool disableLogging; // Declare disableLogging as extern
|
||||
|
||||
// Global mutex for thread-safe logging
|
||||
extern std::mutex logMutex; // Declare logMutex as extern
|
||||
|
||||
/**
|
||||
* @brief Logs a message with a timestamp to a log file in a thread-safe manner.
|
||||
*
|
||||
* @param message The message to be logged.
|
||||
*/
|
||||
void logMessage(const std::string& message);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // DEBUG_FUNCS_HPP
|
||||
@@ -0,0 +1,89 @@
|
||||
/********************************************************************************
|
||||
* File: download_funcs.hpp
|
||||
* Author: ppkantorski
|
||||
* Description:
|
||||
* This header file contains functions for downloading and extracting files
|
||||
* using libcurl and miniz. It includes functions for downloading files from URLs,
|
||||
* writing received data to a file, and extracting files from ZIP archives.
|
||||
*
|
||||
* For the latest updates and contributions, visit the project's GitHub repository.
|
||||
* (GitHub Repository: https://github.com/ppkantorski/Ultrahand-Overlay)
|
||||
*
|
||||
* Note: Please be aware that this notice cannot be altered or removed. It is a part
|
||||
* of the project's documentation and must remain intact.
|
||||
*
|
||||
* Licensed under both GPLv2 and CC-BY-4.0
|
||||
* Copyright (c) 2024 ppkantorski
|
||||
********************************************************************************/
|
||||
#pragma once
|
||||
#ifndef DOWNLOAD_FUNCS_HPP
|
||||
#define DOWNLOAD_FUNCS_HPP
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
#include <switch.h>
|
||||
|
||||
#define CURL_DISABLE_DEFLATE
|
||||
#include <curl/curl.h>
|
||||
#include <zlib.h>
|
||||
#include <minizip/unzip.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <mutex>
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
|
||||
#include "global_vars.hpp"
|
||||
#include "string_funcs.hpp"
|
||||
#include "get_funcs.hpp"
|
||||
#include "path_funcs.hpp"
|
||||
#include "debug_funcs.hpp"
|
||||
|
||||
namespace ult {
|
||||
// Constants for buffer sizes
|
||||
|
||||
extern size_t DOWNLOAD_READ_BUFFER;
|
||||
extern size_t DOWNLOAD_WRITE_BUFFER;
|
||||
extern size_t UNZIP_READ_BUFFER;
|
||||
extern size_t UNZIP_WRITE_BUFFER;
|
||||
|
||||
// Path to the CA certificate
|
||||
//extern const std::string cacertPath;
|
||||
//extern const std::string cacertURL;
|
||||
|
||||
// Thread-safe atomic flags for operation control
|
||||
extern std::atomic<bool> abortDownload;
|
||||
extern std::atomic<bool> abortUnzip;
|
||||
extern std::atomic<int> downloadPercentage;
|
||||
extern std::atomic<int> unzipPercentage;
|
||||
|
||||
// User agent string for curl requests
|
||||
inline constexpr const char* userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36";
|
||||
|
||||
// Custom deleters for CURL handles
|
||||
struct CurlDeleter {
|
||||
void operator()(CURL* curl) const;
|
||||
};
|
||||
|
||||
// Thread-safe callback functions
|
||||
#if !USING_FSTREAM_DIRECTIVE
|
||||
size_t writeCallback(void* ptr, size_t size, size_t nmemb, FILE* stream);
|
||||
#else
|
||||
size_t writeCallback(void* ptr, size_t size, size_t nmemb, std::ostream* stream);
|
||||
#endif
|
||||
|
||||
int progressCallback(void* ptr, curl_off_t totalToDownload, curl_off_t nowDownloaded, curl_off_t totalToUpload, curl_off_t nowUploaded);
|
||||
|
||||
|
||||
// Thread-safe initialization and cleanup functions
|
||||
void initializeCurl();
|
||||
void cleanupCurl();
|
||||
|
||||
// Main API functions - thread-safe and optimized
|
||||
bool downloadFile(const std::string& url, const std::string& toDestination, bool noPercentagePolling=false);
|
||||
bool unzipFile(const std::string& zipFilePath, const std::string& extractTo);
|
||||
}
|
||||
|
||||
#endif // DOWNLOAD_FUNCS_HPP
|
||||
@@ -0,0 +1,160 @@
|
||||
/********************************************************************************
|
||||
* File: get_funcs.hpp
|
||||
* Author: ppkantorski
|
||||
* Description:
|
||||
* This header file contains functions for retrieving information and data
|
||||
* from various sources, including file system and JSON files. It includes
|
||||
* functions for obtaining overlay module information, reading file contents,
|
||||
* and parsing JSON data.
|
||||
*
|
||||
* For the latest updates and contributions, visit the project's GitHub repository.
|
||||
* (GitHub Repository: https://github.com/ppkantorski/Ultrahand-Overlay)
|
||||
*
|
||||
* Note: Please be aware that this notice cannot be altered or removed. It is a part
|
||||
* of the project's documentation and must remain intact.
|
||||
*
|
||||
* Licensed under both GPLv2 and CC-BY-4.0
|
||||
* Copyright (c) 2024 ppkantorski
|
||||
********************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef GET_FUNCS_HPP
|
||||
#define GET_FUNCS_HPP
|
||||
|
||||
|
||||
#include <cstring>
|
||||
#include <dirent.h>
|
||||
#include <fnmatch.h>
|
||||
#include "debug_funcs.hpp"
|
||||
#include "string_funcs.hpp"
|
||||
|
||||
|
||||
namespace ult {
|
||||
struct DirCloser {
|
||||
void operator()(DIR* dir) const {
|
||||
if (dir) closedir(dir);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Reads the contents of a file and returns it as a string, normalizing line endings.
|
||||
*
|
||||
* @param filePath The path to the file to be read.
|
||||
* @return The content of the file as a string with line endings normalized to '\n'.
|
||||
*/
|
||||
//std::string getFileContents(const std::string& filePath);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Concatenates the provided directory and file names to form a destination path.
|
||||
*
|
||||
* @param destinationDir The directory where the file should be placed.
|
||||
* @param fileName The name of the file.
|
||||
* @return The destination path as a string.
|
||||
*/
|
||||
std::string getDestinationPath(const std::string& destinationDir, const std::string& fileName);
|
||||
|
||||
/**
|
||||
* @brief Extracts the value part from a string line containing a key-value pair.
|
||||
*
|
||||
* @param line The string line containing a key-value pair (e.g., "key=value").
|
||||
* @return The extracted value as a string. If no value is found, an empty string is returned.
|
||||
*/
|
||||
std::string getValueFromLine(const std::string& line);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Extracts the name from a file path, including handling directories.
|
||||
*
|
||||
* @param path The file path from which to extract the name.
|
||||
* @return The extracted name as a string. If the path indicates a directory, it extracts the last directory name.
|
||||
* If the path is empty or no name is found, an empty string is returned.
|
||||
*/
|
||||
std::string getNameFromPath(const std::string& path);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Extracts the file name from a full file path.
|
||||
*
|
||||
* This function takes a filesystem path and returns only the file name,
|
||||
* stripping away any directory paths that precede it.
|
||||
*
|
||||
* @param path The full path to the file.
|
||||
* @return The file name extracted from the full path.
|
||||
*/
|
||||
std::string getFileName(const std::string& path);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Extracts the name of the parent directory from a given file path at a specified level.
|
||||
*
|
||||
* @param path The file path from which to extract the parent directory name.
|
||||
* @param level The level of the parent directory to extract (0 for immediate parent, 1 for grandparent, and so on).
|
||||
* @return The name of the parent directory at the specified level.
|
||||
*/
|
||||
std::string getParentDirNameFromPath(const std::string& path, size_t level = 0);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Extracts the parent directory path from a given file path.
|
||||
*
|
||||
* @param path The file path from which to extract the parent directory path.
|
||||
* @return The parent directory path.
|
||||
*/
|
||||
std::string getParentDirFromPath(const std::string& path);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Gets a list of subdirectories in a directory.
|
||||
*
|
||||
* @param directoryPath The path of the directory to search.
|
||||
* @return A vector of strings containing the names of subdirectories.
|
||||
*/
|
||||
std::vector<std::string> getSubdirectories(const std::string& directoryPath);
|
||||
|
||||
// Cache to store directory status
|
||||
// Assuming a very simple cache implementation
|
||||
//extern std::vector<std::pair<std::string, bool>> directoryCache;
|
||||
|
||||
bool isDirectory(struct dirent* entry, const std::string& path);
|
||||
|
||||
/**
|
||||
* @brief Recursively retrieves a list of files from a directory.
|
||||
*
|
||||
* @param directoryPath The path of the directory to search.
|
||||
* @return A vector of strings containing the paths of the files.
|
||||
*/
|
||||
std::vector<std::string> getFilesListFromDirectory(const std::string& directoryPath);
|
||||
|
||||
// Helper function to check if a path is a directory
|
||||
//bool isDirectoryCached(const struct dirent* entry, const std::string& fullPath) {
|
||||
// struct stat st;
|
||||
// if (stat(fullPath.c_str(), &st) != 0) return false;
|
||||
// return S_ISDIR(st.st_mode);
|
||||
//}
|
||||
|
||||
|
||||
|
||||
void handleDirectory(const std::string& basePath, const std::vector<std::string>& parts, size_t partIndex, std::vector<std::string>& results, bool directoryOnly, size_t maxLines=0);
|
||||
/**
|
||||
* @brief Gets a list of files and folders based on a wildcard pattern.
|
||||
*
|
||||
* This function searches for files and folders in a directory that match the
|
||||
* specified wildcard pattern.
|
||||
*
|
||||
* @param pathPattern The wildcard pattern to match files and folders.
|
||||
* @return A vector of strings containing the paths of matching files and folders.
|
||||
*/
|
||||
std::vector<std::string> getFilesListByWildcards(const std::string& pathPattern, size_t maxLines=0);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,171 @@
|
||||
/********************************************************************************
|
||||
* File: global_vars.hpp
|
||||
* Author: ppkantorski
|
||||
* Description:
|
||||
* This header file provides the definitions of global constants and paths used
|
||||
* throughout the Ultrahand Overlay project. These constants are essential for
|
||||
* file management and configuration settings within the application.
|
||||
*
|
||||
* For the latest updates and contributions, visit the project's GitHub repository:
|
||||
* GitHub Repository: https://github.com/ppkantorski/Ultrahand-Overlay
|
||||
*
|
||||
* Note: This notice is integral to the project's documentation and must not be
|
||||
* altered or removed.
|
||||
*
|
||||
* Licensed under both GPLv2 and CC-BY-4.0
|
||||
* Copyright (c) 2024 ppkantorski
|
||||
********************************************************************************/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <atomic>
|
||||
#include <set>
|
||||
|
||||
// Auto-detect constexpr std::string support based on C++ version
|
||||
#if __cplusplus >= 202400L
|
||||
#define CONSTEXPR_STRING constexpr
|
||||
#else
|
||||
#define CONSTEXPR_STRING const
|
||||
#endif
|
||||
|
||||
namespace ult {
|
||||
extern const std::string CONFIG_FILENAME;
|
||||
|
||||
extern const std::string ULTRAHAND_PROJECT_NAME;
|
||||
extern const std::string CAPITAL_ULTRAHAND_PROJECT_NAME;
|
||||
|
||||
extern const std::string ROOT_PATH;
|
||||
extern const std::string SETTINGS_PATH;
|
||||
extern const std::string ULTRAHAND_CONFIG_INI_PATH;
|
||||
extern const std::string TESLA_CONFIG_INI_PATH;
|
||||
extern const std::string LANG_PATH;
|
||||
extern const std::string THEMES_PATH;
|
||||
extern const std::string WALLPAPERS_PATH;
|
||||
extern const std::string FLAGS_PATH;
|
||||
extern const std::string NOTIFICATIONS_PATH;
|
||||
extern const std::string PAYLOADS_PATH;
|
||||
extern const std::string HB_APPSTORE_JSON;
|
||||
|
||||
// Can be overriden with APPEARANCE_OVERRIDE_PATH directive
|
||||
extern std::string THEME_CONFIG_INI_PATH;
|
||||
extern std::string WALLPAPER_PATH;
|
||||
|
||||
|
||||
//#if IS_LAUNCHER_DIRECTIVE
|
||||
extern const std::string SPLIT_PROJECT_NAME_1;
|
||||
extern const std::string SPLIT_PROJECT_NAME_2;
|
||||
extern const std::string BOOT_PACKAGE_FILENAME;
|
||||
extern const std::string EXIT_PACKAGE_FILENAME;
|
||||
extern const std::string PACKAGE_FILENAME;
|
||||
|
||||
extern const std::string DOWNLOADS_PATH;
|
||||
extern const std::string EXPANSION_PATH;
|
||||
extern const std::string FUSE_DATA_INI_PATH;
|
||||
extern const std::string PACKAGE_PATH;
|
||||
extern const std::string OVERLAY_PATH;
|
||||
extern const std::string OVERLAYS_INI_FILEPATH;
|
||||
extern const std::string PACKAGES_INI_FILEPATH;
|
||||
|
||||
extern const std::string NOTIFICATIONS_FLAG_FILEPATH;
|
||||
|
||||
extern const std::set<std::string> PROTECTED_FILES;
|
||||
|
||||
extern const std::string ULTRAHAND_REPO_URL;
|
||||
extern const std::string INCLUDED_THEME_FOLDER_URL;
|
||||
extern const std::string LATEST_RELEASE_INFO_URL;
|
||||
extern const std::string NX_OVLLOADER_ZIP_URL;
|
||||
extern const std::string NX_OVLLOADER_PLUS_ZIP_URL;
|
||||
extern const std::string OLD_NX_OVLLOADER_ZIP_URL;
|
||||
extern const std::string OLD_NX_OVLLOADER_PLUS_ZIP_URL;
|
||||
extern const std::string UPDATER_PAYLOAD_URL;
|
||||
|
||||
extern const std::string LAUNCH_ARGS_STR;
|
||||
extern const std::string USE_LAUNCH_ARGS_STR;
|
||||
extern const std::string USE_QUICK_LAUNCH_STR;
|
||||
extern const std::string USE_BOOT_PACKAGE_STR;
|
||||
extern const std::string USE_EXIT_PACKAGE_STR;
|
||||
extern const std::string USE_LOGGING_STR;
|
||||
|
||||
//#endif
|
||||
|
||||
extern const std::string TESLA_COMBO_STR;
|
||||
extern const std::string ULTRAHAND_COMBO_STR;
|
||||
|
||||
extern const std::string FUSE_STR;
|
||||
extern const std::string TESLA_STR;
|
||||
extern const std::string ERISTA_STR;
|
||||
extern const std::string MARIKO_STR;
|
||||
extern const std::string KEY_COMBO_STR;
|
||||
extern const std::string DEFAULT_LANG_STR;
|
||||
|
||||
|
||||
extern const std::string LIST_STR;
|
||||
extern const std::string LIST_FILE_STR;
|
||||
extern const std::string JSON_STR;
|
||||
extern const std::string JSON_FILE_STR;
|
||||
extern const std::string INI_FILE_STR;
|
||||
extern const std::string HEX_FILE_STR;
|
||||
extern const std::string PACKAGE_STR;
|
||||
extern const std::string PACKAGES_STR;
|
||||
extern const std::string OVERLAY_STR;
|
||||
extern const std::string OVERLAYS_STR;
|
||||
extern const std::string IN_OVERLAY_STR;
|
||||
extern const std::string IN_HIDDEN_OVERLAY_STR;
|
||||
extern const std::string IN_HIDDEN_PACKAGE_STR;
|
||||
extern const std::string FILE_STR;
|
||||
extern const std::string SYSTEM_STR;
|
||||
extern const std::string MODE_STR;
|
||||
extern const std::string GROUPING_STR;
|
||||
extern const std::string FOOTER_STR;
|
||||
extern const std::string TOGGLE_STR;
|
||||
extern const std::string LEFT_STR;
|
||||
extern const std::string RIGHT_STR;
|
||||
extern const std::string CENTER_STR;
|
||||
extern const std::string HIDE_STR;
|
||||
extern const std::string STAR_STR;
|
||||
extern const std::string PRIORITY_STR;
|
||||
extern const std::string ON_STR;
|
||||
extern const std::string OFF_STR;
|
||||
extern const std::string CAPITAL_ON_STR;
|
||||
extern const std::string CAPITAL_OFF_STR;
|
||||
extern const std::string TRUE_STR;
|
||||
extern const std::string FALSE_STR;
|
||||
extern const std::string GLOBAL_STR;
|
||||
extern const std::string DEFAULT_STR;
|
||||
extern const std::string SLOT_STR;
|
||||
extern const std::string OPTION_STR;
|
||||
extern const std::string FORWARDER_STR;
|
||||
extern const std::string TEXT_STR;
|
||||
extern const std::string TABLE_STR;
|
||||
extern const std::string TRACKBAR_STR;
|
||||
extern const std::string STEP_TRACKBAR_STR;
|
||||
extern const std::string NAMED_STEP_TRACKBAR_STR;
|
||||
extern const std::string NULL_STR;
|
||||
extern const std::string THEME_STR;
|
||||
extern const std::string NOT_AVAILABLE_STR;
|
||||
extern const std::string MEMORY_STR;
|
||||
|
||||
// Pre-defined symbols
|
||||
extern const std::string OPTION_SYMBOL;
|
||||
extern const std::string DROPDOWN_SYMBOL;
|
||||
extern const std::string CHECKMARK_SYMBOL;
|
||||
extern const std::string CROSSMARK_SYMBOL;
|
||||
extern const std::string DOWNLOAD_SYMBOL;
|
||||
extern const std::string UNZIP_SYMBOL;
|
||||
extern const std::string COPY_SYMBOL;
|
||||
extern const std::string INPROGRESS_SYMBOL;
|
||||
extern const std::string STAR_SYMBOL;
|
||||
extern const std::string DIVIDER_SYMBOL;
|
||||
|
||||
extern const std::vector<std::string> THROBBER_SYMBOLS;
|
||||
|
||||
extern std::atomic<int> downloadPercentage;
|
||||
extern std::atomic<int> unzipPercentage;
|
||||
extern std::atomic<int> copyPercentage;
|
||||
extern std::atomic<int> displayPercentage;
|
||||
|
||||
void resetPercentages();
|
||||
}
|
||||
@@ -0,0 +1,211 @@
|
||||
/********************************************************************************
|
||||
* File: hex_funcs.hpp
|
||||
* Author: ppkantorski
|
||||
* Description:
|
||||
* This header file provides functions for working with hexadecimal data in C++.
|
||||
* It includes functions for converting between ASCII and hexadecimal strings,
|
||||
* finding hexadecimal data offsets in a file, and editing hexadecimal data in a file.
|
||||
*
|
||||
* For the latest updates and contributions, visit the project's GitHub repository.
|
||||
* (GitHub Repository: https://github.com/ppkantorski/Ultrahand-Overlay)
|
||||
*
|
||||
* Note: Please be aware that this notice cannot be altered or removed. It is a part
|
||||
* of the project's documentation and must remain intact.
|
||||
*
|
||||
* Licensed under both GPLv2 and CC-BY-4.0
|
||||
* Copyright (c) 2024 ppkantorski
|
||||
********************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef HEX_FUNCS_HPP
|
||||
#define HEX_FUNCS_HPP
|
||||
|
||||
#if !USING_FSTREAM_DIRECTIVE // For not using fstream (needs implementing)
|
||||
#include <stdio.h>
|
||||
#else
|
||||
#include <fstream>
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
//#include <cstdio> // Added for FILE and fopen
|
||||
#include <cstring> // Added for std::memcmp
|
||||
#include <mutex>
|
||||
#include <shared_mutex>
|
||||
|
||||
#include <global_vars.hpp>
|
||||
#include <debug_funcs.hpp>
|
||||
#include <string_funcs.hpp>
|
||||
|
||||
|
||||
namespace ult {
|
||||
extern size_t HEX_BUFFER_SIZE;
|
||||
|
||||
|
||||
// For improving the speed of hexing consecutively with the same file and asciiPattern.
|
||||
extern std::unordered_map<std::string, std::string> hexSumCache; // MOVED TO main.cpp
|
||||
|
||||
// Lookup table for hex characters
|
||||
inline constexpr char hexLookup[] = "0123456789ABCDEF";
|
||||
|
||||
|
||||
// ULTRA-FAST hex conversion with lookup table
|
||||
inline constexpr unsigned char hexTable[256] = {
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,3,4,5,6,7,8,9,0,0,0,0,0,0,
|
||||
0,10,11,12,13,14,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,10,11,12,13,14,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
||||
};
|
||||
|
||||
|
||||
extern void clearHexSumCache();
|
||||
extern size_t getHexSumCacheSize();
|
||||
|
||||
/**
|
||||
* @brief Converts an ASCII string to a hexadecimal string.
|
||||
*
|
||||
* This function takes an ASCII string as input and converts it into a hexadecimal string.
|
||||
*
|
||||
* @param asciiStr The ASCII string to convert.
|
||||
* @return The corresponding hexadecimal string.
|
||||
*/
|
||||
|
||||
|
||||
// Function to convert ASCII string to Hex string
|
||||
std::string asciiToHex(const std::string& asciiStr);
|
||||
|
||||
/**
|
||||
* @brief Converts a decimal string to a hexadecimal string.
|
||||
*
|
||||
* This function takes a decimal string as input and converts it into a hexadecimal string.
|
||||
*
|
||||
* @param decimalStr The decimal string to convert.
|
||||
* @return The corresponding hexadecimal string.
|
||||
*/
|
||||
std::string decimalToHex(const std::string& decimalStr, int byteGroupSize = 2);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Converts a hexadecimal string to a decimal string.
|
||||
*
|
||||
* This function takes a hexadecimal string as input and converts it into a decimal string.
|
||||
*
|
||||
* @param hexStr The hexadecimal string to convert.
|
||||
* @return The corresponding decimal string.
|
||||
*/
|
||||
std::string hexToDecimal(const std::string& hexStr);
|
||||
|
||||
|
||||
|
||||
std::string hexToReversedHex(const std::string& hexadecimal, int order = 2);
|
||||
|
||||
/**
|
||||
* @brief Converts a decimal string to a reversed hexadecimal string.
|
||||
*
|
||||
* This function takes a decimal string as input, converts it into a hexadecimal
|
||||
* string, and reverses the resulting hexadecimal string in groups of byteGroupSize.
|
||||
*
|
||||
* @param decimalStr The decimal string to convert.
|
||||
* @param byteGroupSize The grouping byteGroupSize for reversing the hexadecimal string.
|
||||
* @return The reversed hexadecimal string.
|
||||
*/
|
||||
std::string decimalToReversedHex(const std::string& decimalStr, int byteGroupSize = 2);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Finds the offsets of hexadecimal data in a file.
|
||||
*
|
||||
* This function searches for occurrences of hexadecimal data in a binary file
|
||||
* and returns the file offsets where the data is found.
|
||||
*
|
||||
* @param filePath The path to the binary file.
|
||||
* @param hexData The hexadecimal data to search for.
|
||||
* @return A vector of strings containing the file offsets where the data is found.
|
||||
*/
|
||||
std::vector<std::string> findHexDataOffsets(const std::string& filePath, const std::string& hexData);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Edits hexadecimal data in a file at a specified offset.
|
||||
*
|
||||
* This function opens a binary file, seeks to a specified offset, and replaces
|
||||
* the data at that offset with the provided hexadecimal data.
|
||||
*
|
||||
* @param filePath The path to the binary file.
|
||||
* @param offsetStr The offset in the file to performthe edit.
|
||||
* @param hexData The hexadecimal data to replace at the offset.
|
||||
*/
|
||||
void hexEditByOffset(const std::string& filePath, const std::string& offsetStr, const std::string& hexData);
|
||||
|
||||
/**
|
||||
* @brief Edits a specific offset in a file with custom hexadecimal data.
|
||||
*
|
||||
* This function searches for a custom pattern in the file and calculates a new offset
|
||||
* based on user-provided offsetStr and the found pattern. It then replaces the data
|
||||
* at the calculated offset with the provided hexadecimal data.
|
||||
*
|
||||
* @param filePath The path to the binary file.
|
||||
* @param offsetStr The user-provided offset for the edit.
|
||||
* @param customPattern The custom pattern to search for in the file.
|
||||
* @param hexDataReplacement The hexadecimal data to replace at the calculated offset.
|
||||
* @param occurrence The occurrence/index of the data to replace (default is "0" to replace all occurrences).
|
||||
*/
|
||||
void hexEditByCustomOffset(const std::string& filePath, const std::string& customAsciiPattern, const std::string& offsetStr, const std::string& hexDataReplacement, size_t occurrence = 0);
|
||||
|
||||
/**
|
||||
* @brief Finds and replaces hexadecimal data in a file.
|
||||
*
|
||||
* This function searches for occurrences of hexadecimal data in a binary file
|
||||
* and replaces them with a specified hexadecimal replacement data.
|
||||
*
|
||||
* @param filePath The path to the binary file.
|
||||
* @param hexDataToReplace The hexadecimal data to search for and replace.
|
||||
* @param hexDataReplacement The hexadecimal data to replace with.
|
||||
* @param occurrence The occurrence/index of the data to replace (default is "0" to replace all occurrences).
|
||||
*/
|
||||
void hexEditFindReplace(const std::string& filePath, const std::string& hexDataToReplace, const std::string& hexDataReplacement, size_t occurrence = 0);
|
||||
|
||||
/**
|
||||
* @brief Finds and replaces hexadecimal data in a file.
|
||||
*
|
||||
* This function searches for occurrences of hexadecimal data in a binary file
|
||||
* and replaces them with a specified hexadecimal replacement data.
|
||||
*
|
||||
* @param filePath The path to the binary file.
|
||||
* @param hexDataToReplace The hexadecimal data to search for and replace.
|
||||
* @param hexDataReplacement The hexadecimal data to replace with.
|
||||
* @param occurrence The occurrence/index of the data to replace (default is "0" to replace all occurrences).
|
||||
*/
|
||||
std::string parseHexDataAtCustomOffset(const std::string& filePath, const std::string& customAsciiPattern, const std::string& offsetStr, size_t length, size_t occurrence = 0);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Finds and replaces hexadecimal data in a file.
|
||||
*
|
||||
* This function searches for occurrences of hexadecimal data in a binary file
|
||||
* and replaces them with a specified hexadecimal replacement data.
|
||||
*
|
||||
* @param filePath The path to the binary file.
|
||||
* @param hexDataToReplace The hexadecimal data to search for and replace.
|
||||
* @param hexDataReplacement The hexadecimal data to replace with.
|
||||
* @param occurrence The occurrence/index of the data to replace (default is "0" to replace all occurrences).
|
||||
*/
|
||||
|
||||
std::string replaceHexPlaceholder(const std::string& arg, const std::string& hexPath);
|
||||
|
||||
|
||||
|
||||
std::string extractVersionFromBinary(const std::string &filePath);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,344 @@
|
||||
/********************************************************************************
|
||||
* File: ini_funcs.hpp
|
||||
* Author: ppkantorski
|
||||
* Description:
|
||||
* This header file provides functions for working with INI (Initialization) files
|
||||
* in C++. It includes functions for reading, parsing, and editing INI files,
|
||||
* as well as cleaning INI file formatting.
|
||||
*
|
||||
* For the latest updates and contributions, visit the project's GitHub repository.
|
||||
* (GitHub Repository: https://github.com/ppkantorski/Ultrahand-Overlay)
|
||||
*
|
||||
* Note: Please be aware that this notice cannot be altered or removed. It is a part
|
||||
* of the project's documentation and must remain intact.
|
||||
*
|
||||
* Licensed under both GPLv2 and CC-BY-4.0
|
||||
* Copyright (c) 2024 ppkantorski
|
||||
********************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef INI_FUNCS_HPP
|
||||
#define INI_FUNCS_HPP
|
||||
|
||||
#if !USING_FSTREAM_DIRECTIVE // For not using fstream (needs implementing)
|
||||
#include <stdio.h>
|
||||
#else
|
||||
#include <fstream>
|
||||
//#include "nx_fstream.hpp"
|
||||
#endif
|
||||
|
||||
#include <cstring> // For std::string, strlen(), etc.
|
||||
#include <string> // For std::string
|
||||
#include <vector> // For std::vector
|
||||
#include <map> // For std::map
|
||||
//#include <sstream> // For std::istringstream
|
||||
#include <algorithm> // For std::remove_if
|
||||
//#include <cctype> // For ::isspace
|
||||
|
||||
#include <shared_mutex>
|
||||
#include <unordered_map>
|
||||
#include <mutex>
|
||||
|
||||
#include "get_funcs.hpp"
|
||||
#include "path_funcs.hpp"
|
||||
|
||||
namespace ult {
|
||||
|
||||
extern void clearIniMutexCache();
|
||||
|
||||
extern size_t INI_BUFFER_SIZE;
|
||||
extern size_t INI_BUFFER_LARGE;
|
||||
|
||||
/**
|
||||
* @brief Represents a package header structure.
|
||||
*
|
||||
* This structure holds information about a package header, including version,
|
||||
* creator, and description.
|
||||
*/
|
||||
struct PackageHeader {
|
||||
std::string title;
|
||||
std::string display_title;
|
||||
std::string version;
|
||||
std::string creator;
|
||||
std::string about;
|
||||
std::string credits;
|
||||
std::string color;
|
||||
std::string show_version;
|
||||
std::string show_widget;
|
||||
|
||||
void clear() {
|
||||
title.clear();
|
||||
display_title.clear();
|
||||
version.clear();
|
||||
creator.clear();
|
||||
about.clear();
|
||||
credits.clear();
|
||||
color.clear();
|
||||
show_version.clear();
|
||||
show_widget.clear();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Retrieves the package header information from an INI file.
|
||||
*
|
||||
* This function parses an INI file and extracts the package header information.
|
||||
*
|
||||
* @param filePath The path to the INI file.
|
||||
* @return The package header structure.
|
||||
*/
|
||||
PackageHeader getPackageHeaderFromIni(const std::string& filePath);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Splits a string into a vector of substrings using a specified delimiter.
|
||||
*
|
||||
* This function splits a given string into multiple substrings based on the specified delimiter.
|
||||
*
|
||||
* @param str The input string to be split.
|
||||
* @param delim The delimiter character used for splitting (default is space ' ').
|
||||
* @return A vector of substrings obtained by splitting the input string.
|
||||
*/
|
||||
std::vector<std::string> split(const std::string& str, char delim = ' ');
|
||||
|
||||
|
||||
/**
|
||||
* @brief Parses an INI-formatted string into a map of sections and key-value pairs.
|
||||
*
|
||||
* This function parses an INI-formatted string and organizes the data into a map,
|
||||
* where sections are keys and key-value pairs are stored within each section.
|
||||
*
|
||||
* @param str The INI-formatted string to parse.
|
||||
* @return A map representing the parsed INI data.
|
||||
*/
|
||||
std::map<std::string, std::map<std::string, std::string>> parseIni(const std::string &str);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Parses an INI file and returns its content as a map of sections and key-value pairs.
|
||||
*
|
||||
* This function reads the contents of an INI file located at the specified path,
|
||||
* parses it into a map structure, where section names are keys and key-value pairs
|
||||
* are stored within each section.
|
||||
*
|
||||
* @param configIniPath The path to the INI file to be parsed.
|
||||
* @return A map representing the parsed INI data.
|
||||
*/
|
||||
std::map<std::string, std::map<std::string, std::string>> getParsedDataFromIniFile(const std::string& configIniPath);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Parses an INI file and retrieves key-value pairs from a specific section.
|
||||
*
|
||||
* This function reads the contents of an INI file located at the specified path,
|
||||
* and returns the key-value pairs within a specific section.
|
||||
*
|
||||
* @param configIniPath The path to the INI file to be parsed.
|
||||
* @param sectionName The name of the section to retrieve key-value pairs from.
|
||||
* @return A map representing the key-value pairs in the specified section.
|
||||
*/
|
||||
std::map<std::string, std::string> getKeyValuePairsFromSection(const std::string& configIniPath, const std::string& sectionName);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Parses sections from an INI file and returns them as a list of strings.
|
||||
*
|
||||
* This function reads an INI file and extracts the section names from it.
|
||||
*
|
||||
* @param filePath The path to the INI file.
|
||||
* @return A vector of section names.
|
||||
*/
|
||||
std::vector<std::string> parseSectionsFromIni(const std::string& filePath);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Parses a specific value from a section and key in an INI file.
|
||||
*
|
||||
* @param filePath The path to the INI file.
|
||||
* @param sectionName The name of the section containing the desired key.
|
||||
* @param keyName The name of the key whose value is to be retrieved.
|
||||
* @return The value as a string, or an empty string if the key or section isn't found.
|
||||
*/
|
||||
std::string parseValueFromIniSection(const std::string& filePath, const std::string& sectionName, const std::string& keyName);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Cleans the formatting of an INI file by removing empty lines and standardizing section formatting.
|
||||
*
|
||||
* This function takes an INI file located at the specified path, removes empty lines,
|
||||
* and standardizes the formatting of sections by ensuring that there is a newline
|
||||
* between each section's closing ']' and the next section's opening '['.
|
||||
*
|
||||
* @param filePath The path to the INI file to be cleaned.
|
||||
*/
|
||||
void cleanIniFormatting(const std::string& filePath);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Modifies or creates an INI file by adding or updating key-value pairs in the specified section.
|
||||
*
|
||||
* This function attempts to open the specified INI file for reading. If the file doesn't exist,
|
||||
* it creates a new file and adds the specified section and key-value pair. If the file exists,
|
||||
* it reads its contents, modifies or adds the key-value pair in the specified section, and saves
|
||||
* the changes back to the original file.
|
||||
*
|
||||
* @param fileToEdit The path to the INI file to be modified or created.
|
||||
* @param desiredSection The name of the section in which the key-value pair should be added or updated.
|
||||
* @param desiredKey The key for the key-value pair to be added or updated.
|
||||
* @param desiredValue The new value for the key-value pair.
|
||||
* @param desiredNewKey (Optional) If provided, the function will rename the key while preserving the original value.
|
||||
*/
|
||||
void setIniFile(const std::string& fileToEdit, const std::string& desiredSection, const std::string& desiredKey, const std::string& desiredValue, const std::string& desiredNewKey = "", const std::string& comment = "");
|
||||
|
||||
|
||||
/**
|
||||
* @brief Sets the value of a key in an INI file within the specified section and cleans the formatting.
|
||||
*
|
||||
* This function sets the value of the specified key within the given section of the INI file.
|
||||
* If the key or section does not exist, it creates them. After updating the INI file,
|
||||
* it cleans the formatting to ensure proper INI file structure.
|
||||
*
|
||||
* @param fileToEdit The path to the INI file to be modified or created.
|
||||
* @param desiredSection The name of the section in which the key-value pair should be added or updated.
|
||||
* @param desiredKey The key for the key-value pair to be added or updated.
|
||||
* @param desiredValue The new value for the key-value pair.
|
||||
*/
|
||||
void setIniFileValue(const std::string& fileToEdit, const std::string& desiredSection, const std::string& desiredKey, const std::string& desiredValue, const std::string& comment="");
|
||||
|
||||
/**
|
||||
* @brief Sets the key name to a new name in an INI file within the specified section and cleans the formatting.
|
||||
*
|
||||
* This function sets the key name to a new name within the given section of the INI file.
|
||||
* If the key or section does not exist, it creates them. After updating the INI file,
|
||||
* it cleans the formatting to ensure proper INI file structure.
|
||||
*
|
||||
* @param fileToEdit The path to the INI file to be modified or created.
|
||||
* @param desiredSection The name of the section in which the key-name change should occur.
|
||||
* @param desiredKey The key name to be changed.
|
||||
* @param desiredNewKey The new key name to replace the original key name.
|
||||
*/
|
||||
void setIniFileKey(const std::string& fileToEdit, const std::string& desiredSection, const std::string& desiredKey, const std::string& desiredNewKey, const std::string& comment="");
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Adds a new section to an INI file.
|
||||
*
|
||||
* This function adds a new section with the specified name to the INI file located at the
|
||||
* specified path. If the section already exists, it does nothing.
|
||||
*
|
||||
* @param filePath The path to the INI file.
|
||||
* @param sectionName The name of the section to add.
|
||||
*/
|
||||
void addIniSection(const std::string& filePath, const std::string& sectionName);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Renames a section in an INI file.
|
||||
*
|
||||
* This function renames the section with the specified current name to the specified new name
|
||||
* in the INI file located at the specified path. If the current section does not exist, or if the
|
||||
* new section name already exists, it does nothing.
|
||||
*
|
||||
* @param filePath The path to the INI file.
|
||||
* @param currentSectionName The name of the section to rename.
|
||||
* @param newSectionName The new name for the section.
|
||||
*/
|
||||
void renameIniSection(const std::string& filePath, const std::string& currentSectionName, const std::string& newSectionName);
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Removes a section from an INI file.
|
||||
*
|
||||
* This function removes the section with the specified name, including all its associated key-value
|
||||
* pairs, from the INI file located at the specified path. If the section does not exist in the file,
|
||||
* it does nothing.
|
||||
*
|
||||
* @param filePath The path to the INI file.
|
||||
* @param sectionName The name of the section to remove.
|
||||
*/
|
||||
void removeIniSection(const std::string& filePath, const std::string& sectionName);
|
||||
|
||||
|
||||
// Removes a key-value pair from an ini accordingly.
|
||||
void removeIniKey(const std::string& filePath, const std::string& sectionName, const std::string& keyName);
|
||||
|
||||
|
||||
//void saveIniFileData(const std::string& filePath, const std::map<std::string, std::map<std::string, std::string>>& data) {
|
||||
// std::ofstream file(filePath);
|
||||
// if (!file.is_open()) {
|
||||
// // Handle error: could not open file
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// for (const auto& section : data) {
|
||||
// file << "[" << section.first << "]\n";
|
||||
// for (const auto& kv : section.second) {
|
||||
// file << kv.first << "=" << kv.second << "\n";
|
||||
// }
|
||||
// file << "\n"; // Separate sections with a newline
|
||||
// }
|
||||
//
|
||||
// file.close();
|
||||
//}
|
||||
|
||||
|
||||
void syncIniValue(std::map<std::string, std::map<std::string, std::string>>& packageConfigData,
|
||||
const std::string& packageConfigIniPath,
|
||||
const std::string& optionName,
|
||||
const std::string& key,
|
||||
std::string& value);
|
||||
|
||||
/**
|
||||
* @brief Parses a command line into individual parts, handling quoted strings.
|
||||
*
|
||||
* @param line The command line to parse.
|
||||
* @return A vector of strings containing the parsed command parts.
|
||||
*/
|
||||
std::vector<std::string> parseCommandLine(const std::string& line);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Loads and parses options from an INI file.
|
||||
*
|
||||
* This function reads and parses options from an INI file, organizing them by section.
|
||||
*
|
||||
* @param packageIniPath The path to the INI file.
|
||||
* @return A vector containing pairs of section names and their associated key-value pairs.
|
||||
*/
|
||||
std::vector<std::pair<std::string, std::vector<std::vector<std::string>>>> loadOptionsFromIni(const std::string& packageIniPath);
|
||||
|
||||
/**
|
||||
* @brief Loads a specific section from an INI file.
|
||||
*
|
||||
* This function reads and parses a specific section from an INI file.
|
||||
*
|
||||
* @param packageIniPath The path to the INI file.
|
||||
* @param sectionName The name of the section to load.
|
||||
* @return A vector of commands within the specified section.
|
||||
*/
|
||||
std::vector<std::vector<std::string>> loadSpecificSectionFromIni(const std::string& packageIniPath, const std::string& sectionName);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Saves INI data structure to a file.
|
||||
*
|
||||
* This function writes a complete INI data structure to the specified file path.
|
||||
* The data structure should be organized as sections containing key-value pairs.
|
||||
*
|
||||
* @param filePath The path to the INI file to write.
|
||||
* @param data The complete INI data structure to save.
|
||||
*/
|
||||
void saveIniFileData(const std::string& filePath, const std::map<std::string, std::map<std::string, std::string>>& data);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,107 @@
|
||||
/********************************************************************************
|
||||
* File: json_funcs.hpp
|
||||
* Author: ppkantorski
|
||||
* Description:
|
||||
* This header file provides functions for working with JSON files in C++ using
|
||||
* the `cJSON` library. It includes a function to read JSON data from a file.
|
||||
*
|
||||
* For the latest updates and contributions, visit the project's GitHub repository.
|
||||
* (GitHub Repository: https://github.com/ppkantorski/Ultrahand-Overlay)
|
||||
*
|
||||
* Note: Please be aware that this notice cannot be altered or removed. It is a part
|
||||
* of the project's documentation and must remain intact.
|
||||
*
|
||||
* Licensed under both GPLv2 and CC-BY-4.0
|
||||
* Copyright (c) 2024 ppkantorski
|
||||
********************************************************************************/
|
||||
#pragma once
|
||||
#ifndef JSON_FUNCS_HPP
|
||||
#define JSON_FUNCS_HPP
|
||||
#if !USING_FSTREAM_DIRECTIVE // For not using fstream (needs implementing)
|
||||
#include <stdio.h>
|
||||
#else
|
||||
#include <fstream>
|
||||
#endif
|
||||
#include <string>
|
||||
#include <cJSON.h>
|
||||
#include "string_funcs.hpp"
|
||||
#include <switch.h>
|
||||
|
||||
namespace ult {
|
||||
// Define json_t as an opaque type to maintain API compatibility
|
||||
typedef void json_t;
|
||||
|
||||
// Define a custom deleter for json_t*
|
||||
struct JsonDeleter {
|
||||
void operator()(json_t* json) const {
|
||||
if (json) {
|
||||
cJSON_Delete(reinterpret_cast<cJSON*>(json));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief Reads JSON data from a file and returns it as a `json_t` object.
|
||||
*
|
||||
* @param filePath The path to the JSON file.
|
||||
* @return A `json_t` object representing the parsed JSON data. Returns `nullptr` on error.
|
||||
*/
|
||||
json_t* readJsonFromFile(const std::string& filePath);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Parses a JSON string into a json_t object.
|
||||
*
|
||||
* This function takes a JSON string as input and parses it into a json_t object using cJSON library's `cJSON_Parse` function.
|
||||
* If parsing fails, it logs the error and returns nullptr.
|
||||
*
|
||||
* @param input The input JSON string to parse.
|
||||
* @return A json_t object representing the parsed JSON, or nullptr if parsing fails.
|
||||
*/
|
||||
json_t* stringToJson(const std::string& input);
|
||||
|
||||
|
||||
// Function to get a string from a JSON object
|
||||
std::string getStringFromJson(const json_t* root, const char* key);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Loads a JSON file from the specified path and retrieves a string value for a given key.
|
||||
*
|
||||
* This function combines the functionality of loading a JSON file and retrieving a string value associated
|
||||
* with a given key in a single step.
|
||||
*
|
||||
* @param filePath The path to the JSON file.
|
||||
* @param key The key whose associated string value is to be retrieved.
|
||||
* @return A string containing the value associated with the given key, or an empty string if the key is not found.
|
||||
*/
|
||||
std::string getStringFromJsonFile(const std::string& filePath, const std::string& key);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Sets a value in a JSON file, creating the file if it doesn't exist.
|
||||
*
|
||||
* @param filePath The path to the JSON file.
|
||||
* @param key The key to set.
|
||||
* @param value The value to set (auto-detected type).
|
||||
* @param createIfNotExists Whether to create the file if it doesn't exist.
|
||||
* @return true if successful, false otherwise.
|
||||
*/
|
||||
bool setJsonValue(const std::string& filePath, const std::string& key, const std::string& value, bool createIfNotExists = false);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Renames a key in a JSON file.
|
||||
*
|
||||
* @param filePath The path to the JSON file.
|
||||
* @param oldKey The current key name.
|
||||
* @param newKey The new key name.
|
||||
* @return true if successful, false otherwise.
|
||||
*/
|
||||
bool renameJsonKey(const std::string& filePath, const std::string& oldKey, const std::string& newKey);
|
||||
|
||||
|
||||
void pushNotificationJson(const std::string& text, size_t fontSize=28);
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,110 @@
|
||||
/********************************************************************************
|
||||
* File: list_funcs.hpp
|
||||
* Author: ppkantorski
|
||||
* Description:
|
||||
* This header file contains function declarations and utility functions related
|
||||
* to working with lists and vectors of strings. These functions are used in the
|
||||
* Ultrahand Overlay project to perform various operations on lists, such as
|
||||
* removing entries, filtering, and more.
|
||||
*
|
||||
* For the latest updates and contributions, visit the project's GitHub repository.
|
||||
* (GitHub Repository: https://github.com/ppkantorski/Ultrahand-Overlay)
|
||||
*
|
||||
* Note: Please be aware that this notice cannot be altered or removed. It is a part
|
||||
* of the project's documentation and must remain intact.
|
||||
*
|
||||
* Licensed under both GPLv2 and CC-BY-4.0
|
||||
* Copyright (c) 2024 ppkantorski
|
||||
********************************************************************************/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef LIST_FUNCS_HPP
|
||||
#define LIST_FUNCS_HPP
|
||||
|
||||
#if !USING_FSTREAM_DIRECTIVE // For not using fstream (needs implementing)
|
||||
#include <stdio.h>
|
||||
#else
|
||||
#include <fstream>
|
||||
#endif
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
#include "debug_funcs.hpp"
|
||||
#include "string_funcs.hpp"
|
||||
#include "get_funcs.hpp"
|
||||
|
||||
|
||||
namespace ult {
|
||||
|
||||
std::vector<std::string> splitIniList(const std::string& value);
|
||||
|
||||
|
||||
std::string joinIniList(const std::vector<std::string>& list);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Removes entries from a vector of strings that match a specified entry.
|
||||
*
|
||||
* This function removes entries from the `itemsList` vector of strings that match the `entry`.
|
||||
*
|
||||
* @param entry The entry to be compared against the elements in `itemsList`.
|
||||
* @param itemsList The vector of strings from which matching entries will be removed.
|
||||
*/
|
||||
void removeEntryFromList(const std::string& entry, std::vector<std::string>& itemsList);
|
||||
|
||||
/**
|
||||
* @brief Filters a list of strings based on a specified filter list.
|
||||
*
|
||||
* This function filters a list of strings (`itemsList`) by removing entries that match any
|
||||
* of the criteria specified in the `filterList`. It uses the `removeEntryFromList` function
|
||||
* to perform the removal.
|
||||
*
|
||||
* @param filterList The list of entries to filter by. Entries in `itemsList` matching any entry in this list will be removed.
|
||||
* @param itemsList The list of stringsto be filtered.
|
||||
*/
|
||||
void filterItemsList(const std::vector<std::string>& filterList, std::vector<std::string>& itemsList);
|
||||
|
||||
|
||||
// Function to read file into a vector of strings
|
||||
std::vector<std::string> readListFromFile(const std::string& filePath, size_t maxLines=0);
|
||||
|
||||
|
||||
// Function to get an entry from the list based on the index
|
||||
std::string getEntryFromListFile(const std::string& listPath, size_t listIndex);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Splits a string into a vector of strings using a delimiter.
|
||||
*
|
||||
* This function splits the input string into multiple strings using the specified delimiter.
|
||||
*
|
||||
* @param str The input string to split.
|
||||
* @return A vector of strings containing the split values.
|
||||
*/
|
||||
std::vector<std::string> stringToList(const std::string& str);
|
||||
|
||||
|
||||
// Function to read file into a set of strings
|
||||
std::unordered_set<std::string> readSetFromFile(const std::string& filePath);
|
||||
|
||||
|
||||
// Function to write a set to a file
|
||||
void writeSetToFile(const std::unordered_set<std::string>& fileSet, const std::string& filePath);
|
||||
|
||||
|
||||
// Function to compare two file lists and save duplicates to an output file
|
||||
void compareFilesLists(const std::string& txtFilePath1, const std::string& txtFilePath2, const std::string& outputTxtFilePath);
|
||||
|
||||
|
||||
// Helper function to read a text file and process each line with a callback
|
||||
void processFileLines(const std::string& filePath, const std::function<void(const std::string&)>& callback);
|
||||
|
||||
|
||||
void compareWildcardFilesLists(const std::string& wildcardPatternFilePath, const std::string& txtFilePath, const std::string& outputTxtFilePath);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,108 @@
|
||||
/********************************************************************************
|
||||
* File: mod_funcs.hpp
|
||||
* Author: ppkantorski
|
||||
* Description:
|
||||
* This header file contains function declarations and utility functions for IPS
|
||||
* binary generations. These functions are used in the Ultrahand Overlay project
|
||||
* to convert `.pchtxt` mods into `.ips` binaries.
|
||||
*
|
||||
* For the latest updates and contributions, visit the project's GitHub repository.
|
||||
* (GitHub Repository: https://github.com/ppkantorski/Ultrahand-Overlay)
|
||||
*
|
||||
* Note: Please be aware that this notice cannot be altered or removed. It is a part
|
||||
* of the project's documentation and must remain intact.
|
||||
*
|
||||
* Licensed under both GPLv2 and CC-BY-4.0
|
||||
* Copyright (c) 2024 ppkantorski
|
||||
********************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef MOD_FUNCS_HPP
|
||||
#define MOD_FUNCS_HPP
|
||||
|
||||
#if !USING_FSTREAM_DIRECTIVE // For not using fstream (needs implementing)
|
||||
#include <stdio.h>
|
||||
#else
|
||||
#include <fstream>
|
||||
#endif
|
||||
|
||||
//#include <sstream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <sys/stat.h>
|
||||
#include "debug_funcs.hpp"
|
||||
#include "path_funcs.hpp"
|
||||
#include "hex_funcs.hpp"
|
||||
#include <iomanip> // Include this header for std::setw and std::setfill
|
||||
|
||||
namespace ult {
|
||||
inline constexpr const char* IPS32_HEAD_MAGIC = "IPS32";
|
||||
inline constexpr const char* IPS32_FOOT_MAGIC = "EEOF";
|
||||
|
||||
//const std::string CHEAT_HEADER = "// auto generated by pchtxt2cheat\n\n";
|
||||
extern const std::string CHEAT_TYPE;
|
||||
extern const std::string CHEAT_EXT;
|
||||
extern const std::string CHEAT_ENCODING;
|
||||
|
||||
/**
|
||||
* @brief Checks if a cheat already exists in the cheat file.
|
||||
* @param cheatFilePath The path to the cheat file.
|
||||
* @param newCheat The new cheat to check.
|
||||
* @return True if the cheat exists, otherwise false.
|
||||
*/
|
||||
bool cheatExists(const std::string &cheatFilePath, const std::string &newCheat);
|
||||
|
||||
/**
|
||||
* @brief Appends a new cheat to the cheat file.
|
||||
* @param cheatFilePath The path to the cheat file.
|
||||
* @param newCheat The new cheat to append.
|
||||
*/
|
||||
void appendCheatToFile(const std::string &cheatFilePath, const std::string &newCheat);
|
||||
|
||||
/**
|
||||
* @brief Extracts the cheat name from the given file path.
|
||||
* @param filePath The full file path.
|
||||
* @return The extracted cheat name.
|
||||
*/
|
||||
std::string extractCheatName(const std::string &filePath);
|
||||
|
||||
// Helper function to determine if a string is a valid title ID
|
||||
bool isValidTitleID(const std::string &str);
|
||||
|
||||
// Function to find the title ID in the text, avoiding the @nsobid- line
|
||||
std::string findTitleID(const std::string &text);
|
||||
|
||||
/**
|
||||
* @brief Converts a .pchtxt file to a cheat file.
|
||||
* @param pchtxtPath The file path to the .pchtxt file.
|
||||
* @param cheatName The name of the cheat.
|
||||
* @param outCheatPath The file path for the output cheat file.
|
||||
* @return True if the conversion was successful, false otherwise.
|
||||
*/
|
||||
bool pchtxt2cheat(const std::string &pchtxtPath, std::string cheatName = "", std::string outCheatPath = "");
|
||||
|
||||
// Corrected helper function to convert values to big-endian format
|
||||
uint32_t toBigEndian(uint32_t value);
|
||||
|
||||
uint16_t toBigEndian(uint16_t value);
|
||||
|
||||
// Helper function to convert a vector of bytes to a hex string for logging
|
||||
|
||||
std::string hexToString(const std::vector<uint8_t>& bytes);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Converts a .pchtxt file to an IPS file using fstream.
|
||||
*
|
||||
* This function reads the contents of a .pchtxt file, extracts the address-value pairs,
|
||||
* and generates an IPS file with the provided output folder.
|
||||
*
|
||||
* @param pchtxtPath The file path to the .pchtxt file.
|
||||
* @param outputFolder The folder path for the output IPS file.
|
||||
* @return True if the conversion was successful, false otherwise.
|
||||
*/
|
||||
bool pchtxt2ips(const std::string& pchtxtPath, const std::string& outputFolder);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,279 @@
|
||||
/********************************************************************************
|
||||
* File: path_funcs.hpp
|
||||
* Author: ppkantorski
|
||||
* Description:
|
||||
* This header file contains function declarations and utility functions related
|
||||
* to file and directory path manipulation. These functions are used in the
|
||||
* Ultrahand Overlay project to handle file operations, such as creating
|
||||
* directories, moving files, and more.
|
||||
*
|
||||
* For the latest updates and contributions, visit the project's GitHub repository.
|
||||
* (GitHub Repository: https://github.com/ppkantorski/Ultrahand-Overlay)
|
||||
*
|
||||
* Note: Please be aware that this notice cannot be altered or removed. It is a part
|
||||
* of the project's documentation and must remain intact.
|
||||
*
|
||||
* Licensed under both GPLv2 and CC-BY-4.0
|
||||
* Copyright (c) 2024 ppkantorski
|
||||
********************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef PATH_FUNCS_HPP
|
||||
#define PATH_FUNCS_HPP
|
||||
|
||||
#if !USING_FSTREAM_DIRECTIVE // For not using fstream (needs implementing)
|
||||
#include <stdio.h>
|
||||
#else
|
||||
#include <fstream>
|
||||
#endif
|
||||
|
||||
#include <memory>
|
||||
#include <dirent.h>
|
||||
#include <sys/stat.h>
|
||||
#include "global_vars.hpp"
|
||||
#include "string_funcs.hpp"
|
||||
#include "get_funcs.hpp"
|
||||
#include <queue>
|
||||
#include <mutex>
|
||||
|
||||
|
||||
namespace ult {
|
||||
extern std::atomic<bool> abortFileOp;
|
||||
|
||||
extern size_t COPY_BUFFER_SIZE; // Made const for thread safety
|
||||
extern std::atomic<int> copyPercentage;
|
||||
|
||||
// Mutex for thread-safe logging operations
|
||||
extern std::mutex logMutex;
|
||||
|
||||
/**
|
||||
* @brief Checks if a path points to a directory.
|
||||
*
|
||||
* This function checks if the specified path points to a directory.
|
||||
*
|
||||
* @param path The path to check.
|
||||
* @return True if the path is a directory, false otherwise.
|
||||
*/
|
||||
bool isDirectory(const std::string& path);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Checks if a path points to a file.
|
||||
*
|
||||
* This function checks if the specified path points to a file.
|
||||
*
|
||||
* @param path The path to check.
|
||||
* @return True if the path is a file, false otherwise.
|
||||
*/
|
||||
bool isFile(const std::string& path);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Checks if a path points to a file or directory.
|
||||
*
|
||||
* This function checks if the specified path points to either a file or a directory.
|
||||
*
|
||||
* @param path The path to check.
|
||||
* @return True if the path points to a file or directory, false otherwise.
|
||||
*/
|
||||
bool isFileOrDirectory(const std::string& path);
|
||||
|
||||
|
||||
bool isDirectoryEmpty(const std::string& dirPath);
|
||||
|
||||
/**
|
||||
* @brief Creates a single directory if it doesn't exist.
|
||||
*
|
||||
* This function checks if the specified directory exists, and if not, it creates the directory.
|
||||
*
|
||||
* @param directoryPath The path of the directory to be created.
|
||||
*/
|
||||
void createSingleDirectory(const std::string& directoryPath);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Creates a directory and its parent directories if they don't exist.
|
||||
*
|
||||
* This function creates a directory specified by `directoryPath` and also creates any parent directories
|
||||
* if they don't exist. It handles nested directory creation.
|
||||
*
|
||||
* @param directoryPath The path of the directory to be created.
|
||||
*/
|
||||
void createDirectory(const std::string& directoryPath);
|
||||
|
||||
|
||||
#if !USING_FSTREAM_DIRECTIVE
|
||||
void writeLog(FILE* logFile, const std::string& line);
|
||||
#else
|
||||
void writeLog(std::ofstream& logFile, const std::string& line);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Creates a text file with the specified content.
|
||||
*
|
||||
* This function creates a text file specified by `filePath` and writes the given `content` to the file.
|
||||
*
|
||||
* @param filePath The path of the text file to be created.
|
||||
* @param content The content to be written to the text file.
|
||||
*/
|
||||
void createTextFile(const std::string& filePath, const std::string& content);
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Deletes a file or directory.
|
||||
*
|
||||
* This function deletes the file or directory specified by `path`. It can delete both files and directories.
|
||||
*
|
||||
* @param path The path of the file or directory to be deleted.
|
||||
*/
|
||||
void deleteFileOrDirectory(const std::string& pathToDelete, const std::string& logSource = "");
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Deletes files or directories that match a specified pattern.
|
||||
*
|
||||
* This function deletes files or directories specified by `pathPattern` by matching against a pattern.
|
||||
* It identifies files or directories that match the pattern and deletes them.
|
||||
*
|
||||
* @param pathPattern The pattern used to match and delete files or directories.
|
||||
*/
|
||||
void deleteFileOrDirectoryByPattern(const std::string& pathPattern, const std::string& logSource = "");
|
||||
|
||||
|
||||
void moveDirectory(const std::string& sourcePath, const std::string& destinationPath,
|
||||
const std::string& logSource = "", const std::string& logDestination = "");
|
||||
|
||||
|
||||
|
||||
bool moveFile(const std::string& sourcePath, const std::string& destinationPath,
|
||||
const std::string& logSource = "", const std::string& logDestination = "");
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Moves a file or directory to a new destination.
|
||||
*
|
||||
* This function moves a file or directory from the `sourcePath` to the `destinationPath`. It can handle both
|
||||
* files and directories and ensures that the destination directory exists before moving.
|
||||
*
|
||||
* @param sourcePath The path of the source file or directory.
|
||||
* @param destinationPath The path of the destination where the file or directory will be moved.
|
||||
*/
|
||||
void moveFileOrDirectory(const std::string& sourcePath, const std::string& destinationPath,
|
||||
const std::string& logSource = "", const std::string& logDestination = "");
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Moves files or directories matching a specified pattern to a destination directory.
|
||||
*
|
||||
* This function identifies files or directories that match the `sourcePathPattern` and moves them to the `destinationPath`.
|
||||
* It processes each matching entry in the source directory pattern and moves them to the specified destination.
|
||||
*
|
||||
* @param sourcePathPattern The pattern used to match files or directories to be moved.
|
||||
* @param destinationPath The destination directory where matching files or directories will be moved.
|
||||
*/
|
||||
void moveFilesOrDirectoriesByPattern(const std::string& sourcePathPattern, const std::string& destinationPath,
|
||||
const std::string& logSource = "", const std::string& logDestination = "");
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Copies a single file from the source path to the destination path.
|
||||
*
|
||||
* This function copies a single file specified by `fromFile` to the location specified by `toFile`.
|
||||
*
|
||||
* @param fromFile The path of the source file to be copied.
|
||||
* @param toFile The path of the destination where the file will be copied.
|
||||
*/
|
||||
void copySingleFile(const std::string& fromFile, const std::string& toFile, long long& totalBytesCopied, const long long totalSize,
|
||||
const std::string& logSource = "", const std::string& logDestination = "");
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Recursively calculates the total size of the given file or directory.
|
||||
* @param path The path to the file or directory.
|
||||
* @return The total size in bytes of all files within the directory or the size of a file.
|
||||
*/
|
||||
long long getTotalSize(const std::string& path);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Copies a file or directory from the source path to the destination path.
|
||||
*
|
||||
* This function copies a file or directory specified by `fromFileOrDirectory` to the location specified by `toFileOrDirectory`.
|
||||
* If the source is a regular file, it copies the file to the destination. If the source is a directory, it recursively copies
|
||||
* the entire directory and its contents to the destination.
|
||||
*
|
||||
* @param fromPath The path of the source file or directory to be copied.
|
||||
* @param toPath The path of the destination where the file or directory will be copied.
|
||||
*/
|
||||
void copyFileOrDirectory(const std::string& fromPath, const std::string& toPath, long long* totalBytesCopied = nullptr, long long totalSize = 0,
|
||||
const std::string& logSource = "", const std::string& logDestination = "");
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Copies files or directories matching a specified pattern to a destination directory.
|
||||
*
|
||||
* This function identifies files or directories that match the `sourcePathPattern` and copies them to the `toDirectory`.
|
||||
* It processes each matching entry in the source directory pattern and copies them to the specified destination.
|
||||
*
|
||||
* @param sourcePathPattern The pattern used to match files or directories to be copied.
|
||||
* @param toDirectory The destination directory where matching files or directories will be copied.
|
||||
*/
|
||||
void copyFileOrDirectoryByPattern(const std::string& sourcePathPattern, const std::string& toDirectory,
|
||||
const std::string& logSource = "", const std::string& logDestination = "");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Mirrors the deletion of files from a source directory to a target directory.
|
||||
*
|
||||
* This function mirrors the deletion of files from a `sourcePath` directory to a `targetPath` directory.
|
||||
* It deletes corresponding files in the `targetPath` that match the source directory structure.
|
||||
*
|
||||
* @param sourcePath The path of the source directory.
|
||||
* @param targetPath The path of the target directory where files will be mirrored and deleted.
|
||||
* Default is "sdmc:/". You can specify a different target path if needed.
|
||||
*/
|
||||
void mirrorFiles(const std::string& sourcePath, const std::string targetPath, const std::string mode);
|
||||
|
||||
|
||||
/**
|
||||
* @brief For each match of the wildcard pattern, creates an empty text file
|
||||
* named basename.txt inside the output directory.
|
||||
* Uses FILE* if !USING_FSTREAM_DIRECTIVE is defined, otherwise uses std::ofstream.
|
||||
*
|
||||
* @param wildcardPattern A path with a wildcard, such as /some/path/[*].
|
||||
* Each match results in a file named after the basename.
|
||||
* @param outputDir Directory where the output files will be written.
|
||||
* Created if it doesn't already exist.
|
||||
*/
|
||||
void createFlagFiles(const std::string& wildcardPattern, const std::string& outputDir);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Removes all files starting with "._" from a directory and its subdirectories.
|
||||
*
|
||||
* This function recursively scans the specified directory and removes all files
|
||||
* whose names start with "._" (commonly macOS metadata files). It processes
|
||||
* all subdirectories recursively.
|
||||
*
|
||||
* @param sourcePath The path of the directory to clean.
|
||||
*/
|
||||
void dotCleanDirectory(const std::string& sourcePath);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,273 @@
|
||||
/********************************************************************************
|
||||
* File: string_funcs.hpp
|
||||
* Author: ppkantorski
|
||||
* Description:
|
||||
* This header file contains function declarations and utility functions for string
|
||||
* manipulation. These functions are used in the Ultrahand Overlay project to
|
||||
* perform operations like trimming whitespaces, removing quotes, replacing
|
||||
* multiple slashes, and more.
|
||||
*
|
||||
* For the latest updates and contributions, visit the project's GitHub repository.
|
||||
* (GitHub Repository: https://github.com/ppkantorski/Ultrahand-Overlay)
|
||||
*
|
||||
* Note: Please be aware that this notice cannot be altered or removed. It is a part
|
||||
* of the project's documentation and must remain intact.
|
||||
*
|
||||
* Licensed under both GPLv2 and CC-BY-4.0
|
||||
* Copyright (c) 2024 ppkantorski
|
||||
********************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef STRING_FUNCS_HPP
|
||||
#define STRING_FUNCS_HPP
|
||||
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <iterator>
|
||||
#include <vector>
|
||||
//#include <jansson.h>
|
||||
//#include <regex>
|
||||
#include <algorithm>
|
||||
#include <sys/stat.h>
|
||||
#include <dirent.h>
|
||||
#include "global_vars.hpp"
|
||||
#include "debug_funcs.hpp"
|
||||
|
||||
namespace ult {
|
||||
|
||||
extern std::string to_string(int value);
|
||||
extern int stoi(const std::string& str, std::size_t* pos = nullptr, int base = 10);
|
||||
extern float stof(const std::string& str);
|
||||
|
||||
|
||||
/**
|
||||
* @brief A lightweight string stream class that mimics basic functionality of std::istringstream.
|
||||
*/
|
||||
class StringStream {
|
||||
public:
|
||||
StringStream() : position(0), hexMode(false), validState(true) {}
|
||||
|
||||
|
||||
// Add this constructor to accept a string
|
||||
StringStream(const std::string& input) : data(input), position(0), hexMode(false) {}
|
||||
|
||||
// Set hex mode
|
||||
StringStream& hex() {
|
||||
hexMode = true;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Reset hex mode
|
||||
StringStream& resetHex() {
|
||||
hexMode = false;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Mimics std::getline() with a delimiter
|
||||
bool getline(std::string& output, char delimiter);
|
||||
|
||||
// Mimics operator >> to split by whitespace
|
||||
StringStream& operator>>(std::string& output);
|
||||
|
||||
// Overload the << operator to insert strings and integers
|
||||
StringStream& operator<<(const std::string& input);
|
||||
StringStream& operator<<(const char* input);
|
||||
StringStream& operator<<(char input);
|
||||
StringStream& operator<<(int input); // Handles int insertion with hex support
|
||||
StringStream& operator<<(long long input); // for long long
|
||||
|
||||
// Conversion to bool for checking stream state (success/failure)
|
||||
explicit operator bool() const {
|
||||
return validState;
|
||||
}
|
||||
|
||||
std::string str() const;
|
||||
void clear() { data.clear(); position = 0; } // Add clear function
|
||||
|
||||
private:
|
||||
std::string data;
|
||||
size_t position;
|
||||
bool hexMode;
|
||||
bool validState; // Track if the stream is in a valid state
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Trims leading and trailing whitespaces from a string.
|
||||
*
|
||||
* This function removes leading and trailing whitespaces, tabs, newlines, carriage returns, form feeds,
|
||||
* and vertical tabs from the input string.
|
||||
*
|
||||
* @param str The input string to trim.
|
||||
* @return The trimmed string.
|
||||
*/
|
||||
void trim(std::string& str);
|
||||
|
||||
|
||||
|
||||
// Function to trim newline characters from the end of a string
|
||||
void trimNewline(std::string& str);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Removes all white spaces from a string.
|
||||
*
|
||||
* This function removes all white spaces, including spaces, tabs, newlines, carriage returns, form feeds,
|
||||
* and vertical tabs from the input string.
|
||||
*
|
||||
* @param str The input string to remove white spaces from.
|
||||
* @return The string with white spaces removed.
|
||||
*/
|
||||
std::string removeWhiteSpaces(const std::string& str);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Removes quotes from a string.
|
||||
*
|
||||
* This function removes single and double quotes from the beginning and end of the input string.
|
||||
*
|
||||
* @param str The input string to remove quotes from.
|
||||
* @return The string with quotes removed.
|
||||
*/
|
||||
void removeQuotes(std::string& str);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Replaces multiple consecutive slashes with a single slash in a string.
|
||||
*
|
||||
* This function replaces sequences of two or more consecutive slashes with a single slash in the input string.
|
||||
*
|
||||
* @param input The input string to process.
|
||||
* @return The string with multiple slashes replaced.
|
||||
*/
|
||||
std::string replaceMultipleSlashes(const std::string& input);
|
||||
|
||||
|
||||
void resolveDirectoryTraversal(std::string& path);
|
||||
|
||||
/**
|
||||
* @brief Preprocesses a path string by replacing multiple slashes and adding "sdmc:" prefix.
|
||||
*
|
||||
* This function preprocesses a path string by removing multiple consecutive slashes,
|
||||
* adding the "sdmc:" prefix if not present, and modifying the input string in place.
|
||||
*
|
||||
* @param path The input path string to preprocess, passed by reference.
|
||||
*/
|
||||
void preprocessPath(std::string& path, const std::string& packagePath = "");
|
||||
|
||||
/**
|
||||
* @brief Preprocesses a URL string by adding "https://" prefix.
|
||||
*
|
||||
* This function preprocesses a URL string by adding the "https://" prefix if not already present.
|
||||
*
|
||||
* @param path The input URL string to preprocess, passed by reference and modified in-place.
|
||||
*/
|
||||
void preprocessUrl(std::string& path);
|
||||
|
||||
/**
|
||||
* @brief Drops the file extension from a filename.
|
||||
*
|
||||
* This function removes the file extension (characters after the last dot) from the input filename string.
|
||||
*
|
||||
* @param filename The input filename from which to drop the extension, passed by reference and modified in-place.
|
||||
*/
|
||||
void dropExtension(std::string& filename);
|
||||
|
||||
/**
|
||||
* @brief Checks if a string starts with a given prefix.
|
||||
*
|
||||
* This function checks if the input string starts with the specified prefix.
|
||||
*
|
||||
* @param str The input string to check.
|
||||
* @param prefix The prefix to check for.
|
||||
* @return True if the string starts with the prefix, false otherwise.
|
||||
*/
|
||||
bool startsWith(const std::string& str, const std::string& prefix);
|
||||
|
||||
|
||||
// Helper function to check if a string is a valid integer
|
||||
bool isValidNumber(const std::string& str);
|
||||
|
||||
// For properly handling placeholder replacements
|
||||
std::string returnOrNull(const std::string& value);
|
||||
|
||||
|
||||
// Function to slice a string from start to end index
|
||||
std::string sliceString(const std::string& str, size_t start, size_t end);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Converts a string to lowercase.
|
||||
*
|
||||
* This function takes a string as input and returns a lowercase version of that string.
|
||||
*
|
||||
* @param str The input string to convert to lowercase.
|
||||
* @return The lowercase version of the input string.
|
||||
*/
|
||||
|
||||
std::string stringToLowercase(const std::string& str);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Converts a string to uppercase.
|
||||
*
|
||||
* This function takes a string as input and returns an uppercase version of that string.
|
||||
*
|
||||
* @param str The input string to convert to uppercase.
|
||||
* @return The uppercase version of the input string.
|
||||
*/
|
||||
|
||||
std::string stringToUppercase(const std::string& str);
|
||||
|
||||
/**
|
||||
* @brief Formats a priority string to a desired width.
|
||||
*
|
||||
* This function takes a priority string and formats it to a specified desired width by padding with '0's if it's shorter
|
||||
* or truncating with '9's if it's longer.
|
||||
*
|
||||
* @param priority The input priority string to format.
|
||||
* @param desiredWidth The desired width of the formatted string (default is 4).
|
||||
* @return A formatted priority string.
|
||||
*/
|
||||
std::string formatPriorityString(const std::string& priority, int desiredWidth = 4);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Removes the part of the string after the first occurrence of '?' character.
|
||||
*
|
||||
* This function takes a string and removes the portion of the string that appears after
|
||||
* the first '?' character, if found. If no '?' character is present, the string remains unchanged.
|
||||
*
|
||||
* @param input The input string from which to remove the tag, passed by reference and modified in-place.
|
||||
*/
|
||||
void removeTag(std::string &input);
|
||||
|
||||
std::string getFirstLongEntry(const std::string& input, size_t minLength = 8);
|
||||
|
||||
|
||||
// This will take a string like "v1.3.5-abasdfasdfa" and output "1.3.5". string could also look like "test-1.3.5-1" or "v1.3.5" and we will only want "1.3.5"
|
||||
std::string cleanVersionLabel(const std::string& input);
|
||||
|
||||
|
||||
std::string extractTitle(const std::string& input);
|
||||
|
||||
|
||||
std::vector<std::string> splitString(const std::string& str, const std::string& delimiter);
|
||||
|
||||
|
||||
// Function to split a string by a delimiter and return a specific index
|
||||
std::string splitStringAtIndex(const std::string& str, const std::string& delimiter, size_t index);
|
||||
|
||||
|
||||
std::string customAlign(int number);
|
||||
|
||||
#if IS_LAUNCHER_DIRECTIVE
|
||||
std::string inputExists(const std::string& input);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,719 @@
|
||||
/********************************************************************************
|
||||
* File: tsl_utils.hpp
|
||||
* Author: ppkantorski
|
||||
* Description:
|
||||
* 'tsl_utils.hpp' is a central utility header for the Ultrahand Overlay project,
|
||||
* containing a variety of functions and definitions related to system status,
|
||||
* input handling, and application-specific behavior on the Nintendo Switch.
|
||||
* This header provides essential utilities for interacting with the system,
|
||||
* managing key input, and enhancing overlay functionality.
|
||||
*
|
||||
* The utilities defined here are designed to operate independently, facilitating
|
||||
* robust system interaction capabilities required for custom overlays.
|
||||
*
|
||||
* For the latest updates and contributions, visit the project's GitHub repository:
|
||||
* GitHub Repository: https://github.com/ppkantorski/Ultrahand-Overlay
|
||||
*
|
||||
* Note: This notice is integral to the project's documentation and must not be
|
||||
* altered or removed.
|
||||
*
|
||||
* Licensed under both GPLv2 and CC-BY-4.0
|
||||
* Copyright (c) 2024 ppkantorski
|
||||
********************************************************************************/
|
||||
|
||||
|
||||
#pragma once
|
||||
#ifndef TSL_UTILS_HPP
|
||||
#define TSL_UTILS_HPP
|
||||
|
||||
#if !USING_FSTREAM_DIRECTIVE // For not using fstream (needs implementing)
|
||||
#include <stdio.h>
|
||||
#else
|
||||
#include <fstream>
|
||||
#endif
|
||||
|
||||
#include <ultra.hpp>
|
||||
#include <switch.h>
|
||||
#include <arm_neon.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <strings.h>
|
||||
//#include <math.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <cwctype>
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
#include <mutex>
|
||||
#include <memory>
|
||||
//#include <chrono>
|
||||
#include <list>
|
||||
#include <stack>
|
||||
#include <map>
|
||||
#include <barrier>
|
||||
|
||||
#ifndef APPROXIMATE_cos
|
||||
// Approximation for cos(x) using Taylor series around 0
|
||||
#define APPROXIMATE_cos(x) (1 - (x) * (x) / 2 + (x) * (x) * (x) * (x) / 24) // valid for small x
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef APPROXIMATE_ifloor
|
||||
#define APPROXIMATE_ifloor(x) ((int)((x) >= 0 ? (x) : (x) - 1)) // truncate toward negative infinity
|
||||
#define APPROXIMATE_iceil(x) ((int)((x) == (int)(x) ? (x) : ((x) > 0 ? (int)(x) + 1 : (int)(x)))) // truncate toward positive infinity
|
||||
#endif
|
||||
|
||||
#ifndef APPROXIMATE_sqrt
|
||||
// Fast approximation for sqrt using Newton's method
|
||||
#define APPROXIMATE_sqrt(x) ((x) <= 0 ? 0 : (x) / 2.0 * (3.0 - ((x) * (x) * 0.5))) // Approximation for x close to 1
|
||||
#define APPROXIMATE_pow(x, y) ((y) == 0 ? 1 : ((y) == 1 ? (x) : APPROXIMATE_sqrt(x))) // limited to approximate sqrt if y=0.5
|
||||
#endif
|
||||
|
||||
#ifndef APPROXIMATE_fmod
|
||||
#define APPROXIMATE_fmod(x, y) ((x) - ((int)((x) / (y)) * (y))) // equivalent to x - floor(x/y) * y
|
||||
#endif
|
||||
|
||||
#ifndef APPROXIMATE_cos
|
||||
// Approximation for cos(x) using Taylor series around 0
|
||||
#define APPROXIMATE_cos(x) (1 - (x) * (x) / 2 + (x) * (x) * (x) * (x) / 24) // valid for small x
|
||||
#endif
|
||||
|
||||
#ifndef APPROXIMATE_acos
|
||||
#define APPROXIMATE_acos(x) (1.5708 - (x) - (x)*(x)*(x) / 6) // limited approximation for acos in range [-1, 1]
|
||||
#endif
|
||||
|
||||
#ifndef APPROXIMATE_fabs
|
||||
#define APPROXIMATE_fabs(x) ((x) < 0 ? -(x) : (x))
|
||||
#endif
|
||||
|
||||
struct OverlayCombo {
|
||||
std::string path; // full overlay path
|
||||
std::string launchArg; // empty = use per-overlay launch_args key, otherwise a “mode” arg
|
||||
};
|
||||
|
||||
struct SwapDepth {
|
||||
u32 value;
|
||||
explicit SwapDepth(u32 v) : value(v) {}
|
||||
};
|
||||
|
||||
namespace ult {
|
||||
extern bool correctFrameSize; // for detecting the correct Overlay display size
|
||||
|
||||
extern u16 DefaultFramebufferWidth; ///< Width of the framebuffer
|
||||
extern u16 DefaultFramebufferHeight; ///< Height of the framebuffer
|
||||
|
||||
extern std::unordered_map<std::string, std::string> translationCache;
|
||||
|
||||
extern std::unordered_map<u64, OverlayCombo> g_entryCombos;
|
||||
extern std::atomic<bool> launchingOverlay;
|
||||
extern std::atomic<bool> settingsInitialized;
|
||||
extern std::atomic<bool> currentForeground;
|
||||
//extern std::mutex simulatedNextPageMutex;
|
||||
|
||||
//void loadOverlayKeyCombos();
|
||||
//std::string getOverlayForKeyCombo(u64 keys);
|
||||
|
||||
bool readFileContent(const std::string& filePath, std::string& content);
|
||||
void parseJsonContent(const std::string& content, std::unordered_map<std::string, std::string>& result);
|
||||
bool parseJsonToMap(const std::string& filePath, std::unordered_map<std::string, std::string>& result);
|
||||
|
||||
bool loadTranslationsFromJSON(const std::string& filePath);
|
||||
|
||||
extern u16 activeHeaderHeight;
|
||||
|
||||
bool consoleIsDocked();
|
||||
|
||||
std::string getTitleIdAsString();
|
||||
|
||||
extern std::string lastTitleID;
|
||||
extern std::atomic<bool> resetForegroundCheck;
|
||||
|
||||
|
||||
//extern bool isLauncher;
|
||||
extern std::atomic<bool> internalTouchReleased;
|
||||
extern u32 layerEdge;
|
||||
extern bool useRightAlignment;
|
||||
extern bool useSwipeToOpen;
|
||||
extern bool useLaunchCombos;
|
||||
extern bool useNotifications;
|
||||
extern bool usePageSwap;
|
||||
extern std::atomic<bool> noClickableItems;
|
||||
|
||||
extern bool useDynamicLogo;
|
||||
extern bool useSelectionBG;
|
||||
extern bool useSelectionText;
|
||||
extern bool useSelectionValue;
|
||||
|
||||
|
||||
|
||||
// Define the duration boundaries (for smooth scrolling)
|
||||
//extern const std::chrono::milliseconds initialInterval; // Example initial interval
|
||||
//extern const std::chrono::milliseconds shortInterval; // Short interval after long hold
|
||||
//extern const std::chrono::milliseconds transitionPoint; // Point at which the shortest interval is reached
|
||||
|
||||
|
||||
|
||||
//constexpr std::chrono::milliseconds initialInterval = std::chrono::milliseconds(67); // Example initial interval
|
||||
//constexpr std::chrono::milliseconds shortInterval = std::chrono::milliseconds(10); // Short interval after long hold
|
||||
//constexpr std::chrono::milliseconds transitionPoint = std::chrono::milliseconds(2000); // Point at which the shortest interval is reached
|
||||
|
||||
// Function to interpolate between two durations
|
||||
//std::chrono::milliseconds interpolateDuration(std::chrono::milliseconds start, std::chrono::milliseconds end, float t);
|
||||
|
||||
#if IS_LAUNCHER_DIRECTIVE
|
||||
extern std::atomic<bool> overlayLaunchRequested;
|
||||
extern std::string requestedOverlayPath;
|
||||
extern std::string requestedOverlayArgs;
|
||||
extern std::mutex overlayLaunchMutex;
|
||||
#endif
|
||||
|
||||
|
||||
//#include <filesystem> // Comment out filesystem
|
||||
|
||||
// CUSTOM SECTION START
|
||||
//extern float backWidth, selectWidth, nextPageWidth;
|
||||
extern std::atomic<float> backWidth;
|
||||
extern std::atomic<float> selectWidth;
|
||||
extern std::atomic<float> nextPageWidth;
|
||||
extern std::atomic<bool> inMainMenu;
|
||||
extern std::atomic<bool> inOverlaysPage;
|
||||
extern std::atomic<bool> inPackagesPage;
|
||||
|
||||
extern bool firstBoot; // for detecting first boot
|
||||
|
||||
//static std::unordered_map<std::string, std::string> hexSumCache;
|
||||
|
||||
// Define an atomic bool for interpreter completion
|
||||
extern std::atomic<bool> threadFailure;
|
||||
extern std::atomic<bool> runningInterpreter;
|
||||
extern std::atomic<bool> shakingProgress;
|
||||
|
||||
extern std::atomic<bool> isHidden;
|
||||
extern std::atomic<bool> externalAbortCommands;
|
||||
|
||||
//bool progressAnimation = false;
|
||||
extern bool disableTransparency;
|
||||
//bool useCustomWallpaper = false;
|
||||
extern bool useMemoryExpansion;
|
||||
extern bool useOpaqueScreenshots;
|
||||
|
||||
extern std::atomic<bool> onTrackBar;
|
||||
extern std::atomic<bool> allowSlide;
|
||||
extern std::atomic<bool> unlockedSlide;
|
||||
|
||||
void atomicToggle(std::atomic<bool>& b);
|
||||
|
||||
/**
|
||||
* @brief Shutdown modes for the Ultrahand-Overlay project.
|
||||
*
|
||||
* These macros define the shutdown modes used in the Ultrahand-Overlay project:
|
||||
* - `SpsmShutdownMode_Normal`: Normal shutdown mode.
|
||||
* - `SpsmShutdownMode_Reboot`: Reboot mode.
|
||||
*/
|
||||
#define SpsmShutdownMode_Normal 0
|
||||
#define SpsmShutdownMode_Reboot 1
|
||||
|
||||
/**
|
||||
* @brief Key mapping macros for button keys.
|
||||
*
|
||||
* These macros define button keys for the Ultrahand-Overlay project to simplify key mappings.
|
||||
* For example, `KEY_A` represents the `HidNpadButton_A` key.
|
||||
*/
|
||||
#define KEY_A HidNpadButton_A
|
||||
#define KEY_B HidNpadButton_B
|
||||
#define KEY_X HidNpadButton_X
|
||||
#define KEY_Y HidNpadButton_Y
|
||||
#define KEY_L HidNpadButton_L
|
||||
#define KEY_R HidNpadButton_R
|
||||
#define KEY_ZL HidNpadButton_ZL
|
||||
#define KEY_ZR HidNpadButton_ZR
|
||||
#define KEY_PLUS HidNpadButton_Plus
|
||||
#define KEY_MINUS HidNpadButton_Minus
|
||||
#define KEY_DUP HidNpadButton_Up
|
||||
#define KEY_DDOWN HidNpadButton_Down
|
||||
#define KEY_DLEFT HidNpadButton_Left
|
||||
#define KEY_DRIGHT HidNpadButton_Right
|
||||
#define KEY_SL HidNpadButton_AnySL
|
||||
#define KEY_SR HidNpadButton_AnySR
|
||||
#define KEY_LSTICK HidNpadButton_StickL
|
||||
#define KEY_RSTICK HidNpadButton_StickR
|
||||
#define KEY_UP HidNpadButton_AnyUp
|
||||
#define KEY_DOWN HidNpadButton_AnyDown
|
||||
#define KEY_LEFT HidNpadButton_AnyLeft
|
||||
#define KEY_RIGHT HidNpadButton_AnyRight
|
||||
|
||||
#define SCRIPT_KEY HidNpadButton_Minus
|
||||
#define SYSTEM_SETTINGS_KEY HidNpadButton_Plus
|
||||
#define SETTINGS_KEY HidNpadButton_Y
|
||||
#define STAR_KEY HidNpadButton_X
|
||||
|
||||
|
||||
// Define a mask with all possible key flags
|
||||
#define ALL_KEYS_MASK (KEY_A | KEY_B | KEY_X | KEY_Y | KEY_DUP | KEY_DDOWN | KEY_DLEFT | KEY_DRIGHT | KEY_L | KEY_R | KEY_ZL | KEY_ZR | KEY_SL | KEY_SR | KEY_LSTICK | KEY_RSTICK | KEY_PLUS | KEY_MINUS)
|
||||
|
||||
|
||||
extern bool updateMenuCombos;
|
||||
|
||||
/**
|
||||
* @brief Ultrahand-Overlay Input Macros
|
||||
*
|
||||
* This block of code defines macros for handling input in the Ultrahand-Overlay project.
|
||||
* These macros simplify the mapping of input events to corresponding button keys and
|
||||
* provide aliases for touch and joystick positions.
|
||||
*
|
||||
* The macros included in this block are:
|
||||
*
|
||||
* - `touchPosition`: An alias for a constant `HidTouchState` pointer.
|
||||
* - `touchInput`: An alias for `&touchPos`, representing touch input.
|
||||
* - `JoystickPosition`: An alias for `HidAnalogStickState`, representing joystick input.
|
||||
*
|
||||
* These macros are utilized within the Ultrahand-Overlay project to manage and interpret
|
||||
* user input, including touch and joystick events.
|
||||
*/
|
||||
#define touchPosition const HidTouchState
|
||||
#define touchInput &touchPos
|
||||
#define JoystickPosition HidAnalogStickState
|
||||
|
||||
//void convertComboToUnicode(std::string& combo);
|
||||
|
||||
/**
|
||||
* @brief Combo key mapping
|
||||
*/
|
||||
struct KeyInfo {
|
||||
u64 key;
|
||||
const char* name;
|
||||
const char* glyph;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Combo key mappings
|
||||
*
|
||||
* Ordered as they should be displayed
|
||||
*/
|
||||
extern std::array<KeyInfo, 18> KEYS_INFO;
|
||||
|
||||
std::unordered_map<std::string, std::string> createButtonCharMap();
|
||||
|
||||
extern std::unordered_map<std::string, std::string> buttonCharMap;
|
||||
|
||||
|
||||
void convertComboToUnicode(std::string& combo);
|
||||
|
||||
|
||||
// English string definitions
|
||||
|
||||
extern const std::string whiteColor;
|
||||
extern const std::string blackColor;
|
||||
|
||||
extern std::atomic<bool> languageWasChanged;
|
||||
|
||||
inline constexpr double _M_PI = 3.14159265358979323846; // For double precision
|
||||
inline constexpr double RAD_TO_DEG = 180.0f / _M_PI;
|
||||
|
||||
#if IS_LAUNCHER_DIRECTIVE
|
||||
extern std::string ENGLISH;
|
||||
extern std::string SPANISH;
|
||||
extern std::string FRENCH;
|
||||
extern std::string GERMAN;
|
||||
extern std::string JAPANESE;
|
||||
extern std::string KOREAN;
|
||||
extern std::string ITALIAN;
|
||||
extern std::string DUTCH;
|
||||
extern std::string PORTUGUESE;
|
||||
extern std::string RUSSIAN;
|
||||
extern std::string UKRAINIAN;
|
||||
extern std::string POLISH;
|
||||
extern std::string SIMPLIFIED_CHINESE;
|
||||
extern std::string TRADITIONAL_CHINESE;
|
||||
|
||||
extern std::string OVERLAYS; //defined in libTesla now
|
||||
extern std::string OVERLAYS_ABBR;
|
||||
extern std::string OVERLAY;
|
||||
extern std::string HIDDEN_OVERLAYS;
|
||||
extern std::string PACKAGES; //defined in libTesla now
|
||||
extern std::string PACKAGE;
|
||||
extern std::string HIDDEN_PACKAGES;
|
||||
extern std::string HIDDEN;
|
||||
extern std::string HIDE_OVERLAY;
|
||||
extern std::string HIDE_PACKAGE;
|
||||
extern std::string LAUNCH_ARGUMENTS;
|
||||
extern std::string QUICK_LAUNCH;
|
||||
extern std::string BOOT_COMMANDS;
|
||||
extern std::string EXIT_COMMANDS;
|
||||
extern std::string ERROR_LOGGING;
|
||||
extern std::string COMMANDS;
|
||||
extern std::string SETTINGS;
|
||||
extern std::string FAVORITE;
|
||||
extern std::string MAIN_SETTINGS;
|
||||
extern std::string UI_SETTINGS;
|
||||
|
||||
extern std::string WIDGET;
|
||||
extern std::string WIDGET_ITEMS;
|
||||
extern std::string WIDGET_SETTINGS;
|
||||
extern std::string CLOCK;
|
||||
extern std::string BATTERY;
|
||||
extern std::string SOC_TEMPERATURE;
|
||||
extern std::string PCB_TEMPERATURE;
|
||||
extern std::string BACKDROP;
|
||||
extern std::string DYNAMIC_COLORS;
|
||||
extern std::string CENTER_ALIGNMENT;
|
||||
extern std::string EXTENDED_BACKDROP;
|
||||
extern std::string MISCELLANEOUS;
|
||||
//extern std::string MENU_ITEMS;
|
||||
extern std::string MENU_SETTINGS;
|
||||
extern std::string USER_GUIDE;
|
||||
extern std::string SHOW_HIDDEN;
|
||||
extern std::string SHOW_DELETE;
|
||||
extern std::string PAGE_SWAP;
|
||||
extern std::string RIGHT_SIDE_MODE;
|
||||
extern std::string OVERLAY_VERSIONS;
|
||||
extern std::string PACKAGE_VERSIONS;
|
||||
extern std::string CLEAN_VERSIONS;
|
||||
//extern std::string VERSION_LABELS;
|
||||
extern std::string KEY_COMBO;
|
||||
extern std::string MODE;
|
||||
extern std::string MODES;
|
||||
extern std::string LANGUAGE;
|
||||
extern std::string OVERLAY_INFO;
|
||||
extern std::string SOFTWARE_UPDATE;
|
||||
extern std::string UPDATE_ULTRAHAND;
|
||||
extern std::string UPDATE_LANGUAGES;
|
||||
extern std::string SYSTEM;
|
||||
extern std::string DEVICE_INFO;
|
||||
extern std::string FIRMWARE;
|
||||
extern std::string BOOTLOADER;
|
||||
extern std::string HARDWARE;
|
||||
extern std::string MEMORY;
|
||||
extern std::string VENDOR;
|
||||
extern std::string MODEL;
|
||||
extern std::string STORAGE;
|
||||
extern std::string NOTICE;
|
||||
extern std::string UTILIZES;
|
||||
|
||||
extern std::string MEMORY_EXPANSION;
|
||||
extern std::string REBOOT_REQUIRED;
|
||||
extern std::string LOCAL_IP;
|
||||
extern std::string WALLPAPER;
|
||||
extern std::string THEME;
|
||||
extern std::string DEFAULT;
|
||||
extern std::string ROOT_PACKAGE;
|
||||
extern std::string SORT_PRIORITY;
|
||||
extern std::string OPTIONS;
|
||||
extern std::string FAILED_TO_OPEN;
|
||||
|
||||
extern std::string LAUNCH_COMBOS;
|
||||
extern std::string NOTIFICATIONS;
|
||||
extern std::string OPAQUE_SCREENSHOTS;
|
||||
|
||||
extern std::string PACKAGE_INFO;
|
||||
extern std::string _TITLE;
|
||||
extern std::string _VERSION;
|
||||
extern std::string _CREATOR;
|
||||
extern std::string _ABOUT;
|
||||
extern std::string _CREDITS;
|
||||
|
||||
extern std::string USERGUIDE_OFFSET;
|
||||
extern std::string SETTINGS_MENU;
|
||||
extern std::string SCRIPT_OVERLAY;
|
||||
extern std::string STAR_FAVORITE;
|
||||
extern std::string APP_SETTINGS;
|
||||
extern std::string ON_MAIN_MENU;
|
||||
extern std::string ON_A_COMMAND;
|
||||
extern std::string ON_OVERLAY_PACKAGE;
|
||||
extern std::string FEATURES;
|
||||
extern std::string SWIPE_TO_OPEN;
|
||||
|
||||
extern std::string THEME_SETTINGS;
|
||||
extern std::string DYNAMIC_LOGO;
|
||||
extern std::string SELECTION_BACKGROUND;
|
||||
extern std::string SELECTION_TEXT;
|
||||
extern std::string SELECTION_VALUE;
|
||||
extern std::string LIBULTRAHAND_TITLES;
|
||||
extern std::string LIBULTRAHAND_VERSIONS;
|
||||
extern std::string PACKAGE_TITLES;
|
||||
|
||||
extern std::string ULTRAHAND_HAS_STARTED;
|
||||
extern std::string NEW_UPDATE_IS_AVAILABLE;
|
||||
extern std::string REBOOT_IS_REQUIRED;
|
||||
extern std::string HOLD_A_TO_DELETE;
|
||||
extern std::string SELECTION_IS_EMPTY;
|
||||
|
||||
//extern std::string PACKAGE_VERSIONS;
|
||||
//extern std::string PROGRESS_ANIMATION;
|
||||
|
||||
extern std::string REBOOT_TO;
|
||||
extern std::string REBOOT;
|
||||
extern std::string SHUTDOWN;
|
||||
extern std::string BOOT_ENTRY;
|
||||
#endif
|
||||
|
||||
extern std::string FREE;
|
||||
|
||||
extern std::string DEFAULT_CHAR_WIDTH;
|
||||
extern std::string UNAVAILABLE_SELECTION;
|
||||
|
||||
extern std::string ON;
|
||||
extern std::string OFF;
|
||||
|
||||
extern std::string OK;
|
||||
extern std::string BACK;
|
||||
extern std::string HIDE;
|
||||
extern std::string CANCEL;
|
||||
|
||||
extern std::string GAP_1;
|
||||
extern std::string GAP_2;
|
||||
extern std::atomic<float> halfGap;
|
||||
|
||||
//extern std::string EMPTY;
|
||||
|
||||
#if USING_WIDGET_DIRECTIVE
|
||||
extern std::string SUNDAY;
|
||||
extern std::string MONDAY;
|
||||
extern std::string TUESDAY;
|
||||
extern std::string WEDNESDAY;
|
||||
extern std::string THURSDAY;
|
||||
extern std::string FRIDAY;
|
||||
extern std::string SATURDAY;
|
||||
|
||||
extern std::string JANUARY;
|
||||
extern std::string FEBRUARY;
|
||||
extern std::string MARCH;
|
||||
extern std::string APRIL;
|
||||
extern std::string MAY;
|
||||
extern std::string JUNE;
|
||||
extern std::string JULY;
|
||||
extern std::string AUGUST;
|
||||
extern std::string SEPTEMBER;
|
||||
extern std::string OCTOBER;
|
||||
extern std::string NOVEMBER;
|
||||
extern std::string DECEMBER;
|
||||
|
||||
extern std::string SUN;
|
||||
extern std::string MON;
|
||||
extern std::string TUE;
|
||||
extern std::string WED;
|
||||
extern std::string THU;
|
||||
extern std::string FRI;
|
||||
extern std::string SAT;
|
||||
|
||||
extern std::string JAN;
|
||||
extern std::string FEB;
|
||||
extern std::string MAR;
|
||||
extern std::string APR;
|
||||
extern std::string MAY_ABBR;
|
||||
extern std::string JUN;
|
||||
extern std::string JUL;
|
||||
extern std::string AUG;
|
||||
extern std::string SEP;
|
||||
extern std::string OCT;
|
||||
extern std::string NOV;
|
||||
extern std::string DEC;
|
||||
#endif
|
||||
|
||||
#if IS_LAUNCHER_DIRECTIVE
|
||||
// Constant string definitions (English)
|
||||
void reinitializeLangVars();
|
||||
#endif
|
||||
|
||||
|
||||
// Define the updateIfNotEmpty function
|
||||
void updateIfNotEmpty(std::string& constant, const char* jsonKey, const json_t* jsonData);
|
||||
|
||||
void parseLanguage(const std::string& langFile);
|
||||
|
||||
#if USING_WIDGET_DIRECTIVE
|
||||
void localizeTimeStr(char* timeStr);
|
||||
#endif
|
||||
|
||||
// Unified function to apply replacements
|
||||
void applyLangReplacements(std::string& text, bool isValue = false);
|
||||
|
||||
|
||||
|
||||
//// Map of character widths (pre-calibrated)
|
||||
//extern std::unordered_map<wchar_t, float> characterWidths;
|
||||
|
||||
//extern float defaultNumericCharWidth;
|
||||
|
||||
|
||||
|
||||
// Predefined hexMap
|
||||
//extern const std::array<int, 256> hexMap;
|
||||
inline constexpr std::array<int, 256> hexMap = [] {
|
||||
std::array<int, 256> map = {0};
|
||||
map['0'] = 0; map['1'] = 1; map['2'] = 2; map['3'] = 3; map['4'] = 4;
|
||||
map['5'] = 5; map['6'] = 6; map['7'] = 7; map['8'] = 8; map['9'] = 9;
|
||||
map['A'] = 10; map['B'] = 11; map['C'] = 12; map['D'] = 13; map['E'] = 14; map['F'] = 15;
|
||||
map['a'] = 10; map['b'] = 11; map['c'] = 12; map['d'] = 13; map['e'] = 14; map['f'] = 15;
|
||||
return map;
|
||||
}();
|
||||
|
||||
|
||||
// Prepare a map of default settings
|
||||
extern std::map<const std::string, std::string> defaultThemeSettingsMap;
|
||||
|
||||
bool isNumericCharacter(char c);
|
||||
|
||||
bool isValidHexColor(const std::string& hexColor);
|
||||
|
||||
|
||||
|
||||
float calculateAmplitude(float x, float peakDurationFactor = 0.25f);
|
||||
|
||||
|
||||
|
||||
extern std::atomic<bool> refreshWallpaper;
|
||||
extern std::vector<u8> wallpaperData;
|
||||
extern std::atomic<bool> inPlot;
|
||||
|
||||
extern std::mutex wallpaperMutex;
|
||||
extern std::condition_variable cv;
|
||||
|
||||
|
||||
|
||||
// Function to load the RGBA file into memory and modify wallpaperData directly
|
||||
void loadWallpaperFile(const std::string& filePath, s32 width = 448, s32 height = 720);
|
||||
void loadWallpaperFileWhenSafe();
|
||||
|
||||
void reloadWallpaper();
|
||||
|
||||
// Global variables for FPS calculation
|
||||
//extern double lastTimeCount;
|
||||
//extern int frameCount;
|
||||
//extern float fps;
|
||||
//extern double elapsedTime;
|
||||
|
||||
|
||||
extern std::atomic<bool> themeIsInitialized;
|
||||
|
||||
// Variables for touch commands
|
||||
extern std::atomic<bool> touchingBack;
|
||||
extern std::atomic<bool> touchingSelect;
|
||||
extern std::atomic<bool> touchingNextPage;
|
||||
extern std::atomic<bool> touchingMenu;
|
||||
extern std::atomic<bool> shortTouchAndRelease;
|
||||
extern std::atomic<bool> longTouchAndRelease;
|
||||
extern std::atomic<bool> simulatedBack;
|
||||
//extern bool simulatedBackComplete;
|
||||
extern std::atomic<bool> simulatedSelect;
|
||||
//extern bool simulatedSelectComplete;
|
||||
extern std::atomic<bool> simulatedNextPage;
|
||||
//extern std::atomic<bool> simulatedNextPageComplete;
|
||||
extern std::atomic<bool> simulatedMenu;
|
||||
//extern bool simulatedMenuComplete;
|
||||
extern std::atomic<bool> stillTouching;
|
||||
extern std::atomic<bool> interruptedTouch;
|
||||
extern std::atomic<bool> touchInBounds;
|
||||
|
||||
|
||||
#if USING_WIDGET_DIRECTIVE
|
||||
// Battery implementation
|
||||
extern bool powerInitialized;
|
||||
extern bool powerCacheInitialized;
|
||||
extern uint32_t powerCacheCharge;
|
||||
extern bool powerCacheIsCharging;
|
||||
extern PsmSession powerSession;
|
||||
|
||||
// Define variables to store previous battery charge and time
|
||||
//extern uint32_t prevBatteryCharge;
|
||||
//extern s64 timeOut;
|
||||
|
||||
|
||||
extern std::atomic<uint32_t> batteryCharge;
|
||||
extern std::atomic<bool> isCharging;
|
||||
|
||||
//constexpr std::chrono::seconds min_delay = std::chrono::seconds(3); // Minimum delay between checks
|
||||
|
||||
bool powerGetDetails(uint32_t *_batteryCharge, bool *_isCharging);
|
||||
|
||||
void powerInit(void);
|
||||
|
||||
void powerExit(void);
|
||||
#endif
|
||||
|
||||
// Temperature Implementation
|
||||
extern std::atomic<float> PCB_temperature;
|
||||
extern std::atomic<float> SOC_temperature;
|
||||
|
||||
/*
|
||||
I2cReadRegHandler was taken from Switch-OC-Suite source code made by KazushiMe
|
||||
Original repository link (Deleted, last checked 15.04.2023): https://github.com/KazushiMe/Switch-OC-Suite
|
||||
*/
|
||||
|
||||
Result I2cReadRegHandler(u8 reg, I2cDevice dev, u16 *out);
|
||||
|
||||
|
||||
#define TMP451_SOC_TEMP_REG 0x01 // Register for SOC temperature integer part
|
||||
#define TMP451_SOC_TMP_DEC_REG 0x10 // Register for SOC temperature decimal part
|
||||
#define TMP451_PCB_TEMP_REG 0x00 // Register for PCB temperature integer part
|
||||
#define TMP451_PCB_TMP_DEC_REG 0x15 // Register for PCB temperature decimal part
|
||||
|
||||
// Common helper function to read temperature (integer and fractional parts)
|
||||
Result ReadTemperature(float *temperature, u8 integerReg, u8 fractionalReg, bool integerOnly);
|
||||
|
||||
// Function to get the SOC temperature
|
||||
Result ReadSocTemperature(float *temperature, bool integerOnly = true);
|
||||
|
||||
// Function to get the PCB temperature
|
||||
Result ReadPcbTemperature(float *temperature, bool integerOnly = true);
|
||||
|
||||
|
||||
|
||||
// Time implementation
|
||||
|
||||
extern const std::string DEFAULT_DT_FORMAT;
|
||||
extern std::string datetimeFormat;
|
||||
|
||||
|
||||
// Widget settings
|
||||
//static std::string hideClock, hideBattery, hidePCBTemp, hideSOCTemp;
|
||||
extern bool hideClock, hideBattery, hidePCBTemp, hideSOCTemp, dynamicWidgetColors;
|
||||
extern bool hideWidgetBackdrop, centerWidgetAlignment, extendedWidgetBackdrop;
|
||||
|
||||
#if IS_LAUNCHER_DIRECTIVE
|
||||
void reinitializeWidgetVars();
|
||||
#endif
|
||||
|
||||
extern bool cleanVersionLabels, hideOverlayVersions, hidePackageVersions, useLibultrahandTitles, useLibultrahandVersions, usePackageTitles, usePackageVersions;
|
||||
|
||||
extern const std::string loaderInfo;
|
||||
extern const std::string loaderTitle;
|
||||
extern const bool expandedMemory;
|
||||
|
||||
extern std::string versionLabel;
|
||||
|
||||
#if IS_LAUNCHER_DIRECTIVE
|
||||
void reinitializeVersionLabels();
|
||||
#endif
|
||||
|
||||
|
||||
// Number of renderer threads to use
|
||||
extern const unsigned numThreads;
|
||||
extern std::vector<std::thread> renderThreads;
|
||||
extern const s32 bmpChunkSize;
|
||||
extern std::atomic<s32> currentRow;
|
||||
|
||||
|
||||
|
||||
static std::barrier inPlotBarrier(numThreads, [](){
|
||||
inPlot.store(false, std::memory_order_release);
|
||||
});
|
||||
|
||||
|
||||
//extern std::atomic<unsigned int> barrierCounter;
|
||||
//extern std::mutex barrierMutex;
|
||||
//extern std::condition_variable barrierCV;
|
||||
//
|
||||
//extern void barrierWait();
|
||||
|
||||
|
||||
void initializeThemeVars();
|
||||
|
||||
void initializeUltrahandSettings();
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,47 @@
|
||||
/********************************************************************************
|
||||
* File: ultra.hpp
|
||||
* Author: ppkantorski
|
||||
* Description:
|
||||
* 'ultra.hpp' serves as a central include header for the Ultrahand Overlay project,
|
||||
* bringing together a comprehensive suite of utility functions essential for the
|
||||
* development and operation of custom overlays on the Nintendo Switch. This header
|
||||
* provides consolidated access to functions facilitating debugging, string processing,
|
||||
* file management, JSON manipulation, and more, enhancing the modularity and
|
||||
* reusability of code within the project.
|
||||
*
|
||||
* These utilities are designed to operate independently, providing robust tools to
|
||||
* support complex overlay functionalities and interactions.
|
||||
*
|
||||
* For the latest updates and contributions, visit the project's GitHub repository:
|
||||
* GitHub Repository: https://github.com/ppkantorski/Ultrahand-Overlay
|
||||
*
|
||||
* Note: This notice is integral to the project's documentation and must not be
|
||||
* altered or removed.
|
||||
*
|
||||
* Licensed under both GPLv2 and CC-BY-4.0
|
||||
* Copyright (c) 2024 ppkantorski
|
||||
********************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||
|
||||
#ifndef ULTRA_HPP
|
||||
#define ULTRA_HPP
|
||||
|
||||
// Include all functional headers used in the libUltra library
|
||||
|
||||
#include "global_vars.hpp"
|
||||
#include "debug_funcs.hpp"
|
||||
#include "string_funcs.hpp"
|
||||
#include "get_funcs.hpp"
|
||||
#include "path_funcs.hpp"
|
||||
#include "list_funcs.hpp"
|
||||
#include "json_funcs.hpp"
|
||||
#include "ini_funcs.hpp"
|
||||
#include "hex_funcs.hpp"
|
||||
#include "download_funcs.hpp"
|
||||
#include "mod_funcs.hpp"
|
||||
#include "tsl_utils.hpp"
|
||||
|
||||
#endif // ULTRA_HPP
|
||||
Reference in New Issue
Block a user