MCPcopy Create free account
hub / github.com/LibreSprite/LibreSprite / scanScript

Method scanScript

src/app/script/app_scripting.cpp:105–156  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

103 }
104
105 bool AppScripting::scanScript(const std::string& fullPath) {
106 bool supported = false;
107 auto extension = base::string_to_lower(base::get_file_extension(fullPath));
108 for (auto& entry : script::Engine::getRegistry()) {
109 if (entry.second.hasFlag(extension)) {
110 supported = true;
111 break;
112 }
113 }
114
115 if (!supported)
116 return false;
117
118 std::ifstream file{fullPath};
119
120 if (!file)
121 return false;
122
123 std::string line;
124 while (std::getline(file, line)) {
125 base::trim_string(line, line);
126 auto parts = base::split(line, ' ');
127
128 for (auto& part : parts)
129 base::trim_string(part, part);
130
131 if (parts.empty() || parts[0].size() < 3 || parts[0].substr(0, 3) != "///")
132 break;
133
134 base::trim_string(parts[0].substr(3), parts[0]);
135 if (parts[0].empty()) {
136 parts.erase(parts.begin());
137 if (parts.empty())
138 break;
139 }
140
141 auto key = base::string_to_lower(parts[0]);
142 parts.erase(parts.begin());
143
144 if (key == "listen") {
145 if (!listener) {
146 listener.reset(new EventListener());
147 ui::Manager::getDefault()->addMessageListener(listener.get());
148 }
149 for (auto& event : parts) {
150 eventHooks.insert({event, fullPath});
151 }
152 }
153 }
154
155 return true;
156 }
157
158 void AppScripting::initEngine() {
159 if (!wasInit) {

Callers

nothing calls this directly

Calls 10

string_to_lowerFunction · 0.85
get_file_extensionFunction · 0.85
splitFunction · 0.85
addMessageListenerMethod · 0.80
hasFlagMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
resetMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected