Resource

Resource Basics

Resource Name Export Import Favorites
Resource Version 1.01
Category Catalog
Downloads 716
Release Date 5/28/2020 1:47:46 PM
 

Resource Details

Description This script allows you to export/import Favorites from database to/from file.
Installation Instructions Download the script to your local hard 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 favorites file will overwrite your existing favorites.

NOTE2; After importing your Favorites, you must restart Photo Supreme
Changes in this version 1.01 Made it possible to load an empty favorites file
Special Requirements
 

Author Information

Author Name IDimager Support
 

Available Attachments

Attachment #1 ImportExportFavorites.png
 

Script

  procedure ExportToFile(AFileName: WideString);
  var
    AData: TxomResource;
  begin
    AData := TxomResource.Create(nil);
    if PublicCatalog.EnumGUIDData(CurrentUser.GUID, 'FAVORITES', AData) then
    begin
      AData.ResourceStream.SaveToFile(AFileName);
      Say('Saved as: ' + AFileName);
    end
    else
      Say('No Options 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(CurrentUser.GUID, 'FAVORITES', AData);
      AData.ResourceStream.Position := 0;
      PublicOptions.LoadFromStream(AData.ResourceStream);
      AData.ResourceStream.Position := 0;
      FavoritesGroup.Clear;
      FavoritesGroup.LoadFromStream(AData.ResourceStream);
      Say('Favorites are read from file. Please restart.');
    end
    else
      Say('File ' + AFilename + ' Not Found');
    AData.Free;
  end;

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

  procedure ExportFavorites;
  var
    AFileName: WideString;
  begin
    SaveDialog.DefaultExt := '.favorites';
    SaveDialog.InitialDir := WindowsDesktopDir;
    SaveDialog.FileName := 'PhotoSupreme.favorites'
    SaveDialog.Filter := 'Favorites files|*.favorites|All Files|*.*';
    SaveDialog.Title := 'Export Favorites 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 Favorites to File');
    ACustoms.Add ('Import Favorites from File');
    ACustoms.Add ('Cancel');

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

    if AIdx = 0 then
      ExportFavorites
    else if AIdx = 1 then
      ImportFavorites;
  finally
    ACustoms.Free;
  end;
end;