Skip to content

Commit

Permalink
Core : Add project registering and env features
Browse files Browse the repository at this point in the history
  • Loading branch information
diegomrno committed May 3, 2024
1 parent 8a65527 commit ab7f744
Show file tree
Hide file tree
Showing 7 changed files with 217 additions and 53 deletions.
Binary file modified build/bin/vortex
Binary file not shown.
5 changes: 4 additions & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,17 @@ VxContext *InitRuntime(bool logger)
return ctx;
}

// Project creator,
// Template deployment overrides (project, modules_content, etc...)

VxContext *InitBlankRuntime(bool logger)
{
VxContext *ctx = VortexMaker::CreateContext();
VortexMaker::LogInfo("Bootstrapp", "Initializing runtime...");

// Initialize environment
VortexMaker::InitEnvironment();

ctx->logger = logger;
return ctx;
}
Expand Down
4 changes: 4 additions & 0 deletions main/include/vortex.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ namespace VortexMaker
VORTEX_API void UpdateProjectData();
VORTEX_API void InitEnvironment();

VORTEX_API void RefreshEnvironmentProjects();
VORTEX_API void UpdateEnvironmentProject();
VORTEX_API void UpdateEnvironmentProject(const std::string& oldname);

VORTEX_API std::vector<std::string> SearchFiles(const std::string &path, const std::string &filename);
VORTEX_API std::vector<std::string> SearchSystemFiles(const std::string &path, const std::string &filename);
VORTEX_API std::string SearchFilesRecursive(const fs::path &chemin, const std::string &filename, std::vector<std::string> &file);
Expand Down
93 changes: 51 additions & 42 deletions main/include/vortex_internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include "./templates/interface.h"
//_____________________________________________________________________________


// Enable SSE intrinsics if available
#if (defined __SSE__ || defined __x86_64__ || defined _M_X64 || (defined(_M_IX86_FP) && (_M_IX86_FP >= 1))) && !defined(IMGUI_DISABLE_SSE)
#define IMGUI_ENABLE_SSE
Expand All @@ -38,37 +37,36 @@

// Visual Studio warnings
#ifdef _MSC_VER
#pragma warning (push)
#pragma warning (disable: 4251) // class 'xxx' needs to have dll-interface to be used by clients of struct 'xxx' // when IMGUI_API is set to__declspec(dllexport)
#pragma warning (disable: 26812) // The enum type 'xxx' is unscoped. Prefer 'enum class' over 'enum' (Enum.3). [MSVC Static Analyzer)
#pragma warning (disable: 26495) // [Static Analyzer] Variable 'XXX' is uninitialized. Always initialize a member variable (type.6).
#pragma warning(push)
#pragma warning(disable : 4251) // class 'xxx' needs to have dll-interface to be used by clients of struct 'xxx' // when IMGUI_API is set to__declspec(dllexport)
#pragma warning(disable : 26812) // The enum type 'xxx' is unscoped. Prefer 'enum class' over 'enum' (Enum.3). [MSVC Static Analyzer)
#pragma warning(disable : 26495) // [Static Analyzer] Variable 'XXX' is uninitialized. Always initialize a member variable (type.6).
#if defined(_MSC_VER) && _MSC_VER >= 1922 // MSVC 2019 16.2 or later
#pragma warning (disable: 5054) // operator '|': deprecated between enumerations of different types
#pragma warning(disable : 5054) // operator '|': deprecated between enumerations of different types
#endif
#endif

