Resource

Resource Basics

Resource Name Export Import Custom Field Definitions
Resource Version 1.0
Category Catalog
Downloads 761
Release Date 5/14/2021 11:46:39 AM
 

Resource Details

Description This script allows you to export/import Custom Field Definitions from database to/from file.
Installation Instructions Download the script to your local drive
Usage Instructions 1. Start Photo Supreme
2. Open Tools -> Scripter
3. Load the downloaded script file
4. Click the run button to start the script

NOTE; Use with caution. Importing a Custom Fields definition file will overwrite your existing Custom Fields.

NOTE2; After importing your Custom Fields you must restart Photo Supreme
Changes in this version n.a.
Special Requirements
 

Author Information

Author Name IDimager Support
 

Available Attachments

Attachment #1 ExportImport_CustomFields.png
 

Script

  procedure ExportToFile(AFileName: WideString);
  var
    AData: TxomResource;
  begin
    AData := TxomResource.Create(nil);
    if PublicCatalog.EnumGUIDData(AdminGUID, 'CUSTOMFIELDDEFS', AData) then
    begin
      AData.ResourceStream.SaveToFile(AFileName);
      Say('Saved as: ' + AFileName);
    end
    else
      Say('No Custom Field Definitions Found');
    AData.Free;
  end;

  procedure ImportFromFile(AFileName: WideString);
  var
    AData: TxomResource;
  begin
    AData := TxomResource.Create(nil);
    if WideFileExists(AFileName) then
    begin
      AData.ResourceStream.LoadFromFile(AFileName);
      PublicCatalog.StoreGUIDData(AdminGUID, 'CUSTOMFIELDDEFS', AData);
      AData.ResourceStream.Position := 0;
      PublicOptions.LoadFromStream(AData.ResourceStream);
      Say('Custom Field Definitions are read from file. Please restart.');
    end
    else
      Say('File ' + AFilename + ' Not Found');
    AData.Free;
  end;

  procedure ImportCustomFields;
  var
    AFileName: WideString;
  begin
    OpenDialog.DefaultExt := '.customfields';
    OpenDialog.InitialDir := WindowsDesktopDir;
    OpenDialog.FileName := 'PhotoSupreme.customfields'
    OpenDialog.Filter := 'Custom Field Definition files|*.customfields|All Files|*.*';
    OpenDialog.Title := 'Import Custom Fields From';
    if OpenDialog.Execute then
    begin
      if AskYN('Are you sure your want to overwrite your existing Custom Fields Definitions with that from the selected file?') then
      begin
        AFileName := OpenDialog.FileName;
        ImportFromFile(AFileName);
      end;
    end;
  end;

  procedure ExportCustomFields;
  var
    AFileName: WideString;
  begin
    SaveDialog.DefaultExt := '.customfields';
    SaveDialog.InitialDir := WindowsDesktopDir;
    SaveDialog.FileName := 'PhotoSupreme.customfields'
    SaveDialog.Filter := 'Custom Field Definition files|*.customfields|All Files|*.*';
    SaveDialog.Title := 'Export Custom Fields To';
    if SaveDialog.Execute then
    begin
      AFileName := SaveDialog.FileName;
      ExportToFile(AFileName);
    end;
  end;

var
  ACustoms: TTntStringList;
  AIdx: Integer;
  ACheck: Boolean;
begin
  ACustoms := TTntStringList.Create;
  try
    ACustoms.Add ('Export Custom Fields to File');
    ACustoms.Add ('Import Custom Fields from File');
    ACustoms.Add ('Cancel');

    ACheck := False;
    AIdx := AskCustom(
                       'What operation would you like to perform?',
                       'CAUTION: Importing Custom Fields will overwrite existing Custom Field Definitions',
                       '',
                       '',
                       ACheck,
                       ACustoms
                     );

    if AIdx = 0 then
      ExportCustomFields
    else if AIdx = 1 then
      ImportCustomFields;
  finally
    ACustoms.Free;
  end;
end;