{ **********************************************************************

    This file is part of CodeTyphon Studio (http://www.pilotlogic.com/)    

    See the file COPYING.FPC, included in this distribution,
    for details about the copyright.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 ********************************************************************** }

{$MODE objfpc}
{$H+}

unit ctUtils;

interface

uses sysutils;

const

 cnCTWindir='C:\codetyphon';
 cnCTUnixdir='/usr/local/codetyphon';

function ctGetDirTrail:String;

function ctGetCTVersion:Int64;
function ctGetCTVersionStr:String;

function ctGetFPCVersionStr:String;
function ctGetFPCRevision:Int64;    
function ctGetFPCRevisionStr:String;

function ctGetHostCPU:String;
function ctGetHostOS:String;
function ctGetHostCPUOS:String;

function ctGetCTDir(const usetrail:boolean=False):String;
Function ctGetRuntimesDir(const usetrail:boolean=False):String;
Function ctGetRuntimesCPUOSDir(const usetrail:boolean=False):String;
Function ctGetSettingsDir(const usetrail:boolean=False):String;
Function ctGetbinSettingsDir(const usetrail:boolean=False):String;
Function ctGetbinLibrariesDir(const usetrail:boolean=False):String;

Function ctGetCodeOceanDir(const usetrail:boolean=False):String;
Function ctGetCodeOceanLibrariesDir(const usetrail:boolean=False):String; 
Function ctGetCodeOceanFontsDir(const usetrail:boolean=False):String;  
Function ctGetCodeOceanSoundsDir(const usetrail:boolean=False):String;
Function ctGetCodeOceanPicturesDir(const usetrail:boolean=False):String;
Function ctGetCodeOceanVideoDir(const usetrail:boolean=False):String;

Function ctGetDocFactoryDir(const usetrail:boolean=False):String;
Function ctGetDocFactoryBuildDir(const usetrail:boolean=False):String;
Function ctGetDocFactoryProjectsDir(const usetrail:boolean=False):String;
Function ctGetDocFactoryXMLDir(const usetrail:boolean=False):String;    
Function ctGetDocFactoryXCTDir(const usetrail:boolean=False):String;

Function ctGetCTScriptsDir(const usetrail:boolean=False):String;

Function ctGetCTHelpDir(const usetrail:boolean=False):String;
Function ctGetCTHelpCHMDir(const usetrail:boolean=False):String;
Function ctGetCTHelpHTMLDir(const usetrail:boolean=False):String;
Function ctGetCTHelpPDFDir(const usetrail:boolean=False):String;

function ctGetFPCSrcDir(const usetrail:boolean=False):String;
function ctGetFPCRootDir(const usetrail:boolean=False):String;
function ctGetFPCBitsDir(const usetrail:boolean=False):String;
function ctGetFPCUnitsDir(const usetrail:boolean=False):String;
function ctGetFPCUnitsCPUOSDir(const usetrail:boolean=False):String;
function ctGetFPCBinDir(const usetrail:boolean=False):String;
function ctGetFPCBinCPUOSDir(const usetrail:boolean=False):String;
function ctGetFPCfpmDir(const usetrail:boolean=False):String;
function ctGetFPCfpmCPUOSDir(const usetrail:boolean=False):String;
function ctGetFPCEXEDir(const usetrail:boolean=False):String;
function ctGetFPCcfgDir(const usetrail:boolean=False):String;

function ctGetTyphonDir(const usetrail:boolean=False):String;
function ctGetTyphonBinDir(const usetrail:boolean=False):String;
function ctGetTyphonEXEDir(const usetrail:boolean=False):String;
function ctGetTyphonFilesDir(const usetrail:boolean=False):String; 
function ctGetTyphonDocsDir(const usetrail:boolean=False):String;
function ctGetTyphonPkgLinksDir(const usetrail:boolean=False):String;
function ctGetTyphonToolsSrcDir(const usetrail:boolean=False):String;
function ctGetTyphonToolsBinDir(const usetrail:boolean=False):String;
function ctGetTyphonComponentsDir(const usetrail:boolean=False):String;


implementation

{$I ../compiler/ctversion.inc}
{$I ../compiler/ctfpcrevision.inc}

//-------------- CodeTyphon ------------------


function ctGetCTVersion:Int64;  
begin
 result:=StrToInt(cnCTVer);
end;

function ctGetCTVersionStr:String;
begin
 result:=cnCTVerStr;
end;
       
function ctGetFPCVersionStr:String;
begin
 result:='3.3.1';
end;

function ctGetFPCRevision:Int64;
begin
 result:=StrToInt64(ctfpcRevision);
end;

function ctGetFPCRevisionStr:String;
begin
 result:=ctfpcRevision;
end;

function ctGetCTDir(const usetrail:boolean=False):String;
begin
 {$IFDEF WINDOWS}
 result:=cnCTWindir; 
 {$ELSE}
 result:=cnCTUnixdir;
 {$ENDIF} 

 if usetrail then Result:=Result+ctGetDirTrail;
end;

//.... CodeOcean ....
Function ctGetCodeOceanDir(const usetrail:boolean=False):String;
begin
   result:=ctGetCTDir(true)+'CodeOcean';
 if usetrail then Result:=Result+ctGetDirTrail;  
end;

Function ctGetCodeOceanFontsDir(const usetrail:boolean=False):String;
begin
   result:=ctGetCodeOceanDir(true)+'01_Fonts';
 if usetrail then Result:=Result+ctGetDirTrail;
end;   

Function ctGetCodeOceanSoundsDir(const usetrail:boolean=False):String;
begin
   result:=ctGetCodeOceanDir(true)+'01_Sounds';
 if usetrail then Result:=Result+ctGetDirTrail;
end;

Function ctGetCodeOceanPicturesDir(const usetrail:boolean=False):String;
begin
   result:=ctGetCodeOceanDir(true)+'01_Pictures';
 if usetrail then Result:=Result+ctGetDirTrail;
end;

Function ctGetCodeOceanVideoDir(const usetrail:boolean=False):String;  
begin
   result:=ctGetCodeOceanDir(true)+'01_Video';
 if usetrail then Result:=Result+ctGetDirTrail;
end;

//.... DocFactory ....
Function ctGetDocFactoryDir(const usetrail:boolean=False):String; 
begin
   result:=ctGetCTDir(true)+'DocFactory';
 if usetrail then Result:=Result+ctGetDirTrail;
end;

Function ctGetDocFactoryBuildDir(const usetrail:boolean=False):String;
begin
   result:=ctGetDocFactoryDir(true)+'build';
 if usetrail then Result:=Result+ctGetDirTrail;
end;

Function ctGetDocFactoryProjectsDir(const usetrail:boolean=False):String;
begin
   result:=ctGetDocFactoryDir(true)+'projects';
 if usetrail then Result:=Result+ctGetDirTrail;
end;

Function ctGetDocFactoryXMLDir(const usetrail:boolean=False):String; 
begin
   result:=ctGetDocFactoryDir(true)+'xml';
 if usetrail then Result:=Result+ctGetDirTrail;
end;

Function ctGetDocFactoryXCTDir(const usetrail:boolean=False):String;
begin
   result:=ctGetDocFactoryDir(true)+'xct';
 if usetrail then Result:=Result+ctGetDirTrail;
end;

//.... Runtimes ....
Function ctGetRuntimesDir(const usetrail:boolean=False):String;
begin
   result:=ctGetCTDir(true)+'binRuntimes';
 if usetrail then Result:=Result+ctGetDirTrail;
end;

Function ctGetRuntimesCPUOSDir(const usetrail:boolean=False):String;
begin
   result:=ctGetCTDir(true)+'binRuntimes'+ctGetDirTrail+
                            LowerCase({$i %FPCTARGETCPU%}+'-'+{$i %FPCTARGETOS%});
 if usetrail then Result:=Result+ctGetDirTrail;
end;

Function ctGetCodeOceanLibrariesDir(const usetrail:boolean=False):String;
begin
   result:=ctGetRuntimesCPUOSDir(usetrail);
end;

Function ctGetSettingsDir(const usetrail:boolean=False):String;
begin
   result:=ctGetCTDir(true)+'Settings';
 if usetrail then Result:=Result+ctGetDirTrail;
end;   

Function ctGetbinSettingsDir(const usetrail:boolean=False):String;
begin
   result:=ctGetCTDir(true)+'binSettings';
 if usetrail then Result:=Result+ctGetDirTrail;
end;

Function ctGetbinLibrariesDir(const usetrail:boolean=False):String;
begin
   result:=ctGetCTDir(true)+'binLibraries';
 if usetrail then Result:=Result+ctGetDirTrail;
end;

Function ctGetCTScriptsDir(const usetrail:boolean=False):String;
begin
 {$IFDEF WINDOWS}
 result:=ctGetCTDir(true)+'ScriptsWin';
 {$ELSE}
 result:=ctGetCTDir(true)+'ScriptsLin';
 {$ENDIF}
 if usetrail then Result:=Result+ctGetDirTrail;
end;

Function ctGetCTHelpDir(const usetrail:boolean=False):String;
begin
   result:=ctGetCTDir(true)+'help';
 if usetrail then Result:=Result+ctGetDirTrail;
end;
Function ctGetCTHelpCHMDir(const usetrail:boolean=False):String;
begin
   result:=ctGetCTHelpDir(true)+'chm';
 if usetrail then Result:=Result+ctGetDirTrail;
end;
Function ctGetCTHelpHTMLDir(const usetrail:boolean=False):String;
begin
   result:=ctGetCTHelpDir(true)+'html';
 if usetrail then Result:=Result+ctGetDirTrail;
end;
Function ctGetCTHelpPDFDir(const usetrail:boolean=False):String;
begin
   result:=ctGetCTHelpDir(true)+'pdf';
 if usetrail then Result:=Result+ctGetDirTrail;
end;

//-------------- FPC --------------------------

function ctGetFPCSrcDir(const usetrail:boolean=False):String;
begin
 result:=ctGetCTDir(True)+'fpcsrc';
 if usetrail then Result:=Result+ctGetDirTrail;
end;

function ctGetFPCRootDir(const usetrail:boolean=False):String;
begin
 result:=ctGetCTDir(True)+'fpc';
 if usetrail then Result:=Result+ctGetDirTrail;
end;

function ctGetFPCBitsDir(const usetrail:boolean=False):String;
begin
 {$IFDEF CPU64}
 result:=ctGetFPCRootDir(True)+'fpc64'; 
 {$ELSE}
 result:=ctGetFPCRootDir(True)+'fpc32';
 {$ENDIF}
 if usetrail then Result:=Result+ctGetDirTrail;
end;

function ctGetFPCBinDir(const usetrail:boolean=False):String;
begin
 result:=ctGetFPCBitsDir(True)+'bin';
 if usetrail then Result:=Result+ctGetDirTrail;
end;      
function ctGetFPCBinCPUOSDir(const usetrail:boolean=False):String;
begin
 result:=ctGetFPCBinDir(True)+ctGetHostCPUOS;
 if usetrail then Result:=Result+ctGetDirTrail;
end;

function ctGetFPCUnitsDir(const usetrail:boolean=False):String;
begin
 result:=ctGetFPCBitsDir(True)+'units';
 if usetrail then Result:=Result+ctGetDirTrail;
end;
function ctGetFPCUnitsCPUOSDir(const usetrail:boolean=False):String;
begin
 result:=ctGetFPCUnitsDir(true)+ctGetHostCPUOS;
 if usetrail then Result:=Result+ctGetDirTrail;
end;

function ctGetFPCfpmDir(const usetrail:boolean=False):String;
begin
 result:=ctGetFPCBitsDir(True)+'fpmkinst';
 if usetrail then Result:=Result+ctGetDirTrail;
end;
function ctGetFPCfpmCPUOSDir(const usetrail:boolean=False):String;
begin
 result:=ctGetFPCfpmDir(True)+ctGetHostCPUOS;
 if usetrail then Result:=Result+ctGetDirTrail;
end;

function ctGetFPCEXEDir(const usetrail:boolean=False):String;
begin
 result:=ctGetFPCBinDir(true)+ctGetHostCPUOS;
 if usetrail then Result:=Result+ctGetDirTrail;
end;

function ctGetFPCcfgDir(const usetrail:boolean=False):String;  
begin
 result:=ctGetFPCEXEDir(usetrail);
end; 

//-------------- Typhon IDE ---------------------

function ctGetTyphonDir(const usetrail:boolean=False):String;
begin
 result:=ctGetCTDir(True)+'typhon';
 if usetrail then Result:=Result+ctGetDirTrail;
end;

function ctGetTyphonBinDir(const usetrail:boolean=False):String;
begin
 {$IFDEF CPU64}
   result:=ctGetTyphonDir(True)+'bin64';
 {$ELSE}
   result:=ctGetTyphonDir(True)+'bin32';
 {$ENDIF}
 if usetrail then Result:=Result+ctGetDirTrail;
end;

function ctGetTyphonEXEDir(const usetrail:boolean=False):String; 
begin
 result:=ctGetTyphonBinDir(usetrail);
end; 

function ctGetTyphonFilesDir(const usetrail:boolean=False):String;
begin
 result:=ctGetTyphonDir(True)+'files';
 if usetrail then Result:=Result+ctGetDirTrail;
end;

function ctGetTyphonDocsDir(const usetrail:boolean=False):String;
begin
 result:=ctGetTyphonDir(True)+'docs';
 if usetrail then Result:=Result+ctGetDirTrail;
end; 

function ctGetTyphonPkgLinksDir(const usetrail:boolean=False):String;
begin
 result:=ctGetTyphonDir(True)+'pkglinks';
 if usetrail then Result:=Result+ctGetDirTrail;
end; 

function ctGetTyphonToolsSrcDir(const usetrail:boolean=False):String;
begin
 result:=ctGetTyphonDir(True)+'tools';
 if usetrail then Result:=Result+ctGetDirTrail;
end;

function ctGetTyphonToolsBinDir(const usetrail:boolean=False):String;
begin
 result:=ctGetTyphonBinDir(usetrail);
end;

function ctGetTyphonComponentsDir(const usetrail:boolean=False):String;
begin
 result:=ctGetTyphonDir(True)+'components';
 if usetrail then Result:=Result+ctGetDirTrail;
end;

//-------------- GENERAL ---------------------

function ctGetDirTrail:String;
begin
 result:='/';
 {$IFDEF WINDOWS}
 result:='\';
 {$ENDIF}
end;

function ctGetHostCPU:String;
begin
result:='';

{$ifdef CPUi386}
   result:='i386';
{$endif}
{$ifdef CPUx86_64}
   result:='x86_64';
{$endif}
{$ifdef CPUARM}
   result:='arm';
{$endif}
{$ifdef CPUaarch64}
   result:='aarch64';
{$endif}    
{$ifdef CPUsparc}
   result:='sparc';
{$endif}     
{$ifdef CPUsparc64}
   result:='sparc64';
{$endif}     
{$ifdef CPUpowerpc}
   result:='powerpc';
{$endif}     
{$ifdef CPUpowerpc64}
   result:='powerpc64';
{$endif}     
{$ifdef CPUmips}
   result:='mips';
{$endif}
{$ifdef CPUmips64}
   result:='mips64';
{$endif}

end;

function ctGetHostOS:String; 
begin
result:='';
{$ifdef Windows}
  {$ifdef CPU32}
     result:='win32';
  {$endif}
  {$ifdef CPU64}
     result:='win64';
  {$endif}
{$ELSE}
  {$ifdef linux}
   result:='linux';
  {$endif}
  {$ifdef freebsd}
    result:='freebsd';
  {$endif}
  {$ifdef openbsd}
    result:='openbsd';
  {$endif}
  {$ifdef netbsd}
    result:='netbsd';
  {$endif}
  {$ifdef dragonfly}
    result:='dragonfly';
  {$endif}
  {$ifdef darwin}
    result:='darwin';
  {$endif}
  {$IF DEFINED(solaris) or DEFINED(sunos)}
    result:='solaris';
  {$endif}
{$endif}
end;

function ctGetHostCPUOS:String;
begin
  result:=ctGetHostCPU+'-'+ctGetHostOS;
end;

end.
