mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-29 19:20:09 +00:00
Replaced old DIRS structure with ResourceFinder class.
This commit is contained in:
parent
513844c538
commit
f2f1bb26f2
@ -14,6 +14,7 @@ COMMON_SOURCES = \
|
||||
src/launcher.cpp \
|
||||
src/mem_utils.cpp \
|
||||
src/recent_files.cpp \
|
||||
src/resource_finder.cpp \
|
||||
src/ui_context.cpp \
|
||||
src/undoable.cpp \
|
||||
src/commands/cmd_about.cpp \
|
||||
@ -94,7 +95,6 @@ COMMON_SOURCES = \
|
||||
src/core/color.cpp \
|
||||
src/core/config.cpp \
|
||||
src/core/core.cpp \
|
||||
src/core/dirs.cpp \
|
||||
src/core/drop_files.cpp \
|
||||
src/core/file_system.cpp \
|
||||
src/core/job.cpp \
|
||||
|
@ -24,7 +24,6 @@
|
||||
|
||||
#include "commands/command.h"
|
||||
#include "core/core.h"
|
||||
#include "core/dirs.h"
|
||||
#include "modules/gui.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
@ -19,20 +19,20 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <allegro.h>
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "jinete/jinete.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "commands/command.h"
|
||||
#include "console.h"
|
||||
#include "app.h"
|
||||
#include "core/dirs.h"
|
||||
#include "gfxmode.h"
|
||||
#include "intl/intl.h"
|
||||
#include "modules/gui.h"
|
||||
#include "sprite_wrappers.h"
|
||||
#include "modules/palettes.h"
|
||||
#include "resource_finder.h"
|
||||
#include "sprite_wrappers.h"
|
||||
|
||||
#include "tinyxml.h"
|
||||
|
||||
@ -133,18 +133,19 @@ void ConfigureScreen::load_resolutions(ComboBox* resolution, ComboBox* color_dep
|
||||
m_pixelscale.clear();
|
||||
|
||||
// Read from gui.xml
|
||||
DIRS* dirs = filename_in_datadir("gui.xml");
|
||||
ResourceFinder rf;
|
||||
rf.findInDataDir("gui.xml");
|
||||
|
||||
for (DIRS* dir=dirs; dir; dir=dir->next) {
|
||||
PRINTF("Trying to load screen resolutions file from \"%s\"...\n", dir->path);
|
||||
while (const char* path = rf.next()) {
|
||||
PRINTF("Trying to load screen resolutions file from \"%s\"...\n", path);
|
||||
|
||||
if (!exists(dir->path))
|
||||
if (!exists(path))
|
||||
continue;
|
||||
|
||||
PRINTF(" - \"%s\" found\n", dir->path);
|
||||
PRINTF(" - \"%s\" found\n", path);
|
||||
|
||||
TiXmlDocument doc;
|
||||
if (!doc.LoadFile(dir->path))
|
||||
if (!doc.LoadFile(path))
|
||||
throw ase_exception(&doc);
|
||||
|
||||
TiXmlHandle handle(&doc);
|
||||
@ -204,8 +205,6 @@ void ConfigureScreen::load_resolutions(ComboBox* resolution, ComboBox* color_dep
|
||||
}
|
||||
}
|
||||
|
||||
dirs_free(dirs);
|
||||
|
||||
// Current screen size
|
||||
if (!old_res_selected) {
|
||||
m_resolutions.insert(m_resolutions.begin(), std::make_pair(m_newMode.getWidth(), m_newMode.getHeight()));
|
||||
|
@ -21,8 +21,8 @@
|
||||
#include <allegro.h>
|
||||
|
||||
#include "commands/command.h"
|
||||
#include "core/dirs.h"
|
||||
#include "launcher.h"
|
||||
#include "resource_finder.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// about
|
||||
@ -46,17 +46,16 @@ QuickReferenceCommand::QuickReferenceCommand()
|
||||
|
||||
void QuickReferenceCommand::execute(Context* context)
|
||||
{
|
||||
DIRS* dirs = filename_in_docsdir("quickref.pdf");
|
||||
ResourceFinder rf;
|
||||
rf.findInDocsDir("quickref.pdf");
|
||||
|
||||
for (DIRS* dir=dirs; dir; dir=dir->next) {
|
||||
if (!exists(dir->path))
|
||||
while (const char* path = rf.next()) {
|
||||
if (!exists(path))
|
||||
continue;
|
||||
|
||||
Launcher::openFile(dir->path);
|
||||
Launcher::openFile(path);
|
||||
break;
|
||||
}
|
||||
|
||||
dirs_free(dirs);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
@ -26,28 +26,29 @@
|
||||
|
||||
#include "core/cfg.h"
|
||||
#include "core/core.h"
|
||||
#include "core/dirs.h"
|
||||
#include "resource_finder.h"
|
||||
|
||||
static char config_filename[512];
|
||||
|
||||
ConfigModule::ConfigModule()
|
||||
{
|
||||
DIRS *dir, *dirs = cfg_filename_dirs();
|
||||
ResourceFinder rf;
|
||||
rf.findConfigurationFile();
|
||||
|
||||
/* search the configuration file from first to last path */
|
||||
for (dir=dirs; dir; dir=dir->next) {
|
||||
if ((dir->path) && exists(dir->path)) {
|
||||
ustrcpy(config_filename, dir->path);
|
||||
config_filename[0] = 0;
|
||||
|
||||
// Search the configuration file from first to last path
|
||||
while (const char* path = rf.next()) {
|
||||
if (exists(path)) {
|
||||
ustrcpy(config_filename, path);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* if the file wasn't found, we will create configuration file
|
||||
in the first path */
|
||||
if (!dir)
|
||||
ustrcpy(config_filename, dirs->path);
|
||||
|
||||
dirs_free(dirs);
|
||||
// If the file wasn't found, we will create configuration file
|
||||
// in the first path
|
||||
if (config_filename[0] == 0 && rf.first())
|
||||
ustrcpy(config_filename, rf.first());
|
||||
|
||||
override_config_file(config_filename);
|
||||
}
|
||||
|
@ -28,7 +28,7 @@
|
||||
#include "jinete/jbase.h"
|
||||
|
||||
#include "core/core.h"
|
||||
#include "core/dirs.h"
|
||||
#include "resource_finder.h"
|
||||
|
||||
/* DOS and Windows needs "log" files (because their poor stderr support) */
|
||||
#if defined ALLEGRO_DOS || defined ALLEGRO_WINDOWS
|
||||
@ -58,9 +58,9 @@ LoggerModule::LoggerModule()
|
||||
PRINTF("Logger module: starting\n");
|
||||
|
||||
#ifdef NEED_LOG
|
||||
DIRS* dirs = filename_in_bindir("aseprite.log");
|
||||
log_filename = dirs->path;
|
||||
dirs_free(dirs);
|
||||
ResourceFinder rf;
|
||||
rf.findInBinDir("aseprite.log");
|
||||
log_filename = rf.first();
|
||||
#endif
|
||||
|
||||
PRINTF("Logger module: started\n");
|
||||
|
@ -1,246 +0,0 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2010 David Capello
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <allegro/file.h>
|
||||
#include <allegro/system.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "jinete/jbase.h"
|
||||
|
||||
#include "core/core.h"
|
||||
#include "core/dirs.h"
|
||||
|
||||
DIRS *dirs_new()
|
||||
{
|
||||
DIRS* dirs;
|
||||
|
||||
dirs = (DIRS*)jmalloc(sizeof(DIRS));
|
||||
if (!dirs)
|
||||
return NULL;
|
||||
|
||||
dirs->path = NULL;
|
||||
dirs->next = NULL;
|
||||
|
||||
return dirs;
|
||||
}
|
||||
|
||||
void dirs_free(DIRS *dirs)
|
||||
{
|
||||
DIRS *iter, *next;
|
||||
|
||||
for (iter=dirs; iter; iter=next) {
|
||||
next = iter->next;
|
||||
if (iter->path)
|
||||
jfree(iter->path);
|
||||
|
||||
jfree(iter);
|
||||
}
|
||||
}
|
||||
|
||||
void dirs_add_path(DIRS *dirs, const char *path)
|
||||
{
|
||||
if (!dirs->path) {
|
||||
dirs->path = jstrdup(path);
|
||||
}
|
||||
else {
|
||||
DIRS *newone, *lastone;
|
||||
|
||||
for (lastone=dirs; lastone->next; lastone=lastone->next)
|
||||
;
|
||||
|
||||
newone = dirs_new();
|
||||
if (!newone)
|
||||
return;
|
||||
|
||||
newone->path = jstrdup(path);
|
||||
if (!newone->path) {
|
||||
jfree(newone);
|
||||
return;
|
||||
}
|
||||
|
||||
lastone->next = newone;
|
||||
}
|
||||
}
|
||||
|
||||
void dirs_cat_dirs(DIRS *dirs, DIRS *more)
|
||||
{
|
||||
DIRS *lastone, *origmore = more;
|
||||
|
||||
if (!dirs->path) {
|
||||
dirs->path = more->path;
|
||||
more = more->next;
|
||||
|
||||
jfree(origmore);
|
||||
}
|
||||
|
||||
for (lastone=dirs; lastone->next; lastone=lastone->next)
|
||||
;
|
||||
|
||||
lastone->next = more;
|
||||
}
|
||||
|
||||
DIRS *filename_in_bindir(const char *filename)
|
||||
{
|
||||
char buf[1024], path[1024];
|
||||
DIRS *dirs;
|
||||
|
||||
get_executable_name(path, sizeof(path));
|
||||
replace_filename(buf, path, filename, sizeof(buf));
|
||||
|
||||
dirs = dirs_new();
|
||||
dirs_add_path(dirs, buf);
|
||||
|
||||
return dirs;
|
||||
}
|
||||
|
||||
DIRS *filename_in_datadir(const char *filename)
|
||||
{
|
||||
DIRS *dirs = dirs_new();
|
||||
char buf[1024];
|
||||
|
||||
#if defined ALLEGRO_UNIX || defined ALLEGRO_MACOSX
|
||||
|
||||
/* $HOME/.ase/filename */
|
||||
sprintf(buf, ".ase/%s", filename);
|
||||
dirs_cat_dirs(dirs, filename_in_homedir(buf));
|
||||
|
||||
/* $BINDIR/data/filename */
|
||||
sprintf(buf, "data/%s", filename);
|
||||
dirs_cat_dirs(dirs, filename_in_bindir(buf));
|
||||
|
||||
#ifdef DEFAULT_PREFIX
|
||||
/* $PREFIX/ase/filename */
|
||||
sprintf(buf, "%s/share/ase/%s", DEFAULT_PREFIX, filename);
|
||||
dirs_add_path(dirs, buf);
|
||||
#endif
|
||||
|
||||
#ifdef ALLEGRO_MACOSX
|
||||
/* $BINDIR/aseprite.app/Contents/Resources/data/filename */
|
||||
sprintf(buf, "aseprite.app/Contents/Resources/data/%s", filename);
|
||||
dirs_cat_dirs(dirs, filename_in_bindir(buf));
|
||||
#endif
|
||||
|
||||
#elif defined ALLEGRO_WINDOWS || defined ALLEGRO_DOS
|
||||
|
||||
/* $BINDIR/data/filename */
|
||||
sprintf(buf, "data/%s", filename);
|
||||
dirs_cat_dirs(dirs, filename_in_bindir(buf));
|
||||
|
||||
#else
|
||||
|
||||
/* filename */
|
||||
dirs_add_path(dirs, filename);
|
||||
|
||||
#endif
|
||||
|
||||
return dirs;
|
||||
}
|
||||
|
||||
DIRS *filename_in_docsdir(const char *filename)
|
||||
{
|
||||
DIRS *dirs = dirs_new();
|
||||
char buf[1024];
|
||||
|
||||
#if defined ALLEGRO_UNIX || defined ALLEGRO_MACOSX
|
||||
|
||||
/* $BINDIR/docs/filename */
|
||||
sprintf(buf, "docs/%s", filename);
|
||||
dirs_cat_dirs(dirs, filename_in_bindir(buf));
|
||||
|
||||
#ifdef DEFAULT_PREFIX
|
||||
/* $PREFIX/ase/docs/filename */
|
||||
sprintf(buf, "%s/share/ase/docs/%s", DEFAULT_PREFIX, filename);
|
||||
dirs_add_path(dirs, buf);
|
||||
#endif
|
||||
|
||||
#ifdef ALLEGRO_MACOSX
|
||||
/* $BINDIR/aseprite.app/Contents/Resources/docs/filename */
|
||||
sprintf(buf, "aseprite.app/Contents/Resources/docs/%s", filename);
|
||||
dirs_cat_dirs(dirs, filename_in_bindir(buf));
|
||||
#endif
|
||||
|
||||
#elif defined ALLEGRO_WINDOWS || defined ALLEGRO_DOS
|
||||
|
||||
/* $BINDIR/docs/filename */
|
||||
sprintf(buf, "docs/%s", filename);
|
||||
dirs_cat_dirs(dirs, filename_in_bindir(buf));
|
||||
|
||||
#else
|
||||
|
||||
/* filename */
|
||||
dirs_add_path(dirs, filename);
|
||||
|
||||
#endif
|
||||
|
||||
return dirs;
|
||||
}
|
||||
|
||||
DIRS *filename_in_homedir(const char *filename)
|
||||
{
|
||||
DIRS *dirs = dirs_new();
|
||||
|
||||
#if defined ALLEGRO_UNIX || defined ALLEGRO_MACOSX
|
||||
|
||||
char *env = getenv("HOME");
|
||||
char buf[1024];
|
||||
|
||||
if ((env) && (*env)) {
|
||||
/* $HOME/filename */
|
||||
sprintf(buf, "%s/%s", env, filename);
|
||||
dirs_add_path(dirs, buf);
|
||||
}
|
||||
else {
|
||||
PRINTF("You don't have set $HOME variable\n");
|
||||
dirs_add_path(dirs, filename);
|
||||
}
|
||||
|
||||
#elif defined ALLEGRO_WINDOWS || defined ALLEGRO_DOS
|
||||
|
||||
/* $PREFIX/data/filename */
|
||||
dirs_cat_dirs(dirs, filename_in_datadir(filename));
|
||||
|
||||
#else
|
||||
|
||||
/* filename */
|
||||
dirs_add_path(dirs, filename);
|
||||
|
||||
#endif
|
||||
|
||||
return dirs;
|
||||
}
|
||||
|
||||
DIRS *cfg_filename_dirs()
|
||||
{
|
||||
DIRS *dirs = dirs_new();
|
||||
|
||||
#if defined ALLEGRO_UNIX || defined ALLEGRO_MACOSX
|
||||
|
||||
/* $HOME/.asepriterc */
|
||||
dirs_cat_dirs(dirs, filename_in_homedir(".asepriterc"));
|
||||
|
||||
#endif
|
||||
|
||||
/* $BINDIR/aseprite.ini */
|
||||
dirs_cat_dirs(dirs, filename_in_bindir("aseprite.ini"));
|
||||
|
||||
return dirs;
|
||||
}
|
@ -22,18 +22,18 @@
|
||||
|
||||
#include "jinete/jinete.h"
|
||||
|
||||
#include "console.h"
|
||||
#include "app.h"
|
||||
#include "console.h"
|
||||
#include "core/cfg.h"
|
||||
#include "core/color.h"
|
||||
#include "core/core.h"
|
||||
#include "core/dirs.h"
|
||||
#include "dialogs/filesel.h"
|
||||
#include "modules/gui.h"
|
||||
#include "modules/palettes.h"
|
||||
#include "raster/blend.h"
|
||||
#include "raster/image.h"
|
||||
#include "raster/sprite.h"
|
||||
#include "resource_finder.h"
|
||||
#include "util/clipboard.h"
|
||||
#include "util/misc.h"
|
||||
#include "widgets/colbar.h"
|
||||
@ -234,36 +234,33 @@ static Image* render_text(Sprite* sprite, FONT *f, const char *text, int color)
|
||||
|
||||
static FONT *my_load_font(const char *filename)
|
||||
{
|
||||
DIRS *dirs, *dir;
|
||||
FONT *f = NULL;
|
||||
char buf[256];
|
||||
|
||||
/* directories to search */
|
||||
dirs = dirs_new();
|
||||
// Directories to search
|
||||
ResourceFinder rf;
|
||||
|
||||
dirs_add_path(dirs, filename);
|
||||
rf.addPath(filename);
|
||||
|
||||
usprintf(buf, "fonts/%s", filename);
|
||||
dirs_cat_dirs(dirs, filename_in_datadir(buf));
|
||||
rf.findInDataDir(buf);
|
||||
|
||||
usprintf(buf, "fonts/%s", get_filename(filename));
|
||||
dirs_cat_dirs(dirs, filename_in_datadir(buf));
|
||||
rf.findInDataDir(buf);
|
||||
|
||||
/* search the font */
|
||||
for (dir=dirs; dir; dir=dir->next) {
|
||||
/* load the font */
|
||||
f = ji_font_load(dir->path);
|
||||
// Search the font
|
||||
while (const char* path = rf.next()) {
|
||||
// Load the font
|
||||
f = ji_font_load(path);
|
||||
if (f)
|
||||
break;
|
||||
else {
|
||||
if (exists(dir->path))
|
||||
PRINTF("Unknown font format \"%s\"\n", dir->path);
|
||||
if (exists(path))
|
||||
PRINTF("Unknown font format \"%s\"\n", path);
|
||||
}
|
||||
}
|
||||
|
||||
dirs_free(dirs);
|
||||
|
||||
/* error loading font */
|
||||
// Error loading font
|
||||
if (!f) {
|
||||
Console console;
|
||||
console.printf(_("Error loading font.\n"));
|
||||
|
@ -18,13 +18,13 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <set>
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <cassert>
|
||||
#include <cctype>
|
||||
#include <iterator>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <allegro.h>
|
||||
#include <allegro/internal/aintern.h>
|
||||
@ -34,12 +34,11 @@
|
||||
|
||||
#include "app.h"
|
||||
#include "core/cfg.h"
|
||||
#include "core/dirs.h"
|
||||
#include "file/file.h"
|
||||
#include "modules/gfx.h"
|
||||
#include "modules/gui.h"
|
||||
#include "widgets/fileview.h"
|
||||
#include "recent_files.h"
|
||||
#include "widgets/fileview.h"
|
||||
|
||||
#if (DEVICE_SEPARATOR != 0) && (DEVICE_SEPARATOR != '\0')
|
||||
# define HAVE_DRIVES
|
||||
|
@ -25,13 +25,13 @@
|
||||
#include "jinete/jlist.h"
|
||||
|
||||
#include "core/cfg.h"
|
||||
#include "core/dirs.h"
|
||||
#include "effect/convmatr.h"
|
||||
#include "effect/effect.h"
|
||||
#include "modules/palettes.h"
|
||||
#include "raster/image.h"
|
||||
#include "raster/palette.h"
|
||||
#include "raster/rgbmap.h"
|
||||
#include "resource_finder.h"
|
||||
#include "util/filetoks.h"
|
||||
|
||||
/* TODO warning: this number could be dangerous for big filters */
|
||||
@ -159,7 +159,6 @@ void reload_matrices_stock()
|
||||
"convmatr.def", NULL };
|
||||
char *s, buf[256], leavings[4096];
|
||||
int i, c, w, h, div, bias;
|
||||
DIRS *dirs, *dir;
|
||||
ConvMatr *convmatr;
|
||||
FILE *f;
|
||||
char *name;
|
||||
@ -167,11 +166,12 @@ void reload_matrices_stock()
|
||||
clean_matrices_stock();
|
||||
|
||||
for (i=0; names[i]; i++) {
|
||||
dirs = filename_in_datadir(names[i]);
|
||||
ResourceFinder rf;
|
||||
rf.findInDataDir(names[i]);
|
||||
|
||||
for (dir=dirs; dir; dir=dir->next) {
|
||||
/* open matrices stock file */
|
||||
f = fopen(dir->path, "r");
|
||||
while (const char* path = rf.next()) {
|
||||
// Open matrices stock file
|
||||
f = fopen(path, "r");
|
||||
if (!f)
|
||||
continue;
|
||||
|
||||
@ -285,11 +285,9 @@ void reload_matrices_stock()
|
||||
if (convmatr)
|
||||
convmatr_free(convmatr);
|
||||
|
||||
/* close the file */
|
||||
// Close the file
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
dirs_free(dirs);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,10 +24,10 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "core/cfg.h"
|
||||
#include "core/dirs.h"
|
||||
#include "intl/intl.h"
|
||||
#include "intl/msgids.h"
|
||||
#include "modules/gui.h"
|
||||
#include "resource_finder.h"
|
||||
|
||||
IntlModule::IntlModule()
|
||||
{
|
||||
@ -51,22 +51,20 @@ IntlModule::~IntlModule()
|
||||
void intl_load_lang()
|
||||
{
|
||||
const char *lang = intl_get_lang();
|
||||
DIRS *dirs, *dir;
|
||||
char buf[512];
|
||||
|
||||
sprintf(buf, "po/%s.po", lang);
|
||||
dirs = filename_in_datadir(buf);
|
||||
ResourceFinder rf;
|
||||
rf.findInDataDir(buf);
|
||||
|
||||
for (dir=dirs; dir; dir=dir->next) {
|
||||
if ((dir->path) && exists (dir->path)) {
|
||||
if (msgids_load (dir->path) < 0) {
|
||||
/* TODO error loading language file... doesn't matter */
|
||||
while (const char* path = rf.next()) {
|
||||
if (exists(path)) {
|
||||
if (msgids_load(path) < 0) {
|
||||
// TODO error loading language file... doesn't matter
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
dirs_free(dirs);
|
||||
}
|
||||
|
||||
const char *intl_get_lang()
|
||||
|
@ -22,17 +22,16 @@
|
||||
#include <allegro/internal/aintern.h>
|
||||
|
||||
#include "jinete/jintern.h"
|
||||
#include "jinete/jrect.h"
|
||||
#include "jinete/jsystem.h"
|
||||
#include "jinete/jtheme.h"
|
||||
#include "jinete/jrect.h"
|
||||
|
||||
#include "Vaca/Rect.h"
|
||||
#include "Vaca/Point.h"
|
||||
#include "Vaca/Rect.h"
|
||||
|
||||
#include "console.h"
|
||||
#include "app.h"
|
||||
#include "console.h"
|
||||
#include "core/cfg.h"
|
||||
#include "core/dirs.h"
|
||||
#include "modules/gfx.h"
|
||||
#include "modules/gui.h"
|
||||
#include "modules/palettes.h"
|
||||
|
@ -29,21 +29,20 @@
|
||||
#include <winalleg.h>
|
||||
#endif
|
||||
|
||||
#include "Vaca/SharedPtr.h"
|
||||
#include "jinete/jinete.h"
|
||||
#include "jinete/jintern.h"
|
||||
#include "Vaca/SharedPtr.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "commands/command.h"
|
||||
#include "commands/commands.h"
|
||||
#include "commands/params.h"
|
||||
#include "console.h"
|
||||
#include "app.h"
|
||||
#include "core/cfg.h"
|
||||
#include "core/core.h"
|
||||
#include "core/dirs.h"
|
||||
#include "core/drop_files.h"
|
||||
#include "intl/msgids.h"
|
||||
#include "gfxmode.h"
|
||||
#include "intl/msgids.h"
|
||||
#include "modules/editors.h"
|
||||
#include "modules/gfx.h"
|
||||
#include "modules/gui.h"
|
||||
@ -51,13 +50,14 @@
|
||||
#include "modules/rootmenu.h"
|
||||
#include "modules/skinneable_theme.h"
|
||||
#include "raster/sprite.h"
|
||||
#include "resource_finder.h"
|
||||
#include "sprite_wrappers.h"
|
||||
#include "tools/toolbox.h"
|
||||
#include "ui_context.h"
|
||||
#include "util/recscr.h"
|
||||
#include "widgets/editor.h"
|
||||
#include "widgets/statebar.h"
|
||||
#include "widgets/toolbar.h"
|
||||
#include "tools/toolbox.h"
|
||||
|
||||
#define REBUILD_RECENT_LIST 2
|
||||
#define REFRESH_FULL_SCREEN 4
|
||||
@ -613,7 +613,6 @@ static void reload_default_font()
|
||||
JTheme theme = ji_get_theme();
|
||||
SkinneableTheme* skinneable_theme = static_cast<SkinneableTheme*>(theme);
|
||||
const char *user_font;
|
||||
DIRS *dirs, *dir;
|
||||
|
||||
// No font for now
|
||||
if (theme->default_font && theme->default_font != font)
|
||||
@ -622,18 +621,18 @@ static void reload_default_font()
|
||||
theme->default_font = NULL;
|
||||
|
||||
// Directories
|
||||
dirs = dirs_new();
|
||||
ResourceFinder rf;
|
||||
|
||||
user_font = get_config_string("Options", "UserFont", "");
|
||||
if ((user_font) && (*user_font))
|
||||
dirs_add_path(dirs, user_font);
|
||||
rf.addPath(user_font);
|
||||
|
||||
// TODO This should be in SkinneableTheme class
|
||||
dirs_cat_dirs(dirs, filename_in_datadir(skinneable_theme->get_font_filename().c_str()));
|
||||
rf.findInDataDir(skinneable_theme->get_font_filename().c_str());
|
||||
|
||||
// Try to load the font
|
||||
for (dir=dirs; dir; dir=dir->next) {
|
||||
theme->default_font = ji_font_load(dir->path);
|
||||
while (const char* path = rf.next()) {
|
||||
theme->default_font = ji_font_load(path);
|
||||
if (theme->default_font) {
|
||||
if (ji_font_is_scalable(theme->default_font))
|
||||
ji_font_set_size(theme->default_font, 8*jguiscale());
|
||||
@ -641,8 +640,6 @@ static void reload_default_font()
|
||||
}
|
||||
}
|
||||
|
||||
dirs_free(dirs);
|
||||
|
||||
// default font: the Allegro one
|
||||
if (!theme->default_font)
|
||||
theme->default_font = font;
|
||||
@ -677,27 +674,24 @@ void save_window_pos(JWidget window, const char *section)
|
||||
JWidget load_widget(const char *filename, const char *name)
|
||||
{
|
||||
JWidget widget;
|
||||
DIRS *it, *dirs;
|
||||
char buf[512];
|
||||
bool found = false;
|
||||
|
||||
dirs = dirs_new();
|
||||
ResourceFinder rf;
|
||||
|
||||
rf.addPath(filename);
|
||||
|
||||
usprintf(buf, "widgets/%s", filename);
|
||||
rf.findInDataDir(buf);
|
||||
|
||||
dirs_add_path(dirs, filename);
|
||||
dirs_cat_dirs(dirs, filename_in_datadir(buf));
|
||||
|
||||
for (it=dirs; it; it=it->next) {
|
||||
if (exists(it->path)) {
|
||||
ustrcpy(buf, it->path);
|
||||
while (const char* path = rf.next()) {
|
||||
if (exists(path)) {
|
||||
ustrcpy(buf, path);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
dirs_free(dirs);
|
||||
|
||||
if (!found)
|
||||
throw widget_file_not_found(filename);
|
||||
|
||||
|
@ -18,23 +18,23 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <allegro/file.h>
|
||||
#include <allegro/unicode.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <allegro/unicode.h>
|
||||
#include <allegro/file.h>
|
||||
|
||||
#include "jinete/jinete.h"
|
||||
|
||||
#include "commands/commands.h"
|
||||
#include "app.h"
|
||||
#include "commands/command.h"
|
||||
#include "commands/commands.h"
|
||||
#include "commands/params.h"
|
||||
#include "console.h"
|
||||
#include "app.h"
|
||||
#include "core/core.h"
|
||||
#include "core/dirs.h"
|
||||
#include "intl/intl.h"
|
||||
#include "modules/rootmenu.h"
|
||||
#include "modules/gui.h"
|
||||
#include "modules/rootmenu.h"
|
||||
#include "resource_finder.h"
|
||||
#include "tools/toolbox.h"
|
||||
#include "util/filetoks.h"
|
||||
#include "widgets/menuitem.h"
|
||||
@ -100,19 +100,20 @@ static int load_root_menu()
|
||||
cel_popup_menu = NULL;
|
||||
cel_movement_popup_menu = NULL;
|
||||
|
||||
DIRS* dirs = filename_in_datadir("gui.xml");
|
||||
ResourceFinder rf;
|
||||
rf.findInDataDir("gui.xml");
|
||||
|
||||
for (DIRS* dir=dirs; dir; dir=dir->next) {
|
||||
PRINTF("Trying to load GUI definition file from \"%s\"...\n", dir->path);
|
||||
while (const char* path = rf.next()) {
|
||||
PRINTF("Trying to load GUI definition file from \"%s\"...\n", path);
|
||||
|
||||
if (!exists(dir->path))
|
||||
if (!exists(path))
|
||||
continue;
|
||||
|
||||
PRINTF(" - \"%s\" found\n", dir->path);
|
||||
PRINTF(" - \"%s\" found\n", path);
|
||||
|
||||
/* open the XML menu definition file */
|
||||
TiXmlDocument doc;
|
||||
if (!doc.LoadFile(dir->path))
|
||||
if (!doc.LoadFile(path))
|
||||
throw ase_exception(&doc);
|
||||
|
||||
TiXmlHandle handle(&doc);
|
||||
@ -121,12 +122,12 @@ static int load_root_menu()
|
||||
/* load menus */
|
||||
/**************************************************/
|
||||
|
||||
PRINTF(" - Loading menus from \"%s\"...\n", dir->path);
|
||||
PRINTF(" - Loading menus from \"%s\"...\n", path);
|
||||
|
||||
root_menu = load_menu_by_id(handle, "main_menu");
|
||||
if (!root_menu)
|
||||
throw ase_exception("Error loading main menu from file:\n%s\nReinstall the application.",
|
||||
static_cast<const char*>(dir->path));
|
||||
static_cast<const char*>(path));
|
||||
|
||||
layer_popup_menu = load_menu_by_id(handle, "layer_popup");
|
||||
frame_popup_menu = load_menu_by_id(handle, "frame_popup");
|
||||
@ -137,7 +138,7 @@ static int load_root_menu()
|
||||
/* load keyboard shortcuts for commands */
|
||||
/**************************************************/
|
||||
|
||||
PRINTF(" - Loading commands keyboard shortcuts from \"%s\"...\n", dir->path);
|
||||
PRINTF(" - Loading commands keyboard shortcuts from \"%s\"...\n", path);
|
||||
|
||||
// <gui><keyboard><commands><key>
|
||||
TiXmlElement* xmlKey = handle
|
||||
@ -190,7 +191,7 @@ static int load_root_menu()
|
||||
/* load keyboard shortcuts for tools */
|
||||
/**************************************************/
|
||||
|
||||
PRINTF(" - Loading tools keyboard shortcuts from \"%s\"...\n", dir->path);
|
||||
PRINTF(" - Loading tools keyboard shortcuts from \"%s\"...\n", path);
|
||||
|
||||
// <gui><keyboard><tools><key>
|
||||
xmlKey = handle
|
||||
@ -220,13 +221,11 @@ static int load_root_menu()
|
||||
}
|
||||
}
|
||||
|
||||
dirs_free(dirs);
|
||||
|
||||
// no menus
|
||||
// No menus
|
||||
if (!root_menu)
|
||||
throw ase_exception("Error loading main menu\n");
|
||||
|
||||
/* sets the "menu" of the "menu-bar" to the new "root-menu" */
|
||||
// Sets the "menu" of the "menu-bar" to the new "root-menu"
|
||||
if (app_get_menubar()) {
|
||||
jmenubar_set_menu(app_get_menubar(), root_menu);
|
||||
app_get_top_window()->remap_window();
|
||||
|
@ -21,15 +21,15 @@
|
||||
#include <allegro.h>
|
||||
#include <allegro/internal/aintern.h>
|
||||
|
||||
#include "Vaca/SharedPtr.h"
|
||||
#include "jinete/jinete.h"
|
||||
#include "jinete/jintern.h"
|
||||
#include "Vaca/SharedPtr.h"
|
||||
|
||||
#include "core/dirs.h"
|
||||
#include "loadpng.h"
|
||||
#include "ase_exception.h"
|
||||
#include "modules/skinneable_theme.h"
|
||||
#include "loadpng.h"
|
||||
#include "modules/gui.h"
|
||||
#include "modules/skinneable_theme.h"
|
||||
#include "resource_finder.h"
|
||||
|
||||
#include "tinyxml.h"
|
||||
|
||||
@ -164,20 +164,21 @@ void SkinneableTheme::reload_skin()
|
||||
// Load the skin sheet
|
||||
std::string sheet_filename = ("skins/" + m_selected_skin + "/sheet.png");
|
||||
{
|
||||
DIRS* dirs = filename_in_datadir(sheet_filename.c_str());
|
||||
for (DIRS* dir=dirs; dir; dir=dir->next) {
|
||||
if ((dir->path) && exists(dir->path)) {
|
||||
ResourceFinder rf;
|
||||
rf.findInDataDir(sheet_filename.c_str());
|
||||
|
||||
while (const char* path = rf.next()) {
|
||||
if (exists(path)) {
|
||||
int old_color_conv = _color_conv;
|
||||
set_color_conversion(COLORCONV_NONE);
|
||||
|
||||
PALETTE pal;
|
||||
m_sheet_bmp = load_png(dir->path, pal);
|
||||
m_sheet_bmp = load_png(path, pal);
|
||||
|
||||
set_color_conversion(old_color_conv);
|
||||
break;
|
||||
}
|
||||
}
|
||||
dirs_free(dirs);
|
||||
}
|
||||
if (!m_sheet_bmp)
|
||||
throw ase_exception("Error loading %s file", sheet_filename.c_str());
|
||||
@ -200,13 +201,15 @@ void SkinneableTheme::regen()
|
||||
|
||||
// Load the skin XML
|
||||
std::string xml_filename = "skins/" + m_selected_skin + "/skin.xml";
|
||||
DIRS* dirs = filename_in_datadir(xml_filename.c_str());
|
||||
for (DIRS* dir=dirs; dir; dir=dir->next) {
|
||||
if (!dir->path || !exists(dir->path))
|
||||
ResourceFinder rf;
|
||||
rf.findInDataDir(xml_filename.c_str());
|
||||
|
||||
while (const char* path = rf.next()) {
|
||||
if (!exists(path))
|
||||
continue;
|
||||
|
||||
TiXmlDocument doc;
|
||||
if (!doc.LoadFile(dir->path))
|
||||
if (!doc.LoadFile(path))
|
||||
throw ase_exception(&doc);
|
||||
|
||||
TiXmlHandle handle(&doc);
|
||||
@ -311,7 +314,6 @@ void SkinneableTheme::regen()
|
||||
|
||||
break;
|
||||
}
|
||||
dirs_free(dirs);
|
||||
}
|
||||
|
||||
BITMAP* SkinneableTheme::cropPartFromSheet(BITMAP* bmp, int x, int y, int w, int h, bool cursor)
|
||||
|
179
src/resource_finder.cpp
Normal file
179
src/resource_finder.cpp
Normal file
@ -0,0 +1,179 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2010 David Capello
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <allegro.h>
|
||||
|
||||
#include "resource_finder.h"
|
||||
|
||||
ResourceFinder::ResourceFinder()
|
||||
{
|
||||
m_current = 0;
|
||||
}
|
||||
|
||||
const char* ResourceFinder::first()
|
||||
{
|
||||
if (!m_paths.empty())
|
||||
return m_paths[0].c_str();
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* ResourceFinder::next()
|
||||
{
|
||||
if (m_current == m_paths.size())
|
||||
return NULL;
|
||||
|
||||
return m_paths[m_current++].c_str();
|
||||
}
|
||||
|
||||
void ResourceFinder::addPath(std::string path)
|
||||
{
|
||||
m_paths.push_back(path);
|
||||
}
|
||||
|
||||
void ResourceFinder::findInBinDir(const char* filename)
|
||||
{
|
||||
char buf[1024], path[1024];
|
||||
|
||||
get_executable_name(path, sizeof(path));
|
||||
replace_filename(buf, path, filename, sizeof(buf));
|
||||
|
||||
addPath(buf);
|
||||
}
|
||||
|
||||
void ResourceFinder::findInDataDir(const char* filename)
|
||||
{
|
||||
char buf[1024];
|
||||
|
||||
#if defined ALLEGRO_UNIX || defined ALLEGRO_MACOSX
|
||||
|
||||
// $HOME/.ase/filename
|
||||
sprintf(buf, ".ase/%s", filename);
|
||||
findInHomeDir(buf);
|
||||
|
||||
// $BINDIR/data/filename
|
||||
sprintf(buf, "data/%s", filename);
|
||||
findInBinDir(buf);
|
||||
|
||||
#ifdef DEFAULT_PREFIX
|
||||
// $PREFIX/ase/filename
|
||||
sprintf(buf, "%s/share/ase/%s", DEFAULT_PREFIX, filename);
|
||||
addPath(buf);
|
||||
#endif
|
||||
|
||||
#ifdef ALLEGRO_MACOSX
|
||||
// $BINDIR/aseprite.app/Contents/Resources/data/filename
|
||||
sprintf(buf, "aseprite.app/Contents/Resources/data/%s", filename);
|
||||
findInBinDir(buf);
|
||||
#endif
|
||||
|
||||
#elif defined ALLEGRO_WINDOWS || defined ALLEGRO_DOS
|
||||
|
||||
// $BINDIR/data/filename
|
||||
sprintf(buf, "data/%s", filename);
|
||||
findInBinDir(buf);
|
||||
|
||||
#else
|
||||
|
||||
// filename
|
||||
addPath(filename);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void ResourceFinder::findInDocsDir(const char* filename)
|
||||
{
|
||||
char buf[1024];
|
||||
|
||||
#if defined ALLEGRO_UNIX || defined ALLEGRO_MACOSX
|
||||
|
||||
// $BINDIR/docs/filename
|
||||
sprintf(buf, "docs/%s", filename);
|
||||
findInBinDir(buf);
|
||||
|
||||
#ifdef DEFAULT_PREFIX
|
||||
// $PREFIX/ase/docs/filename
|
||||
sprintf(buf, "%s/share/ase/docs/%s", DEFAULT_PREFIX, filename);
|
||||
addPath(buf);
|
||||
#endif
|
||||
|
||||
#ifdef ALLEGRO_MACOSX
|
||||
// $BINDIR/aseprite.app/Contents/Resources/docs/filename
|
||||
sprintf(buf, "aseprite.app/Contents/Resources/docs/%s", filename);
|
||||
findInBinDir(buf);
|
||||
#endif
|
||||
|
||||
#elif defined ALLEGRO_WINDOWS || defined ALLEGRO_DOS
|
||||
|
||||
// $BINDIR/docs/filename
|
||||
sprintf(buf, "docs/%s", filename);
|
||||
findInBinDir(buf);
|
||||
|
||||
#else
|
||||
|
||||
// filename
|
||||
addPath(filename);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
void ResourceFinder::findInHomeDir(const char* filename)
|
||||
{
|
||||
#if defined ALLEGRO_UNIX || defined ALLEGRO_MACOSX
|
||||
|
||||
char *env = getenv("HOME");
|
||||
char buf[1024];
|
||||
|
||||
if ((env) && (*env)) {
|
||||
// $HOME/filename
|
||||
sprintf(buf, "%s/%s", env, filename);
|
||||
addPath(buf);
|
||||
}
|
||||
else {
|
||||
PRINTF("You don't have set $HOME variable\n");
|
||||
addPath(filename);
|
||||
}
|
||||
|
||||
#elif defined ALLEGRO_WINDOWS || defined ALLEGRO_DOS
|
||||
|
||||
// $PREFIX/data/filename
|
||||
findInDataDir(filename);
|
||||
|
||||
#else
|
||||
|
||||
// filename
|
||||
addPath(filename);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
void ResourceFinder::findConfigurationFile()
|
||||
{
|
||||
#if defined ALLEGRO_UNIX || defined ALLEGRO_MACOSX
|
||||
|
||||
// $HOME/.asepriterc
|
||||
findInHomeDir(".asepriterc");
|
||||
|
||||
#endif
|
||||
|
||||
// $BINDIR/aseprite.ini
|
||||
findInBinDir("aseprite.ini");
|
||||
}
|
@ -16,28 +16,37 @@
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef CORE_DIRS_H_INCLUDED
|
||||
#define CORE_DIRS_H_INCLUDED
|
||||
#ifndef RESOURCE_FINDER_H_INCLUDED
|
||||
#define RESOURCE_FINDER_H_INCLUDED
|
||||
|
||||
typedef struct DIRS DIRS;
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct DIRS
|
||||
class ResourceFinder
|
||||
{
|
||||
char *path;
|
||||
struct DIRS *next;
|
||||
public:
|
||||
ResourceFinder();
|
||||
|
||||
const char* first();
|
||||
const char* next();
|
||||
|
||||
void addPath(std::string path);
|
||||
|
||||
void findInBinDir(const char* filename);
|
||||
void findInDataDir(const char* filename);
|
||||
void findInDocsDir(const char* filename);
|
||||
void findInHomeDir(const char* filename);
|
||||
void findConfigurationFile();
|
||||
|
||||
private:
|
||||
// Disable copy
|
||||
ResourceFinder(const ResourceFinder&);
|
||||
ResourceFinder& operator==(const ResourceFinder&);
|
||||
|
||||
// Members
|
||||
std::vector<std::string> m_paths;
|
||||
int m_current;
|
||||
};
|
||||
|
||||
DIRS *dirs_new();
|
||||
void dirs_free(DIRS *dirs);
|
||||
void dirs_add_path(DIRS *dirs, const char *path);
|
||||
void dirs_cat_dirs(DIRS *dirs, DIRS *more);
|
||||
|
||||
DIRS *filename_in_bindir(const char *filename);
|
||||
DIRS *filename_in_datadir(const char *filename);
|
||||
DIRS *filename_in_docsdir(const char *filename);
|
||||
DIRS *filename_in_homedir(const char *filename);
|
||||
DIRS *filename_in_homedir(const char *filename);
|
||||
DIRS *cfg_filename_dirs();
|
||||
|
||||
#endif
|
||||
|
@ -23,21 +23,21 @@
|
||||
#include <allegro/fixed.h>
|
||||
#include <allegro/fmaths.h>
|
||||
|
||||
#include "core/dirs.h"
|
||||
#include "ase_exception.h"
|
||||
#include "raster/algo.h"
|
||||
#include "raster/image.h"
|
||||
#include "raster/mask.h"
|
||||
#include "raster/pen.h"
|
||||
#include "raster/sprite.h"
|
||||
#include "resource_finder.h"
|
||||
#include "tools/toolbox.h"
|
||||
#include "ase_exception.h"
|
||||
|
||||
#include "tinyxml.h"
|
||||
|
||||
#include "tools/inks.h"
|
||||
#include "tools/controllers.h"
|
||||
#include "tools/point_shapes.h"
|
||||
#include "tools/inks.h"
|
||||
#include "tools/intertwiners.h"
|
||||
#include "tools/point_shapes.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ -120,18 +120,19 @@ void ToolBox::loadTools()
|
||||
{
|
||||
PRINTF("Loading ASE tools\n");
|
||||
|
||||
DIRS* dirs = filename_in_datadir("gui.xml");
|
||||
ResourceFinder rf;
|
||||
rf.findInDataDir("gui.xml");
|
||||
|
||||
for (DIRS* dir=dirs; dir; dir=dir->next) {
|
||||
PRINTF("Trying to load tools from \"%s\"...\n", dir->path);
|
||||
while (const char* path = rf.next()) {
|
||||
PRINTF("Trying to load tools from \"%s\"...\n", path);
|
||||
|
||||
if (!exists(dir->path))
|
||||
if (!exists(path))
|
||||
continue;
|
||||
|
||||
PRINTF(" - \"%s\" found\n", dir->path);
|
||||
PRINTF(" - \"%s\" found\n", path);
|
||||
|
||||
TiXmlDocument doc;
|
||||
if (!doc.LoadFile(dir->path))
|
||||
if (!doc.LoadFile(path))
|
||||
throw ase_exception(&doc);
|
||||
|
||||
// For each group
|
||||
@ -174,8 +175,6 @@ void ToolBox::loadTools()
|
||||
xmlGroup = xmlGroup->NextSiblingElement();
|
||||
}
|
||||
}
|
||||
|
||||
dirs_free(dirs);
|
||||
}
|
||||
|
||||
void ToolBox::loadToolProperties(TiXmlElement* xmlTool, Tool* tool, int button, const std::string& suffix)
|
||||
|
Loading…
x
Reference in New Issue
Block a user