[Gambas-user] Files inside executables - access strategy advice (advanced)

Benoît Minisini gambas at ...1...
Sun Sep 2 03:54:50 CEST 2012


Le 02/09/2012 03:44, Bruce a écrit :
> Is there an easy way to access files inside a library or component
> executable?  Or more correctly, "What is the best way..."
>
> I am abstracting some common database methods into a library out of
> several of our apps.  The problem I am having is that these methods rely
> on some metadata files that currently have to be copied into each
> application (and thus is a potential version error source).  I would
> like to put the metadata inside the library executable so that every app
> using the library will be using the same metadata files.
>
> Here's the structure that is giving me Grief!
>
> MyApplication ---uses---> LibAppData ---uses--> LibBO
>
> LibBO provides the low level database access and consists of primarily a
> class that acts as the parent class for all the LibAppData classes,
> which in turn represent fairly complex "business data objects".  At the
> moment the metadata representing the persistence maps for the objects
> reside in a "BOMeta" subdir in (each of) the MyApplication executables.
> These metadata files are needed by LibBO.  I can access them simply by
> using
>          File.Load("BOMeta/" & <objectfilename>)
> which works fine as it's just like accessing any file within the
> executable archive.
>
> Maybe a real example would help explain.  Two of our major apps are
> "ManageStable" and "ManageAuctions" (the latter allows the user to
> submit horses for sale at auctions.)
> Both of these use a "horse" business object in LibAppData, so they both
> currently need to have the metadata file "horseBO.meta" included at the
> application level.  I want to move that metadata file into LibAppData.
> But then LibBO cannot just access the file using the above simple
> method.
>
> So far I have planned it along the following line:
> 1) In LibAppData HorseBO._init() needs to copy all its metadata files
> into a Temp$ directory.  This should be done in _init so that the files
> are only copied once during an execution, not everytime a horse object
> is created.
> 2) LibBO can then expect to find the metadata in the
> relevant /tmp/gambas.500/<process> directory.
>
> However, this fails to impress as firstly, there are over 30 different
> business object classes and the copy would be invoked every time one of
> the LibAppData classes is loaded and secondly, only some of the business
> object classes are used by an individual app.
>
> Can anyone see or suggest a better way to do this?
>
> tia
> Bruce
>

I don't think I have understood everything...

A library can access any file located in the main project (by using the 
special notation "../<path>").

But a library cannot access files from other libraries, and the main 
project cannot access files of any library too.

A workaround is opening the file where it is accessible, and sending 
File references through libraries.

Regards,

-- 
Benoît Minisini




More information about the User mailing list