mirror of
https://github.com/wiiu-env/AutobootModule.git
synced 2024-11-29 05:54:16 +01:00
39 lines
1.4 KiB
C++
39 lines
1.4 KiB
C++
#pragma once
|
|
|
|
#include <cstdint>
|
|
#include <malloc.h>
|
|
#include <memory>
|
|
#include <string_view>
|
|
#include <vector>
|
|
|
|
template<class T, class... Args>
|
|
std::unique_ptr<T> make_unique_nothrow(Args &&...args) noexcept(noexcept(T(std::forward<Args>(args)...))) {
|
|
return std::unique_ptr<T>(new (std::nothrow) T(std::forward<Args>(args)...));
|
|
}
|
|
|
|
template<typename T>
|
|
inline typename std::unique_ptr<T> make_unique_nothrow(size_t num) noexcept {
|
|
return std::unique_ptr<T>(new (std::nothrow) std::remove_extent_t<T>[num]());
|
|
}
|
|
|
|
template<class T, class... Args>
|
|
std::shared_ptr<T> make_shared_nothrow(Args &&...args) noexcept(noexcept(T(std::forward<Args>(args)...))) {
|
|
return std::shared_ptr<T>(new (std::nothrow) T(std::forward<Args>(args)...));
|
|
}
|
|
|
|
template<typename... Args>
|
|
std::string string_format(const std::string &format, Args... args) {
|
|
int size_s = std::snprintf(nullptr, 0, format.c_str(), args...) + 1; // Extra space for '\0'
|
|
auto size = static_cast<size_t>(size_s);
|
|
auto buf = std::make_unique<char[]>(size);
|
|
std::snprintf(buf.get(), size, format.c_str(), args...);
|
|
return std::string(buf.get(), buf.get() + size - 1); // We don't want the '\0' inside
|
|
}
|
|
|
|
bool GetTitleIdOfDisc(uint64_t *titleId, bool *discPresent);
|
|
|
|
bool DeleteMLCUpdateDirectory();
|
|
|
|
bool RestoreMLCUpdateDirectory();
|
|
|
|
bool LoadFileIntoBuffer(std::string_view path, std::vector<uint8_t> &buffer); |