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

 SlavaNap source code.

 Copyright 2001,2002 by CyberAlien@users.sourceforge.net
 Released under GNU General Public License

 Latest version is available at
 http://slavanap2.sourceforge.net

*********************************************************}
program SlavaNap;

uses
  {$IFNDEF MemCheckStackTrace}
    S_Heap,
  {$ELSE}
    // MemCheckを使うときは：
    // 「スタックフレームの作成」ON
    // 「TD32デバッグ情報を含める」ON
    // 条件定義に「MemCheckStackTrace」
    // 実行時パッケージをつかわないで構築
    MemCheck in 'MemCheck200\MemCheck.pas',
  {$ENDIF}
  Windows,
  Classes2 in 'Classes2.pas',
  Forms,
  Form in 'Form.pas' {SlavaNapMain},
  BlckSock in 'BlckSock.pas',
  SynSock in 'SynSock.pas',
  MainForm in 'MainForm.pas' {SlavaNapWindow},
  Vars in 'Vars.pas',
  Bans in 'Bans.pas',
  STypes in 'STypes.pas',
  Constants in 'Constants.pas',
  Thread in 'Thread.pas',
  Lang in 'Lang.pas',
  Users in 'Users.pas',
  Handler in 'Handler.pas',
  Napigator in 'Napigator.pas',
  Share in 'Share.pas',
  Settings in 'Settings.pas' {SlavaNapSettings},
  Languages in 'Languages.pas' {SlavaNapLanguage},
  Servers in 'Servers.pas',
  Registered in 'Registered.pas',
  LocalUsers in 'LocalUsers.pas',
  Console in 'Console.pas',
  Channels in 'Channels.pas',
  Config in 'Config.pas',
  QueryOption in 'QueryOption.pas' {SlavaNapQueryOption},
  EditDialog in 'EditDialog.pas' {SlavaNapEdit},
  ChannelForm in 'ChannelForm.pas' {SlavaNapChannelWindow},
  ChanAttr in 'ChanAttr.pas' {SlavaNapChannelAttr},
  ServerAttr in 'ServerAttr.pas' {SlavaNapServerAttr},
  ChatForm in 'ChatForm.pas' {SlavaNapChatWindow},
  WhoisForm in 'WhoisForm.pas' {SlavaNapWhois},
  AboutForm in 'AboutForm.pas' {SlavaNapAbout},
  SetupForm in 'SetupForm.pas' {SlavaNapSetup},
  SlavaMenu in 'SlavaMenu.pas',
  SlavaMasks in 'SlavaMasks.pas',
  SlavaStrings in 'SlavaStrings.pas',
  InvitationForm in 'InvitationForm.pas' {SlavaNapInvitation},
  ModeForm in 'ModeForm.pas' {SlavaNapMode},
  Dagsta in 'Dagsta.pas',
  Class_CmdList in 'Class_CmdList.pas',
  Memory_Manager in 'Memory_Manager.pas',
  Class_Cmd2List in 'Class_Cmd2List.pas',
  Blocks in 'Blocks.pas',
  Keywords in 'Keywords.pas',
  Keywords2 in 'Keywords2.pas',
  Share2 in 'Share2.pas',
  BrowseForm in 'BrowseForm.pas' {SlavaNapBrowseWindow},
  AnnounceForm in 'AnnounceForm.pas' {SlavaNapAnnounceWindow},
  Crypt in 'Crypt.pas',
  SysUtils,
  StringResources in 'StringResources.pas';

{$R *.RES}
{$I Defines.pas}

{$IFNDEF MULTIPLE_INSTANCES}
var
  HWnd: Integer;
{$ENDIF}

