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

Fabien Bodard gambas.fr at ...626...
Sun Sep 2 10:32:53 CEST 2012


2012/9/2 Fabien Bodard <gambas.fr at ...626...>:
> 2012/9/2 Bruce <bbruen at ...2308...>:
>> On Sun, 2012-09-02 at 03:54 +0200, Benoît Minisini wrote:
>>> 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>").
>>>
>> Yes, and that works fine.
>>
>>> But a library cannot access files from other libraries, and the main
>>> project cannot access files of any library too.
>>>
>> That's right too.
>>
>>> A workaround is opening the file where it is accessible, and sending
>>> File references through libraries.
>>>
>> This is the bit that I can't get to work. The library cannot open a file
>> inside its' @own executable@ using that "special notation" as that
>> refers to the main project (and therefore I can't send the File
>> references).
>>
>>> Regards,
>>>
>>
>> regards
>> Bruce
>>
>>
>>
>> ------------------------------------------------------------------------------
>> Live Security Virtual Conference
>> Exclusive live event will cover all the ways today's security and
>> threat landscape has changed and how IT managers can respond. Discussions
>> will include endpoint security, mobile security and the latest in malware
>> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
>> _______________________________________________
>> Gambas-user mailing list
>> Gambas-user at lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
>
> NO, Benoit say that :
>
>
> In the library :
>
> Public Function GetFile(sFile as String) as File
>
>   Dim hFile as File
>   Return Open sFile For read
>
> End
>
>
>
>
> In the main program
>
> Dim hFile as File
>
> hFile = MyLibClass.GetFile("dir/file")
>
> End
>
> Then you can use for example
>
> Line Input #hFile, s
>
>
>
>
> --
> Fabien Bodard

Haa and for the invert ... Get the file from the main program :

Public sub Main
Dim hFile as File
Dim hLibClass as hLibClass
File =Open sFile For read
hLibClass = New hLibClas(hFile)

End


in Library

Public sub _New(hFile as File)

dim s as string

Line Input #hFile, s



-- 
Fabien Bodard




More information about the User mailing list