// Clang/GCC warnings with -Weverything
#if defined(__clang__)
#pragma clang diagnostic push
#if __has_warning("-Wunknown-warning-option")
#pragma clang diagnostic ignored "-Wunknown-warning-option" // warning: unknown warning group 'xxx'
#pragma clang diagnostic ignored "-Wunknown-warning-option" // warning: unknown warning group 'xxx'
#endif
#pragma clang diagnostic ignored "-Wunknown-pragmas" // warning: unknown warning group 'xxx'
#pragma clang diagnostic ignored "-Wfloat-equal" // warning: comparing floating point with == or != is unsafe // storing and comparing against same constants ok, for ImFloor()
#pragma clang diagnostic ignored "-Wunused-function" // for stb_textedit.h
#pragma clang diagnostic ignored "-Wmissing-prototypes" // for stb_textedit.h
#pragma clang diagnostic ignored "-Wunknown-pragmas" // warning: unknown warning group 'xxx'
#pragma clang diagnostic ignored "-Wfloat-equal" // warning: comparing floating point with == or != is unsafe // storing and comparing against same constants ok, for ImFloor()
#pragma clang diagnostic ignored "-Wunused-function" // for stb_textedit.h
#pragma clang diagnostic ignored "-Wmissing-prototypes" // for stb_textedit.h
#pragma clang diagnostic ignored "-Wold-style-cast"
#pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant"
#pragma clang diagnostic ignored "-Wdouble-promotion"
#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion" // warning: implicit conversion from 'xxx' to 'float' may lose precision
#pragma clang diagnostic ignored "-Wmissing-noreturn" // warning: function 'xxx' could be declared with attribute 'noreturn'
#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion" // warning: implicit conversion from 'xxx' to 'float' may lose precision
#pragma clang diagnostic ignored "-Wmissing-noreturn" // warning: function 'xxx' could be declared with attribute 'noreturn'
#elif defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpragmas" // warning: unknown option after '#pragma GCC diagnostic' kind
#pragma GCC diagnostic ignored "-Wclass-memaccess" // [__GNUC__ >= 8] warning: 'memset/memcpy' clearing/writing an object of type 'xxxx' with no trivial copy-assignment; use assignment or value-initialization instead
#pragma GCC diagnostic ignored "-Wpragmas" // warning: unknown option after '#pragma GCC diagnostic' kind
#pragma GCC diagnostic ignored "-Wclass-memaccess" // [__GNUC__ >= 8] warning: 'memset/memcpy' clearing/writing an object of type 'xxxx' with no trivial copy-assignment; use assignment or value-initialization instead
#endif


//_____________________________________________________________________________
// [SECTION] Forward declarations
//_____________________________________________________________________________
Expand Down Expand Up @@ -101,61 +99,75 @@ extern VORTEX_API VxContext *CVortexMaker; // Current implicit context pointer

//_____________________________________________________________________________

