unit XData.Wizard.Console;

interface

uses
  ToolsAPI, TMS.ServerWizard.Application;

type
  TTMSXDataConsoleApplicationWizard = class(TTMSBCLCustomApplicationWizard)
  strict protected
    procedure Execute; override;
    function GetComment: string; override;
    function GetFrameworkTypes: TArray<string>; override;
    function GetGlyph: Cardinal; override;
    function GetIDString: string; override;
    function GetName: string; override;
    function GetPlatforms: TArray<string>; override;
  end;

  TTMSConsoleProjectCreator = class(TTMSBCLCustomProjectCreator)
  strict protected
    function GetCreatorType: string; override;
    function GetFrameworkType: string; override;
    function GetPlatforms: TArray<string>; override;
    function GetPreferredPlatform: string; override;
    function GetShowSource: Boolean; override;
    function NewProjectSource(const AProjectName: string): IOTAFile; override;
  end;

implementation

uses
  System.SysUtils, System.Classes, System.IOUtils, Winapi.Windows,
  Vcl.Forms, PlatformApi, XData.Resource;

{ TTMSXDataConsoleApplicationWizard }

procedure TTMSXDataConsoleApplicationWizard.Execute;
var
{$IF COMPILERVERSION > 31}
  lCreator: IOTAProjectCreator190;
{$ELSE}
  lCreator: IOTAProjectCreator160;
{$IFEND}
  lProjectDir: string;
  lProjectName: string;
  lUnitIdent: string;
  lClassName: string;
  lFileName: string;
  lModuleServices: IOTAModuleServices;
begin
  if Supports(BorlandIDEServices, IOTAModuleServices, lModuleServices) then
  begin
    lModuleServices.GetNewModuleAndClassName('', lUnitIdent, lClassName, lFileName);
    lProjectDir := TPath.GetDirectoryName(lFileName);
    lProjectName := FindNewProjectName(TTMSBCLUtility.GetActiveProjectGroup, lProjectDir);

    lCreator := TTMSConsoleProjectCreator.Create(lProjectName, lProjectDir, lUnitIdent, lClassName, lFileName);
    lModuleServices.CreateModule(lCreator);
  end;
end;

function TTMSXDataConsoleApplicationWizard.GetComment: string;
begin
  Result := TMSWebXDataIDEResources.SNewXDataConsoleServer;
end;

function TTMSXDataConsoleApplicationWizard.GetFrameworkTypes: TArray<string>;
begin
  Result := TArray<string>.Create(sFrameworkTypeNone);
end;

function TTMSXDataConsoleApplicationWizard.GetGlyph: Cardinal;
const
  cIconName = 'XDATAWIZARDSERVICEICON';
begin
  Result := LoadIcon(HInstance, MakeIntResource(cIconName));
end;

function TTMSXDataConsoleApplicationWizard.GetIDString: string;
const
  cIdString = 'TMS.XData.Server.Console';
begin
  Result := cIdString;
end;

function TTMSXDataConsoleApplicationWizard.GetName: string;
begin
  Result := TMSWebXDataIDEResources.SXDataConsoleServer;
end;

function TTMSXDataConsoleApplicationWizard.GetPlatforms: TArray<string>;
begin
  Result := TArray<string>.Create(cWin32Platform, cWin64Platform,
    {$IF COMPILERVERSION >= 32}cLinux64Platform,{$IFEND}
    cOSX32Platform);
end;

{ TTMSConsoleProjectCreator }

function TTMSConsoleProjectCreator.GetCreatorType: string;
begin
  Result := sConsole;
end;

function TTMSConsoleProjectCreator.GetFrameworkType: string;
begin
  Result := sFrameworkTypeNone;
end;

function TTMSConsoleProjectCreator.GetPlatforms: TArray<string>;
begin
  Result := TArray<string>.Create(cWin32Platform, cWin64Platform,
    {$IF COMPILERVERSION >= 32}cLinux64Platform,{$IFEND}
    cOSX32Platform);
end;

function TTMSConsoleProjectCreator.GetPreferredPlatform: string;
begin
  Result := cWin32Platform;
end;

function TTMSConsoleProjectCreator.GetShowSource: Boolean;
begin
  Result := True;
end;

function TTMSConsoleProjectCreator.NewProjectSource(const AProjectName: string): IOTAFile;
begin
  Result := TTMSBCLBaseProjectFile.Create(AProjectName, 'XDATACONSOLE', HInstance);
end;

end.
