Move to Google format

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

View File

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

View File

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

View File

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

View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

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