/* LaserTankApp.cpp
**
** This file is part of wxLaserTank.
**
** Copyright © 2002, 2009 Gary Harris
**
** Based on LaserTank ver 4.1.2 by Jim Kindley.
**
** wxLaserTank is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License as
** published by the Free Software Foundation; either version 2 of
** the License, or (at your option) any later version.
**
** 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. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; see the file docs\gpl.txt.
** If not, write to the Free Software Foundation, Inc.,
** 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Gary Harris
** garyjharris@sourceforge.net
*/
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
// For compilers that support pre-compilation, includes "wx.h".
#include <wx/wxprec.h>
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
// Include your minimal set of headers here, or wx.h
#include <wx/wx.h>
#endif
#include <wx/xrc/xmlres.h>
#include "wx/wxprec.h"
#include <wx/utils.h>
#include <wx/cmdline.h> // For command line processing.
#include <wx/fileconf.h>
#include <wx/stdpaths.h>
#include "LaserTankApp.h"
#include "LaserTankFrm.h"
#include "LT32l_us.h"
// Create a new application object: this macro will allow wxWindows to create
// the application object during program execution (it's better than using a
// static object for many reasons) and also declares the accessor function
// wxGetApp() which will return the reference of the right type (i.e. LaserTankApp and
// not wxApp)
//(*AppHeaders
//#include <wx/image.h>
//*)
IMPLEMENT_APP(LaserTankApp)
// ============================================================================
// implementation
// ============================================================================
// ----------------------------------------------------------------------------
// the application class
// ----------------------------------------------------------------------------
// 'Main program' equivalent: the program execution "starts" here
bool LaserTankApp::OnInit()
{
// Get Command line stuff
static const wxCmdLineEntryDesc cmdLineDesc[] =
{
{ wxCMD_LINE_PARAM, NULL, NULL, _T("level file"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL},
{ wxCMD_LINE_NONE }
};
// Parse command line
wxString cmdFilename;
wxCmdLineParser cmdParser(cmdLineDesc, argc, argv);
cmdParser.Parse(false);
// Check for a level filename
wxFileName fName;
if (cmdParser.GetParamCount() > 0){
cmdFilename = cmdParser.GetParam(0);
// Under Windows when invoking via a document
// in Explorer, we are passed the short form.
// So normalize and make the long form.
fName.Assign(cmdFilename);
// Check file suffix and only accept level files.
if(fName.GetExt().CmpNoCase(wxT("lvl")) == 0){
fName.Normalize(wxPATH_NORM_LONG|wxPATH_NORM_DOTS|wxPATH_NORM_TILDE|wxPATH_NORM_ABSOLUTE);
cmdFilename = fName.GetFullPath();
}
}
//**** Disable the default command line handling here as nothing else works.
// call the base class initialization method, currently it only parses a
// few common command-line options but it could be do more in the future
// if ( !wxApp::OnInit() )
// return false;
// Get the app. path.
wxStandardPathsBase& stdp = wxStandardPaths::Get();
wxString sAppPath = stdp.GetExecutablePath().BeforeLast(wxFileName::GetPathSeparator()) + wxFileName::GetPathSeparator();
// Get the saved window position co-ords.
wxFileConfig *pConfig = new wxFileConfig(wxEmptyString, wxEmptyString, sAppPath + INIFileName, wxEmptyString, wxCONFIG_USE_RELATIVE_PATH);
wxInt32 xp = pConfig->Read(cfgSCREEN + cfgXpos, 0L);
wxInt32 yp = pConfig->Read(cfgSCREEN + cfgYpos, 0L);
delete wxConfigBase::Set((wxConfigBase *) NULL);
// Localisation.
int lang = wxLocale::GetSystemLanguage();
m_locale.Init(lang);
wxLocale::AddCatalogLookupPathPrefix(wxT("./lang"));
m_locale.AddCatalog(wxT("wxlasertank"));
// create the main application window
LaserTankFrame *frame = new LaserTankFrame(LTG->App_Title(), wxPoint(xp, yp), wxSize(602, 370), cmdFilename, sAppPath);
// Check for multiple instances. Exit if already running.
const wxString name = wxString::Format(GetAppName() + wxT("-%s"), wxGetUserId().c_str());
m_checker = new wxSingleInstanceChecker(name);
if(m_checker->IsAnotherRunning()){
wxMessageDialog dialog(frame,
_("Another instance of the program is running, exiting.\n"),
LTG->txt007(),
wxOK|wxICON_ERROR);
dialog.ShowModal();
delete m_checker;
return false;
}
//SetClientSize and show it (the frames, unlike simple controls, are not shown when
// created initially)
frame->Show(true);
// Return the main frame window
SetTopWindow(frame);
// success: wxApp::OnRun() will be called which will enter the main message
// loop and the application will run. If we returned FALSE here, the
// application would exit immediately.
return true;
}
int LaserTankApp::OnExit()
{
wxDELETE(m_checker);
wxASSERT(!m_checker);
return 0;
}