From e17a50b34b12354054a3f092c7be10b0697609c0 Mon Sep 17 00:00:00 2001 From: David Bannon Date: Mon, 16 May 2022 12:58:09 +1000 Subject: [PATCH] Fix Win newline, better reporting of bad JSON --- components/exampleswindow/uexampledata.pas | 23 ++++++++++++++------- components/exampleswindow/ulaz_examples.pas | 18 ++++++++-------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/components/exampleswindow/uexampledata.pas b/components/exampleswindow/uexampledata.pas index a414902058..1c9a992c4d 100644 --- a/components/exampleswindow/uexampledata.pas +++ b/components/exampleswindow/uexampledata.pas @@ -420,6 +420,9 @@ begin Result := False; ExtractFromJSON('Category', jItem, Cat); // An empty Cat is acceptable but undesirable. if not ExtractFromJSON('Description', jItem, Desc) then exit(False); + {$ifdef WINDOWS} + Desc := Desc.Replace(#10, #13#10, [rfReplaceAll]); + {$endif} KeyWords := TStringList.Create; ExtractArrayFromJSON('Keywords', jItem, Keywords); if AName <> '' then @@ -442,23 +445,25 @@ function TExampleData.ScanLocalTree(Path : string; PathAbs : boolean) : boolean; var STL : TStringList = nil; FileContent : TStringList; - St : string; + St, DirN : string; begin STL := FindAllFiles(Path, '*' + MetaFileExt, True); try for St in STL do begin - if pos('master' + MetaFileExt, St) > 0 then continue; // don't do master if you stumble across one - if pos(cExamplesDir, St) > 0 then continue; // thats our downloaded location + if pos('master' + MetaFileExt, St) > 0 then continue; // don't do master if you stumble across one + if pos(cExamplesDir, St) > 0 then continue; // thats our downloaded location + DirN := copy(St, 1, length(St) - length(ExtractFileName(St)) -1); // now path without filename + if ExtractFileName(DirN) = 'backup' then continue; FileContent := TStringList.Create; - FileContent.LoadFromFile(St); // Thats contents of one individual metadata file try + FileContent.LoadFromFile(St); // That is contents of one individual metadata file if PathAbs then Result := ReadSingleJSON(FileContent, St) else Result := ReadSingleJSON(FileContent, copy(St, Path.Length+1, 1000)); if not Result then begin debugln('Offending file is ' + St); debugln(ErrorMsg); - exit(False); + //exit(False); // process all the good ones anyway, hope thats good.... end; finally FileContent.Free; @@ -482,18 +487,20 @@ begin jItem := jData.Items[0]; except on E: EJSONParser do begin - ErrorMsg := 'ERROR EJSONParser- invalid JSON ' + E.Message; + ErrorMsg := 'ERROR EJSONParser- invalid JSON in ' + PathToStore + + ' ' + E.Message; jData := Nil; // Appears nothing is allocated if error ? exit(false); end; on E: EScannerError do begin // Thats in jsonscanner unit, Must doc on Wiki !!! - ErrorMsg := 'ERROR EScanner- invalid JSON ' + E.Message; // this is typically a single \ + ErrorMsg := 'ERROR EScanner- invalid JSON in ' + PathToStore // this is typically a single \ + + ' ' + E.Message; jData := Nil; // Appears nothing is allocated if error ? exit(false); end; end; if TJSONObject(jItem).Count = 0 then begin - debugln('WARNING - file does not contain suitable JSON : '); + debugln('WARNING - file ' + PathToStore + ' does not contain suitable JSON : '); exit(false); end; InsertJSONData(jItem, PathToStore, TJSONObject(jData).Names[0]); diff --git a/components/exampleswindow/ulaz_examples.pas b/components/exampleswindow/ulaz_examples.pas index 14438e1a3a..c82d79edfa 100644 --- a/components/exampleswindow/ulaz_examples.pas +++ b/components/exampleswindow/ulaz_examples.pas @@ -25,6 +25,7 @@ Notes - David Bannon, Feb 2022 } {$mode objfpc}{$H+} +{$define EXTESTMODE} {X$define ONLINE_EXAMPLES} @@ -52,6 +53,7 @@ type EditSearch: TEdit; ListView1: TListView; Memo1: TMemo; + Panel1: TPanel; Splitter2: TSplitter; StatusBar1: TStatusBar; procedure ButtonCloseClick(Sender: TObject); @@ -481,15 +483,13 @@ begin Ex.LoadExData(FromLazSrcTree); {$endif} if Ex.ErrorMsg <> '' then - Showmessage(Ex.ErrorMsg) - else begin - ex.getCategoryData(CheckGroupCategory.Items); // This sets the name of all categories in the CheckGroup - for i := 0 to CheckGroupCategory.items.Count-1 do // check all the categories we found. - CheckGroupCategory.Checked[i] := true; - ListView1.Clear; - PrimeCatFilter(); - LoadUpListView(); - end; + Showmessage(Ex.ErrorMsg); // Note : previously, we treated this as fatal ? + ex.getCategoryData(CheckGroupCategory.Items); // This sets the name of all categories in the CheckGroup + for i := 0 to CheckGroupCategory.items.Count-1 do // check all the categories we found. + CheckGroupCategory.Checked[i] := true; + ListView1.Clear; + PrimeCatFilter(); + LoadUpListView(); if EditSearch.Text <> rsExSearchPrompt then KeyWordSearch() else EditSearch.SetFocus;