Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to distribute files (such as .reg, third party utilities, office docs etc) within your apps

Status
Not open for further replies.

GriffMG

Programmer
Mar 4, 2002
6,288
1
38
FR
I thought it might be helpful to explain how I distribute the files that are required to
support my applications using a free table within the app itself.

First I add a table to the application called BINARIES.DBF it has a simple structure:

Name (character 10) not null
Binary (memo (binary)) not null

I add records to this for each file I want to include, then replace the Binary field with the file I want
Code:
select 0
use ("D:\projects\myproject\binaries")
append blank
replace binaries.Name with "WORDFILE1", binaries.binary with filetostr("the file I want.docx")
use

Then when I need the file deployed I just do this (m.WHERAMI is a variable that has the location of the .exe):
Code:
select 0
use ("D:\projects\myproject\binaries")
locate for name="WORDFILE1"
strtofile(binaries.binary,m.WHEREAMI+"WordFile.docx")
use

To use this to distribute and install the reg changes for W11 and general fields I put a button on my utilities menu
with this code in the click method:
Code:
IF !MYFILE(m.WHEREAMI+"BitmapImage.reg")
	SELECT 0
	USE (D:\projects\myproject\BINARIES")
	LOCATE FOR NAME = "BITMAP"
	IF FOUND()
		STRTOFILE(sound.sound,m.WHEREAMI+"BitmapImage.reg")
		BROWSER(m.WHEREAMI+"BitmapImage.reg")
	ENDIF
	USE
ENDIF
IF !MYFILE(m.WHEREAMI+"Paint.Picture.reg")
	SELECT 0
	USE (D:\projects\myproject\BINARIES")
	LOCATE FOR NAME = "PAINT"
	IF FOUND()
		STRTOFILE(sound.sound,m.WHEREAMI+"Paint.Picture.reg")
		BROWSER(m.WHEREAMI+"Paint.Picture.reg")
	ENDIF
	USE
ENDIF

Myfile() is a variation on FILE() that eliminates the false positives caused by the Path
Browser is just a wrapper for ShellExecute
Code:
FUNCTION MYFILE
	PARAMETER m.FILENAME
	PRIVATE m.FILENAME,m.FLG
	m.FLG = .F.
	IF !EMPTY(m.FILENAME)
		IF ADIR(TMPDIRFILES,m.FILENAME) > 0
			m.FLG = .T.
		ENDIF
	ENDIF
	RETURN(m.FLG)

FUNCTION BROWSER
	PARAMETER m.FILENAME,m.LINEPARAMS,m.TESTFILE
	LOCAL LNRETVAL, LCOPERATION
	PRIVATE m.FILENAME,m.LINEPARAMS,m.TESTFILE
	LCOPERATION = "Open"
	**
	DECLARE INTEGER ShellExecute IN SHELL32.DLL ;
		INTEGER handle,;
		STRING @sFile,;
		STRING @lp,;
		STRING @DIR,;
		STRING @dir1,;
		INTEGER ncmd
	**
	IF PCOUNT() < 3
		m.TESTFILE = .T.
	ENDIF
	IF PCOUNT() < 2
		m.LINEPARAMS = ""
	ENDIF
	IF m.TESTFILE
		IF MYFILE(m.FILENAME)
			LNRETVAL = SHELLEXECUTE(0, LCOPERATION, m.FILENAME, m.LINEPARAMS, "", 1)
		ELSE
			MESSAGEBOX("Unable to locate the file/folder/web page:"+m.FILENAME,48,"Problem")
		ENDIF
	ELSE
		LNRETVAL = SHELLEXECUTE(0, LCOPERATION, m.FILENAME, m.LINEPARAMS, "", 1)
	ENDIF
	CLEAR DLLS SHELLEXECUTE
	RETURN(.F.)

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
Why use a table to store the binaries?

You can embed any file into an EXE and copy it outside with STRTOFILE(FILETOSTR('filename'),'destination\filename'), provided the file doesn't exceed 16MB.
I hear you saying Locate in the table is simple enough and you're even able to have longer files in a binary memo.

Well, there's the problem STRTOFILE() is limited to 16MB, not so much FILETOSTR.

Chriss
 
Hello,

we include a "systable" in the project.

It contains dbc, dll, .exe for commandline tools, icons/picture (because of foxypreviewer) to be extracted to user's \temp on startup.
There is a field description (for us) and a utype I field. Depending on utype and userlicence tools/pictures will be extracted or not.
It also decides whether alway overwrite.
Having the dbc always local made the 1709 errors disappear.
Its easy to update systable content and with REFOX packs very good.

Regards
Tom

 
I download (or update) the files from a file server on the internet.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top