-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathMergeDialog.cpp
More file actions
118 lines (96 loc) · 2.94 KB
/
MergeDialog.cpp
File metadata and controls
118 lines (96 loc) · 2.94 KB
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
111
112
113
114
115
116
117
118
#include "MergeDialog.h"
#include "wx/hyperlink.h"
#include "wx/log.h"
#include "wx/msgdlg.h"
#include "wx/busyinfo.h"
MergeDialog::MergeDialog( wxWindow* parent ):
BaseMergeDialog( parent )
{
m_backupAvailable = false;
GetSizer()->SetMinSize(wxDLG_UNIT(this, wxSize(260, 60)));
m_sdbSizerOK->SetLabel(_("Merge"));
wxHyperlinkCtrl* linkCtrl = new wxHyperlinkCtrl(this, wxID_ANY, _("Restore Base WAD"), "");
m_sdbSizer->Insert(0, linkCtrl, wxSizerFlags().Center().Border());
m_sdbSizer->InsertSpacer(1, -1);
m_sdbSizer->Layout();
linkCtrl->Bind(wxEVT_COMMAND_HYPERLINK, &MergeDialog::OnRestoreClicked, this);
Fit();
Center();
}
void MergeDialog::OnRestoreClicked(wxCommandEvent& event)
{
if (!wxFileExists(GetBackupFileName()))
{
wxLogError(_("Backup file not found"));
return;
}
bool success = false;
wxMessageDialog msgDlg(this, _("Are you sure you wan't to restore this file from the backup copy?"), _("Warning"), wxICON_WARNING | wxYES_NO);
msgDlg.SetYesNoLabels(_("Restore"), _("Don't Restore"));
if (msgDlg.ShowModal() == wxID_YES)
{
wxBusyInfo busyInfo(_("Restoring from backup..."));
wxBusyCursor busyCursor;
if (!wxCopyFile(GetBackupFileName(), m_baseFilePicker->GetFileName().GetFullPath(), true))
wxLogError(_("Backup could not be restored"));
else
success = true;
}
if (success)
wxMessageBox(_("Backup successfully restored"), _("Information"), wxICON_INFORMATION|wxOK, this);
}
bool MergeDialog::TransferDataFromWindow()
{
if (!BaseMergeDialog::TransferDataFromWindow())
return false;
if (!m_baseFilePicker->GetFileName().Exists())
{
wxLogError(_("Base file not found"));
return false;
}
if (!m_patchFilePicker->GetFileName().Exists())
{
wxLogError(_("Patch file not found"));
return false;
}
CheckBackup();
if (!ConfirmBackup())
return false;
return true;
}
bool MergeDialog::ConfirmBackup()
{
if (m_backupAvailable)
return true;
wxMessageDialog msgDlg(this, _("Backup recommended\n\nBefore modifying the file it is recommend to create a backup.\nDo you wish to create a backup now?"),
_("Warning"), wxICON_WARNING | wxYES_NO | wxCANCEL);
msgDlg.SetYesNoLabels(_("Backup"), _("Don't backup"));
switch (msgDlg.ShowModal()) {
case wxID_YES:
{
wxBusyInfo busyInfo(_("Creating backup..."));
wxBusyCursor busyCursor;
if (!wxCopyFile(m_baseFilePicker->GetFileName().GetFullPath(), GetBackupFileName()))
{
wxLogError(_("Backup could not be created"));
return false;
} else {
CheckBackup();
return true;
}
}
case wxID_NO:
return true;
default:
return false;
}
}
void MergeDialog::CheckBackup()
{
m_backupAvailable = wxFileExists(GetBackupFileName());
}
wxString MergeDialog::GetBackupFileName() const
{
wxString backupFileName = m_baseFilePicker->GetFileName().GetFullPath() + "_bkup";
return backupFileName;
}