/[pcsx2_0.9.7]/trunk/pcsx2/gui/Dialogs/CreateMemoryCardDialog.cpp
ViewVC logotype

Contents of /trunk/pcsx2/gui/Dialogs/CreateMemoryCardDialog.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 280 - (show annotations) (download)
Thu Dec 23 12:02:12 2010 UTC (9 years, 2 months ago) by william
File size: 6359 byte(s)
re-commit (had local access denied errors when committing)
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 "ConfigurationDialog.h"
18 #include "System.h"
19
20 #include "MemoryCardFile.h"
21
22 #include <wx/filepicker.h>
23 #include <wx/ffile.h>
24
25 using namespace pxSizerFlags;
26
27 extern wxString GetMsg_McdNtfsCompress();
28
29 wxFilePickerCtrl* CreateMemoryCardFilePicker( wxWindow* parent, uint portidx, uint slotidx, const wxString& filename=wxEmptyString )
30 {
31 return new wxFilePickerCtrl( parent, wxID_ANY, filename,
32 wxsFormat(_("Select memory card for Port %u / Slot %u"), portidx+1, slotidx+1), // picker window title
33 L"*.ps2", // default wildcard
34 wxDefaultPosition, wxDefaultSize,
35 wxFLP_DEFAULT_STYLE & ~wxFLP_FILE_MUST_EXIST
36 );
37
38 }
39
40 Dialogs::CreateMemoryCardDialog::CreateMemoryCardDialog( wxWindow* parent, uint slot, const wxDirName& mcdpath, const wxString& mcdfile )
41 : wxDialogWithHelpers( parent, _("Create new memory card") )
42 , m_mcdpath( mcdpath.IsOk() ? mcdpath : (wxDirName)g_Conf->Mcd[slot].Filename.GetPath() )
43 , m_mcdfile( mcdfile.IsEmpty() ? g_Conf->Mcd[slot].Filename.GetFullName() : mcdfile )
44 {
45 SetMinWidth( 472 );
46 m_filepicker = NULL;
47 m_slot = slot;
48
49 CreateControls();
50
51 //m_filepicker = CreateMemoryCardFilePicker( this, m_port, m_slot, filepath );
52
53 // ----------------------------
54 // Sizers and Layout
55 // ----------------------------
56
57 if( m_radio_CardSize ) m_radio_CardSize->Realize();
58
59 wxBoxSizer& s_buttons( *new wxBoxSizer(wxHORIZONTAL) );
60 s_buttons += new wxButton( this, wxID_OK, _("Create") ) | pxProportion(2);
61 s_buttons += pxStretchSpacer(3);
62 s_buttons += new wxButton( this, wxID_CANCEL ) | pxProportion(2);
63
64 wxBoxSizer& s_padding( *new wxBoxSizer(wxVERTICAL) );
65
66 //s_padding += Heading(_("Select the size for your new memory card."));
67
68 if( m_filepicker )
69 s_padding += m_filepicker | StdExpand();
70 else
71 {
72 s_padding += Heading( _( "New card will be saved to:" ) ) | StdExpand();
73 s_padding += Heading( (m_mcdpath + m_mcdfile).GetFullPath() ).Unwrapped() | StdExpand();
74 }
75
76 s_padding += m_radio_CardSize | StdExpand();
77 #ifdef __WXMSW__
78 if( m_check_CompressNTFS )
79 s_padding += m_check_CompressNTFS | StdExpand();
80 #endif
81
82 s_padding += 12;
83 s_padding += s_buttons | StdCenter();
84
85 *this += s_padding | StdExpand();
86
87 Connect( wxID_OK, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( CreateMemoryCardDialog::OnOk_Click ) );
88 }
89
90 wxDirName Dialogs::CreateMemoryCardDialog::GetPathToMcds() const
91 {
92 return m_filepicker ? (wxDirName)m_filepicker->GetPath() : m_mcdpath;
93 }
94
95 // When this GUI is moved into the FileMemoryCard plugin (where it eventually belongs),
96 // this function will be removed and the MemoryCardFile::Create() function will be used
97 // instead.
98 static bool CreateIt( const wxString& mcdFile, uint sizeInMB )
99 {
100 //int enc[16] = {0x77,0x7f,0x7f,0x77,0x7f,0x7f,0x77,0x7f,0x7f,0x77,0x7f,0x7f,0,0,0,0};
101
102 u8 m_effeffs[528*16];
103 memset8<0xff>( m_effeffs );
104
105 Console.WriteLn( L"(FileMcd) Creating new %uMB memory card: " + mcdFile, sizeInMB );
106
107 wxFFile fp( mcdFile, L"wb" );
108 if( !fp.IsOpened() ) return false;
109
110 static const int MC2_MBSIZE = 1024 * 528 * 2; // Size of a single megabyte of card data
111
112 for( uint i=0; i<(MC2_MBSIZE*sizeInMB)/sizeof(m_effeffs); i++ )
113 {
114 if( fp.Write( m_effeffs, sizeof(m_effeffs) ) == 0 )
115 return false;
116 }
117 return true;
118 }
119
120 void Dialogs::CreateMemoryCardDialog::OnOk_Click( wxCommandEvent& evt )
121 {
122 // Save status of the NTFS compress checkbox for future reference.
123 // [TODO] Remove g_Conf->McdCompressNTFS, and have this dialog load/save directly from the ini.
124
125 #ifdef __WXMSW__
126 g_Conf->McdCompressNTFS = m_check_CompressNTFS->GetValue();
127 #endif
128
129 if( !CreateIt(
130 m_filepicker ? m_filepicker->GetPath() : (m_mcdpath + m_mcdfile).GetFullPath(),
131 m_radio_CardSize ? m_radio_CardSize->SelectedItem().SomeInt : 8
132 ) )
133 {
134 Msgbox::Alert(
135 _("Error: The memory card could not be created."),
136 _("memory card creation error")
137 );
138 return;
139 }
140 EndModal( wxID_OK );
141 }
142
143 void Dialogs::CreateMemoryCardDialog::CreateControls()
144 {
145 #ifdef __WXMSW__
146 m_check_CompressNTFS = new pxCheckBox( this,
147 _("Use NTFS compression when creating this card."),
148 GetMsg_McdNtfsCompress()
149 );
150
151 m_check_CompressNTFS->SetToolTip( pxEt( "!ContextTip:ChangingNTFS",
152 L"NTFS compression can be changed manually at any time by using file properties from Windows Explorer."
153 )
154 );
155
156 // Initial value of the checkbox is saved between calls to the dialog box. If the user checks
157 // the option, it remains checked for future dialog. If the user unchecks it, ditto.
158 m_check_CompressNTFS->SetValue( g_Conf->McdCompressNTFS );
159 #endif
160
161 const RadioPanelItem tbl_CardSizes[] =
162 {
163 RadioPanelItem(_("8 MB [most compatible]"), _("This is the standard Sony-provisioned size, and is supported by all games and BIOS versions."))
164 . SetToolTip(_("Always use this option if you want the safest and surest memory card behavior."))
165 . SetInt(8),
166
167 RadioPanelItem(_("16 MB"), _("A typical size for 3rd-party memory cards which should work with most games."))
168 . SetToolTip(_("16 and 32 MB cards have roughly the same compatibility factor."))
169 . SetInt(16),
170
171 RadioPanelItem(_("32 MB"), _("A typical size for 3rd-party memory cards which should work with most games."))
172 . SetToolTip(_("16 and 32 MB cards have roughly the same compatibility factor."))
173 . SetInt(32),
174
175 RadioPanelItem(_("64 MB"), _("Low compatibility warning: Yes it's very big, but may not work with many games."))
176 . SetToolTip(_("Use at your own risk. Erratic memory card behavior is possible (though unlikely)."))
177 . SetInt(64)
178 };
179
180 m_radio_CardSize = new pxRadioPanel( this, tbl_CardSizes );
181 m_radio_CardSize->SetDefaultItem(0);
182 }
183

  ViewVC Help
Powered by ViewVC 1.1.22