1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
/***************************************************************
* Purpose: Code for Application Class
* Author: ZenJu (zhnmju123@gmx.de)
* Created: 2009-07-06
* Copyright: ZenJu (http://sourceforge.net/projects/freefilesync/)
**************************************************************/
#include "application.h"
#include "mainDialog.h"
#include <wx/event.h>
#include "resources.h"
#include <wx/msgdlg.h>
#include "../shared/localization.h"
#include "xmlFreeFileSync.h"
#include "../shared/standardPaths.h"
#include <wx/file.h>
#ifdef FFS_LINUX
#include <gtk/gtk.h>
#endif
IMPLEMENT_APP(Application);
bool Application::OnInit()
{
//do not call wxApp::OnInit() to avoid using default commandline parser
//Note: initialization is done in the FIRST idle event instead of OnInit. Reason: Commandline mode requires the wxApp eventhandler to be established
//for UI update events. This is not the case at the time of OnInit().
Connect(wxEVT_IDLE, wxIdleEventHandler(Application::OnStartApplication), NULL, this);
return true;
}
void Application::OnStartApplication(wxIdleEvent& event)
{
Disconnect(wxEVT_IDLE, wxIdleEventHandler(Application::OnStartApplication), NULL, this);
//if appname is not set, the default is the executable's name!
SetAppName(wxT("FreeFileSync")); //use a different app name, to have "GetUserDataDir()" return the same directory as for FreeFileSync
#ifdef FFS_LINUX
::gtk_rc_parse("styles.rc"); //remove inner border from bitmap buttons
#endif
//initialize help controller
helpController.reset(new wxHelpController);
helpController->Initialize(FreeFileSync::getInstallationDir() +
#ifdef FFS_WIN
wxT("FreeFileSync.chm"));
#elif defined FFS_LINUX
wxT("Help/FreeFileSync.hhp"));
#endif
//set program language
FreeFileSync::CustomLocale::getInstance().setLanguage(RealtimeSync::getProgramLanguage());
//try to set config/batch-filename set by %1 parameter
wxString cfgFilename;
if (argc > 1)
{
const wxString filename(argv[1]);
if (wxFileExists(filename)) //load file specified by %1 parameter:
cfgFilename = filename;
else if (wxFileExists(filename + wxT(".ffs_real")))
cfgFilename = filename + wxT(".ffs_real");
else if (wxFileExists(filename + wxT(".ffs_batch")))
cfgFilename = filename + wxT(".ffs_batch");
else
{
wxMessageBox(wxString(_("File does not exist:")) + wxT(" \"") + filename + wxT("\""), _("Error"), wxOK | wxICON_ERROR);
return;
}
}
GlobalResources::getInstance().load(); //loads bitmap resources on program startup
MainDialog* frame = new MainDialog(NULL, cfgFilename, *helpController);
frame->SetIcon(*GlobalResources::getInstance().programIcon); //set application icon
frame->Show();
}
bool Application::OnExceptionInMainLoop()
{
throw; //just re-throw exception and avoid display of additional exception messagebox: it will be caught in OnRun()
}
int Application::OnRun()
{
try
{
wxApp::OnRun();
}
catch (const std::exception& e) //catch all STL exceptions
{
//unfortunately it's not always possible to display a message box in this erroneous situation, however (non-stream) file output always works!
wxFile safeOutput(FreeFileSync::getLastErrorTxtFile(), wxFile::write);
safeOutput.Write(wxString::FromAscii(e.what()));
wxMessageBox(wxString::FromAscii(e.what()), _("An exception occured!"), wxOK | wxICON_ERROR);
return -9;
}
return 0; //program's return value
}
|