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
|
||||
} // namespace helper
|
@ -3,8 +3,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct NpiProject
|
||||
{
|
||||
struct NpiProject {
|
||||
std::string name;
|
||||
std::string author;
|
||||
std::string description;
|
||||
@ -17,19 +16,19 @@ struct NpiProject
|
||||
std::vector<std::string> 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<std::string> arch_flags;
|
||||
std::vector<std::string> 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";
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
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