View Full Version : INI file to control my app?
TheProg
03-14-2008, 02:47 PM
Hi I am really not sure how to explain this, but I will try my best.
I am making a new setup program, and this will setup various programs, drivers & customisations.
The part I am stuck at is there is a page with 2 buttons (1 labeled T30 & the other T41), now when someone clicks on the relevant button, I need my program to store the users choice in a .ini file, as in the code below:
INIFile.SetValue(_WindowsFolder.."\\NewInstall.ini", "System Information", "Laptop Make", "IBM Thinkpad T41");
Now this is the tricky bit, I have a button on the next page called "Install Drivers" and what I need is that it will install the relevant set of drivers for the chosen button above (either T30 or T41) as the zip files are labeled "T30 Drivers" and "T41 Drivers" so is it at all possible that if I clicked on the T30 button it would store this choice in the ini file, and then when I click on the drivers button for it to unzip the relevant zip?
Thanks all! :)
ShadowUK
03-14-2008, 04:42 PM
if (INIFile.GetValue(_WindowsFolder.."\\NewInstall.ini", "System Information", "Laptop Make",) == "IBM Thinkpad T41") then
-- The laptop is a IBM Thinkpad T41
else
-- The laptop is a IBM Thinkpad T30
end
Now this is just quick out of my head just as an example. You can expand on this and use the File.Install function to install the files rather then extracting them directly to the location you want. You'll have to extract the files to a temp location, then install them from that location. That is of course if you want them to be installed like that? Also, don't forget to clean up after yourself, any files you put on the users machine that are not absolutely required to be there should be removed, always.
Just a note. I use local variables when ever possible. They are faster, and they are cleared right after they are no longer used. Global variables in Lua are not cleared until a garbagecollect is done, they are also slower. Unless you absolutely need all your variables to be global, remember to put 'local' in front of them. You will notice the difference in speed, and in memory usage. And it is good programming practice.
So with that, the example:
Button 1 ; T41
INIFile.SetValue(_WindowsFolder.."\\NewInstall.ini", "System Information", "Laptop Make", "IBM Thinkpad T41");
Button 2; T30
INIFile.SetValue(_WindowsFolder.."\\NewInstall.ini", "System Information", "Laptop Make", "IBM Thinkpad T30");
Button 3; Drivers Install
local usrModel = INIFile.GetValue(_WindowsFolder.."\\NewInstall.ini", "System Information", "Laptop Make");
if (usrModel ~= "") then
-- Install drivers. This way will only work if the drivers .zip
-- archives are named the same as what you store in the ini.
local sDrvFile = _SourceFolder.."\\"..usrModel..".zip";
local sExtractLocation = "where ever you want them extracted too";
-- Extract to location
Zip.Extract(sDrvFile, {"*.*"}, sExtractLocation, true, false, "", ZIP_OVERWRITE_NEWER, nil);
local err = Application.GetLastError();
if (err ~= 0) then
Dialog.Message("Error", _tblErrorMessages[err], MB_OK, MB_ICONEXCLAMATION);
return -1; --return false, return what ever to stop any further code execution.
end
end
TheProg
03-15-2008, 06:00 AM
Thanks ever so much for your replies and you *REALLY* need to get more sleep if your up here till all hours hehe :)
@ Bags: thanks for your opening lines, but this project is for just my household PC's, and I have set the drivers zip to extract to d:\drivers (second partition on laptop hard drive, I put all the data like programs, my music, pics, email & MSN folders on a second partition, as if the main boot part fails, I still have the stuff safe that is important to me, but also do a full drive backup once a week & made a lil network backup util so all my docs & stuff get copied over to my server hd far safe keeping!)
I shall try out the code later and post back with what I find :)
Thanks once again you 2 :)
rexzooly
03-15-2008, 07:04 AM
Thanks ever so much for your replies and you *REALLY* need to get more sleep if your up here till all hours hehe :)
@ Bags: thanks for your opening lines, but this project is for just my household PC's, and I have set the drivers zip to extract to d:\drivers (second partition on laptop hard drive, I put all the data like programs, my music, pics, email & MSN folders on a second partition, as if the main boot part fails, I still have the stuff safe that is important to me, but also do a full drive backup once a week & made a lil network backup util so all my docs & stuff get copied over to my server hd far safe keeping!)
I shall try out the code later and post back with what I find :)
Thanks once again you 2 :)
just to state something here doing that to a drive is really not a good idea
its alwasys better to have 2 drives to do that kinda thing with as the drives will last longer.
but i guess we all do it at one point i had mine partioned a thou times
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.