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

File diff suppressed because it is too large Load Diff

View File

@ -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);

View File

@ -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 <stdio.h>";
const char *sample_code =
const char *sample_header =
"// 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"
"int main() {\n"