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

 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
  s_heap,
  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;

{$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.
