/[pcsx2_0.9.7]/trunk/pcsx2/gui/Panels/MemoryCardsPanel.cpp
ViewVC logotype

Contents of /trunk/pcsx2/gui/Panels/MemoryCardsPanel.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (show annotations) (download)
Tue Sep 7 03:24:11 2010 UTC (9 years, 11 months ago) by william
File size: 4357 byte(s)
committing r3113 initial commit again...
1 /* PCSX2 - PS2 Emulator for PCs
2 * Copyright (C) 2002-2010 PCSX2 Dev Team
3 *
4 * PCSX2 is free software: you can redistribute it and/or modify it under the terms
5 * of the GNU Lesser General Public License as published by the Free Software Found-
6 * ation, either version 3 of the License, or (at your option) any later version.
7 *
8 * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10 * PURPOSE. See the GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License along with PCSX2.
13 * If not, see <http://www.gnu.org/licenses/>.
14 */
15
16 #include "PrecompiledHeader.h"
17 #include "ConfigurationPanels.h"
18 #include "MemoryCardPanels.h"
19
20 #include "Dialogs/ConfigurationDialog.h"
21
22 #include <wx/filepicker.h>
23 #include <wx/ffile.h>
24 #include <wx/dir.h>
25
26 using namespace pxSizerFlags;
27 using namespace Panels;
28
29
30 // =====================================================================================================
31 // MemoryCardInfoPanel (implementations)
32 // =====================================================================================================
33 MemoryCardInfoPanel::MemoryCardInfoPanel( wxWindow* parent, uint slot )
34 : BaseApplicableConfigPanel( parent, wxVERTICAL ) //, wxEmptyString )
35 {
36 m_slot = slot;
37
38 SetMinSize( wxSize(128, 48) );
39
40 Connect( wxEVT_PAINT, wxPaintEventHandler(MemoryCardInfoPanel::paintEvent) );
41
42 // [TODO] Add Unmount button.
43 }
44
45
46 void MemoryCardInfoPanel::paintEvent(wxPaintEvent & evt)
47 {
48 wxPaintDC dc( this );
49 pxWindowTextWriter writer( dc );
50
51 writer.Bold();
52
53 // Create DC and plot some text (and images!)
54 writer.WriteLn( m_DisplayName );
55
56 //dc.DrawCircle( dc.GetSize().GetWidth()/2, 24, dc.GetSize().GetWidth()/4 );
57
58 if( !m_ErrorMessage.IsEmpty() )
59 {
60 writer.WriteLn();
61 writer.WriteLn( m_ErrorMessage );
62 }
63 else if( m_cardInfo )
64 {
65 writer.Normal();
66
67 writer.WriteLn( wxsFormat( L"%d MB (%s)",
68 m_cardInfo->SizeInMB,
69 m_cardInfo->IsFormatted ? _("Formatted") : _("Unformatted") )
70 );
71 }
72 }
73
74 void MemoryCardInfoPanel::Eject()
75 {
76 m_cardInfo = NULL;
77 Refresh();
78 }
79
80 void MemoryCardInfoPanel::Apply()
81 {
82 if( m_cardInfo && m_cardInfo->Filename.GetFullName().IsEmpty() ) m_cardInfo = NULL;
83
84 if( m_cardInfo )
85 {
86 wxFileName absfile( Path::Combine( g_Conf->Folders.MemoryCards, m_cardInfo->Filename ) );
87
88 // The following checks should be theoretically unreachable, unless the user's
89 // filesystem is changed form under our nose. A little validation goes a
90 // long way. :p
91
92 if( absfile.IsDir() )
93 {
94 Eject();
95 throw Exception::CannotApplySettings( this,
96 // Diagnostic
97 wxsFormat( L"Memorycard in slot %u conflicts with an existing directory.", m_slot ),
98 // Translated
99 wxsFormat(
100 _("Cannot use or create the memorycard in slot %u: the filename conflicts with an existing directory."),
101 m_slot
102 )
103 );
104 }
105
106 if( !absfile.FileExists() )
107 {
108 Eject();
109 throw Exception::CannotApplySettings( this,
110 // Diagnostic
111 wxsFormat( L"Memorycard in slot %u is no longer valid.", m_slot ),
112 // Translated
113 wxsFormat(
114 _("The configured memorycard in slot %u no longer exists. Please create a new memory card, or leave the slot unmounted."),
115 m_slot
116 )
117 );
118 }
119
120 g_Conf->Mcd[m_slot].Filename = m_cardInfo->Filename;
121 g_Conf->Mcd[m_slot].Enabled = true;
122 }
123 else
124 {
125 // Card is either disabled or in an error state.
126
127 g_Conf->Mcd[m_slot].Enabled = false;
128 g_Conf->Mcd[m_slot].Filename.Clear();
129 }
130 }
131
132 void MemoryCardInfoPanel::AppStatusEvent_OnSettingsApplied()
133 {
134 m_cardInfo = NULL;
135
136 // Collect Info and Format Strings
137
138 wxString fname( g_Conf->Mcd[m_slot].Filename.GetFullPath() );
139 if( fname.IsEmpty() )
140 {
141 m_DisplayName = _("No Card (empty)");
142 m_cardInfo = NULL;
143 }
144 else
145 {
146 wxFileName absfile( Path::Combine( g_Conf->Folders.MemoryCards, fname ) );
147 wxFileName relfile( fname );
148
149 if( !m_cardInfo )
150 {
151 m_cardInfo = new McdListItem();
152 if( !EnumerateMemoryCard( *m_cardInfo, absfile.GetFullPath() ) )
153 {
154 m_ErrorMessage = _("Read Error: Card is truncated or corrupted.");
155 }
156 }
157
158 absfile.Normalize();
159 relfile.Normalize();
160
161 m_DisplayName = ( absfile == relfile ) ? relfile.GetFullName() : relfile.GetFullPath();
162 }
163
164 Refresh();
165 }

  ViewVC Help
Powered by ViewVC 1.1.22