She's ALMOST ready, Sepulchre, & here the the 'prototype' screen of it:
APK Hosts File ReWriter 1.0++:
Thusfar (I just have to pull some hardcodes, which I am going to switch to Open Dialogboxes & Save Dialogboxes, because currently I am using hardcoded locations to my files to import/scrub, normalize, & export... as to file locations & exported files (not consistent here, yet))
"The LITTLE engine, that could", & here is the "Active Ingredient" recursively called routine (not a function anymore, OR even an "inlined function" (possible in Delphi/Object Pascal, right inside of a procedure/subroutine no less)):
=============================
procedure TForm1.Button3Click(Sender: TObject); register;
var
I:Integer;
J:Integer;
begin inherited;
ProgressBar1.Min:=0;
ProgressBar1.Max:=Form1.ListBox1.Items.Count - 1;
Screen.Cursor:=crHourGlass;
ListBox1.OnClick(self); //Puts it into first entry + selected... apk
Form1.ListBox2.AddItem(Form1.ListBox1.Items[0], Self);
If GlobalCPUFlag <> 1 then Application.ProcessMessages;
BitBtn1.Enabled:=False;
Button1.Enabled:=False;
Button2.Enabled:=False;
Button3.Enabled:=False;
Button4.Enabled:=False;
DeleteSelectedItem1.Enabled:=False;
Label3.Caption:= Trim(DateTimeToStr(now));
Label3.Update;
Label3.Refresh;
Label4.Caption:= Trim('Waiting to load temporary variable for comparison to complete...');
Label4.Update;
Label4.Refresh;
StatusBar1.SimpleText:= Trim('Waiting to load temporary variable for comparison to complete...');
StatusBar1.Update;
StatusBar1.Refresh;
If GlobalCPUFlag <> 1 then Application.ProcessMessages;
try
//================================================== ============
// Main RECURSIVELY CALLED Engine/Algorithm... apk
//================================================== ============
{COPYRIGHT APK - Alexander Peter Kowalski 06/01/2008 onwards}
For I:= 0 to Form1.ListBox1.Items.Count-1 do
begin
Form1.ListBox1.Selected[i];
Form1.ListBox1.ItemIndex:= i;
//--------------------------------------------------------------
// I was using J:= 0 to Form1.ListBox1.Items.Count -1 here, but technically, it's unneeded: Just
// Go from the current record being searched for dups because the ones before it have been checked... apk
//--------------------------------------------------------------
For J:=i to Form1.ListBox1.Items.Count - 1 do //this "inner loop" does it... apk
begin
If Form1.ListBox1.items[i] = Form1.Label5.Caption then
begin
Form1.ListBox1.Items.Delete(i);
end;
end;
Form1.Label10.Caption:= IntToStr(i) + ' of ' + IntToStr(Form1.ListBox1.Items.Count);
Form1.Label10.Update;
Form1.Label10.Refresh;
ProgressBar1.Position:=i;
ProgressBar1.Update;
StatusBar1.SimpleText:=Trim(Label5.Caption) + ' being compared to ' + ListBox1.Items[i] + ' ...';
StatusBar1.Update;
StatusBar1.Refresh;
//--------------------------------------------------------------
// So far, this is an efficiency savings using i vs. 0 to on inner loop... apk
//--------------------------------------------------------------
end;
//================================================== ============
except
SaveNewListtoDisk1.OnClick(Application.MainForm); //This stalls all the buttons f'ing up
//& saves file "on-the-fly"... apk
Screen.Cursor:=crDefault;
BitBtn1.Enabled:=True;
Button1.Enabled:=True;
Button2.Enabled:=True;
Button3.Enabled:=True;
Button4.Enabled:=True;
DeleteSelectedItem1.Enabled:=True;
StatusBar1.SimpleText:= Trim('Executing Recursive Function...');
StatusBar1.Update;
StatusBar1.Refresh;
If GlobalCPUFlag <> 1 then Application.ProcessMessages;
ListBox1.Selected[0];
ListBox1.ItemIndex:=0;
ListBox2.Selected[0];
ListBox2.ItemIndex:=0;
ListBox1.OnClick(self); //Puts it into first entry + selected... apk
Button3.OnClick(Self); //CREATES THE RECURSION EFFECT VIA USING ERRORS/ABENDS TO DO SO & IT WORKS... apk
If GlobalCPUFlag <> 1 then Application.ProcessMessages;
end;
Screen.Cursor:=crDefault;
If GlobalCPUFlag <> 1 then Application.ProcessMessages;
BitBtn1.Enabled:=True;
Button1.Enabled:=True;
Button2.Enabled:=True;
Button3.Enabled:=True;
Button4.Enabled:=True;
DeleteSelectedItem1.Enabled:=True;
Label4.Caption:= Trim(DateTimeToStr(now));
Label4.Update;
Label4.Refresh;
StatusBar1.SimpleText:=Trim('DONE Removing Duplicates (file normalized)...');
StatusBar1.Update;
StatusBar1.Refresh;
ShowMessage(Trim('Now, rightclick on right pane for popup menu to save disk and you are done normalizing the HOSTS file vs. repeat entries'));
If GlobalCPUFlag <> 1 then Application.ProcessMessages;
end;
=============================
That's the 'recursively self-calling' engine I ended up using Sepulchre... & SHE WORKS (all of it) - It now will (as far as features):
- 1.) Format & "scrub", + import ANY other custom HOSTS file out there, into the MOST efficient format line by line I know of ( 0.0.0.0<singlespace>IPAddress<cr+lf> )
- 2.) Check your HOSTS file for entries into it (new ones, either rejecting them as already existing, OR, adding new one if NOT present already)
- 3.) "Normalize" (remove repeat entries, that often occur by importing the hosts file entries of others) the entire HOSTS file, F A S T (or, rather, faster & more efficiently than I had before, due to better "engine/algorithm" I use above)
(
As a last feature, probably in a tabbed interface setup as I am running out of 'screen real estate' there above - I am going to add a "PINGER" to it also, so folks looking to speed up their websites favs. can add THOSE too, & have the convenience of a 'built-in' ping for getting IP Addresses of various URL's too, quick & easy!)
Right now though, I'd like it to go faster, & maybe by turning to another method, I MAY get it (vs. the line-by-line, "brute force" compare engine I use now, currently)... but, we'll see!
Neat "innovation" in it too, IF you noticed, on its "inner loop", sepulchre: - That's one of it NOT going back thru the ones above the current entry being examined, presently/already!
(As the ones above it have already been checked, vs. itself + all others in the list/array, further "sieving down" the dataset it has to 'vector thru' in those listbox arrays, every iteration (each run, it gets smaller & F A S T E R))
*
In fact, I illustrated that VERY EFFECT to my pal Jack last night, with a smaller 'test dataset' which HE put the repeat entries into it, 3,000 items worth, with around 100 repeat entries from multiple diff. sites... not a single repeated entry remained, of 10 diff. sites put into the HOSTS file test dataset we built (2004 records long).
It tore thru that, 205 records a minute, during normalization (removal of repeat items, its SLOWEST part no less) @ the start, which is its slowest point to work on (MUCH faster once past the midway point), & GOT FASTER once it got past the 1/2 way point... I told him it would (& we proved it, not just in theory!)
APK