begin
  GetApplicationDir;
  StartLogStartup;
  LogStartup('slavanap: starting app');
  Application.ShowMainForm := False;
  LogStartup('slavanap: Application.Initialize');
  Application.Initialize;
  LogStartup('slavanap: InitCommandLine');
  InitCommandLine;
  LogStartup('slavanap: checking multiple instances');
  {$IFNDEF MULTIPLE_INSTANCES}
  if not Allow_Multiple_Instances then
  if FindWindow('TSlavaNapMain', 'SlavaNap') <> 0 then
  begin
    HWnd := FindWindow('TSlavaNapWindow', nil);
    if HWnd <> 0 then
    begin
      ShowWindow(HWnd, SW_SHOWNORMAL);
      SetForegroundWindow(HWnd);
    end;
    Application.Terminate;
    Exit;
  end;
  {$ENDIF}
  if FileExists(ApplicationDir + 'config') then
    IsSetupFailed := False
  else
    ShowSetup;
  // セットアップをキャンセルした場合は起動しない
  if IsSetupFailed then Exit;
  LogStartup('slavanap: ShowWindow(Application.Handle, SW_HIDE);');
  ShowWindow(Application.Handle, SW_HIDE);
  LogStartup('slavanap: Application.CreateForm(TSlavaNapMain, SlavaNapMain);');
  Application.CreateForm(TSlavaNapMain, SlavaNapMain);
  LogStartup('slavanap: Application.CreateForm(TSlavaNapInvitation, SlavaNapInvitation);');
  Application.CreateForm(TSlavaNapInvitation, SlavaNapInvitation);
  LogStartup('slavanap: Application.CreateForm(TSlavaNapMode, SlavaNapMode);');
  Application.CreateForm(TSlavaNapMode, SlavaNapMode);
  LogStartup('slavanap: Application.CreateForm(TSlavaNapLanguage, SlavaNapLanguage);');
  Application.CreateForm(TSlavaNapLanguage, SlavaNapLanguage);
  LogStartup('slavanap: Application.CreateForm(TSlavaNapWindow, SlavaNapWindow);');
  Application.CreateForm(TSlavaNapWindow, SlavaNapWindow);
  LogStartup('slavanap: SetWindowLong(Application.Handle, GWL_EXSTYLE, GetWindowLong(Application.Handle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW);');
  SetWindowLong(Application.Handle, GWL_EXSTYLE, GetWindowLong(Application.Handle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW);
  LogStartup('slavanap: SlavaNapWindow.Show;');
  SlavaNapWindow.Show;

  LogStartup('slavanap: Application.CreateForm(TSlavaNapSettings, SlavaNapSettings);');
  Application.CreateForm(TSlavaNapSettings, SlavaNapSettings);
  LogStartup('slavanap: Application.CreateForm(TSlavaNapQueryOption, SlavaNapQueryOption);');
  Application.CreateForm(TSlavaNapQueryOption, SlavaNapQueryOption);
  LogStartup('slavanap: Application.CreateForm(TSlavaNapEdit, SlavaNapEdit);');
  Application.CreateForm(TSlavaNapEdit, SlavaNapEdit);
  LogStartup('slavanap: Application.CreateForm(TSlavaNapChannelAttr, SlavaNapChannelAttr);');
  Application.CreateForm(TSlavaNapChannelAttr, SlavaNapChannelAttr);
  LogStartup('slavanap: Application.CreateForm(TSlavaNapServerAttr, SlavaNapServerAttr);');
  Application.CreateForm(TSlavaNapServerAttr, SlavaNapServerAttr);
  LogStartup('slavanap: Application.CreateForm(TSlavaNapChatWindow, SlavaNapChatWindow);');
  Application.CreateForm(TSlavaNapChatWindow, SlavaNapChatWindow);
  LogStartup('slavanap: Application.CreateForm(TSlavaNapAbout, SlavaNapAbout);');
  Application.CreateForm(TSlavaNapAbout, SlavaNapAbout);
  // LogStartup('slavanap: SetWindowLong(Application.Handle, GWL_EXSTYLE, GetWindowLong(Application.Handle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW);');
  // SetWindowLong(Application.Handle, GWL_EXSTYLE, GetWindowLong(Application.Handle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW);
  // LogStartup('slavanap: SlavaNapWindow.Show;');
  // SlavaNapWindow.Show;
  LogStartup('slavanap: if not ShowForm then SlavaNapWindow.Hide;');
  if not ShowForm then
    SlavaNapWindow.Hide;
  LogStartup('slavanap: Application.Run;');
  Application.Run;
end.
