Hello everyone,

I recently had a need to write a bit of code that would allow my app to "know" where the HF classic data files were stored on my app's network. In a production environment, my app's EXE is installed on each client PC and on a "main" PC acting as the system "server" in the "C:\Program Files\System" folders. The HF classic data files are stored in a shared folder on the "server" such as "C:\SystemData" and shared appropriately (Where "System" is your app name).

This all came about via a topic I raised on the main Windev forum concerning "where does WD look for data files?" - [forum.mysnip.de]

Via this thread, I decided to go down the INI file route.

So, here goes - You'll need something like the code below for the INI file processing. I've tried to keep it logical rather than "fancy" for maintenance purposes. It needs to go in your Project Code (well that's were I put it), before any data files are processed.

// Setup var for processing INI file
gproviINIResult is int
gprovsFolder is string

// Handle the INI file for Network drive location
IF fDirectoryExist(fExeDir()) THEN
	
	// If INI file exists then read the 'Drive' entry
	IF fFileExist(fExeDir + "\System.INI") THEN
		// If found, then read it
		gprovsFolder = INIRead("NetworkDrive","Drive","",fExeDir + "\System.INI")
	ELSE
		// INI file not found, so browse for network drive
		gprovsFolder = UserSelectDataDir()
		// Test for no folder selected
		IF gprovsFolder = "" THEN
			// Error already reported in UserSelectDataDir, so get out of here
			EndProgram()
		ELSE
			// Directory selected, so Create/Write INI file entry
			gproviINIResult = INIWrite("NetworkDrive","Drive",gprovsFolder,fExeDir + "\System.INI")
		END
	END
ELSE
	
	// Directory doesn't already exist, so create DIR
	fMakeDir(fExeDir())
	// INI file not found, so browse for network drive
	gprovsFolder = UserSelectDataDir()
	// Test for no folder selected
	IF gprovsFolder = "" THEN
		// Error already reported in UserSelectDataDir, so get out of here
		EndProgram()
	ELSE
		// Directory selected, so Create/Write INI file entry
		gproviINIResult = INIWrite("NetworkDrive","Drive",gprovsFolder,fExeDir + "\System.INI")
	END
END

// Now swap to the drive selected...
HChangeDir("*",gprovsFolder)

The UserSelectDataDir is a procedure purely to avoid repeating the code:

PROCEDURE UserSelectDataDir()

glocalsDataFolder is string

// Browse for network drive
glocalsDataFolder = fSelectDir("", "Select a directory...", "I can't seem to locate your data files. Please select the server network directory that contains your data files OR, if this is your server, select the local directory that contains the data files.", "")

// Test for no folder selected
IF glocalsDataFolder = "" THEN
	Error("You must select a local or network folder  to continue!","Please re-run the system.",...
	"If this problem persists or you are not able to select the required folder, then please contact your system administrator for help.")
END

// Return the folder (blank or otherwise)
RESULT glocalsDataFolder

So now when you run your app on each PC for the first time, you'll be asked where your data files are. From then on, your app will read the INI file on each PC to locate the data files. If you move your data files for any reason, then all you need to do is either amend the INI files on the PC's or delete them and you'll be re-prompted - it's as simple as that! :cheers:

Hope this helps you on your way...
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: