Changeset 178 for trunk/UCore.pas


Ignore:
Timestamp:
Mar 27, 2018, 11:07:44 AM (6 years ago)
Author:
chronos
Message:
  • Modified: Examples moved to subdirectory Examples.
  • Added: Support for override of default project file opened on first application start.
  • Modified: Fixed displaying of command line help.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UCore.pas

    r174 r178  
    4040    procedure SetAlwaysOnTop(AValue: Boolean);
    4141    function FindFirstNonOption: string;
     42    procedure WriteLnConsole(Text: string);
    4243  public
    4344    AcronymDb: TAcronymDb;
     
    6970const
    7071  ExampleFile = 'Example acronyms.adp';
     72  DefaultOverrideFile = 'Default.txt';
     73
     74resourcestring
     75  SStartMinimizedInTray = 'Start minimized in system tray';
     76  SShowThisHelp = 'Show this help';
     77  SOptions = 'options';
     78  SProjectFile = 'project file';
    7179
    7280
     
    108116end;
    109117
     118procedure TCore.WriteLnConsole(Text: string);
     119begin
     120  {$IFDEF WINDOWS}
     121  if not IsConsole then begin
     122    IsConsole := True;
     123    SysInitStdIO;
     124  end;
     125  {$ENDIF}
     126  WriteLn(Text);
     127end;
     128
    110129procedure TCore.Initialize;
    111130var
    112131  FileNameOption: string;
    113132  ExampleFileName: string;
     133  DefaultOverrideFileName: string;
     134  ExamplesDir: string;
     135  Lines: TStringList;
     136  Output: string;
    114137begin
    115138  if not InitializeStarted then begin
     
    117140    LoadConfig;
    118141
    119     {$IFDEF 0}
    120142    if Application.HasOption('h', 'help') then begin
    121       WriteLn('AcronymDecoder <project file>');
    122       WriteLn('  -t    --tray   Start minimized in system tray');
    123       WriteLn('  -h    --help  Show this help');
     143      Output := 'AcronymDecoder [' + SOptions + '] <' + SProjectFile + '>' + LineEnding;
     144      Output := Output + '  -t    --tray   ' + SStartMinimizedInTray + LineEnding;
     145      Output := Output + '  -h    --help   ' + SShowThisHelp + LineEnding;
     146      WriteLnConsole(Output);
    124147      Application.Terminate;
    125148      Exit;
    126149    end;
    127     {$ENDIF}
    128150
    129151    if Application.HasOption('t', 'tray') then begin
     
    131153    end;
    132154
    133     ExampleFileName := ExtractFileDir(Application.ExeName) + DirectorySeparator + ExampleFile;
     155    ExamplesDir := ExtractFileDir(Application.ExeName) + DirectorySeparator +
     156      'Examples';
     157    {$IFDEF Linux}
     158    // If installed in Linux system then use installation directory for po files
     159    if Application.ExeName = '/usr/bin/' + ExtractFileNameOnly(Application.ExeName) then
     160      ExamplesDir := '/usr/share/' + ExtractFileNameOnly(Application.ExeName) +
     161        DirectorySeparator + 'Examples';
     162    {$ENDIF}
     163    ExampleFileName := ExamplesDir + DirectorySeparator + ExampleFile;
     164
     165    // To override default project file put new project name to default file
     166    DefaultOverrideFileName := ExamplesDir + DirectorySeparator + DefaultOverrideFile;
     167    if FileExists(DefaultOverrideFileName) then begin
     168      Lines := TStringList.Create;
     169      Lines.LoadFromFile(DefaultOverrideFileName);
     170      if Lines.Count > 0 then
     171        ExampleFileName := ExamplesDir + DirectorySeparator + Lines[0];
     172      Lines.Free;
     173    end;
     174
    134175    FileNameOption := FindFirstNonOption;
    135176    if FileNameOption <> '' then begin
     
    144185    if FileExists(ExampleFileName) then begin
    145186      // Open default database with examples if no item is in recent openned history
    146       FileNameOption := ExtractFileDir(Application.ExeName) + DirectorySeparator + ExampleFile;
    147       {$IFDEF Linux}
    148       // If installed in Linux system then use installation directory for po files
    149       if Application.ExeName = '/usr/bin/' + ExtractFileNameOnly(Application.ExeName) then
    150         FileNameOption := '/usr/share/' + ExtractFileNameOnly(Application.ExeName) + '/Examples/' + ExampleFile;
    151       {$ENDIF}
    152       FormMain.ProjectOpen(FileNameOption);
     187      FormMain.ProjectOpen(ExampleFileName);
    153188    end else begin
    154189      // Create empty file
Note: See TracChangeset for help on using the changeset viewer.