2013-08-09 08:01:20 +08:00
|
|
|
/* Aseprite
|
2013-01-27 23:13:13 +08:00
|
|
|
* Copyright (C) 2001-2013 David Capello
|
2007-09-19 07:57:02 +08:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2007-09-19 07:57:02 +08:00
|
|
|
#include "config.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#endif
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/modules.h"
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/modules/gui.h"
|
|
|
|
#include "app/modules/palettes.h"
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
namespace app {
|
|
|
|
|
|
|
|
struct Module {
|
2007-09-19 07:57:02 +08:00
|
|
|
const char *name;
|
2008-10-01 09:27:51 +08:00
|
|
|
int (*init)();
|
|
|
|
void (*exit)();
|
2007-09-19 07:57:02 +08:00
|
|
|
int reqs;
|
2009-10-14 22:09:59 +08:00
|
|
|
bool installed;
|
2013-08-06 08:20:19 +08:00
|
|
|
};
|
2007-09-19 07:57:02 +08:00
|
|
|
|
|
|
|
static Module module[] =
|
|
|
|
{
|
2013-08-06 08:20:19 +08: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-19 07:57:02 +08:00
|
|
|
|
2012-01-06 06:45:03 +08:00
|
|
|
DEF_MODULE(palette, 0),
|
|
|
|
DEF_MODULE(gui, REQUIRE_INTERFACE),
|
2007-09-19 07:57:02 +08:00
|
|
|
};
|
|
|
|
|
2007-09-20 08:32:35 +08:00
|
|
|
static int modules = sizeof(module) / sizeof(Module);
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2010-01-29 11:15:33 +08:00
|
|
|
LegacyModules::LegacyModules(int requirements)
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
2009-08-05 09:53:02 +08:00
|
|
|
for (int c=0; c<modules; c++)
|
2009-10-14 22:09:59 +08:00
|
|
|
if ((module[c].reqs & requirements) == module[c].reqs) {
|
2007-09-20 08:32:35 +08:00
|
|
|
PRINTF("Installing module: %s\n", module[c].name);
|
2009-08-05 09:53:02 +08:00
|
|
|
|
2007-09-20 08:32:35 +08:00
|
|
|
if ((*module[c].init)() < 0)
|
2012-01-06 06:45:03 +08:00
|
|
|
throw base::Exception("Error initializing module: %s",
|
|
|
|
static_cast<const char*>(module[c].name));
|
2008-02-04 10:37:26 +08:00
|
|
|
|
2009-10-14 22:09:59 +08:00
|
|
|
module[c].installed = true;
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-29 11:15:33 +08:00
|
|
|
LegacyModules::~LegacyModules()
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
2009-08-05 09:53:02 +08:00
|
|
|
for (int c=modules-1; c>=0; c--)
|
2007-09-19 07:57:02 +08:00
|
|
|
if (module[c].installed) {
|
2007-09-20 08:32:35 +08:00
|
|
|
PRINTF("Unstalling module: %s\n", module[c].name);
|
|
|
|
(*module[c].exit)();
|
2009-10-14 22:09:59 +08:00
|
|
|
module[c].installed = false;
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
}
|
2013-08-06 08:20:19 +08:00
|
|
|
|
|
|
|
} // namespace app
|