diff --git a/cformat.sh b/cformat.sh index 4ebde23..1739f5b 100644 --- a/cformat.sh +++ b/cformat.sh @@ -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 # 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! -clang-format --verbose -i --style=file $FILE_LIST +clang-format --verbose -i --style=Google $FILE_LIST diff --git a/include/fileHash.hpp b/include/fileHash.hpp index 1bd2808..db6f14c 100644 --- a/include/fileHash.hpp +++ b/include/fileHash.hpp @@ -8,26 +8,21 @@ #include #include -inline std::string fix_path(const std::string &path) -{ - if (path.find('\\') == path.npos) - return path; +inline std::string fix_path(const std::string &path) { + if (path.find('\\') == path.npos) return path; std::string ret = path; std::replace(ret.begin(), ret.end(), '\\', '/'); return ret; } -inline std::string stupid_hash(const std::string &file) -{ +inline std::string stupid_hash(const std::string &file) { std::ifstream iff(file); - if (!iff.is_open()) - { + if (!iff.is_open()) { return std::to_string(rand()); } unsigned long long check_sum = 0x0ULL; char tmp; - while (iff.get(tmp)) - { + while (iff.get(tmp)) { check_sum += (unsigned long long)tmp; } iff.close(); @@ -36,20 +31,14 @@ inline std::string stupid_hash(const std::string &file) return ret.str(); } -inline std::map -createHashes(const std::vector &dirs, - const std::string &extension) -{ +inline std::map createHashes( + const std::vector &dirs, const std::string &extension) { std::map hashes; - for (auto const &it : dirs) - { - for (const auto &file : std::filesystem::directory_iterator(it)) - { - if (file.is_regular_file()) - { + for (auto const &it : dirs) { + for (const auto &file : std::filesystem::directory_iterator(it)) { + if (file.is_regular_file()) { 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); } } @@ -58,15 +47,12 @@ createHashes(const std::vector &dirs, return hashes; } -inline std::vector -getChangedFiles(const std::map &oldHashes) -{ +inline std::vector getChangedFiles( + const std::map &oldHashes) { std::vector changedFiles; - for (const auto &file : oldHashes) - { + for (const auto &file : oldHashes) { std::string newHash = stupid_hash(file.first); - if (newHash != file.second) - { + if (newHash != file.second) { changedFiles.push_back(std::filesystem::path(file.first)); } } diff --git a/include/helper.hpp b/include/helper.hpp index ab022b7..ef63a95 100644 --- a/include/helper.hpp +++ b/include/helper.hpp @@ -6,6 +6,6 @@ namespace helper { std::string GenerateUniqueId(); void ArrayToFile(unsigned char *array_, size_t size_, std::string filename); 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); -} // namespace helper \ No newline at end of file +} // namespace helper \ No newline at end of file diff --git a/include/prj_def.hpp b/include/prj_def.hpp index 9f127b3..26261e8 100644 --- a/include/prj_def.hpp +++ b/include/prj_def.hpp @@ -3,8 +3,7 @@ #include #include -struct NpiProject -{ +struct NpiProject { std::string name; std::string author; std::string description; @@ -17,19 +16,19 @@ struct NpiProject std::vector lib_dirs; std::string icon_path; - std::string banner_path; // depends ctr_type - std::string banner_a_path; // depends ctr_type - std::string rsf_path; // depends ctr_type - std::string logo_lz11_path; // depends ctr_type + std::string banner_path; // depends ctr_type + std::string banner_a_path; // depends ctr_type + std::string rsf_path; // depends ctr_type + std::string logo_lz11_path; // depends ctr_type std::string dir_gfx; std::string dir_gfxbuild; std::string dir_romfs; - std::string unique_id; // depends ctr_type - std::string prod; // depends ctr_type - std::string platform; // Platforms: 3ds, desktop - bool ctr_type; // depends platform + std::string unique_id; // depends ctr_type + std::string prod; // depends ctr_type + std::string platform; // Platforms: 3ds, desktop + bool ctr_type; // depends platform std::vector arch_flags; std::vector c_flags; @@ -43,8 +42,7 @@ struct NpiProject std::string asm_compiler; }; -inline void Prj_InitDefault(NpiProject &project, bool cia) -{ +inline void Prj_InitDefault(NpiProject &project, bool cia) { project.name = "Sample"; project.author = "Sample"; 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.icon_path = "app/icon.png"; - if (cia) - { + if (cia) { project.banner_path = "app/banner.png"; project.banner_a_path = "app/banner_audio.wav"; 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_romfs = "romfs/"; - if (cia) - { + if (cia) { project.unique_id = "0xff3ff"; project.prod = "NPI7"; } diff --git a/source/helper.cpp b/source/helper.cpp index 134a556..7e5bf57 100644 --- a/source/helper.cpp +++ b/source/helper.cpp @@ -1,10 +1,14 @@ +#include + #include +#include #include #include #include +#include #include #include -#include +#include #include #include #include @@ -12,11 +16,6 @@ #include #include -#include - -#include -#include - #define CCRED "\033[31m" #define CCGREEN "\033[32m" #define CCYELLOW "\033[33m" @@ -27,45 +26,48 @@ #define veccmp(vec1, vec2) (vec1.size() == vec2.size()) -void updateProgressBar(float progress) -{ - std::cout << CCYELLOW << "[" << static_cast(progress * 100.0) << " %] " - << CCRESET; +void updateProgressBar(float progress, std::string f) { + const int w = 50; + int pos = static_cast(progress * w); + + 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(progress * 100.0) + << "% " << CCRESET << '\r'; + std::cout.flush(); } template -std::pair js_catch(const nlohmann::json &js, const std::string &at) -{ +std::pair js_catch(const nlohmann::json &js, const std::string &at) { bool exists = true; - if (!js.contains(at) || js[at].is_null()) - exists = false; + if (!js.contains(at) || js[at].is_null()) exists = false; return std::make_pair(js[at].get(), 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::vector -get_files_in_dir(const std::vector &dir_paths, - const std::string &extension) -{ +std::vector get_files_in_dir( + const std::vector &dir_paths, const std::string &extension) { std::vector files; - for (const auto &dir_path : dir_paths) - { - if (!std::filesystem::exists(dir_path)) - continue; - for (const auto &entry : std::filesystem::directory_iterator(dir_path)) - { - if (std::filesystem::is_regular_file(entry.path())) - { + for (const auto &dir_path : dir_paths) { + if (!std::filesystem::exists(dir_path)) continue; + for (const auto &entry : std::filesystem::directory_iterator(dir_path)) { + if (std::filesystem::is_regular_file(entry.path())) { std::string fn = entry.path().string(); - if (fn.length() > extension.length()) - { - if (fn.ends_with(extension)) - { + if (fn.length() > extension.length()) { + if (fn.ends_with(extension)) { files.push_back(fix_path(entry.path().string())); } } @@ -76,93 +78,70 @@ get_files_in_dir(const std::vector &dir_paths, return files; } -void Js2Vec(std::vector &vec, nlohmann::json js) -{ +void Js2Vec(std::vector &vec, nlohmann::json js) { vec.clear(); - for (auto const &it : js) - { + for (auto const &it : js) { vec.push_back(it.get()); } } void Vec2Json(std::vector vec, nlohmann::json &js, - NpiProject ref) -{ + NpiProject ref) { int indx = 0; - for (auto const &it : vec) - { + for (auto const &it : vec) { js[indx] = it; indx++; } } -std::string Flags2Str(std::vector flags) -{ +std::string Flags2Str(std::vector flags) { std::string res = ""; - for (auto const &it : flags) - res += "-" + it + " "; + for (auto const &it : flags) res += "-" + it + " "; return res; } -std::string IncludeDirs(std::vector dirs) -{ +std::string IncludeDirs(std::vector dirs) { std::string res = ""; - for (auto const &it : dirs) - res += "-I " + it + " "; + for (auto const &it : dirs) res += "-I " + it + " "; return res; } -std::string LibIncludes(std::vector dirs) -{ +std::string LibIncludes(std::vector dirs) { std::string res = ""; - for (auto const &it : dirs) - res += "-I " + it + "include/ "; + for (auto const &it : dirs) res += "-I " + it + "include/ "; return res; } void VecGetExtra(std::vector &result, - std::vector input, NpiProject ref) -{ + std::vector input, NpiProject ref) { result.clear(); - for (auto const &it : input) - { - if (it == "[arch_flags]") - { - for (auto const &af : ref.arch_flags) - { + for (auto const &it : input) { + if (it == "[arch_flags]") { + for (auto const &af : ref.arch_flags) { result.push_back(af); } - } - else if (it == "[c_flags]") - { - for (auto const &cf : ref.c_flags) - { + } else if (it == "[c_flags]") { + for (auto const &cf : ref.c_flags) { result.push_back(cf); } - } - else - { + } else { result.push_back(it); } } } void ReplVariables(std::string &str, const std::string &from, - const std::string &to) -{ - if (from.empty()) - return; + const std::string &to) { + if (from.empty()) return; 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); - start_pos += to.length(); // In case 'to' contains 'from', like replacing - // 'x' with 'yx' + start_pos += to.length(); // In case 'to' contains 'from', like replacing + // 'x' with 'yx' } } -void AutoRepl(std::string &str) -{ +void AutoRepl(std::string &str) { std::string dkp_env = getenv("DEVKITPRO"); std::string cwd = std::filesystem::current_path().string(); ReplVariables(str, "{DEVKITPRO}", dkp_env); @@ -170,73 +149,57 @@ void AutoRepl(std::string &str) } void ReplVector(std::vector &vec, const std::string &from, - const std::string &to) -{ - for (size_t i = 0; i < vec.size(); i++) - ReplVariables(vec[i], from, to); + const std::string &to) { + for (size_t i = 0; i < vec.size(); i++) ReplVariables(vec[i], from, to); } -void AutoVecRepl(std::vector &strs) -{ - for (size_t i = 0; i < strs.size(); i++) - AutoRepl(strs[i]); +void AutoVecRepl(std::vector &strs) { + 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->c_flags, src.c_flags, src); VecGetExtra(prj->cxx_flags, src.cxx_flags, - prj[0]); // Use Prj as ref cause arch_flags already written + prj[0]); // Use Prj as ref cause arch_flags already written VecGetExtra(prj->as_flags, src.as_flags, src); VecGetExtra(prj->linker_flags, src.linker_flags, src); } std::string LinkerInput(std::vector o_files, - std::vector d_files) -{ + std::vector d_files) { std::string res = ""; /*if (o_files.size() != d_files.size()) { std::cerr << "The Number of .d and .o files is wrong"; return ""; }*/ for (size_t i = 0; i < o_files.size(); i++) - res += o_files[i].string() + " "; // + d_files[i].string() + " "; + res += o_files[i].string() + " "; // + d_files[i].string() + " "; return res; } -std::string Libs(std::vector libs) -{ +std::string Libs(std::vector libs) { std::string res = ""; - for (auto const &it : libs) - res += "-l" + it + " "; + for (auto const &it : libs) res += "-l" + it + " "; return res; } -std::string LibPaths(std::vector libs) -{ +std::string LibPaths(std::vector libs) { std::string res = ""; - for (auto const &it : libs) - res += "-L" + it + "lib/ "; + for (auto const &it : libs) res += "-L" + it + "lib/ "; return res; } -void DeleteFiles(std::string path, std::vector extensions) -{ - for (const auto &entry : std::filesystem::directory_iterator(path)) - { - if (std::filesystem::is_directory(entry)) - { +void DeleteFiles(std::string path, std::vector extensions) { + for (const auto &entry : std::filesystem::directory_iterator(path)) { + if (std::filesystem::is_directory(entry)) { DeleteFiles(fix_path(entry.path().string()), extensions); - } - else - { - for (const auto &ext : extensions) - { - if (entry.path().extension() == ext) - { + } else { + for (const auto &ext : extensions) { + if (entry.path().extension() == ext) { 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; break; } @@ -245,18 +208,14 @@ void DeleteFiles(std::string path, std::vector extensions) } } -void DeleteDirectory(std::string path) -{ - for (const auto &entry : std::filesystem::directory_iterator(path)) - { - if (std::filesystem::is_directory(entry)) - { +void DeleteDirectory(std::string path) { + for (const auto &entry : std::filesystem::directory_iterator(path)) { + if (std::filesystem::is_directory(entry)) { DeleteDirectory(fix_path(entry.path().string())); - } - else - { + } else { 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; } } @@ -266,8 +225,7 @@ void DeleteDirectory(std::string path) << 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 c_hashes = createHashes(prj.source_dirs, ".c"); 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"); nlohmann::json jscpp_hashes; - for (auto const &it : cpp_hashes) - jscpp_hashes[it.first] = it.second; + for (auto const &it : cpp_hashes) jscpp_hashes[it.first] = it.second; nlohmann::json jsc_hashes; - for (auto const &it : c_hashes) - jsc_hashes[it.first] = it.second; + for (auto const &it : c_hashes) jsc_hashes[it.first] = it.second; nlohmann::json jshpp_hashes; - for (auto const &it : hpp_hashes) - jshpp_hashes[it.first] = it.second; + for (auto const &it : hpp_hashes) jshpp_hashes[it.first] = it.second; nlohmann::json jsh_hashes; - for (auto const &it : h_hashes) - jsh_hashes[it.first] = it.second; + for (auto const &it : h_hashes) jsh_hashes[it.first] = it.second; nlohmann::json jsv_pica_hashes; - for (auto const &it : v_pica_hashes) - jsv_pica_hashes[it.first] = it.second; + for (auto const &it : v_pica_hashes) jsv_pica_hashes[it.first] = it.second; nlohmann::json jsshlist_hashes; - for (auto const &it : shlist_hashes) - jsshlist_hashes[it.first] = it.second; + for (auto const &it : shlist_hashes) jsshlist_hashes[it.first] = it.second; nlohmann::json jss_hashes; - for (auto const &it : s_hashes) - jss_hashes[it.first] = it.second; + for (auto const &it : s_hashes) jss_hashes[it.first] = it.second; nlohmann::json jst3s_hashes; - for (auto const &it : t3s_hashes) - jst3s_hashes[it.first] = it.second; + for (auto const &it : t3s_hashes) jst3s_hashes[it.first] = it.second; nlohmann::json hashes; hashes["cpp"] = jscpp_hashes; @@ -318,12 +268,10 @@ void GenerateHashes(NpiProject prj, std::string dir_) } std::map GetHashMap(std::string dir_, - std::string extension) -{ + std::string extension) { nlohmann::json js; std::ifstream is(dir_ + "/build/hashes.json"); - if (!is) - { + if (!is) { std::cerr << "[-]hashes.json not in " << dir_ + "/build/" << "!\n"; exit(-1); @@ -335,18 +283,92 @@ std::map GetHashMap(std::string dir_, std::replace(mod_ext.begin(), mod_ext.end(), '.', '_'); std::map res; - for (auto &[filename, hash] : js[mod_ext].items()) - { + for (auto &[filename, hash] : js[mod_ext].items()) { res[filename] = hash; } 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 std::string dkp_env = "C:/devkitPro/"; - std::cout << CCYELLOW << "[+] Warning: Windows Usage Detected!\n[+] Make sure you have devkitpro installed at !" << CCRESET << std::endl; + std::cout << CCYELLOW + << "[+] Warning: Windows Usage Detected!\n[+] Make sure you have " + "devkitpro installed at !" + << CCRESET << std::endl; #else std::string dkp_env = getenv("DEVKITPRO"); #endif @@ -385,8 +407,7 @@ void CompileProject(NpiProject &prj, std::string dir_) std::vector t3s_files_; if (!std::filesystem::exists( - std::filesystem::path(dir_ + "/build/hashes.json"))) - { + std::filesystem::path(dir_ + "/build/hashes.json"))) { GenerateHashes(prj, dir_); cpp_files_ = get_files_in_dir(prj.source_dirs, ".cpp"); 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"); s_files_ = get_files_in_dir(prj.source_dirs, ".s"); t3s_files_ = get_files_in_dir({std::string(dir_ + "/gfx")}, ".t3s"); - } - else - { + } else { cpp_files_ = getChangedFiles(GetHashMap(dir_, ".cpp")); c_files_ = getChangedFiles(GetHashMap(dir_, ".c")); 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")); t3s_files_ = getChangedFiles(GetHashMap(dir_, ".t3s")); 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"); c_files_ = get_files_in_dir(prj.source_dirs, ".c"); } } 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"); c_files_ = get_files_in_dir(prj.source_dirs, ".c"); } 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"); 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); 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(); - if (prga <= 0) - { + if (prga <= 0) { prgc = 1; prga = 1; std::cout << CCGREEN << "[+] Everything is Up to date..." << CCRESET @@ -442,113 +459,56 @@ void CompileProject(NpiProject &prj, std::string dir_) return; } - for (auto const &it : t3s_files_) - { - 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; - if (reqres != 0) - any_errors = true; + for (auto const &it : t3s_files_) { + prgc++; + updateProgressBar(((float)prgc / (float)wa), it.filename().string()); + Tex3ds_Compile(dir_, dkp_env, it, prj); } - for (auto const &it : v_pica_files_) - { - 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) - 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 : v_pica_files_) { + prgc++; + updateProgressBar(((float)prgc / (float)wa), it.filename().string()); + Picasso_Compile(dir_, dkp_env, it, prj); } - 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_ + - "/build/" + fix_path(it.stem().string()) + ".o " + Flags2Str(prj.cxx_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; + + } + else + {*/ + for (auto const &it : cpp_files_) { + prgc++; + updateProgressBar(((float)prgc / (float)wa), it.filename().string()); + C_CXX_Compile(true, dir_, it, prj); } - for (auto const &it : c_files_) - { - std::string command = - 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(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; + for (auto const &it : c_files_) { + prgc++; + updateProgressBar(((float)prgc / (float)wa), it.filename().string()); + C_CXX_Compile(false, dir_, it, prj); } + //} + // updateProgressBar(1.f); + std::cout << std::endl; std::vector o_files = get_files_in_dir({dir_ + "/build/"}, ".o"); std::vector d_files = get_files_in_dir({dir_ + "/build/"}, ".d"); - if (!any_errors) - { + if (!any_errors) { std::string command = prj.linker + " -o " + dir_ + "/" + prj.name + ".elf " + LinkerInput(o_files, d_files) + " " + Libs(prj.libraries) + " " + LibPaths(prj.lib_dirs) + " " + Flags2Str(prj.linker_flags); std::cout << CCBLUE << "[+] Linking..." << CCRESET << std::endl; int reqres = system(command.c_str()); - if (reqres != 0) - any_errors = true; - if (prj.ctr_type) - { - command = "bannertool makebanner -i \"app/banner.png\" -a " - "\"app/BannerAudio.wav\" -o \"build/banner.bin\""; + if (reqres != 0) any_errors = true; + if (prj.ctr_type) { + command = + "bannertool makebanner -i \"app/banner.png\" -a " + "\"app/BannerAudio.wav\" -o \"build/banner.bin\""; std::cout << CCBLUE << "[+] Creating Banner..." << CCRESET << std::endl; reqres = system(command.c_str()); std::cout << (reqres == 0 ? CCGREEN : CCRED) @@ -570,16 +530,15 @@ void CompileProject(NpiProject &prj, std::string dir_) std::cout << (reqres == 0 ? CCGREEN : CCRED) << (reqres == 0 ? "[+] " : "[-] ") << prj.name + ".3dsx " << std::endl; - if (prj.ctr_type) - { + if (prj.ctr_type) { command = "makerom -f cia -target t -exefslogo -o " + dir_ + "/" + prj.name + - ".cia -elf " + dir_ + "/" + prj.name + ".elf " + " -rsf " + dir_ + "/" + - prj.rsf_path + " -banner " + dir_ + "/build/banner.bin" + " -icon " + - dir_ + "/build/icon.bin" + " -logo " + dir_ + "/" + prj.logo_lz11_path + - " -DAPP_ROMFS=" + dir_ + "/" + prj.dir_romfs + " -major " + - std::to_string(prj.vmajor) + " -minor " + std::to_string(prj.vminor) + - " -micro " + std::to_string(prj.vbuild) + + ".cia -elf " + dir_ + "/" + prj.name + ".elf " + " -rsf " + dir_ + + "/" + prj.rsf_path + " -banner " + dir_ + "/build/banner.bin" + + " -icon " + dir_ + "/build/icon.bin" + " -logo " + dir_ + "/" + + prj.logo_lz11_path + " -DAPP_ROMFS=" + dir_ + "/" + prj.dir_romfs + + " -major " + std::to_string(prj.vmajor) + " -minor " + + std::to_string(prj.vminor) + " -micro " + std::to_string(prj.vbuild) + " -DAPP_VERSION_MAJOR=" + std::to_string(prj.vmajor); std::cout << CCBLUE << "[+] Creating Cia..." << CCRESET << std::endl; reqres = system(command.c_str()); @@ -589,8 +548,7 @@ void CompileProject(NpiProject &prj, std::string dir_) } } - if (any_errors) - { + if (any_errors) { std::cout << CCRED << "\nErrors Happened!\nTake a look at the Top of this Message...\n" @@ -602,224 +560,206 @@ void CompileProject(NpiProject &prj, std::string dir_) std::cout << CCRESET << std::endl; } -namespace helper -{ - std::string GenerateUniqueId() - { - std::random_device rd; - std::mt19937 gen(rd()); - std::uniform_int_distribution<> dis(0, 15); +namespace helper { +std::string GenerateUniqueId() { + std::random_device rd; + std::mt19937 gen(rd()); + std::uniform_int_distribution<> dis(0, 15); - std::stringstream ss; - ss << "0x"; - for (int i = 0; i < 5; ++i) - { - ss << std::hex << dis(gen); - } - - std::string hex_str = ss.str(); - return hex_str; + std::stringstream ss; + ss << "0x"; + for (int i = 0; i < 5; ++i) { + ss << std::hex << dis(gen); } - void ArrayToFile(unsigned char *array_, size_t size_, std::string filename) - { - std::ofstream file(filename, std::ios::binary); + std::string hex_str = ss.str(); + return hex_str; +} - if (!file.is_open()) - { - std::cerr << CCRED << "[-]: Could not open file" << CCRESET << std::endl; - return; - } +void ArrayToFile(unsigned char *array_, size_t size_, std::string filename) { + std::ofstream file(filename, std::ios::binary); - file.write(reinterpret_cast(array_), size_); - - file.close(); + if (!file.is_open()) { + std::cerr << CCRED << "[-]: Could not open file" << CCRESET << std::endl; + return; } - void GenerateTemplateFile(std::string path, NpiProject prj) - { - nlohmann::ordered_json js; - js["project_name"] = prj.name; - js["author"] = prj.author; - js["description"] = prj.description; - js["vmajor"] = prj.vmajor; - js["vminor"] = prj.vminor; - js["vbuild"] = prj.vbuild; - if (prj.ctr_type) - { - js["unique_id"] = prj.unique_id; - js["prod_code"] = prj.prod; - } - js["platform"] = prj.platform; - if (prj.platform == "3ds") - { - js["cia"] = prj.ctr_type; - } + file.write(reinterpret_cast(array_), size_); - nlohmann::json source_dirs; - Vec2Json(prj.source_dirs, source_dirs, prj); - js["source_dirs"] = source_dirs; + file.close(); +} - nlohmann::json include_dirs; - Vec2Json(prj.include_dirs, include_dirs, prj); - js["include_dirs"] = include_dirs; - - nlohmann::json libraries; - Vec2Json(prj.libraries, libraries, prj); - js["libraries"] = libraries; - - nlohmann::json lib_dirs; - Vec2Json(prj.lib_dirs, lib_dirs, prj); - js["lib_dirs"] = lib_dirs; - - js["icon_path"] = prj.icon_path; - if (prj.ctr_type) - { - js["banner_path"] = prj.banner_path; - js["banner_a_path"] = prj.banner_a_path; - js["rsf_path"] = prj.rsf_path; - js["logo_lz11_path"] = prj.logo_lz11_path; - } - - js["dir_gfx"] = prj.dir_gfx; - js["dir_gfxbuild"] = prj.dir_gfxbuild; - js["dir_romfs"] = prj.dir_romfs; - - nlohmann::json arch_flags; - Vec2Json(prj.arch_flags, arch_flags, prj); - js["arch_flags"] = arch_flags; - - nlohmann::json c_flags; - Vec2Json(prj.c_flags, c_flags, prj); - js["c_flags"] = c_flags; - - nlohmann::json cxx_flags; - Vec2Json(prj.cxx_flags, cxx_flags, prj); - js["cxx_flags"] = cxx_flags; - - nlohmann::json as_flags; - Vec2Json(prj.as_flags, as_flags, prj); - js["as_flags"] = as_flags; - - nlohmann::json linker_flags; - Vec2Json(prj.linker_flags, linker_flags, prj); - js["linker_flags"] = linker_flags; - - js["cxx_compiler"] = prj.cxx_compiler; - js["c_compiler"] = prj.c_compiler; - js["asm_compiler"] = prj.asm_compiler; - js["linker"] = prj.linker; - - std::ofstream fout(path); - fout << js.dump(4); - fout.close(); +void GenerateTemplateFile(std::string path, NpiProject prj) { + nlohmann::ordered_json js; + js["project_name"] = prj.name; + js["author"] = prj.author; + js["description"] = prj.description; + js["vmajor"] = prj.vmajor; + js["vminor"] = prj.vminor; + js["vbuild"] = prj.vbuild; + if (prj.ctr_type) { + js["unique_id"] = prj.unique_id; + js["prod_code"] = prj.prod; + } + js["platform"] = prj.platform; + if (prj.platform == "3ds") { + js["cia"] = prj.ctr_type; } - void CompileProject(std::string path) - { - std::string dkp_env = getenv("DEVKITPRO"); - if (dkp_env.c_str() == NULL) - { - std::cerr << CCRED << "[-] Please set DEVKITPRO ENV Variable!\n" - << CCRESET; - return; - } - nlohmann::json js; - std::ifstream is(path + "/build.json"); - if (!is) - { - std::cerr << CCRED << "[-] build.json not in " << path << "!\n" - << CCRESET; - return; - } - is >> js; + nlohmann::json source_dirs; + Vec2Json(prj.source_dirs, source_dirs, prj); + js["source_dirs"] = source_dirs; - is.close(); + nlohmann::json include_dirs; + Vec2Json(prj.include_dirs, include_dirs, prj); + js["include_dirs"] = include_dirs; - std::cout << CCBLUE << "[+] Compiling at " << path << " ...\n" - << CCRESET; + nlohmann::json libraries; + Vec2Json(prj.libraries, libraries, prj); + js["libraries"] = libraries; - NpiProject prj; - auto __name = js_catch(js, "project_name"); - auto __author = js_catch(js, "author"); - auto __vmajor = js_catch(js, "vmajor"); - auto __vminor = js_catch(js, "vminor"); - auto __vbuild = js_catch(js, "vbuild"); - auto __platform = js_catch(js, "platform"); - auto __ctr_type = js_catch(js, "cia"); - auto __description = js_catch(js, "description"); + nlohmann::json lib_dirs; + Vec2Json(prj.lib_dirs, lib_dirs, prj); + js["lib_dirs"] = lib_dirs; - std::pair __unique_id; - std::pair __prod; - if (__ctr_type.first) - { - __unique_id = js_catch(js, "unique_id"); - __prod = js_catch(js, "prod_code"); - } - - std::pair __banner_path; - std::pair __banner_a_path; - std::pair __rsf_path; - std::pair __logo_lz11_path; - - auto __icon_path = js_catch(js, "icon_path"); - if (__ctr_type.first) - { - __banner_path = js_catch(js, "banner_path"); - __banner_a_path = js_catch(js, "banner_a_path"); - __rsf_path = js_catch(js, "rsf_path"); - __logo_lz11_path = js_catch(js, "logo_lz11_path"); - } - auto __dir_gfx = js_catch(js, "dir_gfx"); - auto __dir_gfxbuild = js_catch(js, "dir_gfxbuild"); - auto __dir_romfs = js_catch(js, "dir_romfs"); - - auto __cxx_compiler = js_catch(js, "cxx_compiler"); - auto __c_compiler = js_catch(js, "c_compiler"); - auto __asm_compiler = js_catch(js, "asm_compiler"); - auto __linker = js_catch(js, "linker"); - - prj.name = __name.first; - prj.author = __author.first; - prj.vmajor = __vmajor.first; - prj.vminor = __vminor.first; - prj.vbuild = __vbuild.first; - prj.description = __description.first; - prj.unique_id = __unique_id.first; - prj.prod = __prod.first; - prj.platform = __platform.first; - prj.ctr_type = __ctr_type.first; - - prj.icon_path = __icon_path.first; - prj.banner_path = __banner_path.first; - prj.banner_a_path = __banner_a_path.first; - prj.rsf_path = __rsf_path.first; - prj.logo_lz11_path = __logo_lz11_path.first; - prj.dir_gfx = __dir_gfx.first; - prj.dir_gfxbuild = __dir_gfxbuild.first; - prj.dir_romfs = __dir_romfs.first; - - Js2Vec(prj.arch_flags, js["arch_flags"]); - Js2Vec(prj.linker_flags, js["linker_flags"]); - Js2Vec(prj.c_flags, js["c_flags"]); - Js2Vec(prj.cxx_flags, js["cxx_flags"]); - Js2Vec(prj.as_flags, js["as_flags"]); - Js2Vec(prj.source_dirs, js["source_dirs"]); - Js2Vec(prj.include_dirs, js["include_dirs"]); - Js2Vec(prj.lib_dirs, js["lib_dirs"]); - Js2Vec(prj.libraries, js["libraries"]); - prj.cxx_compiler = __cxx_compiler.first; - prj.c_compiler = __c_compiler.first; - prj.asm_compiler = __asm_compiler.first; - prj.linker = __linker.first; - NpiProject _2build = prj; - ProcessPrj2Cmp(&_2build, prj); - CompileProject(_2build, path); + js["icon_path"] = prj.icon_path; + if (prj.ctr_type) { + js["banner_path"] = prj.banner_path; + js["banner_a_path"] = prj.banner_a_path; + js["rsf_path"] = prj.rsf_path; + js["logo_lz11_path"] = prj.logo_lz11_path; } - void CleanProject(std::string path) - { - DeleteFiles(path, {".3dsx", ".cia", ".elf"}); - DeleteFiles(path + "/" + "romfs", {".t3x"}); - DeleteDirectory(path + "/build"); + + js["dir_gfx"] = prj.dir_gfx; + js["dir_gfxbuild"] = prj.dir_gfxbuild; + js["dir_romfs"] = prj.dir_romfs; + + nlohmann::json arch_flags; + Vec2Json(prj.arch_flags, arch_flags, prj); + js["arch_flags"] = arch_flags; + + nlohmann::json c_flags; + Vec2Json(prj.c_flags, c_flags, prj); + js["c_flags"] = c_flags; + + nlohmann::json cxx_flags; + Vec2Json(prj.cxx_flags, cxx_flags, prj); + js["cxx_flags"] = cxx_flags; + + nlohmann::json as_flags; + Vec2Json(prj.as_flags, as_flags, prj); + js["as_flags"] = as_flags; + + nlohmann::json linker_flags; + Vec2Json(prj.linker_flags, linker_flags, prj); + js["linker_flags"] = linker_flags; + + js["cxx_compiler"] = prj.cxx_compiler; + js["c_compiler"] = prj.c_compiler; + js["asm_compiler"] = prj.asm_compiler; + js["linker"] = prj.linker; + + std::ofstream fout(path); + fout << js.dump(4); + fout.close(); +} + +void CompileProject(std::string path, bool async) { + std::string dkp_env = getenv("DEVKITPRO"); + if (dkp_env.c_str() == NULL) { + std::cerr << CCRED << "[-] Please set DEVKITPRO ENV Variable!\n" << CCRESET; + return; } -} // namespace helper \ No newline at end of file + nlohmann::json js; + std::ifstream is(path + "/build.json"); + if (!is) { + std::cerr << CCRED << "[-] build.json not in " << path << "!\n" << CCRESET; + return; + } + is >> js; + + is.close(); + + std::cout << CCBLUE << "[+] Compiling at " << path << " ...\n" << CCRESET; + + NpiProject prj; + auto __name = js_catch(js, "project_name"); + auto __author = js_catch(js, "author"); + auto __vmajor = js_catch(js, "vmajor"); + auto __vminor = js_catch(js, "vminor"); + auto __vbuild = js_catch(js, "vbuild"); + auto __platform = js_catch(js, "platform"); + auto __ctr_type = js_catch(js, "cia"); + auto __description = js_catch(js, "description"); + + std::pair __unique_id; + std::pair __prod; + if (__ctr_type.first) { + __unique_id = js_catch(js, "unique_id"); + __prod = js_catch(js, "prod_code"); + } + + std::pair __banner_path; + std::pair __banner_a_path; + std::pair __rsf_path; + std::pair __logo_lz11_path; + + auto __icon_path = js_catch(js, "icon_path"); + if (__ctr_type.first) { + __banner_path = js_catch(js, "banner_path"); + __banner_a_path = js_catch(js, "banner_a_path"); + __rsf_path = js_catch(js, "rsf_path"); + __logo_lz11_path = js_catch(js, "logo_lz11_path"); + } + auto __dir_gfx = js_catch(js, "dir_gfx"); + auto __dir_gfxbuild = js_catch(js, "dir_gfxbuild"); + auto __dir_romfs = js_catch(js, "dir_romfs"); + + auto __cxx_compiler = js_catch(js, "cxx_compiler"); + auto __c_compiler = js_catch(js, "c_compiler"); + auto __asm_compiler = js_catch(js, "asm_compiler"); + auto __linker = js_catch(js, "linker"); + + prj.name = __name.first; + prj.author = __author.first; + prj.vmajor = __vmajor.first; + prj.vminor = __vminor.first; + prj.vbuild = __vbuild.first; + prj.description = __description.first; + prj.unique_id = __unique_id.first; + prj.prod = __prod.first; + prj.platform = __platform.first; + prj.ctr_type = __ctr_type.first; + + prj.icon_path = __icon_path.first; + prj.banner_path = __banner_path.first; + prj.banner_a_path = __banner_a_path.first; + prj.rsf_path = __rsf_path.first; + prj.logo_lz11_path = __logo_lz11_path.first; + prj.dir_gfx = __dir_gfx.first; + prj.dir_gfxbuild = __dir_gfxbuild.first; + prj.dir_romfs = __dir_romfs.first; + + Js2Vec(prj.arch_flags, js["arch_flags"]); + Js2Vec(prj.linker_flags, js["linker_flags"]); + Js2Vec(prj.c_flags, js["c_flags"]); + Js2Vec(prj.cxx_flags, js["cxx_flags"]); + Js2Vec(prj.as_flags, js["as_flags"]); + Js2Vec(prj.source_dirs, js["source_dirs"]); + Js2Vec(prj.include_dirs, js["include_dirs"]); + Js2Vec(prj.lib_dirs, js["lib_dirs"]); + Js2Vec(prj.libraries, js["libraries"]); + prj.cxx_compiler = __cxx_compiler.first; + prj.c_compiler = __c_compiler.first; + prj.asm_compiler = __asm_compiler.first; + prj.linker = __linker.first; + NpiProject _2build = prj; + ProcessPrj2Cmp(&_2build, prj); + CompileProject(_2build, path, async); +} +void CleanProject(std::string path) { + DeleteFiles(path, {".3dsx", ".cia", ".elf"}); + DeleteFiles(path + "/" + "romfs", {".t3x"}); + DeleteDirectory(path + "/build"); +} +} // namespace helper \ No newline at end of file diff --git a/source/main.cpp b/source/main.cpp index 871ee4c..dc560ac 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -1,35 +1,29 @@ #include -#include -#include -#include -#include - #include #include +#include +#include +#include #include #include +#include #include #include -#include +#include // Console CLear String #define cons_clear std::cout << "\x1B[2J\x1B[H" // Make String Uppercase -void ToUpperCase(std::string &str) -{ +void ToUpperCase(std::string &str) { std::transform(str.begin(), str.end(), str.begin(), - [](unsigned char c) - { return std::toupper(c); }); + [](unsigned char c) { return std::toupper(c); }); } // Check if String is Valid Hex String -bool isValidHex(const std::string &str) -{ - for (char c : str) - { - if (!isxdigit(c)) - { +bool isValidHex(const std::string &str) { + for (char c : str) { + if (!isxdigit(c)) { return false; } } @@ -37,44 +31,34 @@ bool isValidHex(const std::string &str) } // Check for tools -void CheckTools() -{ +void CheckTools() { std::vector installed; std::vector not_installed; int res = 0; res = system("makerom"); - if (!res) - { + if (!res) { not_installed.push_back("makerom"); - } - else - { + } else { installed.push_back("makerom"); } res = system("bannertool"); - if (!res) - { + if (!res) { not_installed.push_back("bannertool"); - } - else - { + } else { installed.push_back("bannertool"); } std::cout << " is set to: " << getenv("DEVKITPRO") << "\n"; std::cout << "Tools-Check:\n"; - for (auto const &it : installed) - { + for (auto const &it : installed) { 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"; } } // Print Usage/Help -void PrintHelp() -{ +void PrintHelp() { std::cout << "npi-build v0.1\n"; std::cout << "Commands:\n"; std::cout << "help: Display this\n"; @@ -89,13 +73,10 @@ void PrintHelp() } // 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 - std::filesystem::create_directories( - 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 + "/app")); + std::filesystem::create_directories(std::filesystem::path(dst_dir + "/gfx")); std::filesystem::create_directories( std::filesystem::path(dst_dir + "/romfs/gfx")); 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"); sample_hdr << sample_header; sample_hdr.close(); - if (type_ == 1) - { + if (type_ == 1) { helper::ArrayToFile(banner_audio, banner_audio_size, dst_dir + "/app/banner_audio.wav"); - helper::ArrayToFile(logo_lz11, logo_lz11_size, - dst_dir + "/app/logo.lz11"); + helper::ArrayToFile(logo_lz11, logo_lz11_size, dst_dir + "/app/logo.lz11"); helper::ArrayToFile(banner, banner_size, dst_dir + "/app/banner.png"); } // Create icon.png @@ -125,25 +104,18 @@ void GenerateProjectDir(const std::string &dst_dir, int type_) } // Process Input Args -void ProcessArgs(int argc, char *argv[]) -{ - if (argc < 2) - { +void ProcessArgs(int argc, char *argv[]) { + if (argc < 2) { // No Args PrintHelp(); return; - } - else if (std::string(argv[1]) == "help") - { + } else if (std::string(argv[1]) == "help") { // Requested Help PrintHelp(); return; - } - else if (std::string(argv[1]) == "generate") - { + } else if (std::string(argv[1]) == "generate") { // Generator - if (argc != 4) - { + if (argc != 4) { // Missing Args / ot too much std::cout << "Wrong Number of Arguments!\n"; return; @@ -154,8 +126,7 @@ void ProcessArgs(int argc, char *argv[]) int type_ = -1; // TODO: // change this if statement - if (type == "3dsx" | type == "cia3dsx") - { + if (type == "3dsx" | type == "cia3dsx") { res = 0; if (type == "3dsx") type_ = 0; @@ -163,8 +134,7 @@ void ProcessArgs(int argc, char *argv[]) type_ = 1; } // Print Error if re is not 0 - if (res) - { + if (res) { std::cout << "Unknown type!\n"; return; } @@ -175,8 +145,7 @@ void ProcessArgs(int argc, char *argv[]) // Generate Project GenerateProjectDir(dst_dir, type_); // Create rsf if cia mode - if (type_ == 1) - { + if (type_ == 1) { char *ret = new char[10000]; std::string uid = helper::GenerateUniqueId(); sprintf(ret, ciaRSF, default_title, default_code, default_romfs_path, @@ -190,9 +159,7 @@ void ProcessArgs(int argc, char *argv[]) NpiProject npr; Prj_InitDefault(npr, (type_ == 1)); 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 // define vars std::string prj_name; @@ -208,8 +175,7 @@ void ProcessArgs(int argc, char *argv[]) // Request Prod Code std::cout << "\ntype Product Code 4 chars [NPI7] >"; std::cin >> prodcode; - if (prodcode.length() != 4) - { + if (prodcode.length() != 4) { // Handle Wrong lengh Error std::cout << "\nWrong Length!\n"; return; @@ -223,26 +189,22 @@ void ProcessArgs(int argc, char *argv[]) std::cin >> unique_id; // Check if random keyword was used bool rnd = false; - if (unique_id == "random") - { + if (unique_id == "random") { // Generate random one unique_id = helper::GenerateUniqueId(); rnd = true; } - if (unique_id.length() != 5 && !rnd) - { + if (unique_id.length() != 5 && !rnd) { // Handle wrong lengh std::cout << "\nWrong Length!\n"; return; } - if (!isValidHex(unique_id) && !rnd) - { + if (!isValidHex(unique_id) && !rnd) { // Handle not hex digits std::cout << "\nId is not valid\n"; return; } - if (!rnd) - { + if (!rnd) { // Add 0x if not random unique_id.insert(0, "0x"); } @@ -250,8 +212,7 @@ void ProcessArgs(int argc, char *argv[]) // Request Project type std::cout << "\nProject type: type 0 for 3dsx\nonly or 1 for cia and 3dsx>"; std::cin >> type_; - if (!(type_ == 0 | type_ == 1)) - { + if (!(type_ == 0 | type_ == 1)) { std::cout << "\nunknown type!\n"; return; } @@ -264,8 +225,7 @@ void ProcessArgs(int argc, char *argv[]) GenerateProjectDir(dst_dir, type_); // Generate RSF if cia mode - if (type_ == 1) - { + if (type_ == 1) { char *ret = new char[10000]; sprintf(ret, ciaRSF, prj_name.c_str(), prodcode.c_str(), default_romfs_path, unique_id.c_str()); @@ -278,18 +238,23 @@ void ProcessArgs(int argc, char *argv[]) NpiProject npr; Prj_InitDefault(npr, (type_ == 1)); npr.name = prj_name; - if (npr.ctr_type) - { + if (npr.ctr_type) { npr.prod = prodcode; npr.unique_id = unique_id; } 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 - helper::CompileProject(fix_path(std::filesystem::current_path().string())); + helper::CompileProject(fix_path(std::filesystem::current_path().string()), + as); } // Check for makerom and bannertool @@ -301,8 +266,7 @@ void ProcessArgs(int argc, char *argv[]) } // Main Entrypoint -int main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) { // Process Input ProcessArgs(argc, argv); diff --git a/source/samplefiles.cpp b/source/samplefiles.cpp index 97c8bc3..5e8e261 100644 --- a/source/samplefiles.cpp +++ b/source/samplefiles.cpp @@ -4,12 +4,12 @@ const char *default_title = "Sample"; const char *default_code = "NPI7"; const char *default_unique_id = "0xff3ff"; const char *default_romfs_path = "romfs"; -const char *sample_header = -"// Sample Header File\n" -"#pragma once\n" -"#include <3ds.h>\n" -"#include "; -const char *sample_code = +const char *sample_header = + "// Sample Header File\n" + "#pragma once\n" + "#include <3ds.h>\n" + "#include "; +const char *sample_code = "// Sample Source Code for Hello World\n\n" "#include \n\n" "int main() {\n"