Re: [AD] Allegro 4.3 file location API

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On November 15, 2005 09:37 pm, Matthew Leverton wrote:
> > I think this changes durasiticaly from version to
> > version.  Sometimes you want it in
> > c:\winnt\application data or other obscure places.
>
> It doesn't matter what you the programmer want, it matters what the
> registry says the user wants. Maybe this is all you are saying, but
> Peter mentioned using the registry to determine the file location.
>
> Regarding the overall idea, I think it is a must.
>
> One note on "APP_RESOURCES -> c:\program files\%APP_ID%\"
>
> I think that would have to be $EXE_FOLDER for Windows.
>
> It would also be nice to be able to tell Allegro to magically look in
> those places when loading bitmaps, etc. For example,
> load_bmp("foo.bmp") would automatically look in APP_RESOURCES for the
> file if a relative path was given. That way you don't have to build
> the paths yourself every time.
>
> I assume you mean for that to happen somehow, but it isn't explicitly
> mentioned.
>

I think thats an excelent idea, extend allegro's current "find resource" crap 
to search a list of PATHs for various types of resources. I made a simple 
setup for my Qt4 apps (attached).

Of course we'll have to have something that fits allegro, and in C, but 
something allong the same lines would make sense. Except, maybe instead of 
the ugly ifdefs, we just use a few entries in allegro's system vtable:

add_resource_path(type, path)
find_resource(type, append)

that should be all thats nesesary..
static QString getDataPath(QString append = QString());
static void addResourcePath(QString p);
static QString getResourcePath(QString p);
template <typename T>
static T findResource(QString name) { return T(getResourcePath(name)); }
QIcon SciQApp::getIcon(QString name) {
   return findResource<QPixmap>(QString("images/%1.png").arg(name));
}

void SciQApp::initResourcePath() {
   QString tmp;
#ifdef Q_OS_UNIX
   // add /home/user/.SciQ
   tmp = catdir(QStringList() + QDir::homePath() + QString(".%1").arg(applicationName()));
   addResourcePath(tmp);

   // add /usr/share/SciQ
   tmp = catdir(QStringList() + QDir::rootPath() + "usr" + "share" + applicationName());
   addResourcePath(tmp);

#elif defined Q_OS_WIN32
   // This win32 code hasn't been tested...
   char szPath[MAX_PATH];
   if(SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, szPath)))
      /*
         CSIDL_APPDATA
            The file system directory that serves as a common repository for application-specific data.
            A typical path is C:\Documents and Settings\username\Application Data.

         I chose to try this before the code in the "else" clause,
         because who knows if the folder is really "Application Data",
         as I assume below.
      */
      tmp = catdir(QStringList() + szPath + applicationName());
   else
      tmp = catdir(QStringList() + QDir::homePath() + "Application Data" + applicationName());

   addResourcePath(tmp);


   QString def = catdir(QStringList() + QDir::rootPath() + "Program Files" + applicationName());
   // if the installer saved a "installpath" var... if not, just assume %ROOT%\Program Files\SciQ
   addResourcePath(qs.value("installpath", def).toString());
#endif

   // And for good measure, add %TEMP%/SciQ
   tmp = catdir(QStringList() + QDir::tempPath() + applicationName());
   addResourcePath(tmp);
}


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/