Move to Google format
This commit is contained in:
parent
a1e6b963d4
commit
b8e861d9b4
@ -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
|
||||
|
@ -8,26 +8,21 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
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<std::string, std::string>
|
||||
createHashes(const std::vector<std::string> &dirs,
|
||||
const std::string &extension)
|
||||
{
|
||||
inline std::map<std::string, std::string> createHashes(
|
||||
const std::vector<std::string> &dirs, const std::string &extension) {
|
||||
std::map<std::string, std::string> 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<std::string> &dirs,
|
||||
return hashes;
|
||||
}
|
||||
|
||||
inline std::vector<std::filesystem::path>
|
||||
getChangedFiles(const std::map<std::string, std::string> &oldHashes)
|
||||
{
|
||||
inline std::vector<std::filesystem::path> getChangedFiles(
|
||||
const std::map<std::string, std::string> &oldHashes) {
|
||||
std::vector<std::filesystem::path> 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));
|
||||
}
|
||||
}
|
||||
|
@ -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
|
@ -3,8 +3,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct NpiProject
|
||||
{
|
||||
struct NpiProject {
|
||||
std::string name;
|
||||
std::string author;
|
||||
std::string description;
|
||||
@ -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";
|
||||
}
|
||||
|
@ -1,10 +1,14 @@
|
||||
#include <math.h>
|
||||
|
||||
#include <condition_variable>
|
||||
#include <fileHash.hpp>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <future>
|
||||
#include <helper.hpp>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <math.h>
|
||||
#include <json.hpp>
|
||||
#include <mutex>
|
||||
#include <random>
|
||||
#include <sstream>
|
||||
@ -12,11 +16,6 @@
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
#include <json.hpp>
|
||||
|
||||
#include <fileHash.hpp>
|
||||
#include <helper.hpp>
|
||||
|
||||
#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<int>(progress * 100.0) << " %] "
|
||||
<< CCRESET;
|
||||
void updateProgressBar(float progress, std::string f) {
|
||||
const int w = 50;
|
||||
int pos = static_cast<int>(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<int>(progress * 100.0)
|
||||
<< "% " << CCRESET << '\r';
|
||||
std::cout.flush();
|
||||
}
|
||||
|
||||
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;
|
||||
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<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::vector<std::filesystem::path>
|
||||
get_files_in_dir(const std::vector<std::string> &dir_paths,
|
||||
const std::string &extension)
|
||||
{
|
||||
std::vector<std::filesystem::path> get_files_in_dir(
|
||||
const std::vector<std::string> &dir_paths, const std::string &extension) {
|
||||
std::vector<std::filesystem::path> 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<std::string> &dir_paths,
|
||||
return files;
|
||||
}
|
||||
|
||||
void Js2Vec(std::vector<std::string> &vec, nlohmann::json js)
|
||||
{
|
||||
void Js2Vec(std::vector<std::string> &vec, nlohmann::json js) {
|
||||
vec.clear();
|
||||
for (auto const &it : js)
|
||||
{
|
||||
for (auto const &it : js) {
|
||||
vec.push_back(it.get<std::string>());
|
||||
}
|
||||
}
|
||||
|
||||
void Vec2Json(std::vector<std::string> 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<std::string> flags)
|
||||
{
|
||||
std::string Flags2Str(std::vector<std::string> 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<std::string> dirs)
|
||||
{
|
||||
std::string IncludeDirs(std::vector<std::string> 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<std::string> dirs)
|
||||
{
|
||||
std::string LibIncludes(std::vector<std::string> 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<std::string> &result,
|
||||
std::vector<std::string> input, NpiProject ref)
|
||||
{
|
||||
std::vector<std::string> 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'
|
||||
}
|
||||
}
|
||||
|
||||
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,20 +149,15 @@ void AutoRepl(std::string &str)
|
||||
}
|
||||
|
||||
void ReplVector(std::vector<std::string> &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<std::string> &strs)
|
||||
{
|
||||
for (size_t i = 0; i < strs.size(); i++)
|
||||
AutoRepl(strs[i]);
|
||||
void AutoVecRepl(std::vector<std::string> &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,
|
||||
@ -193,8 +167,7 @@ void ProcessPrj2Cmp(NpiProject *prj, NpiProject src)
|
||||
}
|
||||
|
||||
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 = "";
|
||||
/*if (o_files.size() != d_files.size()) {
|
||||
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;
|
||||
}
|
||||
|
||||
std::string Libs(std::vector<std::string> libs)
|
||||
{
|
||||
std::string Libs(std::vector<std::string> 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<std::string> libs)
|
||||
{
|
||||
std::string LibPaths(std::vector<std::string> 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<std::string> extensions)
|
||||
{
|
||||
for (const auto &entry : std::filesystem::directory_iterator(path))
|
||||
{
|
||||
if (std::filesystem::is_directory(entry))
|
||||
{
|
||||
void DeleteFiles(std::string path, std::vector<std::string> 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<std::string> 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<std::string, std::string> 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<std::string, std::string> GetHashMap(std::string dir_,
|
||||
std::replace(mod_ext.begin(), mod_ext.end(), '.', '_');
|
||||
|
||||
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;
|
||||
}
|
||||
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 <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
|
||||
std::string dkp_env = getenv("DEVKITPRO");
|
||||
#endif
|
||||
@ -385,8 +407,7 @@ void CompileProject(NpiProject &prj, std::string dir_)
|
||||
std::vector<std::filesystem::path> 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,112 +459,55 @@ 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<std::filesystem::path> o_files =
|
||||
get_files_in_dir({dir_ + "/build/"}, ".o");
|
||||
std::vector<std::filesystem::path> 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 "
|
||||
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());
|
||||
@ -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,31 +560,26 @@ void CompileProject(NpiProject &prj, std::string dir_)
|
||||
std::cout << CCRESET << std::endl;
|
||||
}
|
||||
|
||||
namespace helper
|
||||
{
|
||||
std::string GenerateUniqueId()
|
||||
{
|
||||
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)
|
||||
{
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
ss << std::hex << dis(gen);
|
||||
}
|
||||
|
||||
std::string hex_str = ss.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);
|
||||
|
||||
if (!file.is_open())
|
||||
{
|
||||
if (!file.is_open()) {
|
||||
std::cerr << CCRED << "[-]: Could not open file" << CCRESET << std::endl;
|
||||
return;
|
||||
}
|
||||
@ -634,10 +587,9 @@ namespace helper
|
||||
file.write(reinterpret_cast<char *>(array_), size_);
|
||||
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
|
||||
void GenerateTemplateFile(std::string path, NpiProject prj)
|
||||
{
|
||||
void GenerateTemplateFile(std::string path, NpiProject prj) {
|
||||
nlohmann::ordered_json js;
|
||||
js["project_name"] = prj.name;
|
||||
js["author"] = prj.author;
|
||||
@ -645,14 +597,12 @@ namespace helper
|
||||
js["vmajor"] = prj.vmajor;
|
||||
js["vminor"] = prj.vminor;
|
||||
js["vbuild"] = prj.vbuild;
|
||||
if (prj.ctr_type)
|
||||
{
|
||||
if (prj.ctr_type) {
|
||||
js["unique_id"] = prj.unique_id;
|
||||
js["prod_code"] = prj.prod;
|
||||
}
|
||||
js["platform"] = prj.platform;
|
||||
if (prj.platform == "3ds")
|
||||
{
|
||||
if (prj.platform == "3ds") {
|
||||
js["cia"] = prj.ctr_type;
|
||||
}
|
||||
|
||||
@ -673,8 +623,7 @@ namespace helper
|
||||
js["lib_dirs"] = lib_dirs;
|
||||
|
||||
js["icon_path"] = prj.icon_path;
|
||||
if (prj.ctr_type)
|
||||
{
|
||||
if (prj.ctr_type) {
|
||||
js["banner_path"] = prj.banner_path;
|
||||
js["banner_a_path"] = prj.banner_a_path;
|
||||
js["rsf_path"] = prj.rsf_path;
|
||||
@ -713,31 +662,25 @@ namespace helper
|
||||
std::ofstream fout(path);
|
||||
fout << js.dump(4);
|
||||
fout.close();
|
||||
}
|
||||
}
|
||||
|
||||
void CompileProject(std::string path)
|
||||
{
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
std::cout << CCBLUE << "[+] Compiling at " << path << " ...\n" << CCRESET;
|
||||
|
||||
NpiProject prj;
|
||||
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> __prod;
|
||||
if (__ctr_type.first)
|
||||
{
|
||||
if (__ctr_type.first) {
|
||||
__unique_id = js_catch<std::string>(js, "unique_id");
|
||||
__prod = js_catch<std::string>(js, "prod_code");
|
||||
}
|
||||
@ -763,8 +705,7 @@ namespace helper
|
||||
std::pair<std::string, bool> __logo_lz11_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_a_path = js_catch<std::string>(js, "banner_a_path");
|
||||
__rsf_path = js_catch<std::string>(js, "rsf_path");
|
||||
@ -814,12 +755,11 @@ namespace helper
|
||||
prj.linker = __linker.first;
|
||||
NpiProject _2build = prj;
|
||||
ProcessPrj2Cmp(&_2build, prj);
|
||||
CompileProject(_2build, path);
|
||||
}
|
||||
void CleanProject(std::string path)
|
||||
{
|
||||
CompileProject(_2build, path, async);
|
||||
}
|
||||
void CleanProject(std::string path) {
|
||||
DeleteFiles(path, {".3dsx", ".cia", ".elf"});
|
||||
DeleteFiles(path + "/" + "romfs", {".t3x"});
|
||||
DeleteDirectory(path + "/build");
|
||||
}
|
||||
}
|
||||
} // namespace helper
|
136
source/main.cpp
136
source/main.cpp
@ -1,35 +1,29 @@
|
||||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include <banner.hpp>
|
||||
#include <banner_audio.hpp>
|
||||
#include <fileHash.hpp>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <helper.hpp>
|
||||
#include <icon.hpp>
|
||||
#include <iostream>
|
||||
#include <logo_lz11.hpp>
|
||||
#include <samplefiles.hpp>
|
||||
#include <fileHash.hpp>
|
||||
#include <vector>
|
||||
|
||||
// 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<std::string> installed;
|
||||
std::vector<std::string> 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 << "<DEVKITPRO> 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);
|
||||
|
||||
|
@ -5,10 +5,10 @@ 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 <stdio.h>";
|
||||
"// Sample Header File\n"
|
||||
"#pragma once\n"
|
||||
"#include <3ds.h>\n"
|
||||
"#include <stdio.h>";
|
||||
const char *sample_code =
|
||||
"// Sample Source Code for Hello World\n\n"
|
||||
"#include <common.hpp>\n\n"
|
||||
|
Loading…
Reference in New Issue
Block a user