home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 31 / CDASC_31_1996_juillet_aout.iso / index / source / main.pas < prev    next >
Pascal/Delphi Source File  |  1996-05-05  |  34KB  |  1,020 lines

  1. { Voici l'unitΘ principale du programme qui gΦre toute la partie algorithmique (et donc les bugs)
  2.   de ce programme, on y trouve toutes les variables partagΘes ainsi que les algorithmes de
  3.   recherche ainsi que les parcours d'arborescence. }
  4. unit Main;
  5.  
  6. interface
  7.  
  8. uses
  9.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  10.   Forms, Dialogs, StdCtrls, Buttons, ExtCtrls, Menus;
  11.  
  12. { Nombre maximum de ligne d'une description. }
  13. const MaxDescription = 200 ;
  14.  
  15. type
  16.   TMainForm = class(TForm)
  17.     StatusLine: TPanel;
  18.     Critere2: TGroupBox;
  19.     NonCheck2: TCheckBox;
  20.     EtRadio2: TRadioButton;
  21.     OuRadio2: TRadioButton;
  22.     TexteCritere2: TEdit;
  23.     Critere3: TGroupBox;
  24.     NonCheck3: TCheckBox;
  25.     EtRadio3: TRadioButton;
  26.     OuRadio3: TRadioButton;
  27.     TexteCritere3: TEdit;
  28.     Critere1: TGroupBox;
  29.     NonCheck1: TCheckBox;
  30.     TexteCritere1: TEdit;
  31.     RechercheBtn: TButton;
  32.     QuitterBtn: TButton;
  33.     ListeBox: TListBox;
  34.     AscCheck: TCheckBox;
  35.     VracCheck: TCheckBox;
  36.     AutreCheck: TCheckBox;
  37.     ChargerBtn: TButton;
  38.     SauveBtn: TButton;
  39.     OptBtn: TButton;
  40.     AnnexeCheck: TCheckBox;
  41.     Edit1: TEdit;           { Quelqu'un peut me dire comment afficher des }
  42.     Edit2: TEdit;           { contr⌠les label dans cette boεte? }
  43.     Edit3: TEdit;           { Moi j'arrive pas! Ils sont Visibles, Enabled! }
  44.     procedure FormCreate(Sender: TObject);
  45.     procedure ShowHint(Sender: TObject);
  46.     procedure QuitterBtnClick(Sender: TObject);
  47.     procedure TexteCritere1Change(Sender: TObject);
  48.     procedure TexteCritere2Change(Sender: TObject);
  49.     procedure AscCheckClick(Sender: TObject);
  50.     procedure VracCheckClick(Sender: TObject);
  51.     procedure AutreCheckClick(Sender: TObject);
  52.     procedure ListeBoxClick(Sender: TObject);
  53.     procedure RechercheBtnClick(Sender: TObject);
  54.     procedure ChargerBtnClick(Sender: TObject);
  55.     procedure SauveBtnClick(Sender: TObject);
  56.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  57.     procedure OptBtnClick(Sender: TObject);
  58.   end;
  59.  
  60. type { Type contenant les informations de la configuration. }
  61.      TConfiguration = record
  62.                             IgnoreMAJmin,
  63.                             AnnexeDAbord,
  64.                             ChargeTotal : boolean ;
  65.                             RepertoireDefaut : String ;
  66.                             Fichiers : TStrings ;
  67.                       end ;
  68.      { Il y a quatre sections diffΘrentes. }
  69.      TSection = (Asc, Vrac, Autre, Annexe) ;
  70.  
  71.  
  72. var
  73.   MainForm: TMainForm ;
  74.   TailleDescription : byte ;   { Nombre de ligne dans la description courante. }
  75.   SectionSuivante, FichierSuivant, Quitte : boolean ;  { On a choisi le bouton }
  76.   Configuration : TConfiguration ;
  77.   { Tableau contenant le texte de la description. }
  78.   Description : TStrings ;
  79.  
  80. implementation
  81.  
  82. {$IFDEF Final}
  83.  {$A+,B-,D-,G+,I-,K+,L-,R-,Y-,Z-}
  84. {$ELSE}
  85.  {$D+,L+,Y+}
  86. {$ENDIF}
  87.  
  88. {$R *.DFM}
  89.  
  90. uses IniFiles, Affiche, Scan, Option ;
  91.  
  92. { Taille totale des fichiers sΘlectionnΘs dans chaque section et au total.
  93.   Ces nombres sont dΘterminΘs dans la procΘdure ScruteTaille et jamais modifiΘs
  94.   par la suite et servent pour les barres de progression. }
  95. var TailleAsc, TailleVrac, TailleAnnexe,
  96.     TailleAutre, TailleTotale : Longint ;
  97.     NbAsc, NbVrac : byte ; { Nombre de fichiers dans la section Asc et Vrac. }
  98.  
  99.  
  100. { Renvoie la taille d'un fichier. }
  101. function Taille (nom : String) : longint;
  102. var fic : TSearchRec ;
  103. begin
  104.      if findfirst(nom, 21, fic) = 0
  105.         then
  106.             Taille := fic. Size
  107.         else
  108.             Taille := 0 ;
  109. end ;
  110.  
  111.  
  112. { Convertit une chaεne en nombre. }
  113. function Val2 (chaine : string) : byte ;
  114. var i,code : integer ;
  115. begin
  116.      for i := 1 to length(chaine) do
  117.          if not (chaine[i] in ['0'..'9']) then
  118.             delete(chaine,i,1) ;
  119.      Val(Chaine, I, Code);
  120.      Val2 := i ;
  121. end ;
  122.  
  123.  
  124. { Convertit un nombre en chaεne }
  125. function Str2(nombre : Integer) : string ;
  126. var s : string ;
  127. begin
  128.      Str(nombre, s) ;
  129.      Str2 := s ;
  130. end ;
  131.  
  132.  
  133. { Cette procΘdure rΘcupΦre les informations stockΘs dans le .INI. }
  134. Procedure ChargementPartiel ;
  135. var TrouveIni : TIniFile ;
  136.     Chaine    : String ;
  137.     combien,
  138.     i, j      : Word ;
  139. begin
  140.      { On cherche l'entrΘe "Nombre" }
  141.      TrouveIni := TIniFile.Create(ExtractFilePath(application.exename)+'trouve.ini') ;
  142.      with configuration do
  143.      begin
  144.           IgnoreMAJmin := TrouveIni. ReadBool('WinTrouve', 'IgnoreMAJmin',true) ;
  145.           AnnexeDAbord := TrouveIni. ReadBool('WinTrouve', 'AnnexeDAbord',true) ;
  146.      end ;
  147.      Combien := TrouveIni. ReadInteger('Fichiers standards','Nombre',0) ;
  148.      { Si l'entrΘe existe on scanne les entrΘes Itemx }
  149.      If Combien <> 0 Then
  150.      begin
  151.           { On met toute la liste α faux }
  152.           For i := 0 To MainForm.ListeBox.Items. Count - 1 do
  153.               MainForm.ListeBox.Selected[i] := False ;
  154.           For i := 1 To combien do
  155.           begin
  156.                { On lit une entrΘe... }
  157.                Chaine:=TrouveIni.ReadString('Fichiers standards','Item'+str2(i),'') ;
  158.                { On met α vrai son Θquivalent dans la liste }
  159.                j := 0 ;
  160.                While (j < MainForm.ListeBox.Items.Count)
  161.                       And (MainForm.ListeBox.Items[j] <> Chaine) do
  162.                    inc(j) ;
  163.                If j < MainForm.ListeBox.Items.Count Then
  164.                    MainForm.ListeBox.Selected[j] := True ;
  165.           end ;
  166.      End ;
  167.      { On s'occupe maintenant des fichiers annexes. }
  168.      With configuration do
  169.      begin
  170.           try
  171.           { On cherche combien il y en a. }
  172.           Combien := trouveini. ReadInteger ('Fichiers annexes','Nombre',0) ;
  173.           { Si la liste est dΘjα pleine on la vide avant d'en rajouter d'autres. }
  174.           if Fichiers. Count <> 0 then
  175.              Fichiers. Clear ;
  176.           { On parcourt tous les ΘlΘments. }
  177.           for i:=1 to Combien do
  178.           begin
  179.                Chaine := TrouveIni.ReadString('Fichiers annexes','Item'+str2(i),'') ;
  180.                { On ajoute le fichier dans la liste s'il existe. }
  181.                if (chaine <>'') and (taille(chaine)>0) then
  182.                   Fichiers. Add(chaine) ;
  183.           end ;
  184.           finally
  185.           end ;
  186.      end ;
  187.      { On ferme le .INI. }
  188.      TrouveIni. free;
  189. end ;
  190.  
  191.  
  192. { Cette procΘdure a l'action inverse de la procΘdure prΘcΘdente. Elle sauvegarde dans le .INI
  193.   l'ensemble des rΘglages du programme. }
  194. procedure SauvegardePartielle ;
  195. var i, combien : Word ;
  196.     TrouveIni  : TIniFile ;
  197. begin
  198.      TrouveIni := TIniFile. Create (ExtractFilePath(application.exename)+'trouve.ini') ;
  199.      { Enregistre les paramΦtres gΘnΘraux du programme. }
  200.      With Configuration do
  201.      begin
  202.           trouveini. WriteString('WinTrouve', 'RepertoireDefaut',RepertoireDefaut) ;
  203.           trouveini. WriteBool('WinTrouve', 'IgnoreMAJmin',IgnoreMAJmin) ;
  204.           trouveini. WriteBool('WinTrouve', 'ChargeTotal',ChargeTotal) ;
  205.           trouveini. WriteBool('WinTrouve', 'AnnexeDAbord',AnnexeDAbord) ;
  206.      end ;
  207.      { Enregistre les paramΦtres annexes s'il y en a. }
  208.      With configuration do
  209.      begin
  210.           if Fichiers. Count > 0 then
  211.           begin
  212.                TrouveIni.WriteInteger('Fichiers annexes','Nombre',Fichiers. Count) ;
  213.                for i:=1 to Fichiers. Count do
  214.                    TrouveIni.WriteString('Fichiers annexes','Item'+str2(i), Fichiers[i-1]) ;
  215.           end
  216.           else
  217.               trouveIni. EraseSection ('Fichiers annexes') ;
  218.      end ;
  219.      { On parcourt la liste... }
  220.      i := 0 ;
  221.      combien := 0;
  222.      While i <> MainForm.ListeBox.Items.Count do
  223.      begin
  224.           { Et pour chaque ΘlΘment choisit.... }
  225.           If MainForm.ListeBox.Selected[i] Then
  226.           begin
  227.                { On ajoute son entrΘe dans le .ini }
  228.                inc(combien) ;
  229.                TrouveIni.WriteString('Fichiers standards','Item'+str2(combien),MainForm.ListeBox.Items[i]) ;
  230.           End ;
  231.           inc(i) ;
  232.      end;
  233.      { Enregistre le nombre de composants de section standard. }
  234.      If combien > 0 Then
  235.         TrouveIni.WriteInteger('Fichiers standards','Nombre',combien)
  236.      else
  237.          trouveIni. EraseSection ('Fichiers standards') ;
  238.      { Ferme le .INI. }
  239.      TrouveIni. free;
  240. end ;
  241.  
  242.  
  243.  
  244. { Tri les noms dans la liste pour les mettre dans l'ordre chronologique inverse.
  245.   ordre indique le sens de tri jamais utilisΘ dans l'autre sens ,
  246.   offset indique le dΘcalage des mots 3 pour ASC, 4 pour VRAC,
  247.   debut et fin donne les indices dans la liste des sections asc et vrac. }
  248. procedure tri (ordre : boolean; offset, debut, fini : byte ) ;
  249.  
  250. var i, j    : integer ;
  251.     Valeur2,
  252.     Valeur  : Byte ;
  253. begin
  254.      { Algorithme de tri immonde mais vu qu'il n'y a qu'une vingtaine de chaεne et
  255.        que cette procΘdure et utilisΘe qu'une fois, c'est pas la peine de faire un
  256.        algo de tri par petits tas pour liste  chaεnΘes (salut fred!, private joke). }
  257.      j := fini ;
  258.      while j > debut do
  259.      begin
  260.           i := debut ;
  261.           while i < j do
  262.           begin
  263.                Valeur := Val2(Copy(MainForm.ListeBox.Items[i+1], offset, 2)) ;
  264.                Valeur2 := Val2(Copy(MainForm.ListeBox.Items[i], offset, 2));
  265.                If ((valeur < valeur2) And (ordre)) Or
  266.                    ((Valeur > Valeur2) And Not ordre) Then
  267.                   MainForm. ListeBox. Items.Exchange(i,i+1) ;
  268.                inc (i) ;
  269.           end;
  270.           dec(j) ;
  271.      end ;
  272. end ;
  273.  
  274.  
  275.  
  276. procedure trie( ordre : boolean) ;
  277. begin
  278.      if NbAsc > 0 then
  279.         { tri les asc. }
  280.         tri(ordre, 4, 0, NbAsc - 1) ;
  281.      if NbVrac > NbAsc then
  282.         { tri les vrac. }
  283.         tri(ordre, 5, NbAsc, NbVrac - 1) ;
  284. end ;
  285.  
  286.  
  287.  
  288. { DΘtermine si les boutons sont cochΘs, ou non voire grisΘs. }
  289. procedure DetermineEtat (tipe: byte) ;
  290. var debut, fin,
  291.     i, etat    : byte ;
  292.     Style      : TCheckBoxState;
  293. begin
  294.      case tipe of
  295.       0 : begin
  296.                debut := 0 ;
  297.                fin := nbAsc -1 ;
  298.           end ;
  299.       1 : begin
  300.                debut := nbAsc ;
  301.                fin := nbVrac -1 ;
  302.           end ;
  303.       2 : begin
  304.                debut := nbVrac ;
  305.                fin := MainForm. ListeBox. Items. Count - 1 ;
  306.           end ;
  307.      end ;
  308.      with MainForm. ListeBox do
  309.      begin
  310.           if Selected[debut] then
  311.              etat := 1
  312.           else
  313.              etat := 2 ;
  314.           for i := Debut + 1 to fin do
  315.               if (Selected[i] and (etat = 2)) or (not selected[i] and (etat = 1))
  316.                  then etat := 3 ;
  317.      end ;
  318.      case etat of
  319.       1 : Style := cbChecked;
  320.       2 : Style := cbUnchecked;
  321.       3 : Style := cbGrayed;
  322.      end ;
  323.      case tipe of
  324.       0 : MainForm. AscCheck. State := Style ;
  325.       1 : MainForm. VracCheck. State := Style ;
  326.       2 : MainForm. AutreCheck. State := Style ;
  327.      end ;
  328. end ;
  329.  
  330.  
  331. Procedure CheckState ;
  332. begin
  333.      if MainForm.AscCheck. Enabled then
  334.         DetermineEtat(0) ;
  335.      if MainForm.VracCheck. Enabled then
  336.         DetermineEtat(1) ;
  337.      if MainForm.AutreCheck. Enabled then
  338.         DetermineEtat(2) ;
  339.      if Configuration. Fichiers. Count > 0 then
  340.         MainForm.AnnexeCheck. Checked := true
  341.      else
  342.         MainForm.AnnexeCheck. Checked := false ;
  343. end;
  344.  
  345.  
  346.  
  347. { Cette procΘdure analyse le rΘpertoire par dΘfaut et inspecte tous les fichiers susceptible
  348.   d'Ωtre des descriptions. }
  349. Procedure ScanRepDefaut ;
  350. var fichier : tsearchrec ;
  351.     DosError,
  352.     i       : integer ;
  353. begin
  354.      ChDir(configuration. RepertoireDefaut) ;
  355.      if MainForm. ListeBox <> Nil
  356.         then
  357.             MainForm. ListeBox. Clear ;
  358.      { Parcours des Asc }
  359.      FindFirst('ASC*.ASC', $21, fichier) ;
  360.      i := 0 ;
  361.      DosError := 0 ;
  362.      While DosError=0 do
  363.      begin
  364.           If fichier.Attr and 16 = 16 Then
  365.               DosError:=FindNext (fichier)
  366.           Else
  367.           begin
  368.               { On ajoute le fichier α la liste. }
  369.               MainForm. ListeBox.Items.Add(fichier. name) ;
  370.               inc(i) ;
  371.               DosError:=FindNext (fichier) ;
  372.           End ;
  373.      end ;
  374.      NbAsc := i ;
  375.      { Parcours des Vrac }
  376.      FindFirst('VRAC*.BBS', $21, fichier);
  377.      i := 0 ;
  378.      DosError := 0 ;
  379.      While DosError=0 do
  380.      begin
  381.           If fichier.Attr and 16 = 16 Then { C'est un rΘpertoire... }
  382.               DosError:=FindNext (fichier)
  383.           Else
  384.           begin
  385.               MainForm. ListeBox.Items.Add(fichier. name) ;
  386.               inc(i) ;
  387.               DosError:=FindNext (fichier) ;
  388.           End ;
  389.      end ;
  390.      NbVrac := i + NbAsc ;
  391.      { Parcours des Autres }
  392.      FindFirst('*.BBS', $21, fichier) ;
  393.      i := 0 ;
  394.      DosError := 0 ;
  395.      While DosError=0 do
  396.      begin
  397.           If (fichier.Attr and 16 = 16) or (copy(fichier.name,1,4) ='VRAC') Then
  398.               DosError:=FindNext (fichier)
  399.           Else
  400.           begin
  401.               MainForm. ListeBox.Items.Add(fichier. name) ;
  402.               DosError:=FindNext (fichier) ;
  403.           End ;
  404.      end ;
  405.      trie (false);
  406.      For i := 0 To MainForm. ListeBox.Items.Count - 1 do
  407.          MainForm. ListeBox.Selected[i] := True ;
  408.      If MainForm. ListeBox.Items.Count > 0 Then
  409.          MainForm. ListeBox.TopIndex := 0 ;
  410.      if NbAsc = 0 then
  411.         MainForm. AscCheck. Enabled := False ;
  412.      if NbAsc = NbVrac then
  413.         MainForm. VrAcCheck. Enabled := False ;
  414.      if NbVrac = MainForm. ListeBox. Items. Count then
  415.         MainForm. AutreCheck. Enabled := False ;
  416.      MainForm. ListeBox. TopIndex := 0 ;
  417. end ;
  418.  
  419.  
  420.  
  421. { Cherche s'il existe un fichier d'initialisation de faτon α avoir le rΘpertoire
  422.   par dΘfaut qui est le minimum pour Θviter le plantage (mon dieu que de bug!). }
  423. Procedure ChercheINI ;
  424. var TrouveINI : TINIFile ;
  425. begin
  426.      if Taille('TROUVE.INI')=0 then
  427.      with Configuration do
  428.      begin
  429.           RepertoireDefaut := ExtractFilepath(Application. EXENAME) ;
  430.           { Supprime le '\' α la fin de la chaine. }
  431.           Delete(RepertoireDefaut,length(RepertoireDefaut),1) ;
  432.           { Bien que fichiers soit de type TStrings il faut appeler le constructeur de
  433.             TStringList sinon vous aurez droit α des bug que Delphi n'arrive mΩme pas α
  434.         intercepter. }
  435.           Fichiers := TStringList. Create ;
  436.           ScanRepDefaut ;
  437.           CheckState ;
  438.           ChargeTotal := false ;
  439.           IgnoreMAJmin := true ;
  440.           AnnexeDAbord := true ;
  441.           SauvegardePartielle ;
  442.      end
  443.      else
  444.      begin
  445.           TrouveIni := TIniFile.Create('.\trouve.ini') ;
  446.           with Configuration do
  447.           begin
  448.                RepertoireDefaut := TrouveIni. ReadString('WinTrouve',
  449.                      'RepertoireDefaut',ExtractFilepath(Application. EXENAME)) ;
  450.                ScanRepDefaut ;
  451.                ChargeTotal := TrouveIni. ReadBool('WinTrouve', 'ChargeTotal',false) ;
  452.                Fichiers := TStringList. Create ;
  453.                if ChargeTotal then
  454.                   ChargementPartiel ;
  455.                CheckState ;
  456.                MainForm. ListeBox. TopIndex := 0 ;
  457.           end ;
  458.           TrouveIni. Free ;
  459.      end ;
  460. end ;
  461.  
  462.  
  463. { Calcul la taille de chaque section et le total. }
  464. procedure ScruteTaille ;
  465. var i   : integer ;
  466. begin
  467.      TailleAsc := 0 ;
  468.      TailleVrac := 0 ;
  469.      TailleAutre := 0 ;
  470.      TailleAnnexe := 0 ;
  471.      ChDir(Configuration. RepertoireDefaut) ;
  472.      { Pour tous les ASC et s'ils sont sΘlectionnΘs... }
  473.      for i := 0 to NbAsc - 1 do
  474.      begin
  475.           if MainForm. ListeBox. Selected[i] then
  476.              Inc(TailleAsc,Taille(MainForm. ListeBox. Items[i])) ;
  477.      end ;
  478.      { VRAC... }
  479.      for i := NbAsc to NbVrac - 1 do
  480.      begin
  481.           if MainForm. ListeBox. Selected[i] then
  482.              Inc(TailleVrac,Taille(MainForm. ListeBox. Items[i])) ;
  483.      end ;
  484.      { Autres... }
  485.      for i := NbVrac to MainForm. ListeBox. Items. Count - 1 do
  486.      begin
  487.           if MainForm. ListeBox. Selected[i] then
  488.              Inc(TailleAutre,Taille(MainForm. ListeBox. Items[i])) ;
  489.      end ;
  490.      { Annexes... }
  491.      if MainForm. AnnexeCheck. Checked then
  492.         for i := 0 to Configuration.Fichiers. Count - 1 do
  493.             Inc(TailleAnnexe,Taille(Configuration. Fichiers[i])) ;
  494.      { Ce qui donne en tout. }
  495.      TailleTotale := TailleAsc + TailleVrac + TailleAutre + TailleAnnexe ;
  496. end ;
  497.  
  498.  
  499.  
  500. { RAZ mΘmoire de la description et de l'afficheur. }
  501. procedure RazDescription ;
  502. begin
  503.      if Description. count <> 0 then
  504.         Description. Clear ;
  505.      TailleDescription := 0 ;
  506.      DescForm. ListeDesc. Lines. Clear ;
  507. end ;
  508.  
  509.  
  510. { DΘtermine si on atteint la fin d'une description suivant le type du fichier
  511.   voire le type (NEWS ou MAJ). }
  512. Function fin (phrase : String; tipe : Integer) : Boolean ;
  513. begin
  514.      fin := False ;
  515.      if length(phrase)=0 then exit ;
  516.      Case tipe of
  517.         0 { Cas des BBS }
  518.           : If phrase[1] <> ' ' Then
  519.                 fin := True ;
  520.         1, 2 {Cas des Asc News ou Maj }
  521.           : If (Copy(phrase, 1, 3) = '  ═') or
  522.                (Copy(phrase, 1, 3) = '  ■') Then
  523.                 fin := True
  524.     End;
  525. End ;
  526.  
  527.  
  528. { Transfert la description dans l'afficheur et lui passe le focus. }
  529. Procedure AfficheDesc ;
  530. var i : integer ;
  531. begin
  532.      { On Θlimine les lignes orpheline de la fin de la description. }
  533.      i := TailleDescription ;
  534.      While Description[i-1] = '' do
  535.            i := i - 1 ;
  536.      TailleDescription := i ;
  537.      { On transfert la description dans la liste. }
  538.      For i := 1 To TailleDescription do
  539.          DescForm. ListeDesc. Lines. Add(Description[i-1]) ;
  540.      { On passe le focus en modal α l'afficheur. }
  541.      DescForm. ShowModal ;
  542. end ;
  543.  
  544.  
  545. { Cherche si une chaεne est dans une description. }
  546. Function Scrute (chaine : String) : boolean ;
  547.  
  548.  { Passe une chaine en majuscule. }
  549.  Function UpString ( Str : string ) : String ;
  550.  var ch : string[255] ;
  551.      i  : byte ;
  552.  begin
  553.       { Passe chaque caractΦre en majuscule. }
  554.       for i := 1 to length(str) do
  555.           ch[i] := UpCase(Str[i]) ;
  556.       { Transfert la longueur. }
  557.       SetLength(ch,length(Str)) ;
  558.       UpString := Ch ;
  559.  end ;
  560.  
  561. var i       : word ;
  562.     Trouve2 : Boolean ;
  563. begin
  564.      if Configuration. IgnoreMAJmin then
  565.         chaine := UpString(chaine) ;
  566.      Trouve2 := False ;
  567.      i := 1 ;
  568.      While ((i <= TailleDescription) And (Trouve2 = False)) do
  569.      begin
  570.           if Configuration. IgnoreMAJmin then
  571.              Trouve2 := (Pos(Chaine,UpString(Description[i-1])) <> 0)
  572.           else
  573.              Trouve2 := (Pos(Chaine,Description[i-1]) <> 0) ;
  574.           inc(i) ;
  575.      end ;
  576.      Scrute := Trouve2 ;
  577. End ;
  578.  
  579.  
  580. { Cherche si une description correspond aux critΦres de recherche. C'est un peu spaghetti mais
  581.   τa tourne bien et parfois il faut faire un peu de code "gΘnΘrΘ" pour grossir la taille du
  582.   source! }
  583. Function Search : Boolean ;
  584. var Found,
  585.     Found2 : Boolean ;
  586.     temp   : String ;
  587. begin
  588.      { Analyse du premier critΦre. }
  589.      temp := MainForm.TexteCritere1.Text ;
  590.      Found := Scrute(temp) ;
  591.      If MainForm.NonCheck1.Checked Then
  592.         Found := Not Found ;
  593.      If ((MainForm.TexteCritere2.Text <> '') and (MainForm.TexteCritere2.Enabled)) Then
  594.      begin
  595.  
  596.           { Analyse du second critΦre. }
  597.           temp := MainForm.TexteCritere2.Text ;
  598.           Found2 := Scrute(temp) ;
  599.           If MainForm.NonCheck2.Checked Then
  600.              Found2 := Not Found2 ;
  601.           If MainForm.EtRadio2.Checked Then
  602.              Found := Found And Found2
  603.           Else
  604.               Found := Found Or Found2 ;
  605.  
  606.           { Analyse du troisiΦme critΦre. }
  607.           If ((MainForm.TexteCritere3.Text <> '') and (MainForm.TexteCritere3.Enabled)) Then
  608.           begin
  609.              temp := MainForm.TexteCritere3.Text ;
  610.              Found2 := Scrute(temp) ;
  611.              If MainForm.NonCheck3.Checked Then
  612.                 Found2 := Not Found2 ;
  613.              If MainForm.EtRadio3.Checked Then
  614.                 Found := Found And Found2
  615.              Else
  616.                  Found := Found Or Found2 ;
  617.           End ;
  618.      End ;
  619.      Search := Found ;
  620. End ;
  621.  
  622.  
  623. { Analyse tout un fichier et mets α jour le tipe de fichier. }
  624. procedure ScanFichier (nom : string; tipe : byte) ;
  625. var Resultat   : boolean ;
  626.     TailleFichier,
  627.     TailleTemp : longint ;
  628.     phrase     : string ;
  629.     temp       : PChar ;
  630.     fichier    : Text ;
  631.  
  632.  { Ajoute une ligne dans une description, si c'est possible. }
  633.  procedure ajoute (chaine : string) ;
  634.  begin
  635.       if chaine<>'' then
  636.       begin
  637.            Description. Add(chaine) ;
  638.            Inc(TailleDescription) ;
  639.       end ;
  640.  end ;
  641.  
  642.  { Ajoute une ligne dans la description suivant le type du fichier. }
  643.  procedure ajouteLigne ;
  644.  begin
  645.       { Suivant le type de fichier on garde toute la ligne, soit on oublie
  646.         les 32 premiers caractΦres (qui sont des espaces). }
  647.       if (tipe = 0) then
  648.       begin
  649.            if (TailleDescription = 0) then
  650.                Ajoute(copy (phrase, 1, 31)) ;
  651.            if (length(phrase) > 31) then
  652.                Ajoute(copy (phrase, 32, length(phrase)-31)) ;
  653.       end
  654.       else
  655.           Ajoute(phrase) ;
  656.  end ;
  657.  
  658. begin
  659.      Resultat := False ;
  660.      { TailleTemp indique o∙ en est rendu la recherche. }
  661.      TailleTemp := 0 ;
  662.      assign (fichier, nom );
  663.      reset(fichier) ;
  664.      readln(fichier, phrase) ;
  665.      TailleTemp := length(phrase) + 2 ; { 2 pour le CR LF! }
  666.      RazDescription ;
  667.      AjouteLigne ;
  668.      TailleFichier := taille(nom) ;
  669.      while not eof(fichier) and not quitte and not SectionSuivante
  670.             and not FichierSuivant do
  671.      begin
  672.           readln(fichier, phrase) ;
  673.           Inc(TailleTemp, length(phrase)+2) ;
  674.           { Rends la main α Windows. }
  675.           Application. ProcessMessages ;
  676.           { Si on a fini la description. }
  677.           if fin(phrase, tipe) then
  678.           begin
  679.                ScanForm. FicGauge. Progress := Round(TailleTemp*100/TailleFichier) ;
  680.                { On passe de la section News α la section MAJ? }
  681.                if ((tipe = 1) and (copy (phrase, 1, 3) ='  ■')) then
  682.                   tipe := 2;
  683.                { Si on a trouvΘ le(s) critΦre(s) de recherche. }
  684.                if Search then
  685.                begin
  686.                     case tipe of
  687.                      0 : DescForm. DescLabel. Caption := nom+' fichier type BBS' ;
  688.                      1 : DescForm. DescLabel. Caption := nom+' fichier type DP Tool Club, section NEWS' ;
  689.                      2 : DescForm. DescLabel. Caption := nom+' fichier type DP Tool Club, section MAJ' ;
  690.                     end ;
  691.                     AfficheDesc ;
  692.                end ;
  693.                RazDescription ;
  694.           end ;
  695.           { On vΘrifie que la description n'est pas trop longue. }
  696.           if TailleDescription >= MaxDescription then
  697.           begin
  698.                temp := StrAlloc(60) ;
  699.                StrPCopy(temp, 'Fichier: '+nom+' invalide.') ;
  700.                Application. MessageBox(temp,'Erreur format',0);
  701.                StrDispose (temp) ;
  702.                close (fichier) ;
  703.                RazDescription ;
  704.                Exit ;
  705.           end ;
  706.           AjouteLigne ;
  707.      end ;
  708.      close(fichier) ;
  709. end ; { ScanFichier }
  710.  
  711.  
  712. { Cette procΘdure rΘcupΦre les informations de la configuration pour mettre α jour les valeurs
  713.   des diffΘrentes champs de la boεte. }
  714. procedure InitialiseOnglet;
  715. var i : Integer ;
  716. begin
  717.      with Configuration do
  718.      begin
  719.           OptionForm. RepEdit. Text := RepertoireDefaut;
  720.           OptionForm. DifCheck. Checked := IgnoreMAJmin;
  721.           OptionForm. TotalCheck. Checked := ChargeTotal;
  722.           OptionForm. AnnexeCheck. Checked := AnnexeDAbord;
  723.           if Fichiers. Count > 0 then
  724.           begin
  725.                OptionForm. ListBox. Items. Clear ;
  726.                for i := 0 to Fichiers. Count - 1 do
  727.                    OptionForm. ListBox. Items. Add(Fichiers[i]) ;
  728.           end ;
  729.      end ;
  730. end;
  731.  
  732.  
  733. procedure TMainForm.FormCreate(Sender: TObject);
  734. begin
  735.     Application.OnHint := ShowHint;
  736.     ChercheINI ;
  737.     Description := TStringList. Create ;
  738. end;
  739.  
  740. procedure TMainForm.ShowHint(Sender: TObject);
  741. begin
  742.      StatusLine.Caption := Application.Hint;
  743. end;
  744.  
  745. procedure TMainForm.QuitterBtnClick(Sender: TObject);
  746. begin
  747.      Close ;
  748. end;
  749.  
  750. procedure TMainForm.TexteCritere1Change(Sender: TObject);
  751. begin
  752.      { Lorsque l'on modifie la valeur du champ, s'il devient vide, il
  753.        faut dΘactiver les autres champs. }
  754.      Critere2. Enabled := TexteCritere1. Text<>'';
  755.      Critere2. Visible := Critere2. Enabled ;
  756.      Critere3. Visible := (Critere2. Visible) and (TexteCritere2. Text<>'');
  757.      RechercheBtn. Enabled := Critere2. Enabled ;
  758. end;
  759.  
  760. procedure TMainForm.TexteCritere2Change(Sender: TObject);
  761. begin
  762.      { Voir ci-dessus. }
  763.      Critere3. Enabled := (TexteCritere2. Text<>'') and (Critere2.enabled);
  764.      Critere3. Visible := Critere3. Enabled ;
  765. end;
  766.  
  767. procedure TMainForm.AscCheckClick(Sender: TObject);
  768. var i : integer ;
  769. begin
  770.      if AscCheck. State = cbGrayed then  exit ;
  771.      { Change l'Θtat de toute la section ASC. }
  772.      for i:= 0 to nbAsc-1 do
  773.          ListeBox.Selected[i] := AscCheck.Checked ;
  774. end;
  775.  
  776. procedure TMainForm.VracCheckClick(Sender: TObject);
  777. var i : integer ;
  778. begin
  779.      if VracCheck. State = cbGrayed then  exit ;
  780.      for i:= nbAsc to nbVrac-1 do
  781.          ListeBox.Selected[i] := VracCheck.Checked ;
  782. end;
  783.  
  784. procedure TMainForm.AutreCheckClick(Sender: TObject);
  785. var i : integer ;
  786. begin
  787.      if AutreCheck. State = cbGrayed then  exit ;
  788.      for i:= nbVrac to ListeBox.Items.Count-1 do
  789.          ListeBox.Selected[i] := AutreCheck.Checked ;
  790. end;
  791.  
  792.  
  793. procedure TMainForm.ListeBoxClick(Sender: TObject);
  794. begin
  795.      CheckState ;
  796. end ;
  797.  
  798.  
  799. { Voici la procΘdure la plus bugΘe du programme! C'est la procΘdure qui gΦre la recherche,
  800.   elle parcourt l'ensemble des fichiers en commenτant soit par les annexes ou les ASC et gΦre
  801.   les interruptions ordonnΘes par l'utilisateurs (fichier suivant, section suivante ou Exit!).
  802.   C'est la procΘdure qui a ΘtΘ rΘΘcrite le plus de fois (au moins quatre), quand je dis rΘΘcrit
  803.   c'est rΘΘcrit de la premiΦre α la derniΦre ligne! Car au fur et α mesure que le programme
  804.   avanτait les possibilitΘs se sont accrues et ont quasiment toujours concernΘs cette procΘdure. }
  805. procedure TMainForm.RechercheBtnClick(Sender: TObject);
  806.  
  807. var i, j       : integer ;
  808.     temp       : string ;
  809.     Section    : TSection ;
  810.     tipe       : byte ;
  811.     TailleTemp : LongInt ;
  812.  
  813.  Procedure ChangeSection (i:integer) ;
  814.  begin
  815.       if i >= NbAsc then Section := Vrac ;
  816.       if i >= NbVrac then Section := Autre ;
  817.  end ;
  818.  
  819.  
  820.  { Cette procΘdure cherche le prochain fichier a analysΘ, sachant que pour les ASC, VRAC et Autre
  821.    il faut qu'il soit sΘlectionnΘs et que les annexes il faut tous les analysΘs. }
  822.  function ChercheFichier : String ;
  823.  
  824.  var temp : string ;
  825.  
  826.  begin
  827.       case Section of
  828.        Asc, Vrac, Autre : begin
  829.                                while (i<ListeBox. Items. Count) and
  830.                                      (not ListeBox.Selected[i]) do
  831.                                     inc (i) ;
  832.                                ChangeSection(i) ;
  833.                                if i < ListeBox. Items. Count then
  834.                                begin
  835.                                     temp := ListeBox.Items[i] ;
  836.                                     inc (i) ;
  837.                                end
  838.                                else
  839.                                if not Configuration. AnnexeDAbord
  840.                                   and (Configuration. Fichiers. count <> 0)
  841.                                   and (MainForm. AnnexeCheck. Checked)
  842.                                then
  843.                                begin
  844.                                     Section := Annexe ;
  845.                                     i := 0 ;
  846.                                     temp := Configuration. Fichiers[i] ;
  847.                                end
  848.                                else
  849.                                    temp := '' ;
  850.                           end ;
  851.        Annexe : begin
  852.                      if (i < Configuration. Fichiers. Count) and
  853.                         (MainForm. AnnexeCheck. Checked) then
  854.                      begin
  855.                           temp := Configuration. Fichiers[i] ;
  856.                           inc (i) ;
  857.                      end
  858.                      else
  859.                      if Configuration. AnnexeDAbord
  860.                      then
  861.                      begin
  862.                           Section := Asc ;
  863.                           i := 0 ;
  864.                           temp := ChercheFichier ;
  865.                      end
  866.                      else
  867.                          temp := '' ;
  868.                 end ;
  869.       end ;
  870.       if temp = '' then quitte := true ;
  871.       ChercheFichier := temp ;
  872.  end ;
  873.  
  874.  
  875.  { Cette procΘdure renvoie le type du fichier suivant son extention BBS ou ASC. } 
  876.  function TypeFichier (nom : string) : byte ;
  877.  
  878.  var temp : string ;
  879.      tipe : byte ;
  880.  
  881.  begin
  882.       temp := ExtractFileExt(UpperCase(nom)) ;
  883.       if temp='.BBS' then
  884.          tipe := 0
  885.       else
  886.           tipe := 1 ;
  887.       TypeFichier := tipe ;
  888.  end ;
  889.  
  890.  procedure SauterSection ;
  891.  var k : integer ;
  892.  begin
  893.       SectionSuivante := False ;
  894.       { On teste s'il reste une section.. }
  895.       if ((Section = Annexe) and (not configuration. AnnexeDAbord))
  896.           or
  897.           ((Section = Autre) and (configuration. AnnexeDAbord))
  898.          then
  899.              quitte := true
  900.          else
  901.          begin
  902.               { On saute une section. }
  903.               case Section of
  904.                Asc   : begin
  905.                             j := NbAsc - 1 ;
  906.                 Section := Vrac ;
  907.                        end ;
  908.                Vrac  : begin
  909.                             j := NbVrac -1 ;
  910.                             Section := Autre ;
  911.                        end ;
  912.                Annexe : begin
  913.                              j := 0;
  914.                              for k := i to Configuration. Fichiers. Count - 1 do
  915.                                  inc(TailleTemp,taille(Configuration. Fichiers[k]));
  916.                              Section := Asc ;
  917.                              i:= 0 ;
  918.                         end ;
  919.                Autre : begin
  920.                             j := MainForm. ListeBox. Items. Count - 1 ;
  921.                             Section := Annexe ;
  922.                        end ;
  923.               end ;
  924.               { On calcule la masse de donnΘes que l'on vient de sauter. }
  925.               while (i <= j) and (j<>0) do
  926.               begin
  927.                    if MainForm. ListeBox. Selected[i] then
  928.                    begin
  929.                         temp := MainForm. ListeBox. Items[i] ;
  930.                         inc (TailleTemp, taille(temp)) ;
  931.                    end ;
  932.                    inc (i) ;
  933.               end ;
  934.               { On rafraεchit la gauge. }
  935.               ScanForm. TotalGauge. Progress := round (TailleTemp*100/TailleTotale) ;
  936.          end ;
  937.  end ;
  938.  
  939. begin
  940.      { Parcours tous les fichiers α analyser pour dΘterminer les tailles de chaque section. }
  941.      ScruteTaille ;
  942.      i := 0 ;
  943.      tipe := 1 ;
  944.      { On commence par quoi? }
  945.      if Configuration. AnnexeDAbord then
  946.         Section := Annexe
  947.      else
  948.          Section := Asc ;
  949.      TailleDescription := 0 ;
  950.      { On cache la fenΩtre principale. }
  951.      MainForm. Hide ;
  952.      { On affiche la fenΩtre de progression. }
  953.      ScanForm. Show ;
  954.      TailleTemp := 0 ;
  955.      ScanForm.TotalGauge. Progress := 0 ;
  956.      { On initialise les drapeaux. }
  957.      quitte := false ;
  958.      SectionSuivante := false ;
  959.      { On cherche un fichier. }
  960.      temp := ChercheFichier ;
  961.      While not quitte do
  962.      begin
  963.           { On prΘpare la boεte de progression. }
  964.           ScanForm.FicGroup. Caption :=  'Fichier: ' + ExtractFileName(temp) ;
  965.           ScanForm.FicGauge. Progress := 0 ;
  966.           FichierSuivant := false ;
  967.           { On cherche le type du fichier. }
  968.           tipe := TypeFichier (temp) ;
  969.           { On parcourt le fichier courant. }
  970.           ScanFichier(temp, tipe) ;
  971.           { On rafraεchit la barre de progression. }
  972.           TailleTemp := TailleTemp + Taille(temp) ;
  973.           ScanForm. TotalGauge. Progress := Round(TailleTemp*100/TailleTotale) ;
  974.           { Si on veut sauter la section courante. }
  975.           if SectionSuivante then
  976.              SauterSection ;
  977.           { On cherche un fichier. }
  978.           temp := ChercheFichier ;
  979.      end ;
  980.      ScanForm. Hide ;
  981.      MainForm. Show ;
  982. end;
  983.  
  984.  
  985.  
  986. procedure TMainForm.ChargerBtnClick(Sender: TObject);
  987. begin
  988.      ChargementPartiel ;
  989. end;
  990.  
  991.  
  992.  
  993. procedure TMainForm.SauveBtnClick(Sender: TObject);
  994. begin
  995.      SauvegardePartielle ;
  996. end ;
  997.  
  998.  
  999. procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
  1000. begin
  1001.      SauvegardePartielle ;
  1002.      Description. Free ;
  1003.      Configuration. Fichiers. Free ;
  1004. end;
  1005.  
  1006.  
  1007. procedure TMainForm.OptBtnClick(Sender: TObject);
  1008. var sauvegarde : string ;
  1009. begin
  1010.      Sauvegarde := configuration. RepertoireDefaut ;
  1011.      InitialiseOnglet ;
  1012.      OptionForm. Onglet. PageIndex := 0 ;
  1013.      OptionForm. ShowModal ;
  1014.      if configuration. RepertoireDefaut <> Sauvegarde
  1015.         then
  1016.             ScanRepDefaut ;
  1017. end;
  1018.  
  1019. end.
  1020.