struct VortexMakerDebugAllocInfo {
int TotalAllocCount; // Number of call to MemAlloc().
int TotalFreeCount;
VortexMakerDebugAllocInfo() { memset(this, 0, sizeof(*this)); }
struct VortexMakerDebugAllocInfo
{
int TotalAllocCount; // Number of call to MemAlloc().
int TotalFreeCount;
VortexMakerDebugAllocInfo() { memset(this, 0, sizeof(*this)); }
};

//_____________________________________________________________________________
// [SECTION]: Internal structures
//_____________________________________________________________________________


struct VxSystemLog{
struct VxSystemLog
{
spdlog::level::level_enum m_level;
std::string m_filter;
std::string m_message;
std::string m_timestamp;

VxSystemLog(spdlog::level::level_enum level, std::string filter, std::string message): m_level(level), m_filter(filter), m_message(message) {};
VxSystemLog(spdlog::level::level_enum level, std::string filter, std::string message) : m_level(level), m_filter(filter), m_message(message){};
};

struct VxIO {
int MetricsActiveAllocations;
struct EnvProject
{
std::string name;
std::string path;
std::string version;
std::string description;
std::string logoPath;
};

struct VxIO
{
int MetricsActiveAllocations;

// EM / Editor Modules
std::vector<void *> em_handles;
std::vector<std::shared_ptr<ModuleInterface>> em;
std::vector<std::shared_ptr<ModuleInterface>> sys_em;

// Know projects in system
std::vector<std::shared_ptr<EnvProject>> sys_projects;

// Templates
std::vector<std::shared_ptr<TemplateInterface>> templates;
std::vector<std::shared_ptr<TemplateInterface>> sys_templates;
};


struct VxPaths {
struct VxPaths
{
std::string toolchainDistFolder;
std::string hostDistFolder;
};



//-----------------------------------------------------------------------------
// (Context) VortexMakerContext => Main VortexMaker context.
//-----------------------------------------------------------------------------
// This context contain all user data about VortexMaker functionnal interfaces &
// all instances of custom contents.
//-----------------------------------------------------------------------------
struct VxContext {
bool initialized;
bool logger;
bool logger_registering;
VxIO IO;
VortexMakerDebugAllocInfo debugAllocInfo;
struct VxContext
{
bool initialized;
bool logger;
bool logger_registering;
VxIO IO;
VortexMakerDebugAllocInfo debugAllocInfo;
std::vector<std::shared_ptr<VxSystemLog>> registered_logs;
fs::path projectPath;
fs::path logoPath;
VxPaths paths;
std::string configFilePath;
std::string author;
Expand All @@ -176,8 +188,6 @@ struct VxContext {

//_____________________________________________________________________________



//__________________________________________________________________________________________________________________
// [SECTION]: Internal API of VortexMaker
//__________________________________________________________________________________________________________________
Expand All @@ -186,12 +196,11 @@ struct VxContext {
// Basicly, you don't need to care about this. For all user interactions of
// Hypernet & Vx, go on the main userapi on vortex.h
//__________________________________________________________________________________________________________________
namespace VortexMaker {

// Utils & Base
VORTEX_API void DebugAllocHook(VortexMakerDebugAllocInfo *info, void *ptr,size_t size); // size >= 0 : alloc, size = -1 : free

namespace VortexMaker
{

// Utils & Base
VORTEX_API void DebugAllocHook(VortexMakerDebugAllocInfo *info, void *ptr, size_t size); // size >= 0 : alloc, size = -1 : free

}
//_____________________________________________________________________________
Expand Down
151 changes: 150 additions & 1 deletion main/src/vortex/environment/environment.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "../../../include/vortex.h"
#include "../../../include/vortex_internals.h"


VORTEX_API void VortexMaker::InitEnvironment()
{
Expand Down Expand Up @@ -26,4 +28,151 @@ VORTEX_API void VortexMaker::InitEnvironment()

VortexMaker::createJsonFileIfNotExists(file, default_data);
}
}
}


VORTEX_API void VortexMaker::RefreshEnvironmentProjects()
{
// Get reference to the Vortex context
VxContext &ctx = *CVortexMaker;

std::string path = VortexMaker::getHomeDirectory() + "/.vx/data/projects.json";

std::string json_file = path + "/project.json";

// Verify if the project is valid
try
{
// Load JSON data from the project configuration file
auto json_data = VortexMaker::DumpJSON(json_file);
for(auto project : json_data["projects"])
{
std::shared_ptr<EnvProject> newproject = std::make_shared<EnvProject>();

newproject->name = project["name"].get<std::string>();
newproject->version = project["version"].get<std::string>();
newproject->description = project["description"].get<std::string>();
newproject->path = project["path"].get<std::string>();
newproject->logoPath = project["logoPath"].get<std::string>();

ctx.IO.sys_projects.push_back(newproject);
}

}
catch (const std::exception &e)
{
// Print error if an exception occurs
std::cerr << "Error: " << e.what() << std::endl;
}
}

VORTEX_API void VortexMaker::UpdateEnvironmentProject()
{
// Get reference to the Vortex context
VxContext &ctx = *CVortexMaker;

std::string path = VortexMaker::getHomeDirectory() + "/.vx/data/";
std::string json_file = path + "/projects.json";

// Verify if the project is valid
try
{
// Load JSON data from the project configuration file
auto json_data = VortexMaker::DumpJSON(json_file);

std::string name = ctx.name;

// Check if a project with the given name exists
bool projectExists = false;
for (auto& project : json_data["projects"])
{
if (project["name"].get<std::string>() == name)
{
// Project with the given name exists, update its information
project["version"] = ctx.version;
project["description"] = ctx.description;
project["path"] = ctx.projectPath;
project["logoPath"] = ctx.logoPath;
projectExists = true;
break;
}
}

// If the project doesn't exist, create a new JSON object and add it to the list
if (!projectExists)
{
json_data["projects"].push_back({
{"name", ctx.name},
{"version", ctx.version},
{"description", ctx.description},
{"path", ctx.projectPath},
{"logoPath", ctx.logoPath}
});
}

// Write the updated JSON data back to the file
std::ofstream output(json_file);
output << json_data.dump(4); // Use pretty print with indentation of 4 spaces
output.close();
}
catch (const std::exception &e)
{
// Print error if an exception occurs
std::cerr << "Error: " << e.what() << std::endl;
}
}

VORTEX_API void VortexMaker::UpdateEnvironmentProject(const std::string& oldname)
{
// Get reference to the Vortex context
VxContext &ctx = *CVortexMaker;

std::string path = VortexMaker::getHomeDirectory() + "/.vx/data/";
std::string json_file = path + "/projects.json";

// Verify if the project is valid
try
{
// Load JSON data from the project configuration file
auto json_data = VortexMaker::DumpJSON(json_file);

// Check if a project with the old name exists
bool projectExists = false;
for (auto& project : json_data["projects"])
{
if (project["name"].get<std::string>() == oldname)
{
// Project with the old name exists, update its information
project["name"] = ctx.name;
project["version"] = ctx.version;
project["description"] = ctx.description;
project["path"] = ctx.projectPath;
project["logoPath"] = ctx.logoPath;
projectExists = true;
break;
}
}

// If the project doesn't exist, create a new JSON object and add it to the list
if (!projectExists)
{
json_data["projects"].push_back({
{"name", ctx.name},
{"version", ctx.version},
{"description", ctx.description},
{"path", ctx.projectPath},
{"logoPath", ctx.logoPath}
});
}

// Write the updated JSON data back to the file
std::ofstream output(json_file);
output << json_data.dump(4); // Use pretty print with indentation of 4 spaces
output.close();
}
catch (const std::exception &e)
{
// Print error if an exception occurs
std::cerr << "Error: " << e.what() << std::endl;
}
}
10 changes: 1 addition & 9 deletions main/src/vortex/project/init_project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,6 @@ VORTEX_API void VortexMaker::InitProject(const nlohmann::json& main_configs)
ctx.version = VORTEX_VERSION;
ctx.include_system_templates = main_configs["project"]["include_system_templates"].get<bool>();

/*ctx.packagesPath = main_configs["data"]["packages"].get<std::string>();
ctx.toolchainsPath = main_configs["data"]["toolchains"].get<std::string>();
ctx.gposPath = main_configs["data"]["gpos"].get<std::string>();
ctx.scriptsPath = main_configs["data"]["scripts"].get<std::string>(); // Fixed typo here
ctx.hostsPath = main_configs["data"]["hosts"].get<std::string>();
ctx.paths.toolchainDistFolder = main_configs["dist"]["toolchains"].get<std::string>();
ctx.paths.hostDistFolder = main_configs["dist"]["hosts"].get<std::string>();*/

// Set project path to current working directory
ctx.projectPath = fs::current_path();

Expand All @@ -47,6 +38,7 @@ VORTEX_API void VortexMaker::InitProject(const nlohmann::json& main_configs)
VortexMaker::InitEnvironment();

// Update projet metadata (last opened, etc...) in the ~/.vx/data/projects.json
VortexMaker::UpdateEnvironmentProject();

// Load modules installed in the current project
VortexMaker::LoadEditorModules(ctx.projectPath, ctx.IO.em_handles, ctx.IO.em);
Expand Down
Loading

0 comments on commit ab7f744

Please sign in to comment.