2020-04-16 01:06:41 +01:00
|
|
|
/*
|
2020-07-03 10:31:22 +01:00
|
|
|
* utils.h
|
2020-04-16 01:06:41 +01:00
|
|
|
*
|
2020-07-03 10:31:22 +01:00
|
|
|
* Copyright (c) 2020, DarkMatterCore <pabloacurielz@gmail.com>.
|
|
|
|
*
|
|
|
|
* This file is part of nxdumptool (https://github.com/DarkMatterCore/nxdumptool).
|
|
|
|
*
|
|
|
|
* nxdumptool is free software; you can redistribute it and/or modify it
|
2020-04-16 01:06:41 +01:00
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
|
|
|
*
|
2020-07-03 10:31:22 +01:00
|
|
|
* nxdumptool is distributed in the hope it will be useful, but WITHOUT
|
2020-04-16 01:06:41 +01:00
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2020-04-15 21:50:07 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#ifndef __UTILS_H__
|
|
|
|
#define __UTILS_H__
|
|
|
|
|
2020-07-03 10:31:22 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <ctype.h>
|
2020-07-26 05:57:12 +01:00
|
|
|
#include <math.h>
|
2020-07-03 10:31:22 +01:00
|
|
|
#include <time.h>
|
2020-07-25 06:56:35 +01:00
|
|
|
#include <sys/stat.h>
|
2020-07-12 16:29:08 +01:00
|
|
|
#include <stdatomic.h>
|
2020-04-15 21:50:07 +01:00
|
|
|
#include <switch.h>
|
|
|
|
|
2020-07-22 09:03:28 +01:00
|
|
|
#define APP_BASE_PATH "sdmc:/switch/" APP_TITLE "/"
|
2020-04-15 21:50:07 +01:00
|
|
|
|
2020-04-17 22:59:05 +01:00
|
|
|
#define MEMBER_SIZE(type, member) sizeof(((type*)NULL)->member)
|
2020-04-15 21:50:07 +01:00
|
|
|
|
2020-04-17 22:59:05 +01:00
|
|
|
#define MAX_ELEMENTS(x) ((sizeof((x))) / (sizeof((x)[0])))
|
2020-04-15 21:50:07 +01:00
|
|
|
|
2020-07-13 07:36:17 +01:00
|
|
|
#define LOGFILE(fmt, ...) utilsWriteMessageToLogFile(__func__, fmt, ##__VA_ARGS__)
|
|
|
|
#define LOGBUF(dst, dst_size, fmt, ...) utilsWriteMessageToLogBuffer(dst, dst_size, __func__, fmt, ##__VA_ARGS__)
|
|
|
|
|
2020-04-26 09:35:01 +01:00
|
|
|
#define ALIGN_DOWN(x, y) ((x) & ~((y) - 1))
|
|
|
|
#define ALIGN_UP(x, y) ((((y) - 1) + (x)) & ~((y) - 1))
|
2020-05-11 20:12:03 +01:00
|
|
|
#define IS_ALIGNED(x, y) (((x) & ((y) - 1)) == 0)
|
2020-10-04 08:05:05 +01:00
|
|
|
#define IS_POWER_OF_TWO(x) (((x) & ((x) - 1)) == 0)
|
2020-04-15 21:50:07 +01:00
|
|
|
|
2020-04-17 22:59:05 +01:00
|
|
|
#define BIS_SYSTEM_PARTITION_MOUNT_NAME "sys:"
|
2020-04-15 21:50:07 +01:00
|
|
|
|
2020-07-06 01:10:07 +01:00
|
|
|
#define KEY_NONE 0
|
2020-04-29 22:11:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2020-05-03 00:40:50 +01:00
|
|
|
/// Need to move this to npdm.c/h eventually.
|
2020-07-06 01:10:07 +01:00
|
|
|
#define NPDM_META_MAGIC 0x4D455441 /* "META". */
|
2020-04-29 22:11:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2020-05-03 00:40:50 +01:00
|
|
|
|
2020-04-29 22:11:27 +01:00
|
|
|
|
|
|
|
|
2020-04-15 21:50:07 +01:00
|
|
|
typedef enum {
|
2020-04-16 11:13:11 +01:00
|
|
|
UtilsCustomFirmwareType_Unknown = 0,
|
|
|
|
UtilsCustomFirmwareType_Atmosphere = 1,
|
|
|
|
UtilsCustomFirmwareType_SXOS = 2,
|
|
|
|
UtilsCustomFirmwareType_ReiNX = 3
|
2020-04-15 21:50:07 +01:00
|
|
|
} UtilsCustomFirmwareType;
|
|
|
|
|
2020-05-03 00:40:50 +01:00
|
|
|
bool utilsInitializeResources(void);
|
|
|
|
void utilsCloseResources(void);
|
2020-04-15 21:50:07 +01:00
|
|
|
|
2020-08-18 06:04:13 +01:00
|
|
|
bool utilsCreateThread(Thread *out_thread, ThreadFunc func, void *arg, int cpu_id);
|
|
|
|
void utilsJoinThread(Thread *thread);
|
|
|
|
|
2020-08-15 22:22:49 +01:00
|
|
|
bool utilsIsDevelopmentUnit(void);
|
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
/// hidScanInput() must be called before any of these functions.
|
|
|
|
u64 utilsHidKeysAllDown(void);
|
|
|
|
u64 utilsHidKeysAllHeld(void);
|
|
|
|
|
2020-07-06 01:10:07 +01:00
|
|
|
void utilsWaitForButtonPress(u64 flag);
|
2020-04-15 21:50:07 +01:00
|
|
|
|
2020-10-02 10:53:58 +01:00
|
|
|
bool utilsAppendFormattedStringToBuffer(char **dst, size_t *dst_size, const char *fmt, ...);
|
|
|
|
|
2020-07-13 07:36:17 +01:00
|
|
|
void utilsWriteMessageToLogFile(const char *func_name, const char *fmt, ...);
|
2020-10-02 10:53:58 +01:00
|
|
|
void utilsWriteMessageToLogBuffer(char **dst, size_t *dst_size, const char *func_name, const char *fmt, ...);
|
2020-07-13 07:36:17 +01:00
|
|
|
void utilsWriteLogBufferToLogFile(const char *src);
|
|
|
|
void utilsLogFileMutexControl(bool lock);
|
2020-04-15 21:50:07 +01:00
|
|
|
|
2020-05-05 19:04:23 +01:00
|
|
|
void utilsReplaceIllegalCharacters(char *str, bool ascii_only);
|
2020-04-15 21:50:07 +01:00
|
|
|
|
2020-05-03 00:40:50 +01:00
|
|
|
void utilsTrimString(char *str);
|
2020-04-16 11:13:11 +01:00
|
|
|
|
2020-04-17 22:59:05 +01:00
|
|
|
void utilsGenerateHexStringFromData(char *dst, size_t dst_size, const void *src, size_t src_size);
|
2020-04-15 21:50:07 +01:00
|
|
|
|
2020-07-26 05:57:12 +01:00
|
|
|
void utilsGenerateFormattedSizeString(u64 size, char *dst, size_t dst_size);
|
|
|
|
|
2020-08-01 05:43:55 +01:00
|
|
|
bool utilsGetFreeSpaceFromFileSystem(FsFileSystem *fs, u64 *out);
|
|
|
|
bool utilsGetFreeSpaceFromFileSystemByPath(const char *path, u64 *out);
|
|
|
|
bool utilsGetFreeSdCardFileSystemSpace(u64 *out);
|
|
|
|
|
|
|
|
bool utilsCommitFileSystemChangesByPath(const char *path);
|
|
|
|
bool utilsCommitSdCardFileSystemChanges(void);
|
2020-05-03 00:40:50 +01:00
|
|
|
|
|
|
|
bool utilsCheckIfFileExists(const char *path);
|
|
|
|
|
|
|
|
bool utilsCreateConcatenationFile(const char *path);
|
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
void utilsCreateDirectoryTree(const char *path, bool create_last_element);
|
|
|
|
|
2020-05-03 00:40:50 +01:00
|
|
|
bool utilsAppletModeCheck(void);
|
|
|
|
|
|
|
|
void utilsChangeHomeButtonBlockStatus(bool block);
|
|
|
|
|
|
|
|
u8 utilsGetCustomFirmwareType(void); ///< UtilsCustomFirmwareType.
|
|
|
|
|
2020-04-17 22:59:05 +01:00
|
|
|
FsStorage *utilsGetEmmcBisSystemPartitionStorage(void);
|
2020-04-15 21:50:07 +01:00
|
|
|
|
2020-05-03 00:40:50 +01:00
|
|
|
void utilsOverclockSystem(bool overclock);
|
|
|
|
|
|
|
|
NX_INLINE void utilsSleep(u64 seconds)
|
2020-04-15 21:50:07 +01:00
|
|
|
{
|
2020-04-17 22:59:05 +01:00
|
|
|
if (seconds) svcSleepThread(seconds * (u64)1000000000);
|
2020-04-15 21:50:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* __UTILS_H__ */
|