+ wxArtProvider::Push(new AlternateArtProvider);
+
+#if defined( __WXOSX_MAC__ ) && wxOSX_USE_CARBON
+ wxApp::s_macAboutMenuItemId = wxID_ABOUT;
+ wxFileName::MacRegisterDefaultTypeAndCreator( wxT("htb") , 'HTBD' , 'HTBA' ) ;
+#endif
+
+ int istyle = wxHF_DEFAULT_STYLE;
+
+ wxString service, windowName, titleFormat, argStr;
+ wxString book[10];
+ int bookCount = 0;
+ int i;
+ bool hasService = false;
+ bool hasWindowName = false;
+ bool createServer = false;
+
+#if wxUSE_IPC
+ m_server = NULL;
+#endif
+
+ // Help books are recognized by extension ".hhp" ".htb" or ".zip".
+ // Service and window_name can occur anywhere in arguments,
+ // but service must be first
+ // Other arguments (topic?) could be added
+
+ // modes of operation:
+ // 1) no arguments - stand alone, prompt user for book
+ // 2) books only - stand alone, open books
+ // 3) "--server" as (any) arg - start connection with default service;
+ // also open any books passed as other arguments
+ // 4) at least one argument which is not book, and not "--server" - take first
+ // such argument as service, second (if present) as window name,
+ // start service, open any books
+
+ for( i=1; i<argc; i++ )
+ {
+ argStr = argv[i];
+
+ if ( argStr.Find( wxT(".hhp") ) >= 0
+ || argStr.Find( wxT(".htb") ) >= 0
+ || argStr.Find( wxT(".zip") ) >= 0 )
+ {
+ book[bookCount] = argStr;
+ bookCount++;
+ }
+ else if ( argStr == wxT("--server") )
+ {
+ createServer = true;
+#if defined(__WXMSW__)
+ service = wxT("generic_helpservice");
+#elif defined(__UNIX__)
+ service = wxT("/tmp/") + wxString(wxT("generic_helpservice"));
+#else
+ service = wxT("4242");
+#endif
+ }
+ else if ( !hasService )
+ {
+ service = argStr;
+ hasService = true;
+ createServer = true;
+ }
+ else if ( !hasWindowName )
+ {
+ windowName = argStr;
+ hasWindowName = true;
+ }
+ else if ( argStr.Find( wxT("--Style") ) >= 0 )
+ {
+ long i;
+ wxString numb = argStr.AfterLast(wxT('e'));
+ if ( !(numb.ToLong(&i) ) )
+ {
+ wxLogError( wxT("Integer conversion failed for --Style") );
+ }
+ else
+ {
+ istyle = i;
+ }
+ }
+ else
+ {
+ //unknown - could be topic?
+ }
+ }
+
+ // No book - query user; but not on Mac, since there
+ // may be an AppleEvent to open a document on the way
+#ifndef __WXMAC__
+ if ( bookCount < 1 )
+ {
+ wxString s = wxFileSelector( wxT("Open help file"),
+ wxGetCwd(),
+ wxEmptyString,
+ wxEmptyString,
+ wxT("Help books (*.htb)|*.htb|Help books (*.zip)|*.zip|HTML Help Project (*.hhp)|*.hhp"),
+ wxFD_OPEN | wxFD_FILE_MUST_EXIST,
+ NULL);
+
+ if (!s.empty())
+ {
+ book[0] = s;
+ bookCount = 1;
+ }
+ }
+#endif
+
+#if wxUSE_IPC
+
+ if ( createServer )
+ {
+ // Create a new server
+ m_server = new hvServer;
+
+ if ( !m_server->Create(service) )
+ {
+ wxString wxm = wxT("Server Create failed - service: ");
+ wxString xxm = wxm << service;
+ wxLogError( xxm );
+ //if MSW quits here, probably another copy already exists
+ return false;
+ }
+ createServer = false;
+ wxUnusedVar(createServer);
+ }
+
+#endif // wxUSE_IPC
+
+ //now add help