2015-02-12 15:16:25 +00:00
|
|
|
// Aseprite
|
2018-05-07 03:11:50 +00:00
|
|
|
// Copyright (C) 2001-2018 David Capello
|
2015-02-12 15:16:25 +00:00
|
|
|
//
|
2016-08-26 20:02:58 +00:00
|
|
|
// This program is distributed under the terms of
|
|
|
|
// the End-User License Agreement for Aseprite.
|
2007-09-18 23:57:02 +00:00
|
|
|
|
2013-08-06 00:20:19 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2007-09-18 23:57:02 +00:00
|
|
|
#include "config.h"
|
2013-08-06 00:20:19 +00:00
|
|
|
#endif
|
2007-09-18 23:57:02 +00:00
|
|
|
|
2013-08-06 00:20:19 +00:00
|
|
|
#include "app/modules.h"
|
2007-09-18 23:57:02 +00:00
|
|
|
|
2013-08-06 00:20:19 +00:00
|
|
|
#include "app/modules/gui.h"
|
|
|
|
#include "app/modules/palettes.h"
|
2007-09-18 23:57:02 +00:00
|
|
|
|
2013-08-06 00:20:19 +00:00
|
|
|
namespace app {
|
|
|
|
|
|
|
|
struct Module {
|
2007-09-18 23:57:02 +00:00
|
|
|
const char *name;
|
2008-10-01 01:27:51 +00:00
|
|
|
int (*init)();
|
|
|
|
void (*exit)();
|
2007-09-18 23:57:02 +00:00
|
|
|
int reqs;
|
2009-10-14 14:09:59 +00:00
|
|
|
bool installed;
|
2013-08-06 00:20:19 +00:00
|
|
|
};
|
2007-09-18 23:57:02 +00:00
|
|
|
|
|
|
|
static Module module[] =
|
|
|
|
{
|
2013-08-06 00:20:19 +00:00
|
|
|
#define DEF_MODULE(name, reqs) \
|
|
|
|
{ #name, init_module_##name, exit_module_##name, (reqs), false }
|
|
|
|
|
|
|
|
// This sorting is very important because last modules depend of
|
|
|
|
// first ones.
|
2007-09-18 23:57:02 +00:00
|
|
|
|
2012-01-05 22:45:03 +00:00
|
|
|
DEF_MODULE(palette, 0),
|
2018-05-07 03:11:50 +00:00
|
|
|
#ifdef ENABLE_UI
|
2012-01-05 22:45:03 +00:00
|
|
|
DEF_MODULE(gui, REQUIRE_INTERFACE),
|
2018-05-07 03:11:50 +00:00
|
|
|
#endif
|
2007-09-18 23:57:02 +00:00
|
|
|
};
|
|
|
|
|
2007-09-20 00:32:35 +00:00
|
|
|
static int modules = sizeof(module) / sizeof(Module);
|
2007-09-18 23:57:02 +00:00
|
|
|
|
2010-01-29 03:15:33 +00:00
|
|
|
LegacyModules::LegacyModules(int requirements)
|
2007-09-18 23:57:02 +00:00
|
|
|
{
|
2009-08-05 01:53:02 +00:00
|
|
|
for (int c=0; c<modules; c++)
|
2009-10-14 14:09:59 +00:00
|
|
|
if ((module[c].reqs & requirements) == module[c].reqs) {
|
2016-10-27 15:25:33 +00:00
|
|
|
LOG("MODS: Installing module: %s\n", module[c].name);
|
2009-08-05 01:53:02 +00:00
|
|
|
|
2007-09-20 00:32:35 +00:00
|
|
|
if ((*module[c].init)() < 0)
|
2012-01-05 22:45:03 +00:00
|
|
|
throw base::Exception("Error initializing module: %s",
|
|
|
|
static_cast<const char*>(module[c].name));
|
2008-02-04 02:37:26 +00:00
|
|
|
|
2009-10-14 14:09:59 +00:00
|
|
|
module[c].installed = true;
|
2007-09-18 23:57:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-29 03:15:33 +00:00
|
|
|
LegacyModules::~LegacyModules()
|
2007-09-18 23:57:02 +00:00
|
|
|
{
|
2009-08-05 01:53:02 +00:00
|
|
|
for (int c=modules-1; c>=0; c--)
|
2007-09-18 23:57:02 +00:00
|
|
|
if (module[c].installed) {
|
2016-10-27 15:25:33 +00:00
|
|
|
LOG("MODS: Unstalling module: %s\n", module[c].name);
|
2007-09-20 00:32:35 +00:00
|
|
|
(*module[c].exit)();
|
2009-10-14 14:09:59 +00:00
|
|
|
module[c].installed = false;
|
2007-09-18 23:57:02 +00:00
|
|
|
}
|
|
|
|
}
|
2013-08-06 00:20:19 +00:00
|
|
|
|
|
|
|
} // namespace app
|