Initial Code

This commit is contained in:
2023-11-24 14:42:57 +01:00
parent f236e59cb4
commit 9d6f367c8d
19 changed files with 43496 additions and 0 deletions

5
include/banner.hpp Normal file
View File

@ -0,0 +1,5 @@
#pragma once
#include <cstddef>
extern unsigned char banner[];
extern size_t banner_size;

5
include/banner_audio.hpp Normal file
View File

@ -0,0 +1,5 @@
#pragma once
#include <cstddef>
extern unsigned char banner_audio[];
extern size_t banner_audio_size;

70
include/fileHash.hpp Normal file
View File

@ -0,0 +1,70 @@
#pragma once
#include <chrono>
#include <cstdlib>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <map>
#include <string>
#include <vector>
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)
{
std::ifstream iff(file);
if(!iff.is_open()) {
return std::to_string(rand());
}
unsigned long long check_sum = 0x0ULL;
char tmp;
while (iff.get(tmp))
{
check_sum += (unsigned long long)tmp;
}
iff.close();
std::stringstream ret;
ret << std::hex << check_sum;
return ret.str();
}
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() && file.path().extension() == extension)
{
std::string path = fix_path(file.path().string());
hashes[path] = stupid_hash(path);
}
}
}
return hashes;
}
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)
{
std::string newHash = stupid_hash(file.first);
if (newHash != file.second)
{
changedFiles.push_back(std::filesystem::path(file.first));
}
}
return changedFiles;
}

11
include/helper.hpp Normal file
View File

@ -0,0 +1,11 @@
#pragma once
#include <prj_def.hpp>
#include <string>
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 CleanProject(std::string path);
} // namespace helper

5
include/icon.hpp Normal file
View File

@ -0,0 +1,5 @@
#pragma once
#include <cstddef>
extern unsigned char icon[];
extern size_t icon_size;

24651
include/json.hpp Normal file

File diff suppressed because it is too large Load Diff

5
include/logo_lz11.hpp Normal file
View File

@ -0,0 +1,5 @@
#pragma once
#include <cstddef>
extern unsigned char logo_lz11[];
extern size_t logo_lz11_size;

111
include/prj_def.hpp Normal file
View File

@ -0,0 +1,111 @@
#pragma once
#include <string>
#include <vector>
struct NpiProject {
std::string name;
std::string author;
std::string description;
int vmajor;
int vminor;
int vbuild;
std::vector<std::string> source_dirs;
std::vector<std::string> include_dirs;
std::vector<std::string> libraries;
std::vector<std::string> lib_dirs;
std::string icon_path;
std::string banner_path;
std::string banner_a_path;
std::string rsf_path;
std::string logo_lz11_path;
std::string dir_gfx;
std::string dir_gfxbuild;
std::string dir_romfs;
std::string unique_id;
std::string prod;
std::string platform; // Platforms: 3ds, desktop
std::vector<std::string> arch_flags;
std::vector<std::string> c_flags;
std::vector<std::string> cxx_flags;
std::vector<std::string> as_flags;
std::vector<std::string> linker_flags;
std::string cxx_compiler;
std::string c_compiler;
std::string linker;
std::string asm_compiler;
};
inline void Prj_InitDefault(NpiProject &project) {
project.name = "Sample";
project.author = "Sample";
project.description = "Description";
project.vmajor = 1;
project.vminor = 0;
project.vbuild = 0;
project.source_dirs.push_back("source");
project.include_dirs.push_back("include");
project.libraries.push_back("m");
project.libraries.push_back("stdc++");
project.libraries.push_back("citro2d");
project.libraries.push_back("citro3d");
project.libraries.push_back("ctru");
project.arch_flags.push_back("march=armv6k");
project.arch_flags.push_back("mtune=mpcore");
project.arch_flags.push_back("mfloat-abi=hard");
project.arch_flags.push_back("mtp=soft");
project.c_flags.push_back("g");
project.c_flags.push_back("Wall");
project.c_flags.push_back("Wno-psabi");
project.c_flags.push_back("O2");
project.c_flags.push_back("mword-relocations");
project.c_flags.push_back("fomit-frame-pointer");
project.c_flags.push_back("ffunction-sections");
project.c_flags.push_back("[arch_flags]");
project.c_flags.push_back("D__3DS__");
project.c_flags.push_back("D_GNU_SOURCE=1");
project.cxx_flags.push_back("[c_flags]");
project.cxx_flags.push_back("fno-rtti");
project.cxx_flags.push_back("fno-exceptions");
project.cxx_flags.push_back("std=gnu++20");
project.as_flags.push_back("g");
project.as_flags.push_back("[arch_flags]");
project.linker_flags.push_back("specs=3dsx.specs");
project.linker_flags.push_back("g");
project.linker_flags.push_back("[arch_flags]");
project.linker_flags.push_back("Wl,-Map,./build/code.map");
project.lib_dirs.push_back("{DEVKITPRO}/portlibs/3ds/");
project.lib_dirs.push_back("{DEVKITPRO}/libctru/");
project.cxx_compiler = "{DEVKITPRO}/devkitARM/bin/arm-none-eabi-g++";
project.linker = "{DEVKITPRO}/devkitARM/bin/arm-none-eabi-g++";
project.c_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.banner_path = "app/banner.png";
project.banner_a_path = "app/banner_audio.wav";
project.rsf_path = "app/build-cia.rsf";
project.logo_lz11_path = "app/logo.lz11";
project.dir_gfx = "gfx/";
project.dir_gfxbuild = "romfs/gfx/";
project.dir_romfs = "romfs/";
project.unique_id = "0xff3ff";
project.prod = "NPI7";
project.platform = "3ds";
}

7
include/samplefiles.hpp Normal file
View File

@ -0,0 +1,7 @@
#pragma once
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 *ciaRSF;