<commit_before>unit Unit1;
interface
uses
  Windows, Messages, Classes, Controls, Dialogs, Forms, StdCtrls, StrUtils, SysUtils, FileCtrl,
  KM_Defaults, KM_Scripting, shellapi;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    btnBrowseFile: TButton;
    Label1: TLabel;
    btnValidate: TButton;
    OpenDialog1: TOpenDialog;
    Memo1: TMemo;
    Label2: TLabel;
    btnValidateAll: TButton;
    btnBrowsePath: TButton;
    procedure FormCreate(Sender: TObject);
    procedure btnBrowseFileClick(Sender: TObject);
    procedure btnValidateClick(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure btnValidateAllClick(Sender: TObject);
    procedure Edit1Change(Sender: TObject);
    procedure btnBrowsePathClick(Sender: TObject);
  private
    fScripting: TKMScripting;
    IsValidatePath : Boolean;
    sListFileInFolder : TStringList;

    procedure FindFiles(aPath: String; out aList: TStringList);
    procedure Validate(aPath: string; aReportGood: Boolean);
    procedure WMDropFiles(var Msg: TWMDropFiles); message WM_DROPFILES;
    procedure ComponentReEnabled(aEnabled : Boolean);
  end;


var
  Form1: TForm1;
implementation
uses
  KM_Maps;
const
  EXT_FILE_SCRIPT = '.script';

{$R *.dfm}

procedure TForm1.FindFiles(aPath: String; out aList: TStringList);
var
  SearchRec:TSearchRec;
begin
  FindFirst(aPath+PathDelim+'*', faAnyFile, SearchRec);
  repeat
    if (SearchRec.Name <> '.') and (SearchRec.Name <> '..') then
      if (SearchRec.Attr and faDirectory = faDirectory) then
        FindFiles(aPath + PathDelim + SearchRec.Name, aList)
      else
        if SameText(ExtractFileExt(SearchRec.Name), EXT_FILE_SCRIPT) then
          aList.Add(aPath + PathDelim + SearchRec.Name);
  until (FindNext(SearchRec) <> 0);
  FindClose(SearchRec);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Caption := 'KaM Remake Script Validator (' + GAME_REVISION + ')';

  OpenDialog1.InitialDir := ExtractFilePath(Application.ExeName);

  fScripting := TKMScripting.Create(nil);
  sListFileInFolder := TStringList.Create;

  DragAcceptFiles(Handle, True);
end;


procedure TForm1.FormDestroy(Sender: TObject);
begin
  fScripting.Free;
  sListFileInFolder.Free;
  DragAcceptFiles(Handle, False);
end;

procedure TForm1.btnBrowseFileClick(Sender: TObject);
begin
  if OpenDialog1.Execute then
  Edit1.Text := OpenDialog1.FileName;
end;


procedure TForm1.btnBrowsePathClick(Sender: TObject);
var
  DirValidate : String;
begin
  if not SelectDirectory('Select the folder to Validate scripts', '', DirValidate) then Exit;
  Edit1.Text := DirValidate;
end;

procedure TForm1.Edit1Change(Sender: TObject);
begin
  If (GetFileAttributes(PWideCHar(TEdit(Sender).Text)) and FILE_ATTRIBUTE_DIRECTORY) = FILE_ATTRIBUTE_DIRECTORY then
  begin
    IsValidatePath := true;
    Memo1.Text := 'Selected folders!';
  end
  else
  begin<commit_msg>Ability to validate not only the file and all files and files in a folder [Script Validator]<commit_after>unit Unit1;
interface
uses
  Windows, Messages, Classes, Controls, Dialogs, Forms, StdCtrls, StrUtils, SysUtils, FileCtrl,
  KM_Defaults, KM_Scripting, shellapi;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    btnBrowseFile: TButton;
    Label1: TLabel;
    btnValidate: TButton;
    OpenDialog1: TOpenDialog;
    Memo1: TMemo;
    Label2: TLabel;
    btnValidateAll: TButton;
    btnBrowsePath: TButton;
    procedure FormCreate(Sender: TObject);
    procedure btnBrowseFileClick(Sender: TObject);
    procedure btnValidateClick(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure btnValidateAllClick(Sender: TObject);
    procedure Edit1Change(Sender: TObject);
    procedure btnBrowsePathClick(Sender: TObject);
  private
    fScripting: TKMScripting;
    IsValidatePath : Boolean;
    sListFileInFolder : TStringList;

    procedure FindFiles(aPath: String; out aList: TStringList);
    procedure Validate(aPath: string; aReportGood: Boolean);
    procedure WMDropFiles(var Msg: TWMDropFiles); message WM_DROPFILES;
    procedure ComponentReEnabled(aEnabled : Boolean);
  end;


var
  Form1: TForm1;
implementation
uses
  KM_Maps;
const
  EXT_FILE_SCRIPT = '.script';

{$R *.dfm}

procedure TForm1.FindFiles(aPath: String; out aList: TStringList);
var
  SearchRec:TSearchRec;
begin
  FindFirst(aPath+PathDelim+'*', faAnyFile, SearchRec);
  repeat
    if (SearchRec.Name <> '.') and (SearchRec.Name <> '..') then
      if (SearchRec.Attr and faDirectory = faDirectory) then
        FindFiles(aPath + PathDelim + SearchRec.Name, aList)
      else
        if SameText(ExtractFileExt(SearchRec.Name), EXT_FILE_SCRIPT) then
          aList.Add(aPath + PathDelim + SearchRec.Name);
  until (FindNext(SearchRec) <> 0);
  FindClose(SearchRec);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Caption := 'KaM Remake Script Validator (' + GAME_REVISION + ')';

  OpenDialog1.InitialDir := ExtractFilePath(Application.ExeName);

  fScripting := TKMScripting.Create(nil);
  sListFileInFolder := TStringList.Create;

  DragAcceptFiles(Handle, True);
end;


procedure TForm1.FormDestroy(Sender: TObject);
begin
  fScripting.Free;
  sListFileInFolder.Free;
  DragAcceptFiles(Handle, False);
end;

procedure TForm1.btnBrowseFileClick(Sender: TObject);
begin
  if not OpenDialog1.Execute then Exit;
  Edit1.Text := OpenDialog1.FileName;
end;


procedure TForm1.btnBrowsePathClick(Sender: TObject);
var
  DirValidate : String;
begin
  if not SelectDirectory('Select the folder to Validate scripts', '', DirValidate) then Exit;
  Edit1.Text := DirValidate;
end;

procedure TForm1.Edit1Change(Sender: TObject);
begin
  If (GetFileAttributes(PWideCHar(TEdit(Sender).Text)) and FILE_ATTRIBUTE_DIRECTORY) = FILE_ATTRIBUTE_DIRECTORY then
  begin
    IsValidatePath := true;
    Memo1.Text := 'Selected folders!';
  end
  else
  begin
{'fraction_non_alphanumeric': 0.09898781952307428, 'fraction_numerical': 0.008234688625836336, 'mean_word_length': 4.766567754698318, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4602229', 'n_tokens_mistral': 1974, 'n_tokens_neox': 1930, 'n_words': 451}