Move to Google format

This commit is contained in:
Tobi-D7 2024-03-11 14:13:36 +01:00
parent a1e6b963d4
commit b8e861d9b4
7 changed files with 491 additions and 605 deletions

View File

@ -13,4 +13,4 @@ echo -e "Files found to format = \n\"\"\"\n$FILE_LIST\n\"\"\""
# - NB: do NOT put quotes around `$FILE_LIST` below or else the `clang-format` command will # - NB: do NOT put quotes around `$FILE_LIST` below or else the `clang-format` command will
# mistakenly see the entire blob of newline-separated file names as a SINGLE file name instead # mistakenly see the entire blob of newline-separated file names as a SINGLE file name instead
# of as a new-line separated list of *many* file names! # of as a new-line separated list of *many* file names!
clang-format --verbose -i --style=file $FILE_LIST clang-format --verbose -i --style=Google $FILE_LIST

View File

@ -8,26 +8,21 @@
#include <string> #include <string>
#include <vector> #include <vector>
inline std::string fix_path(const std::string &path) inline std::string fix_path(const std::string &path) {
{ if (path.find('\\') == path.npos) return path;
if (path.find('\\') == path.npos)
return path;
std::string ret = path; std::string ret = path;
std::replace(ret.begin(), ret.end(), '\\', '/'); std::replace(ret.begin(), ret.end(), '\\', '/');
return ret; return ret;
} }
inline std::string stupid_hash(const std::string &file) inline std::string stupid_hash(const std::string &file) {
{
std::ifstream iff(file); std::ifstream iff(file);
if (!iff.is_open()) if (!iff.is_open()) {
{
return std::to_string(rand()); return std::to_string(rand());
} }
unsigned long long check_sum = 0x0ULL; unsigned long long check_sum = 0x0ULL;
char tmp; char tmp;
while (iff.get(tmp)) while (iff.get(tmp)) {
{
check_sum += (unsigned long long)tmp; check_sum += (unsigned long long)tmp;
} }
iff.close(); iff.close();
@ -36,20 +31,14 @@ inline std::string stupid_hash(const std::string &file)
return ret.str(); return ret.str();
} }
inline std::map<std::string, std::string> inline std::map<std::string, std::string> createHashes(
createHashes(const std::vector<std::string> &dirs, const std::vector<std::string> &dirs, const std::string &extension) {
const std::string &extension)
{
std::map<std::string, std::string> hashes; std::map<std::string, std::string> hashes;
for (auto const &it : dirs) for (auto const &it : dirs) {
{ for (const auto &file : std::filesystem::directory_iterator(it)) {
for (const auto &file : std::filesystem::directory_iterator(it)) if (file.is_regular_file()) {
{
if (file.is_regular_file())
{
std::string path = fix_path(file.path().string()); std::string path = fix_path(file.path().string());
if (path.length() > extension.length() && path.ends_with(extension)) if (path.length() > extension.length() && path.ends_with(extension)) {
{
hashes[path] = stupid_hash(path); hashes[path] = stupid_hash(path);
} }
} }
@ -58,15 +47,12 @@ createHashes(const std::vector<std::string> &dirs,
return hashes; return hashes;
} }
inline std::vector<std::filesystem::path> inline std::vector<std::filesystem::path> getChangedFiles(
getChangedFiles(const std::map<std::string, std::string> &oldHashes) const std::map<std::string, std::string> &oldHashes) {
{
std::vector<std::filesystem::path> changedFiles; std::vector<std::filesystem::path> changedFiles;
for (const auto &file : oldHashes) for (const auto &file : oldHashes) {
{
std::string newHash = stupid_hash(file.first); std::string newHash = stupid_hash(file.first);
if (newHash != file.second) if (newHash != file.second) {
{
changedFiles.push_back(std::filesystem::path(file.first)); changedFiles.push_back(std::filesystem::path(file.first));
} }
} }

View File

@ -6,6 +6,6 @@ namespace helper {
std::string GenerateUniqueId(); std::string GenerateUniqueId();
void ArrayToFile(unsigned char *array_, size_t size_, std::string filename); void ArrayToFile(unsigned char *array_, size_t size_, std::string filename);
void GenerateTemplateFile(std::string path, NpiProject prj); void GenerateTemplateFile(std::string path, NpiProject prj);
void CompileProject(std::string path); void CompileProject(std::string path, bool async = false);
void CleanProject(std::string path); void CleanProject(std::string path);
} // namespace helper } // namespace helper

View File

@ -3,8 +3,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
struct NpiProject struct NpiProject {
{
std::string name; std::string name;
std::string author; std::string author;
std::string description; std::string description;
@ -43,8 +42,7 @@ struct NpiProject
std::string asm_compiler; std::string asm_compiler;
}; };
inline void Prj_InitDefault(NpiProject &project, bool cia) inline void Prj_InitDefault(NpiProject &project, bool cia) {
{
project.name = "Sample"; project.name = "Sample";
project.author = "Sample"; project.author = "Sample";
project.description = "Description"; project.description = "Description";
@ -99,8 +97,7 @@ inline void Prj_InitDefault(NpiProject &project, bool cia)
project.asm_compiler = "{DEVKITPRO}/devkitARM/bin/arm-none-eabi-gcc"; project.asm_compiler = "{DEVKITPRO}/devkitARM/bin/arm-none-eabi-gcc";
project.icon_path = "app/icon.png"; project.icon_path = "app/icon.png";
if (cia) if (cia) {
{
project.banner_path = "app/banner.png"; project.banner_path = "app/banner.png";
project.banner_a_path = "app/banner_audio.wav"; project.banner_a_path = "app/banner_audio.wav";
project.rsf_path = "app/build-cia.rsf"; project.rsf_path = "app/build-cia.rsf";
@ -110,8 +107,7 @@ inline void Prj_InitDefault(NpiProject &project, bool cia)
project.dir_gfxbuild = "romfs/gfx/"; project.dir_gfxbuild = "romfs/gfx/";
project.dir_romfs = "romfs/"; project.dir_romfs = "romfs/";
if (cia) if (cia) {
{
project.unique_id = "0xff3ff"; project.unique_id = "0xff3ff";
project.prod = "NPI7"; project.prod = "NPI7";
} }

View File

@ -1,10 +1,14 @@
#include <math.h>
#include <condition_variable> #include <condition_variable>
#include <fileHash.hpp>
#include <filesystem> #include <filesystem>
#include <fstream> #include <fstream>
#include <future> #include <future>
#include <helper.hpp>
#include <iomanip> #include <iomanip>
#include <iostream> #include <iostream>
#include <math.h> #include <json.hpp>
#include <mutex> #include <mutex>
#include <random> #include <random>
#include <sstream> #include <sstream>
@ -12,11 +16,6 @@
#include <string> #include <string>
#include <thread> #include <thread>
#include <json.hpp>
#include <fileHash.hpp>
#include <helper.hpp>
#define CCRED "\033[31m" #define CCRED "\033[31m"
#define CCGREEN "\033[32m" #define CCGREEN "\033[32m"
#define CCYELLOW "\033[33m" #define CCYELLOW "\033[33m"
@ -27,45 +26,48 @@
#define veccmp(vec1, vec2) (vec1.size() == vec2.size()) #define veccmp(vec1, vec2) (vec1.size() == vec2.size())
void updateProgressBar(float progress) void updateProgressBar(float progress, std::string f) {
{ const int w = 50;
std::cout << CCYELLOW << "[" << static_cast<int>(progress * 100.0) << " %] " int pos = static_cast<int>(progress * w);
<< CCRESET;
std::cout << CCYELLOW << "[";
for (int i = 0; i < w; ++i) {
if (i < pos)
std::cout << "=";
else if (i == pos)
std::cout << ">";
else
std::cout << " ";
}
std::cout << "] " << std::setw(3) << static_cast<int>(progress * 100.0)
<< "% " << CCRESET << '\r';
std::cout.flush();
} }
template <typename T> template <typename T>
std::pair<T, bool> js_catch(const nlohmann::json &js, const std::string &at) std::pair<T, bool> js_catch(const nlohmann::json &js, const std::string &at) {
{
bool exists = true; bool exists = true;
if (!js.contains(at) || js[at].is_null()) if (!js.contains(at) || js[at].is_null()) exists = false;
exists = false;
return std::make_pair(js[at].get<T>(), exists); return std::make_pair(js[at].get<T>(), exists);
} }
void recursive_repl(std::string &i, char v1, char v2) void recursive_repl(std::string &i, char v1, char v2) {
{
std::replace(i.begin(), i.end(), v1, v2); std::replace(i.begin(), i.end(), v1, v2);
} }
std::vector<std::filesystem::path> std::vector<std::filesystem::path> get_files_in_dir(
get_files_in_dir(const std::vector<std::string> &dir_paths, const std::vector<std::string> &dir_paths, const std::string &extension) {
const std::string &extension)
{
std::vector<std::filesystem::path> files; std::vector<std::filesystem::path> files;
for (const auto &dir_path : dir_paths) for (const auto &dir_path : dir_paths) {
{ if (!std::filesystem::exists(dir_path)) continue;
if (!std::filesystem::exists(dir_path)) for (const auto &entry : std::filesystem::directory_iterator(dir_path)) {
continue; if (std::filesystem::is_regular_file(entry.path())) {
for (const auto &entry : std::filesystem::directory_iterator(dir_path))
{
if (std::filesystem::is_regular_file(entry.path()))
{
std::string fn = entry.path().string(); std::string fn = entry.path().string();
if (fn.length() > extension.length()) if (fn.length() > extension.length()) {
{ if (fn.ends_with(extension)) {
if (fn.ends_with(extension))
{
files.push_back(fix_path(entry.path().string())); files.push_back(fix_path(entry.path().string()));
} }
} }
@ -76,93 +78,70 @@ get_files_in_dir(const std::vector<std::string> &dir_paths,
return files; return files;
} }
void Js2Vec(std::vector<std::string> &vec, nlohmann::json js) void Js2Vec(std::vector<std::string> &vec, nlohmann::json js) {
{
vec.clear(); vec.clear();
for (auto const &it : js) for (auto const &it : js) {
{
vec.push_back(it.get<std::string>()); vec.push_back(it.get<std::string>());
} }
} }
void Vec2Json(std::vector<std::string> vec, nlohmann::json &js, void Vec2Json(std::vector<std::string> vec, nlohmann::json &js,
NpiProject ref) NpiProject ref) {
{
int indx = 0; int indx = 0;
for (auto const &it : vec) for (auto const &it : vec) {
{
js[indx] = it; js[indx] = it;
indx++; indx++;
} }
} }
std::string Flags2Str(std::vector<std::string> flags) std::string Flags2Str(std::vector<std::string> flags) {
{
std::string res = ""; std::string res = "";
for (auto const &it : flags) for (auto const &it : flags) res += "-" + it + " ";
res += "-" + it + " ";
return res; return res;
} }
std::string IncludeDirs(std::vector<std::string> dirs) std::string IncludeDirs(std::vector<std::string> dirs) {
{
std::string res = ""; std::string res = "";
for (auto const &it : dirs) for (auto const &it : dirs) res += "-I " + it + " ";
res += "-I " + it + " ";
return res; return res;
} }
std::string LibIncludes(std::vector<std::string> dirs) std::string LibIncludes(std::vector<std::string> dirs) {
{
std::string res = ""; std::string res = "";
for (auto const &it : dirs) for (auto const &it : dirs) res += "-I " + it + "include/ ";
res += "-I " + it + "include/ ";
return res; return res;
} }
void VecGetExtra(std::vector<std::string> &result, void VecGetExtra(std::vector<std::string> &result,
std::vector<std::string> input, NpiProject ref) std::vector<std::string> input, NpiProject ref) {
{
result.clear(); result.clear();
for (auto const &it : input) for (auto const &it : input) {
{ if (it == "[arch_flags]") {
if (it == "[arch_flags]") for (auto const &af : ref.arch_flags) {
{
for (auto const &af : ref.arch_flags)
{
result.push_back(af); result.push_back(af);
} }
} } else if (it == "[c_flags]") {
else if (it == "[c_flags]") for (auto const &cf : ref.c_flags) {
{
for (auto const &cf : ref.c_flags)
{
result.push_back(cf); result.push_back(cf);
} }
} } else {
else
{
result.push_back(it); result.push_back(it);
} }
} }
} }
void ReplVariables(std::string &str, const std::string &from, void ReplVariables(std::string &str, const std::string &from,
const std::string &to) const std::string &to) {
{ if (from.empty()) return;
if (from.empty())
return;
size_t start_pos = 0; size_t start_pos = 0;
while ((start_pos = str.find(from, start_pos)) != std::string::npos) while ((start_pos = str.find(from, start_pos)) != std::string::npos) {
{
str.replace(start_pos, from.length(), to); str.replace(start_pos, from.length(), to);
start_pos += to.length(); // In case 'to' contains 'from', like replacing start_pos += to.length(); // In case 'to' contains 'from', like replacing
// 'x' with 'yx' // 'x' with 'yx'
} }
} }
void AutoRepl(std::string &str) void AutoRepl(std::string &str) {
{
std::string dkp_env = getenv("DEVKITPRO"); std::string dkp_env = getenv("DEVKITPRO");
std::string cwd = std::filesystem::current_path().string(); std::string cwd = std::filesystem::current_path().string();
ReplVariables(str, "{DEVKITPRO}", dkp_env); ReplVariables(str, "{DEVKITPRO}", dkp_env);
@ -170,20 +149,15 @@ void AutoRepl(std::string &str)
} }
void ReplVector(std::vector<std::string> &vec, const std::string &from, void ReplVector(std::vector<std::string> &vec, const std::string &from,
const std::string &to) const std::string &to) {
{ for (size_t i = 0; i < vec.size(); i++) ReplVariables(vec[i], from, to);
for (size_t i = 0; i < vec.size(); i++)
ReplVariables(vec[i], from, to);
} }
void AutoVecRepl(std::vector<std::string> &strs) void AutoVecRepl(std::vector<std::string> &strs) {
{ for (size_t i = 0; i < strs.size(); i++) AutoRepl(strs[i]);
for (size_t i = 0; i < strs.size(); i++)
AutoRepl(strs[i]);
} }
void ProcessPrj2Cmp(NpiProject *prj, NpiProject src) void ProcessPrj2Cmp(NpiProject *prj, NpiProject src) {
{
VecGetExtra(prj->arch_flags, src.arch_flags, src); VecGetExtra(prj->arch_flags, src.arch_flags, src);
VecGetExtra(prj->c_flags, src.c_flags, src); VecGetExtra(prj->c_flags, src.c_flags, src);
VecGetExtra(prj->cxx_flags, src.cxx_flags, VecGetExtra(prj->cxx_flags, src.cxx_flags,
@ -193,8 +167,7 @@ void ProcessPrj2Cmp(NpiProject *prj, NpiProject src)
} }
std::string LinkerInput(std::vector<std::filesystem::path> o_files, std::string LinkerInput(std::vector<std::filesystem::path> o_files,
std::vector<std::filesystem::path> d_files) std::vector<std::filesystem::path> d_files) {
{
std::string res = ""; std::string res = "";
/*if (o_files.size() != d_files.size()) { /*if (o_files.size() != d_files.size()) {
std::cerr << "The Number of .d and .o files is wrong"; std::cerr << "The Number of .d and .o files is wrong";
@ -205,38 +178,28 @@ std::string LinkerInput(std::vector<std::filesystem::path> o_files,
return res; return res;
} }
std::string Libs(std::vector<std::string> libs) std::string Libs(std::vector<std::string> libs) {
{
std::string res = ""; std::string res = "";
for (auto const &it : libs) for (auto const &it : libs) res += "-l" + it + " ";
res += "-l" + it + " ";
return res; return res;
} }
std::string LibPaths(std::vector<std::string> libs) std::string LibPaths(std::vector<std::string> libs) {
{
std::string res = ""; std::string res = "";
for (auto const &it : libs) for (auto const &it : libs) res += "-L" + it + "lib/ ";
res += "-L" + it + "lib/ ";
return res; return res;
} }
void DeleteFiles(std::string path, std::vector<std::string> extensions) void DeleteFiles(std::string path, std::vector<std::string> extensions) {
{ for (const auto &entry : std::filesystem::directory_iterator(path)) {
for (const auto &entry : std::filesystem::directory_iterator(path)) if (std::filesystem::is_directory(entry)) {
{
if (std::filesystem::is_directory(entry))
{
DeleteFiles(fix_path(entry.path().string()), extensions); DeleteFiles(fix_path(entry.path().string()), extensions);
} } else {
else for (const auto &ext : extensions) {
{ if (entry.path().extension() == ext) {
for (const auto &ext : extensions)
{
if (entry.path().extension() == ext)
{
std::filesystem::remove(entry); std::filesystem::remove(entry);
std::cout << CCRED << "[*] Deleted file: " << fix_path(entry.path().string()) std::cout << CCRED
<< "[*] Deleted file: " << fix_path(entry.path().string())
<< CCRESET << std::endl; << CCRESET << std::endl;
break; break;
} }
@ -245,18 +208,14 @@ void DeleteFiles(std::string path, std::vector<std::string> extensions)
} }
} }
void DeleteDirectory(std::string path) void DeleteDirectory(std::string path) {
{ for (const auto &entry : std::filesystem::directory_iterator(path)) {
for (const auto &entry : std::filesystem::directory_iterator(path)) if (std::filesystem::is_directory(entry)) {
{
if (std::filesystem::is_directory(entry))
{
DeleteDirectory(fix_path(entry.path().string())); DeleteDirectory(fix_path(entry.path().string()));
} } else {
else
{
std::filesystem::remove(entry); std::filesystem::remove(entry);
std::cout << CCRED << "[*] Deleted file: " << fix_path(entry.path().string()) std::cout << CCRED
<< "[*] Deleted file: " << fix_path(entry.path().string())
<< CCRESET << std::endl; << CCRESET << std::endl;
} }
} }
@ -266,8 +225,7 @@ void DeleteDirectory(std::string path)
<< std::endl; << std::endl;
} }
void GenerateHashes(NpiProject prj, std::string dir_) void GenerateHashes(NpiProject prj, std::string dir_) {
{
auto cpp_hashes = createHashes(prj.source_dirs, ".cpp"); auto cpp_hashes = createHashes(prj.source_dirs, ".cpp");
auto c_hashes = createHashes(prj.source_dirs, ".c"); auto c_hashes = createHashes(prj.source_dirs, ".c");
auto hpp_hashes = createHashes(prj.include_dirs, ".hpp"); auto hpp_hashes = createHashes(prj.include_dirs, ".hpp");
@ -278,29 +236,21 @@ void GenerateHashes(NpiProject prj, std::string dir_)
auto t3s_hashes = createHashes({std::string(dir_ + "/gfx")}, ".t3s"); auto t3s_hashes = createHashes({std::string(dir_ + "/gfx")}, ".t3s");
nlohmann::json jscpp_hashes; nlohmann::json jscpp_hashes;
for (auto const &it : cpp_hashes) for (auto const &it : cpp_hashes) jscpp_hashes[it.first] = it.second;
jscpp_hashes[it.first] = it.second;
nlohmann::json jsc_hashes; nlohmann::json jsc_hashes;
for (auto const &it : c_hashes) for (auto const &it : c_hashes) jsc_hashes[it.first] = it.second;
jsc_hashes[it.first] = it.second;
nlohmann::json jshpp_hashes; nlohmann::json jshpp_hashes;
for (auto const &it : hpp_hashes) for (auto const &it : hpp_hashes) jshpp_hashes[it.first] = it.second;
jshpp_hashes[it.first] = it.second;
nlohmann::json jsh_hashes; nlohmann::json jsh_hashes;
for (auto const &it : h_hashes) for (auto const &it : h_hashes) jsh_hashes[it.first] = it.second;
jsh_hashes[it.first] = it.second;
nlohmann::json jsv_pica_hashes; nlohmann::json jsv_pica_hashes;
for (auto const &it : v_pica_hashes) for (auto const &it : v_pica_hashes) jsv_pica_hashes[it.first] = it.second;
jsv_pica_hashes[it.first] = it.second;
nlohmann::json jsshlist_hashes; nlohmann::json jsshlist_hashes;
for (auto const &it : shlist_hashes) for (auto const &it : shlist_hashes) jsshlist_hashes[it.first] = it.second;
jsshlist_hashes[it.first] = it.second;
nlohmann::json jss_hashes; nlohmann::json jss_hashes;
for (auto const &it : s_hashes) for (auto const &it : s_hashes) jss_hashes[it.first] = it.second;
jss_hashes[it.first] = it.second;
nlohmann::json jst3s_hashes; nlohmann::json jst3s_hashes;
for (auto const &it : t3s_hashes) for (auto const &it : t3s_hashes) jst3s_hashes[it.first] = it.second;
jst3s_hashes[it.first] = it.second;
nlohmann::json hashes; nlohmann::json hashes;
hashes["cpp"] = jscpp_hashes; hashes["cpp"] = jscpp_hashes;
@ -318,12 +268,10 @@ void GenerateHashes(NpiProject prj, std::string dir_)
} }
std::map<std::string, std::string> GetHashMap(std::string dir_, std::map<std::string, std::string> GetHashMap(std::string dir_,
std::string extension) std::string extension) {
{
nlohmann::json js; nlohmann::json js;
std::ifstream is(dir_ + "/build/hashes.json"); std::ifstream is(dir_ + "/build/hashes.json");
if (!is) if (!is) {
{
std::cerr << "[-]hashes.json not in " << dir_ + "/build/" std::cerr << "[-]hashes.json not in " << dir_ + "/build/"
<< "!\n"; << "!\n";
exit(-1); exit(-1);
@ -335,18 +283,92 @@ std::map<std::string, std::string> GetHashMap(std::string dir_,
std::replace(mod_ext.begin(), mod_ext.end(), '.', '_'); std::replace(mod_ext.begin(), mod_ext.end(), '.', '_');
std::map<std::string, std::string> res; std::map<std::string, std::string> res;
for (auto &[filename, hash] : js[mod_ext].items()) for (auto &[filename, hash] : js[mod_ext].items()) {
{
res[filename] = hash; res[filename] = hash;
} }
return res; return res;
} }
void CompileProject(NpiProject &prj, std::string dir_) bool C_CXX_Compile(bool cxx, std::string dir_, std::filesystem::path it,
{ NpiProject prj) {
std::string command =
(cxx ? prj.cxx_compiler : prj.c_compiler) + " -MMD -MP -MF " + dir_ +
"/build/" + fix_path(it.stem().string()) + ".d " + "-c " +
fix_path(it.string()) + " -o " + dir_ + "/build/" +
fix_path(it.stem().string()) + ".o " +
Flags2Str((cxx ? prj.cxx_flags : prj.c_flags)) + " " +
IncludeDirs(prj.include_dirs) + " " + LibIncludes(prj.lib_dirs);
// std::cout << CCMAGENTA << "Compiling: " << CCCYAN <<
// fix_path(it.filename().string())
// << std::endl;
int reqres = system(command.c_str());
// std::cout << (reqres == 0 ? CCGREEN : CCRED)
// << (reqres == 0 ? "[+] " : "[-] ") <<
// fix_path(it.filename().string())
// << std::endl;
return reqres != 0;
}
bool Picasso_Compile(std::string dir_, std::string dkp_env,
std::filesystem::path it, NpiProject prj) {
std::string res_f =
dir_ + "/build/" + fix_path(it.stem().stem().string()) + ".shbin ";
std::string command =
dkp_env + "/tools/bin/picasso -o " + res_f + fix_path(it.string());
// std::cout << CCMAGENTA << "Generating: " << CCCYAN << res_f
// << std::endl;
int reqres = system(command.c_str());
// std::cout << (reqres == 0 ? CCGREEN : CCRED)
// << (reqres == 0 ? "[+] " : "[-] ") << res_f
// << std::endl;
if (reqres != 0) return true;
// Bin2o action
// Mod res_f
std::string erf = res_f;
recursive_repl(erf, '.', '_');
erf = erf.substr(0, erf.length() - 1);
std::string tmp = "t.s";
std::string obj = erf + ".o";
std::string hdr = erf + ".h";
// Convert bin2asm
std::string cmd = "bin2s -a 4 -H " + hdr + ' ' + res_f + " > " + tmp;
reqres = system(cmd.c_str());
if (reqres != 0) return true;
cmd = prj.cxx_compiler + " -x assembler-with-cpp " + tmp + " -c -o " + obj;
reqres = system(cmd.c_str());
// remove asm file
remove(tmp.c_str());
if (reqres != 0) return true;
return false;
}
bool Tex3ds_Compile(std::string dir_, std::string dkp_env,
std::filesystem::path it, NpiProject prj) {
std::string command =
dkp_env + "/tools/bin/tex3ds -i " + fix_path(it.string()) + " -H " +
dir_ + "/build/" + fix_path(it.stem().string()) + ".h" + " -d " + dir_ +
"/build/" + fix_path(it.stem().string()) + ".d" + " -o " + dir_ +
"/romfs/gfx//" + fix_path(it.stem().string()) + ".t3x";
// std::cout << CCMAGENTA << "Generating: " << CCCYAN <<
// fix_path(it.filename().string())
// << std::endl;
int reqres = system(command.c_str());
// std::cout << (reqres == 0 ? CCGREEN : CCRED)
// << (reqres == 0 ? "[+] " : "[-] ") <<
// fix_path(it.filename().string())
// << std::endl;
return reqres != 0;
}
void CompileProject(NpiProject &prj, std::string dir_, bool async = true) {
#ifdef _WIN32 #ifdef _WIN32
std::string dkp_env = "C:/devkitPro/"; std::string dkp_env = "C:/devkitPro/";
std::cout << CCYELLOW << "[+] Warning: Windows Usage Detected!\n[+] Make sure you have devkitpro installed at <C:/devkitPro>!" << CCRESET << std::endl; std::cout << CCYELLOW
<< "[+] Warning: Windows Usage Detected!\n[+] Make sure you have "
"devkitpro installed at <C:/devkitPro>!"
<< CCRESET << std::endl;
#else #else
std::string dkp_env = getenv("DEVKITPRO"); std::string dkp_env = getenv("DEVKITPRO");
#endif #endif
@ -385,8 +407,7 @@ void CompileProject(NpiProject &prj, std::string dir_)
std::vector<std::filesystem::path> t3s_files_; std::vector<std::filesystem::path> t3s_files_;
if (!std::filesystem::exists( if (!std::filesystem::exists(
std::filesystem::path(dir_ + "/build/hashes.json"))) std::filesystem::path(dir_ + "/build/hashes.json"))) {
{
GenerateHashes(prj, dir_); GenerateHashes(prj, dir_);
cpp_files_ = get_files_in_dir(prj.source_dirs, ".cpp"); cpp_files_ = get_files_in_dir(prj.source_dirs, ".cpp");
c_files_ = get_files_in_dir(prj.source_dirs, ".c"); c_files_ = get_files_in_dir(prj.source_dirs, ".c");
@ -394,9 +415,7 @@ void CompileProject(NpiProject &prj, std::string dir_)
shlist_files_ = get_files_in_dir(prj.source_dirs, ".shlist"); shlist_files_ = get_files_in_dir(prj.source_dirs, ".shlist");
s_files_ = get_files_in_dir(prj.source_dirs, ".s"); s_files_ = get_files_in_dir(prj.source_dirs, ".s");
t3s_files_ = get_files_in_dir({std::string(dir_ + "/gfx")}, ".t3s"); t3s_files_ = get_files_in_dir({std::string(dir_ + "/gfx")}, ".t3s");
} } else {
else
{
cpp_files_ = getChangedFiles(GetHashMap(dir_, ".cpp")); cpp_files_ = getChangedFiles(GetHashMap(dir_, ".cpp"));
c_files_ = getChangedFiles(GetHashMap(dir_, ".c")); c_files_ = getChangedFiles(GetHashMap(dir_, ".c"));
v_pica_files_ = getChangedFiles(GetHashMap(dir_, ".v.pica")); v_pica_files_ = getChangedFiles(GetHashMap(dir_, ".v.pica"));
@ -404,22 +423,19 @@ void CompileProject(NpiProject &prj, std::string dir_)
s_files_ = getChangedFiles(GetHashMap(dir_, ".s")); s_files_ = getChangedFiles(GetHashMap(dir_, ".s"));
t3s_files_ = getChangedFiles(GetHashMap(dir_, ".t3s")); t3s_files_ = getChangedFiles(GetHashMap(dir_, ".t3s"));
if ((getChangedFiles(GetHashMap(dir_, ".hpp")).size() != 0) || if ((getChangedFiles(GetHashMap(dir_, ".hpp")).size() != 0) ||
(getChangedFiles(GetHashMap(dir_, ".hpp")).size() != 0)) (getChangedFiles(GetHashMap(dir_, ".hpp")).size() != 0)) {
{
cpp_files_ = get_files_in_dir(prj.source_dirs, ".cpp"); cpp_files_ = get_files_in_dir(prj.source_dirs, ".cpp");
c_files_ = get_files_in_dir(prj.source_dirs, ".c"); c_files_ = get_files_in_dir(prj.source_dirs, ".c");
} }
} }
if (GetHashMap(dir_, ".cpp").size() != cpp_files.size() || if (GetHashMap(dir_, ".cpp").size() != cpp_files.size() ||
GetHashMap(dir_, ".c").size() != c_files.size()) GetHashMap(dir_, ".c").size() != c_files.size()) {
{
cpp_files_ = get_files_in_dir(prj.source_dirs, ".cpp"); cpp_files_ = get_files_in_dir(prj.source_dirs, ".cpp");
c_files_ = get_files_in_dir(prj.source_dirs, ".c"); c_files_ = get_files_in_dir(prj.source_dirs, ".c");
} }
if (GetHashMap(dir_, ".hpp").size() != hpp_files.size() || if (GetHashMap(dir_, ".hpp").size() != hpp_files.size() ||
GetHashMap(dir_, ".h").size() != h_files.size()) GetHashMap(dir_, ".h").size() != h_files.size()) {
{
cpp_files_ = get_files_in_dir(prj.source_dirs, ".cpp"); cpp_files_ = get_files_in_dir(prj.source_dirs, ".cpp");
c_files_ = get_files_in_dir(prj.source_dirs, ".c"); c_files_ = get_files_in_dir(prj.source_dirs, ".c");
} }
@ -432,9 +448,10 @@ void CompileProject(NpiProject &prj, std::string dir_)
ReplVariables(prj.linker, "{DEVKITPRO}", dkp_env); ReplVariables(prj.linker, "{DEVKITPRO}", dkp_env);
int prgc = 0; int prgc = 0;
int wa = cpp_files_.size() + c_files_.size() + t3s_files_.size() +
v_pica_files_.size();
int prga = cpp_files_.size() + c_files_.size(); int prga = cpp_files_.size() + c_files_.size();
if (prga <= 0) if (prga <= 0) {
{
prgc = 1; prgc = 1;
prga = 1; prga = 1;
std::cout << CCGREEN << "[+] Everything is Up to date..." << CCRESET std::cout << CCGREEN << "[+] Everything is Up to date..." << CCRESET
@ -442,112 +459,55 @@ void CompileProject(NpiProject &prj, std::string dir_)
return; return;
} }
for (auto const &it : t3s_files_) for (auto const &it : t3s_files_) {
{ prgc++;
std::string command = dkp_env + "/tools/bin/tex3ds -i " + fix_path(it.string()) + updateProgressBar(((float)prgc / (float)wa), it.filename().string());
" -H " + dir_ + "/build/" + fix_path(it.stem().string()) + Tex3ds_Compile(dir_, dkp_env, it, prj);
".h" + " -d " + dir_ + "/build/" +
fix_path(it.stem().string()) + ".d" + " -o " + dir_ +
"/romfs/gfx//" + fix_path(it.stem().string()) + ".t3x";
std::cout << CCMAGENTA << "Generating: " << CCCYAN << fix_path(it.filename().string())
<< std::endl;
int reqres = system(command.c_str());
std::cout << (reqres == 0 ? CCGREEN : CCRED)
<< (reqres == 0 ? "[+] " : "[-] ") << fix_path(it.filename().string())
<< std::endl;
if (reqres != 0)
any_errors = true;
} }
for (auto const &it : v_pica_files_) for (auto const &it : v_pica_files_) {
{ prgc++;
std::string res_f = dir_ + "/build/" + fix_path(it.stem().stem().string()) + ".shbin "; updateProgressBar(((float)prgc / (float)wa), it.filename().string());
std::string command = dkp_env + "/tools/bin/picasso -o " + Picasso_Compile(dir_, dkp_env, it, prj);
res_f + fix_path(it.string());
std::cout << CCMAGENTA << "Generating: " << CCCYAN << res_f
<< std::endl;
int reqres = system(command.c_str());
std::cout << (reqres == 0 ? CCGREEN : CCRED)
<< (reqres == 0 ? "[+] " : "[-] ") << res_f
<< std::endl;
if (reqres != 0)
any_errors = true;
// Bin2o action
// Mod res_f
std::string erf = res_f;
recursive_repl(erf, '.', '_');
erf = erf.substr(0, erf.length() - 1);
std::string tmp = "t.s";
std::string obj = erf + ".o";
std::string hdr = erf + ".h";
// Convert bin2asm
std::string cmd = "bin2s -a 4 -H " + hdr + ' ' + res_f + " > " + tmp;
reqres = system(cmd.c_str());
if (reqres != 0)
any_errors = true;
cmd = prj.cxx_compiler + " -x assembler-with-cpp " + tmp + " -c -o " + obj;
reqres = system(cmd.c_str());
if (reqres != 0)
any_errors = true;
// remove asm file
remove(tmp.c_str());
} }
for (auto const &it : cpp_files_) /*if (async)
{ {
std::string command =
prj.cxx_compiler + " -MMD -MP -MF " + dir_ + "/build/" + }
fix_path(it.stem().string()) + ".d " + "-c " + fix_path(it.string()) + " -o " + dir_ + else
"/build/" + fix_path(it.stem().string()) + ".o " + Flags2Str(prj.cxx_flags) + {*/
" " + IncludeDirs(prj.include_dirs) + " " + LibIncludes(prj.lib_dirs); for (auto const &it : cpp_files_) {
std::cout << CCMAGENTA << "Compiling: " << CCCYAN << fix_path(it.filename().string()) prgc++;
<< std::endl; updateProgressBar(((float)prgc / (float)wa), it.filename().string());
int reqres = system(command.c_str()); C_CXX_Compile(true, dir_, it, prj);
std::cout << (reqres == 0 ? CCGREEN : CCRED)
<< (reqres == 0 ? "[+] " : "[-] ") << fix_path(it.filename().string())
<< std::endl;
if (reqres != 0)
any_errors = true;
} }
for (auto const &it : c_files_) for (auto const &it : c_files_) {
{ prgc++;
std::string command = updateProgressBar(((float)prgc / (float)wa), it.filename().string());
prj.c_compiler + " -MMD -MP -MF " + dir_ + "/build/" + C_CXX_Compile(false, dir_, it, prj);
fix_path(it.stem().string()) + ".d " + "-c " + fix_path(it.string()) + " -o " + dir_ +
"/build/" + fix_path(it.stem().string()) + ".o " + Flags2Str(prj.c_flags) + " " +
IncludeDirs(prj.include_dirs) + " " + LibIncludes(prj.lib_dirs);
std::cout << CCMAGENTA << "Compiling: " << CCCYAN << fix_path(it.filename().string())
<< std::endl;
int reqres = system(command.c_str());
std::cout << (reqres == 0 ? CCGREEN : CCRED)
<< (reqres == 0 ? "[+] " : "[-] ") << fix_path(it.filename().string())
<< std::endl;
if (reqres != 0)
any_errors = true;
} }
//}
// updateProgressBar(1.f);
std::cout << std::endl;
std::vector<std::filesystem::path> o_files = std::vector<std::filesystem::path> o_files =
get_files_in_dir({dir_ + "/build/"}, ".o"); get_files_in_dir({dir_ + "/build/"}, ".o");
std::vector<std::filesystem::path> d_files = std::vector<std::filesystem::path> d_files =
get_files_in_dir({dir_ + "/build/"}, ".d"); get_files_in_dir({dir_ + "/build/"}, ".d");
if (!any_errors) if (!any_errors) {
{
std::string command = prj.linker + " -o " + dir_ + "/" + prj.name + std::string command = prj.linker + " -o " + dir_ + "/" + prj.name +
".elf " + LinkerInput(o_files, d_files) + " " + ".elf " + LinkerInput(o_files, d_files) + " " +
Libs(prj.libraries) + " " + LibPaths(prj.lib_dirs) + Libs(prj.libraries) + " " + LibPaths(prj.lib_dirs) +
" " + Flags2Str(prj.linker_flags); " " + Flags2Str(prj.linker_flags);
std::cout << CCBLUE << "[+] Linking..." << CCRESET << std::endl; std::cout << CCBLUE << "[+] Linking..." << CCRESET << std::endl;
int reqres = system(command.c_str()); int reqres = system(command.c_str());
if (reqres != 0) if (reqres != 0) any_errors = true;
any_errors = true; if (prj.ctr_type) {
if (prj.ctr_type) command =
{ "bannertool makebanner -i \"app/banner.png\" -a "
command = "bannertool makebanner -i \"app/banner.png\" -a "
"\"app/BannerAudio.wav\" -o \"build/banner.bin\""; "\"app/BannerAudio.wav\" -o \"build/banner.bin\"";
std::cout << CCBLUE << "[+] Creating Banner..." << CCRESET << std::endl; std::cout << CCBLUE << "[+] Creating Banner..." << CCRESET << std::endl;
reqres = system(command.c_str()); reqres = system(command.c_str());
@ -570,16 +530,15 @@ void CompileProject(NpiProject &prj, std::string dir_)
std::cout << (reqres == 0 ? CCGREEN : CCRED) std::cout << (reqres == 0 ? CCGREEN : CCRED)
<< (reqres == 0 ? "[+] " : "[-] ") << prj.name + ".3dsx " << (reqres == 0 ? "[+] " : "[-] ") << prj.name + ".3dsx "
<< std::endl; << std::endl;
if (prj.ctr_type) if (prj.ctr_type) {
{
command = command =
"makerom -f cia -target t -exefslogo -o " + dir_ + "/" + prj.name + "makerom -f cia -target t -exefslogo -o " + dir_ + "/" + prj.name +
".cia -elf " + dir_ + "/" + prj.name + ".elf " + " -rsf " + dir_ + "/" + ".cia -elf " + dir_ + "/" + prj.name + ".elf " + " -rsf " + dir_ +
prj.rsf_path + " -banner " + dir_ + "/build/banner.bin" + " -icon " + "/" + prj.rsf_path + " -banner " + dir_ + "/build/banner.bin" +
dir_ + "/build/icon.bin" + " -logo " + dir_ + "/" + prj.logo_lz11_path + " -icon " + dir_ + "/build/icon.bin" + " -logo " + dir_ + "/" +
" -DAPP_ROMFS=" + dir_ + "/" + prj.dir_romfs + " -major " + prj.logo_lz11_path + " -DAPP_ROMFS=" + dir_ + "/" + prj.dir_romfs +
std::to_string(prj.vmajor) + " -minor " + std::to_string(prj.vminor) + " -major " + std::to_string(prj.vmajor) + " -minor " +
" -micro " + std::to_string(prj.vbuild) + std::to_string(prj.vminor) + " -micro " + std::to_string(prj.vbuild) +
" -DAPP_VERSION_MAJOR=" + std::to_string(prj.vmajor); " -DAPP_VERSION_MAJOR=" + std::to_string(prj.vmajor);
std::cout << CCBLUE << "[+] Creating Cia..." << CCRESET << std::endl; std::cout << CCBLUE << "[+] Creating Cia..." << CCRESET << std::endl;
reqres = system(command.c_str()); reqres = system(command.c_str());
@ -589,8 +548,7 @@ void CompileProject(NpiProject &prj, std::string dir_)
} }
} }
if (any_errors) if (any_errors) {
{
std::cout std::cout
<< CCRED << CCRED
<< "\nErrors Happened!\nTake a look at the Top of this Message...\n" << "\nErrors Happened!\nTake a look at the Top of this Message...\n"
@ -602,31 +560,26 @@ void CompileProject(NpiProject &prj, std::string dir_)
std::cout << CCRESET << std::endl; std::cout << CCRESET << std::endl;
} }
namespace helper namespace helper {
{ std::string GenerateUniqueId() {
std::string GenerateUniqueId()
{
std::random_device rd; std::random_device rd;
std::mt19937 gen(rd()); std::mt19937 gen(rd());
std::uniform_int_distribution<> dis(0, 15); std::uniform_int_distribution<> dis(0, 15);
std::stringstream ss; std::stringstream ss;
ss << "0x"; ss << "0x";
for (int i = 0; i < 5; ++i) for (int i = 0; i < 5; ++i) {
{
ss << std::hex << dis(gen); ss << std::hex << dis(gen);
} }
std::string hex_str = ss.str(); std::string hex_str = ss.str();
return hex_str; return hex_str;
} }
void ArrayToFile(unsigned char *array_, size_t size_, std::string filename) void ArrayToFile(unsigned char *array_, size_t size_, std::string filename) {
{
std::ofstream file(filename, std::ios::binary); std::ofstream file(filename, std::ios::binary);
if (!file.is_open()) if (!file.is_open()) {
{
std::cerr << CCRED << "[-]: Could not open file" << CCRESET << std::endl; std::cerr << CCRED << "[-]: Could not open file" << CCRESET << std::endl;
return; return;
} }
@ -634,10 +587,9 @@ namespace helper
file.write(reinterpret_cast<char *>(array_), size_); file.write(reinterpret_cast<char *>(array_), size_);
file.close(); file.close();
} }
void GenerateTemplateFile(std::string path, NpiProject prj) void GenerateTemplateFile(std::string path, NpiProject prj) {
{
nlohmann::ordered_json js; nlohmann::ordered_json js;
js["project_name"] = prj.name; js["project_name"] = prj.name;
js["author"] = prj.author; js["author"] = prj.author;
@ -645,14 +597,12 @@ namespace helper
js["vmajor"] = prj.vmajor; js["vmajor"] = prj.vmajor;
js["vminor"] = prj.vminor; js["vminor"] = prj.vminor;
js["vbuild"] = prj.vbuild; js["vbuild"] = prj.vbuild;
if (prj.ctr_type) if (prj.ctr_type) {
{
js["unique_id"] = prj.unique_id; js["unique_id"] = prj.unique_id;
js["prod_code"] = prj.prod; js["prod_code"] = prj.prod;
} }
js["platform"] = prj.platform; js["platform"] = prj.platform;
if (prj.platform == "3ds") if (prj.platform == "3ds") {
{
js["cia"] = prj.ctr_type; js["cia"] = prj.ctr_type;
} }
@ -673,8 +623,7 @@ namespace helper
js["lib_dirs"] = lib_dirs; js["lib_dirs"] = lib_dirs;
js["icon_path"] = prj.icon_path; js["icon_path"] = prj.icon_path;
if (prj.ctr_type) if (prj.ctr_type) {
{
js["banner_path"] = prj.banner_path; js["banner_path"] = prj.banner_path;
js["banner_a_path"] = prj.banner_a_path; js["banner_a_path"] = prj.banner_a_path;
js["rsf_path"] = prj.rsf_path; js["rsf_path"] = prj.rsf_path;
@ -713,31 +662,25 @@ namespace helper
std::ofstream fout(path); std::ofstream fout(path);
fout << js.dump(4); fout << js.dump(4);
fout.close(); fout.close();
} }
void CompileProject(std::string path) void CompileProject(std::string path, bool async) {
{
std::string dkp_env = getenv("DEVKITPRO"); std::string dkp_env = getenv("DEVKITPRO");
if (dkp_env.c_str() == NULL) if (dkp_env.c_str() == NULL) {
{ std::cerr << CCRED << "[-] Please set DEVKITPRO ENV Variable!\n" << CCRESET;
std::cerr << CCRED << "[-] Please set DEVKITPRO ENV Variable!\n"
<< CCRESET;
return; return;
} }
nlohmann::json js; nlohmann::json js;
std::ifstream is(path + "/build.json"); std::ifstream is(path + "/build.json");
if (!is) if (!is) {
{ std::cerr << CCRED << "[-] build.json not in " << path << "!\n" << CCRESET;
std::cerr << CCRED << "[-] build.json not in " << path << "!\n"
<< CCRESET;
return; return;
} }
is >> js; is >> js;
is.close(); is.close();
std::cout << CCBLUE << "[+] Compiling at " << path << " ...\n" std::cout << CCBLUE << "[+] Compiling at " << path << " ...\n" << CCRESET;
<< CCRESET;
NpiProject prj; NpiProject prj;
auto __name = js_catch<std::string>(js, "project_name"); auto __name = js_catch<std::string>(js, "project_name");
@ -751,8 +694,7 @@ namespace helper
std::pair<std::string, bool> __unique_id; std::pair<std::string, bool> __unique_id;
std::pair<std::string, bool> __prod; std::pair<std::string, bool> __prod;
if (__ctr_type.first) if (__ctr_type.first) {
{
__unique_id = js_catch<std::string>(js, "unique_id"); __unique_id = js_catch<std::string>(js, "unique_id");
__prod = js_catch<std::string>(js, "prod_code"); __prod = js_catch<std::string>(js, "prod_code");
} }
@ -763,8 +705,7 @@ namespace helper
std::pair<std::string, bool> __logo_lz11_path; std::pair<std::string, bool> __logo_lz11_path;
auto __icon_path = js_catch<std::string>(js, "icon_path"); auto __icon_path = js_catch<std::string>(js, "icon_path");
if (__ctr_type.first) if (__ctr_type.first) {
{
__banner_path = js_catch<std::string>(js, "banner_path"); __banner_path = js_catch<std::string>(js, "banner_path");
__banner_a_path = js_catch<std::string>(js, "banner_a_path"); __banner_a_path = js_catch<std::string>(js, "banner_a_path");
__rsf_path = js_catch<std::string>(js, "rsf_path"); __rsf_path = js_catch<std::string>(js, "rsf_path");
@ -814,12 +755,11 @@ namespace helper
prj.linker = __linker.first; prj.linker = __linker.first;
NpiProject _2build = prj; NpiProject _2build = prj;
ProcessPrj2Cmp(&_2build, prj); ProcessPrj2Cmp(&_2build, prj);
CompileProject(_2build, path); CompileProject(_2build, path, async);
} }
void CleanProject(std::string path) void CleanProject(std::string path) {
{
DeleteFiles(path, {".3dsx", ".cia", ".elf"}); DeleteFiles(path, {".3dsx", ".cia", ".elf"});
DeleteFiles(path + "/" + "romfs", {".t3x"}); DeleteFiles(path + "/" + "romfs", {".t3x"});
DeleteDirectory(path + "/build"); DeleteDirectory(path + "/build");
} }
} // namespace helper } // namespace helper

View File

@ -1,35 +1,29 @@
#include <algorithm> #include <algorithm>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <vector>
#include <banner.hpp> #include <banner.hpp>
#include <banner_audio.hpp> #include <banner_audio.hpp>
#include <fileHash.hpp>
#include <filesystem>
#include <fstream>
#include <helper.hpp> #include <helper.hpp>
#include <icon.hpp> #include <icon.hpp>
#include <iostream>
#include <logo_lz11.hpp> #include <logo_lz11.hpp>
#include <samplefiles.hpp> #include <samplefiles.hpp>
#include <fileHash.hpp> #include <vector>
// Console CLear String // Console CLear String
#define cons_clear std::cout << "\x1B[2J\x1B[H" #define cons_clear std::cout << "\x1B[2J\x1B[H"
// Make String Uppercase // Make String Uppercase
void ToUpperCase(std::string &str) void ToUpperCase(std::string &str) {
{
std::transform(str.begin(), str.end(), str.begin(), std::transform(str.begin(), str.end(), str.begin(),
[](unsigned char c) [](unsigned char c) { return std::toupper(c); });
{ return std::toupper(c); });
} }
// Check if String is Valid Hex String // Check if String is Valid Hex String
bool isValidHex(const std::string &str) bool isValidHex(const std::string &str) {
{ for (char c : str) {
for (char c : str) if (!isxdigit(c)) {
{
if (!isxdigit(c))
{
return false; return false;
} }
} }
@ -37,44 +31,34 @@ bool isValidHex(const std::string &str)
} }
// Check for tools // Check for tools
void CheckTools() void CheckTools() {
{
std::vector<std::string> installed; std::vector<std::string> installed;
std::vector<std::string> not_installed; std::vector<std::string> not_installed;
int res = 0; int res = 0;
res = system("makerom"); res = system("makerom");
if (!res) if (!res) {
{
not_installed.push_back("makerom"); not_installed.push_back("makerom");
} } else {
else
{
installed.push_back("makerom"); installed.push_back("makerom");
} }
res = system("bannertool"); res = system("bannertool");
if (!res) if (!res) {
{
not_installed.push_back("bannertool"); not_installed.push_back("bannertool");
} } else {
else
{
installed.push_back("bannertool"); installed.push_back("bannertool");
} }
std::cout << "<DEVKITPRO> is set to: " << getenv("DEVKITPRO") << "\n"; std::cout << "<DEVKITPRO> is set to: " << getenv("DEVKITPRO") << "\n";
std::cout << "Tools-Check:\n"; std::cout << "Tools-Check:\n";
for (auto const &it : installed) for (auto const &it : installed) {
{
std::cout << "[+]" << it << " is installed!\n"; std::cout << "[+]" << it << " is installed!\n";
} }
for (auto const &it : not_installed) for (auto const &it : not_installed) {
{
std::cout << "[-]" << it << " is not installed!\n"; std::cout << "[-]" << it << " is not installed!\n";
} }
} }
// Print Usage/Help // Print Usage/Help
void PrintHelp() void PrintHelp() {
{
std::cout << "npi-build v0.1\n"; std::cout << "npi-build v0.1\n";
std::cout << "Commands:\n"; std::cout << "Commands:\n";
std::cout << "help: Display this\n"; std::cout << "help: Display this\n";
@ -89,13 +73,10 @@ void PrintHelp()
} }
// Function to generate Directories and Default Files // Function to generate Directories and Default Files
void GenerateProjectDir(const std::string &dst_dir, int type_) void GenerateProjectDir(const std::string &dst_dir, int type_) {
{
// Create Directories // Create Directories
std::filesystem::create_directories( std::filesystem::create_directories(std::filesystem::path(dst_dir + "/app"));
std::filesystem::path(dst_dir + "/app")); std::filesystem::create_directories(std::filesystem::path(dst_dir + "/gfx"));
std::filesystem::create_directories(
std::filesystem::path(dst_dir + "/gfx"));
std::filesystem::create_directories( std::filesystem::create_directories(
std::filesystem::path(dst_dir + "/romfs/gfx")); std::filesystem::path(dst_dir + "/romfs/gfx"));
std::filesystem::create_directories(dst_dir + "/source"); std::filesystem::create_directories(dst_dir + "/source");
@ -112,12 +93,10 @@ void GenerateProjectDir(const std::string &dst_dir, int type_)
std::ofstream sample_hdr(dst_dir + "/include/common.hpp"); std::ofstream sample_hdr(dst_dir + "/include/common.hpp");
sample_hdr << sample_header; sample_hdr << sample_header;
sample_hdr.close(); sample_hdr.close();
if (type_ == 1) if (type_ == 1) {
{
helper::ArrayToFile(banner_audio, banner_audio_size, helper::ArrayToFile(banner_audio, banner_audio_size,
dst_dir + "/app/banner_audio.wav"); dst_dir + "/app/banner_audio.wav");
helper::ArrayToFile(logo_lz11, logo_lz11_size, helper::ArrayToFile(logo_lz11, logo_lz11_size, dst_dir + "/app/logo.lz11");
dst_dir + "/app/logo.lz11");
helper::ArrayToFile(banner, banner_size, dst_dir + "/app/banner.png"); helper::ArrayToFile(banner, banner_size, dst_dir + "/app/banner.png");
} }
// Create icon.png // Create icon.png
@ -125,25 +104,18 @@ void GenerateProjectDir(const std::string &dst_dir, int type_)
} }
// Process Input Args // Process Input Args
void ProcessArgs(int argc, char *argv[]) void ProcessArgs(int argc, char *argv[]) {
{ if (argc < 2) {
if (argc < 2)
{
// No Args // No Args
PrintHelp(); PrintHelp();
return; return;
} } else if (std::string(argv[1]) == "help") {
else if (std::string(argv[1]) == "help")
{
// Requested Help // Requested Help
PrintHelp(); PrintHelp();
return; return;
} } else if (std::string(argv[1]) == "generate") {
else if (std::string(argv[1]) == "generate")
{
// Generator // Generator
if (argc != 4) if (argc != 4) {
{
// Missing Args / ot too much // Missing Args / ot too much
std::cout << "Wrong Number of Arguments!\n"; std::cout << "Wrong Number of Arguments!\n";
return; return;
@ -154,8 +126,7 @@ void ProcessArgs(int argc, char *argv[])
int type_ = -1; int type_ = -1;
// TODO: // TODO:
// change this if statement // change this if statement
if (type == "3dsx" | type == "cia3dsx") if (type == "3dsx" | type == "cia3dsx") {
{
res = 0; res = 0;
if (type == "3dsx") if (type == "3dsx")
type_ = 0; type_ = 0;
@ -163,8 +134,7 @@ void ProcessArgs(int argc, char *argv[])
type_ = 1; type_ = 1;
} }
// Print Error if re is not 0 // Print Error if re is not 0
if (res) if (res) {
{
std::cout << "Unknown type!\n"; std::cout << "Unknown type!\n";
return; return;
} }
@ -175,8 +145,7 @@ void ProcessArgs(int argc, char *argv[])
// Generate Project // Generate Project
GenerateProjectDir(dst_dir, type_); GenerateProjectDir(dst_dir, type_);
// Create rsf if cia mode // Create rsf if cia mode
if (type_ == 1) if (type_ == 1) {
{
char *ret = new char[10000]; char *ret = new char[10000];
std::string uid = helper::GenerateUniqueId(); std::string uid = helper::GenerateUniqueId();
sprintf(ret, ciaRSF, default_title, default_code, default_romfs_path, sprintf(ret, ciaRSF, default_title, default_code, default_romfs_path,
@ -190,9 +159,7 @@ void ProcessArgs(int argc, char *argv[])
NpiProject npr; NpiProject npr;
Prj_InitDefault(npr, (type_ == 1)); Prj_InitDefault(npr, (type_ == 1));
helper::GenerateTemplateFile(dst_dir + "/build.json", npr); helper::GenerateTemplateFile(dst_dir + "/build.json", npr);
} } else if (std::string(argv[1]) == "generate-assist") {
else if (std::string(argv[1]) == "generate-assist")
{
// Generate with Assistant // Generate with Assistant
// define vars // define vars
std::string prj_name; std::string prj_name;
@ -208,8 +175,7 @@ void ProcessArgs(int argc, char *argv[])
// Request Prod Code // Request Prod Code
std::cout << "\ntype Product Code 4 chars [NPI7] >"; std::cout << "\ntype Product Code 4 chars [NPI7] >";
std::cin >> prodcode; std::cin >> prodcode;
if (prodcode.length() != 4) if (prodcode.length() != 4) {
{
// Handle Wrong lengh Error // Handle Wrong lengh Error
std::cout << "\nWrong Length!\n"; std::cout << "\nWrong Length!\n";
return; return;
@ -223,26 +189,22 @@ void ProcessArgs(int argc, char *argv[])
std::cin >> unique_id; std::cin >> unique_id;
// Check if random keyword was used // Check if random keyword was used
bool rnd = false; bool rnd = false;
if (unique_id == "random") if (unique_id == "random") {
{
// Generate random one // Generate random one
unique_id = helper::GenerateUniqueId(); unique_id = helper::GenerateUniqueId();
rnd = true; rnd = true;
} }
if (unique_id.length() != 5 && !rnd) if (unique_id.length() != 5 && !rnd) {
{
// Handle wrong lengh // Handle wrong lengh
std::cout << "\nWrong Length!\n"; std::cout << "\nWrong Length!\n";
return; return;
} }
if (!isValidHex(unique_id) && !rnd) if (!isValidHex(unique_id) && !rnd) {
{
// Handle not hex digits // Handle not hex digits
std::cout << "\nId is not valid\n"; std::cout << "\nId is not valid\n";
return; return;
} }
if (!rnd) if (!rnd) {
{
// Add 0x if not random // Add 0x if not random
unique_id.insert(0, "0x"); unique_id.insert(0, "0x");
} }
@ -250,8 +212,7 @@ void ProcessArgs(int argc, char *argv[])
// Request Project type // Request Project type
std::cout << "\nProject type: type 0 for 3dsx\nonly or 1 for cia and 3dsx>"; std::cout << "\nProject type: type 0 for 3dsx\nonly or 1 for cia and 3dsx>";
std::cin >> type_; std::cin >> type_;
if (!(type_ == 0 | type_ == 1)) if (!(type_ == 0 | type_ == 1)) {
{
std::cout << "\nunknown type!\n"; std::cout << "\nunknown type!\n";
return; return;
} }
@ -264,8 +225,7 @@ void ProcessArgs(int argc, char *argv[])
GenerateProjectDir(dst_dir, type_); GenerateProjectDir(dst_dir, type_);
// Generate RSF if cia mode // Generate RSF if cia mode
if (type_ == 1) if (type_ == 1) {
{
char *ret = new char[10000]; char *ret = new char[10000];
sprintf(ret, ciaRSF, prj_name.c_str(), prodcode.c_str(), sprintf(ret, ciaRSF, prj_name.c_str(), prodcode.c_str(),
default_romfs_path, unique_id.c_str()); default_romfs_path, unique_id.c_str());
@ -278,18 +238,23 @@ void ProcessArgs(int argc, char *argv[])
NpiProject npr; NpiProject npr;
Prj_InitDefault(npr, (type_ == 1)); Prj_InitDefault(npr, (type_ == 1));
npr.name = prj_name; npr.name = prj_name;
if (npr.ctr_type) if (npr.ctr_type) {
{
npr.prod = prodcode; npr.prod = prodcode;
npr.unique_id = unique_id; npr.unique_id = unique_id;
} }
helper::GenerateTemplateFile(dst_dir + "/build.json", npr); helper::GenerateTemplateFile(dst_dir + "/build.json", npr);
} }
else if (std::string(argv[1]) == "build") else if (std::string(argv[1]) == "build") {
{ bool as = false;
if (argc == 3) {
if (std::string(argv[2]) == "async") {
as = true;
}
}
// Run over build.json and build project // Run over build.json and build project
helper::CompileProject(fix_path(std::filesystem::current_path().string())); helper::CompileProject(fix_path(std::filesystem::current_path().string()),
as);
} }
// Check for makerom and bannertool // Check for makerom and bannertool
@ -301,8 +266,7 @@ void ProcessArgs(int argc, char *argv[])
} }
// Main Entrypoint // Main Entrypoint
int main(int argc, char *argv[]) int main(int argc, char *argv[]) {
{
// Process Input // Process Input
ProcessArgs(argc, argv); ProcessArgs(argc, argv);

View File

@ -5,10 +5,10 @@ const char *default_code = "NPI7";
const char *default_unique_id = "0xff3ff"; const char *default_unique_id = "0xff3ff";
const char *default_romfs_path = "romfs"; const char *default_romfs_path = "romfs";
const char *sample_header = const char *sample_header =
"// Sample Header File\n" "// Sample Header File\n"
"#pragma once\n" "#pragma once\n"
"#include <3ds.h>\n" "#include <3ds.h>\n"
"#include <stdio.h>"; "#include <stdio.h>";
const char *sample_code = const char *sample_code =
"// Sample Source Code for Hello World\n\n" "// Sample Source Code for Hello World\n\n"
"#include <common.hpp>\n\n" "#include <common.hpp>\n\n"