From 1e3674ecfa7be8df48809c25b09f0f3d7bf12aab Mon Sep 17 00:00:00 2001 From: tobid7 Date: Sat, 9 Mar 2024 12:46:20 +0100 Subject: [PATCH] Commit All Changes and Start cleanup --- .vscode/c_cpp_properties.json | 15 ++++++ .vscode/settings.json | 7 +++ include/samplefiles.hpp | 2 + source/helper.cpp | 87 ++++++++++++++++++++--------------- source/main.cpp | 19 ++++++++ source/samplefiles.cpp | 20 ++++++++ 6 files changed, 113 insertions(+), 37 deletions(-) create mode 100644 .vscode/c_cpp_properties.json create mode 100644 .vscode/settings.json diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..a03f396 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,15 @@ +{ + "configurations": [ + { + "name": "Linux", + "includePath": [ + "${workspaceFolder}/**" + ], + "defines": [], + "cStandard": "c17", + "cppStandard": "c++20", + "intelliSenseMode": "linux-clang-x64" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..ecc013c --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "files.associations": { + "utility": "cpp", + "ostream": "cpp", + "xstring": "cpp" + } +} \ No newline at end of file diff --git a/include/samplefiles.hpp b/include/samplefiles.hpp index b25cc5f..f02b9ed 100644 --- a/include/samplefiles.hpp +++ b/include/samplefiles.hpp @@ -4,4 +4,6 @@ extern const char *default_title; extern const char *default_code; extern const char *default_unique_id; extern const char *default_romfs_path; +extern const char *sample_header; +extern const char *sample_code; extern const char *ciaRSF; \ No newline at end of file diff --git a/source/helper.cpp b/source/helper.cpp index f6cad83..af5b797 100644 --- a/source/helper.cpp +++ b/source/helper.cpp @@ -33,24 +33,13 @@ void updateProgressBar(float progress) << CCRESET; } -std::string catch_str(nlohmann::json js, std::string at) +template +std::pair js_catch(const nlohmann::json &js, const std::string &at) { + bool exists = true; if (!js.contains(at) || js[at].is_null()) - { - throw std::invalid_argument("required_key is null or missing: " + at); - } - - return js[at].get(); -} - -int catch_int(nlohmann::json js, std::string at) -{ - if (!js.contains(at) || js[at].is_null()) - { - throw std::invalid_argument("required_key is null or missing: " + at); - } - - return js[at].get(); + exists = false; + return std::make_pair(js[at].get(), exists); } std::vector @@ -684,24 +673,48 @@ namespace helper << CCRESET; NpiProject prj; - prj.name = catch_str(js, "project_name"); - prj.author = catch_str(js, "author"); - prj.vmajor = catch_int(js, "vmajor"); - prj.vminor = catch_int(js, "vminor"); - prj.vbuild = catch_int(js, "vbuild"); - prj.description = catch_str(js, "description"); - prj.unique_id = catch_str(js, "unique_id"); - prj.prod = catch_str(js, "prod_code"); - prj.platform = catch_str(js, "platform"); + 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 __description = js_catch(js, "description"); + auto __unique_id = js_catch(js, "unique_id"); + auto __prod = js_catch(js, "prod_code"); + auto __platform = js_catch(js, "platform"); - prj.icon_path = catch_str(js, "icon_path"); - prj.banner_path = catch_str(js, "banner_path"); - prj.banner_a_path = catch_str(js, "banner_a_path"); - prj.rsf_path = catch_str(js, "rsf_path"); - prj.logo_lz11_path = catch_str(js, "logo_lz11_path"); - prj.dir_gfx = catch_str(js, "dir_gfx"); - prj.dir_gfxbuild = catch_str(js, "dir_gfxbuild"); - prj.dir_romfs = catch_str(js, "dir_romfs"); + auto __icon_path = js_catch(js, "icon_path"); + auto __banner_path = js_catch(js, "banner_path"); + auto __banner_a_path = js_catch(js, "banner_a_path"); + auto __rsf_path = js_catch(js, "rsf_path"); + auto __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.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"]); @@ -712,10 +725,10 @@ namespace helper Js2Vec(prj.include_dirs, js["include_dirs"]); Js2Vec(prj.lib_dirs, js["lib_dirs"]); Js2Vec(prj.libraries, js["libraries"]); - prj.cxx_compiler = catch_str(js, "cxx_compiler"); - prj.c_compiler = catch_str(js, "c_compiler"); - prj.asm_compiler = catch_str(js, "asm_compiler"); - prj.linker = catch_str(js, "linker"); + 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); diff --git a/source/main.cpp b/source/main.cpp index 34c9a72..319b15e 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -102,6 +102,8 @@ void ProcessArgs(int argc, char *argv[]) { std::filesystem::path(dst_dir + "/app")); std::filesystem::create_directories( std::filesystem::path(dst_dir + "/gfx")); + std::filesystem::create_directories(dst_dir + "/source"); + std::filesystem::create_directories(dst_dir + "/include"); std::ofstream gfx_keep(dst_dir + "/gfx/.gitkeep"); gfx_keep.close(); std::filesystem::create_directories( @@ -117,6 +119,12 @@ void ProcessArgs(int argc, char *argv[]) { test << ret; test.close(); delete[] ret; + std::ofstream sample_source(dst_dir + "/source/main.cpp"); + sample_source << sample_code; + sample_source.close(); + std::ofstream sample_hdr(dst_dir + "/include/common.hpp"); + sample_hdr << sample_header; + sample_hdr.close(); helper::ArrayToFile(banner_audio, banner_audio_size, dst_dir + "/app/banner_audio.wav"); helper::ArrayToFile(logo_lz11, logo_lz11_size, @@ -182,6 +190,8 @@ void ProcessArgs(int argc, char *argv[]) { std::filesystem::path(dst_dir + "/app")); std::filesystem::create_directories( std::filesystem::path(dst_dir + "/gfx")); + std::filesystem::create_directories(dst_dir + "/source"); + std::filesystem::create_directories(dst_dir + "/include"); std::ofstream gfx_keep(dst_dir + "/gfx/.gitkeep"); gfx_keep.close(); std::filesystem::create_directories( @@ -197,6 +207,12 @@ void ProcessArgs(int argc, char *argv[]) { test << ret; test.close(); delete[] ret; + std::ofstream sample_source(dst_dir + "/source/main.cpp"); + sample_source << sample_code; + sample_source.close(); + std::ofstream sample_hdr(dst_dir + "/include/common.hpp"); + sample_hdr << sample_header; + sample_hdr.close(); helper::ArrayToFile(banner_audio, banner_audio_size, dst_dir + "/app/banner_audio.wav"); helper::ArrayToFile(logo_lz11, logo_lz11_size, @@ -224,6 +240,9 @@ void ProcessArgs(int argc, char *argv[]) { } int main(int argc, char *argv[]) { + //Lapi::Init(); + //Lapi::Exit(); + //return 0; // std::cout << std::filesystem::current_path() << std::endl; ProcessArgs(argc, argv); diff --git a/source/samplefiles.cpp b/source/samplefiles.cpp index 87aa80d..db6e461 100644 --- a/source/samplefiles.cpp +++ b/source/samplefiles.cpp @@ -4,6 +4,26 @@ 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 = + "// Sample Source Code for Hello World\n\n" + "#include \n\n" + "int main() {\n" + " gfxInitDefault();\n" + " consoleInit(GFX_TOP, NULL);\n" + " printf(\"Hello World!\\n\");\n" + " printf(\"Press START to exit!\\n\")" + " while(aptMainLoop()) {\n" + " hidScanInput();\n" + " if(hidKeysDown() & KEY_START) break;\n" + " gfxSwapBuffers();\n" + " }\n" + " gfxExit();\n" + "}"; const char *ciaRSF = "#This File is generated by npi-build!\n" "#Every Changes made will get overwritten\n"