-
Notifications
You must be signed in to change notification settings - Fork 0
/
ModuleManager.h
105 lines (78 loc) · 2.74 KB
/
ModuleManager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#pragma once
#ifndef _SCRIPT_PAD_MODULE_HANDLER_H
#define _SCRIPT_PAD_MODULE_HANDLER_H
#include "interface/LanguageModule.h"
#include "interface/ILanguage.h"
#include "AppWindow.h"
#include "Util.h"
#include <filesystem>
#include "resource.h"
#include "ApplicationData.h"
namespace querier {
using namespace std::filesystem;
typedef LanguageModule*(_cdecl* DLL)(path);
// Loaded language module resources
struct LoadedModule {
std::string name;
// path to dll
path modulePath;
HINSTANCE hLibrary = nullptr;
DLL createModule = nullptr;
};
using LoadedModules = std::map<std::string, LoadedModule*>;
struct ModuleData {
path Path;
path Library;
path SourceFile;
};
struct Module {
Module();
Module(std::string _name, path _path, std::string _lib, LanguageType _type);
std::string Name;
std::string SourceFileExtension;
std::string Library;
LanguageType Type{ Interpreter };
LanguageModule* LanguageModule = nullptr;
bool UnicodeModule = true;
ModuleData Data;
path Path;
};
class ModuleManager {
public:
ModuleManager(AppWindow*);
~ModuleManager();
void Initialize(path, path);
bool LoadModule(std::string, path, path, path, LanguageModule**);
std::map<std::string, Module*> Modules;
path WorkingDirectory,
ModulesDirectory;
inline static std::string s_DefaultModule = "Nodejs",
s_DefaultSourceFileName = "_eval_",
s_DefaultSourceFileExtension = ".mjs";
Module* get_Module(std::string name) {
return Modules[name];
}
json get_ModulesAsJson();
void HandleCommand(ModuleMessage*);
private:
AppWindow* m_MainWindow;
std::vector<path> m_InstalledModules;
std::vector<path> m_WorkspaceItems;
LoadedModules m_LoadedModules;
//AvailableModules m_ModulesAvailable;
static std::map<std::wstring, path> m_wModules;
static std::map<std::string, path> m_Modules;
static std::map<std::string, Module*> m_mModules;
bool load_Modules();
std::vector<Module> get_Modules();
void HandleOutputReceived(std::string ret, std::string);
void HandleErrorReceived(std::string ret, std::string);
void PostApplicationMessage(ApplicationMessage*);
void CleanupLoadedModules();
void CleanupAvailableModules();
void CleanupLanguageModules();
};
void to_json(json& j, const Module& m);
void from_json(const json& j, Module& m);
} //namespace scriptpad
#endif //_SCRIPT_PAD_MODULE_HANDLER_H