(* '=============================================== ' Descript.ion Importer V3 ' Author: H van Zwietering; based on a script from iView: http://www.idimager.com/forum/viewtopic.php?t=1362 ' Modified: franky68 to reflect current descript.ion files ' Modified: H van Zwietering; modified to support PhotoSupreme ' Date: 27-december-2013 '=============================================== *) var key1, line1, line2: WideString; tester, counter: Integer; AIonSL: TTntStringList; i, j, s: Integer; AItem: TImageItem; strPathActive, strPath: WideString; splitter1, splitter2: TTntStringList; keyword: WideString; ACatItem: TCatalogItem; begin if Selected.Count = 0 then begin Say ('No selection made.'); exit; end; Progress.Cancel := False; Progress.Max := Selected.Count; Progress.Show; ACatItem := TCatalogItem.Create (nil); AIonSL := nil; strPathActive := ''; // iterate over every selected item counter := 0; for i := 0 to Selected.Count - 1 do begin Progress.ProgressText := Selected.Items[i].FileName; Progress.Pos := i + 1; if Progress.Cancel then break; key1 := ''; line1 := ''; line2 := ''; tester := 0; AItem := Selected.Items[i]; if not AItem.MediumLoaded then continue; // build Path to descript.ion from folder strPath := WideExtractFilePath (AItem.FileName); strPath := WideIncludeTrailingBackslash(strPath) + 'descript.ion'; if not WideFileExists (strpath) then begin //Say ('No descript.ion file found as ' + strPath); continue; end; if not WideSameText(strPathActive, strPath) then // same as already loaded begin if Assigned(AIonSL) then AIonSL.Free; // open descript.ion AIonSL := TTntStringList.Create; AIonSL.LoadFromFile(strPath); strPathActive := strPath; end; // loop through descript.ion for s := 0 to AIonSL.Count - 1 do begin tester := 0; line1 := AIonSL.Strings[s]; // get keys // key1 := filename // line format = [, ] splitter1 := TTntStringList.Create; p := Pos(' ', line1); // Find the first space and use it to split the filename from the keywords splitter1.Add(Trim(LeftStr(line1, p))); splitter1.Add(Trim(RightStr(line1, Length(line1)-p))); key1 := splitter1.Strings[0]; // if file found in descript.ion, get information if WideSameText (key1, WideExtractFileName (AItem.FileName)) then begin line2 := splitter1.Strings[1]; tester := 1; counter := counter + 1; if not Catalog.FindImageCombined (AItem, ACatItem, False, phtNone) then begin // if the image is not yet in catalog, then create it if not Catalog.AddFile (AItem, ACatItem, False) then Continue; end; // Quote every field in case they contain spaces. We deal with the trimming later line2 := '"' + StrTran(line2, ',', '","') + '"'; splitter2 := TTntStringList.Create; splitter2.CommaText := line2; for j := 0 to splitter2.Count-1 do begin keyword := Trim(splitter2.Strings[j]); AProp := TCatalogItemProp.Create(nil); if not Catalog.FindPropByName (keyword, AProp, '', True) then begin // doesn't exist; ok, create one in the Keywords category AProp.GUID := NewGUID; // give a unique ID AProp.PropName := keyword; Catalog.StorePropToDatabase (AProp, KeywordsGUID, False); end; Catalog.AddPropToItem (ACatItem, AProp, False, False); AProp.Free; end; splitter2.Free; end; splitter1.Free; if (tester = 1) then break; end; // for s end; // for i ACatItem.Free; if Assigned(AIonSL) then AIonSL.Free; Progress.Hide; Say('Descript.ion data imported! (' + IntToStr(counter) + ' records updated)'); end;