/
MemoryCardListPanel.cpp
1244 lines (1010 loc) · 37.7 KB
/
MemoryCardListPanel.cpp
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2010 PCSX2 Dev Team
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* PCSX2 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 PCSX2.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "PrecompiledHeader.h"
#include "AppCoreThread.h"
#include "System.h"
#include "MemoryCardFile.h"
#include "ConfigurationPanels.h"
#include "MemoryCardPanels.h"
#include "Dialogs/ConfigurationDialog.h"
#include "Utilities/IniInterface.h"
#include "../../Sio.h"
#include <wx/filepicker.h>
#include <wx/ffile.h>
#include <wx/dir.h>
static wxDataFormat drag_drop_format(L"PCSX2McdDragDrop");
bool CopyDirectory( const wxString& from, const wxString& to );
bool RemoveDirectory( const wxString& dirname );
using namespace pxSizerFlags;
using namespace Panels;
static bool IsMcdFormatted( wxFFile& fhand )
{
static const char formatted_psx[] = "MC";
static const char formatted_string[] = "Sony PS2 Memory Card Format";
static const int fmtstrlen = sizeof( formatted_string )-1;
char dest[fmtstrlen];
fhand.Read( dest, fmtstrlen );
bool formatted = memcmp( formatted_string, dest, fmtstrlen ) == 0;
if(!formatted) formatted = memcmp( formatted_psx, dest, 2 ) == 0;
return formatted;
}
//sets IsPresent if the file is valid, and derived properties (filename, formatted, size, etc)
bool EnumerateMemoryCard( McdSlotItem& dest, const wxFileName& filename, const wxDirName basePath )
{
dest.IsFormatted = false;
dest.IsPresent = false;
dest.IsPSX = false;
dest.Type = MemoryCardType::MemoryCard_None;
const wxString fullpath( filename.GetFullPath() );
//DevCon.WriteLn( fullpath );
if ( filename.FileExists() ) {
// might be a memory card file
wxFFile mcdFile( fullpath );
if ( !mcdFile.IsOpened() ) { return false; } // wx should log the error for us.
wxFileOffset length = mcdFile.Length();
if( length < (1024*528) && length != 0x20000 )
{
Console.Warning( "... MemoryCard appears to be truncated. Ignoring." );
return false;
}
dest.SizeInMB = (uint)( length / ( 1024 * 528 * 2 ) );
if ( length == 0x20000 ) {
dest.IsPSX = true; // PSX memcard;
dest.SizeInMB = 1; // MegaBIT
}
dest.Type = MemoryCardType::MemoryCard_File;
dest.IsFormatted = IsMcdFormatted( mcdFile );
filename.GetTimes( NULL, &dest.DateModified, &dest.DateCreated );
} else if ( filename.DirExists() ) {
// might be a memory card folder
wxFileName superBlockFileName( fullpath, L"_pcsx2_superblock" );
if ( !superBlockFileName.FileExists() ) { return false; }
wxFFile mcdFile( superBlockFileName.GetFullPath() );
if ( !mcdFile.IsOpened() ) { return false; }
dest.SizeInMB = 0;
dest.Type = MemoryCardType::MemoryCard_Folder;
dest.IsFormatted = IsMcdFormatted( mcdFile );
superBlockFileName.GetTimes( NULL, &dest.DateModified, &dest.DateCreated );
} else {
// is neither
return false;
}
dest.IsPresent = true;
dest.Filename = filename;
if( filename.GetFullPath() == (basePath+filename.GetFullName()).GetFullPath() )
dest.Filename = filename.GetFullName();
return true;
}
//avih: unused
/*
static int EnumerateMemoryCards( McdList& dest, const wxArrayString& files )
{
int pushed = 0;
Console.WriteLn( Color_StrongBlue, "Enumerating memory cards..." );
for( size_t i=0; i<files.GetCount(); ++i )
{
ConsoleIndentScope con_indent;
McdSlotItem mcdItem;
if( EnumerateMemoryCard(mcdItem, files[i]) )
{
dest.push_back( mcdItem );
++pushed;
}
}
if( pushed > 0 )
Console.WriteLn( Color_StrongBlue, "Memory card Enumeration Complete." );
else
Console.WriteLn( Color_StrongBlue, "No valid memory card found." );
return pushed;
}
*/
// --------------------------------------------------------------------------------------
// McdListItem (implementations)
// --------------------------------------------------------------------------------------
bool McdSlotItem::IsMultitapSlot() const
{
return FileMcd_IsMultitapSlot(Slot);
}
uint McdSlotItem::GetMtapPort() const
{
return FileMcd_GetMtapPort(Slot);
}
uint McdSlotItem::GetMtapSlot() const
{
return FileMcd_GetMtapSlot(Slot);
}
// Compares two cards -- If this equality comparison is used on items where
// no filename is specified, then the check will include port and slot.
bool McdSlotItem::operator==( const McdSlotItem& right ) const
{
bool fileEqu;
if( Filename.GetFullName().IsEmpty() )
fileEqu = OpEqu(Slot);
else
fileEqu = OpEqu(Filename);
return fileEqu &&
OpEqu(IsPresent) && OpEqu(IsEnabled) &&
OpEqu(SizeInMB) && OpEqu(IsFormatted) &&
OpEqu(DateCreated) && OpEqu(DateModified);
}
bool McdSlotItem::operator!=( const McdSlotItem& right ) const
{
return operator==( right );
}
// =====================================================================================================
// BaseMcdListPanel (implementations)
// =====================================================================================================
Panels::BaseMcdListPanel::BaseMcdListPanel( wxWindow* parent )
: _parent( parent )
{
m_FolderPicker = new DirPickerPanel( this, FolderId_MemoryCards,
//_("memory card Search Path:"), // static box label
_("Select folder with PS2 memory cards") // dir picker popup label
);
m_listview = NULL;
s_leftside_buttons = NULL;
s_rightside_buttons = NULL;
m_btn_Refresh = new wxButton( this, wxID_ANY, _("Refresh list") );
Bind(wxEVT_BUTTON, &BaseMcdListPanel::OnRefreshSelections, this, m_btn_Refresh->GetId());
}
void Panels::BaseMcdListPanel::RefreshMcds() const
{
wxCommandEvent refit( wxEVT_BUTTON );
refit.SetId( m_btn_Refresh->GetId() );
GetEventHandler()->AddPendingEvent( refit );
}
void Panels::BaseMcdListPanel::CreateLayout()
{
//if( m_listview ) m_listview->SetMinSize( wxSize( 480, 140 ) );
wxFlexGridSizer* s_flex=new wxFlexGridSizer(3,1, 0, 0);
s_flex->AddGrowableCol(0);
s_flex->AddGrowableRow(1);
SetSizer(s_flex);
wxBoxSizer& s_buttons(*new wxBoxSizer( wxHORIZONTAL ));
s_leftside_buttons = new wxBoxSizer( wxHORIZONTAL );
s_rightside_buttons = new wxBoxSizer( wxHORIZONTAL );
s_buttons += s_leftside_buttons | pxAlignLeft;
s_buttons += pxStretchSpacer();
s_buttons += s_rightside_buttons | pxAlignRight;
if( m_FolderPicker ) *this += m_FolderPicker | pxExpand;
else *this += StdPadding;//we need the 'else' because we need these items to land into the proper rows of s_flex.
if( m_listview ) *this += m_listview | pxExpand;
else *this += StdPadding;
*this += s_buttons | pxExpand;
*s_leftside_buttons += m_btn_Refresh;
if (m_listview)
{
IniLoader loader;
ScopedIniGroup group( loader, L"MemoryCardListPanel" );
m_listview->LoadSaveColumns( loader );
}
}
void Panels::BaseMcdListPanel::Apply()
{
// Save column widths to the configuration file. Since these are used *only* by this
// dialog, we use a direct local ini save approach, instead of going through g_conf.
if (m_listview)
{
IniSaver saver;
ScopedIniGroup group( saver, L"MemoryCardListPanel" );
m_listview->LoadSaveColumns(saver);
}
}
void Panels::BaseMcdListPanel::AppStatusEvent_OnSettingsApplied()
{
if( (m_MultitapEnabled[0] != g_Conf->EmuOptions.MultitapPort0_Enabled) ||
(m_MultitapEnabled[1] != g_Conf->EmuOptions.MultitapPort1_Enabled) )
{
m_MultitapEnabled[0] = g_Conf->EmuOptions.MultitapPort0_Enabled;
m_MultitapEnabled[1] = g_Conf->EmuOptions.MultitapPort1_Enabled;
RefreshMcds();
}
}
class McdDropTarget : public wxDropTarget
{
protected:
BaseMcdListView* m_listview;
public:
McdDropTarget( BaseMcdListView* listview=NULL )
{
m_listview = listview;
SetDataObject(new wxCustomDataObject(drag_drop_format));
}
virtual wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def)
{
int flags = 0;
int destViewIndex = m_listview->HitTest( wxPoint(x,y), flags);
if( wxNOT_FOUND == destViewIndex )
destViewIndex=-1;//non list item target is the filesystem placeholder.
if ( !GetData() )
return wxDragNone;
wxCustomDataObject *dobj = static_cast<wxCustomDataObject *>(GetDataObject());
if (dobj->GetDataSize() != sizeof(int))
return wxDragNone;
int sourceViewIndex;
dobj->GetDataHere(&sourceViewIndex);
wxDragResult result = OnDropMcd(
m_listview->GetMcdProvider().GetCardForViewIndex( sourceViewIndex ),
m_listview->GetMcdProvider().GetCardForViewIndex( destViewIndex ),
def
);
if( wxDragNone == result )
return wxDragNone;
m_listview->GetMcdProvider().RefreshMcds();
return result;
}
virtual wxDragResult OnDropMcd( McdSlotItem& src, McdSlotItem& dest, wxDragResult def )
{
if( src.Slot == dest.Slot ) return wxDragNone;
//if( !pxAssert( (src.Slot >= 0) && (dest.Slot >= 0) ) ) return wxDragNone;
const wxDirName basepath( m_listview->GetMcdProvider().GetMcdPath() );
if( wxDragCopy == def )
{
if( !m_listview->GetMcdProvider().UiDuplicateCard(src, dest) )
return wxDragNone;
}
else if( wxDragMove == def )
{ // source can only be an existing card.
// if dest is a ps2-port (empty or not) -> swap cards between ports.
// is dest is a non-ps2-port -> remove card from port.
// Note: For the sake of usability, automatically enable dest if a ps2-port.
if (src.IsPresent)
{
wxFileName tmpFilename = dest.Filename;
bool tmpPresent = dest.IsPresent;
if (src.Slot<0 && m_listview->GetMcdProvider().isFileAssignedToInternalSlot(src.Filename))
m_listview->GetMcdProvider().RemoveCardFromSlot(src.Filename);
dest.Filename = src.Filename;
dest.IsEnabled = dest.IsPresent? dest.IsEnabled:true;
dest.IsPresent = src.IsPresent;
if (dest.Slot>=0)
{//2 internal slots: swap
src.Filename = tmpFilename;
src.IsPresent = tmpPresent;
}
else
{//dest is at the filesystem (= remove card from slot)
src.Filename = L"";
src.IsPresent = false;
src.IsEnabled = false;
}
}
}
return def;
}
};
enum McdMenuId
{
McdMenuId_Create = 0x888,
//McdMenuId_Mount,
McdMenuId_Rename,
McdMenuId_RefreshList,
McdMenuId_AssignUnassign,
McdMenuId_Duplicate,
McdMenuId_Convert,
};
Panels::MemoryCardListPanel_Simple* g_uglyPanel=NULL;
void g_uglyFunc(){if (g_uglyPanel) g_uglyPanel->OnChangedListSelection();}
Panels::MemoryCardListPanel_Simple::~MemoryCardListPanel_Simple() {g_uglyPanel=NULL;}
Panels::MemoryCardListPanel_Simple::MemoryCardListPanel_Simple( wxWindow* parent )
: _parent( parent )
{
m_MultitapEnabled[0] = false;
m_MultitapEnabled[1] = false;
m_listview = new MemoryCardListView_Simple(this);
m_listview->SetMinSize(wxSize(620, m_listview->GetCharHeight() * 13)); // 740 is nice for default font sizes
m_listview->SetDropTarget( new McdDropTarget(m_listview) );
//m_button_Mount = new wxButton(this, wxID_ANY, _("Enable port"));
m_button_AssignUnassign = new wxButton(this, wxID_ANY, _("Eject"));
m_button_Duplicate = new wxButton(this, wxID_ANY, _("Duplicate ..."));
m_button_Rename = new wxButton(this, wxID_ANY, _("Rename ..."));
m_button_Create = new wxButton(this, wxID_ANY, _("Create ..."));
m_button_Convert = new wxButton(this, wxID_ANY, _("Convert ..."));
// ------------------------------------
// Sizer / Layout Section
// ------------------------------------
CreateLayout();
*s_leftside_buttons += 20;
//*s_leftside_buttons += m_button_Mount;
//*s_leftside_buttons += 20;
*s_leftside_buttons += Label(_("Card: ")) | pxMiddle;
*s_leftside_buttons += m_button_AssignUnassign;
*s_leftside_buttons += 20;
*s_leftside_buttons += m_button_Duplicate;
*s_leftside_buttons += 2;
*s_leftside_buttons += m_button_Rename;
*s_leftside_buttons += 2;
*s_leftside_buttons += m_button_Create;
*s_leftside_buttons += 2;
*s_leftside_buttons += m_button_Convert;
SetSizerAndFit(GetSizer());
parent->SetWindowStyle(parent->GetWindowStyle() | wxRESIZE_BORDER);
Bind(wxEVT_LIST_BEGIN_DRAG, &MemoryCardListPanel_Simple::OnListDrag, this, m_listview->GetId());
Bind(wxEVT_LIST_ITEM_SELECTED, &MemoryCardListPanel_Simple::OnListSelectionChanged, this, m_listview->GetId());
Bind(wxEVT_LIST_ITEM_ACTIVATED, &MemoryCardListPanel_Simple::OnItemActivated, this, m_listview->GetId()); //enter or double click
//Deselected is not working for some reason (e.g. when clicking an empty row at the table?) - avih
// wxMSW bug for virtual listviews. Works fine on Linux: http://trac.wxwidgets.org/ticket/1919 - turtleli
Bind(wxEVT_LIST_ITEM_DESELECTED, &MemoryCardListPanel_Simple::OnListSelectionChanged, this, m_listview->GetId());
Bind(wxEVT_LIST_ITEM_RIGHT_CLICK, &MemoryCardListPanel_Simple::OnOpenItemContextMenu, this, m_listview->GetId());
//Bind(wxEVT_BUTTON, &MemoryCardListPanel_Simple::OnMountCard, this, m_button_Mount->GetId());
Bind(wxEVT_BUTTON, &MemoryCardListPanel_Simple::OnCreateOrDeleteCard, this, m_button_Create->GetId());
Bind(wxEVT_BUTTON, &MemoryCardListPanel_Simple::OnConvertCard, this, m_button_Convert->GetId());
Bind(wxEVT_BUTTON, &MemoryCardListPanel_Simple::OnRenameFile, this, m_button_Rename->GetId());
Bind(wxEVT_BUTTON, &MemoryCardListPanel_Simple::OnDuplicateFile, this, m_button_Duplicate->GetId());
Bind(wxEVT_BUTTON, &MemoryCardListPanel_Simple::OnAssignUnassignFile, this, m_button_AssignUnassign->GetId());
// Popup Menu Connections!
//Bind(McdMenuId_Mount, &MemoryCardListPanel_Simple::OnMountCard, this, McdMenuId_Mount);
Bind(wxEVT_MENU, &MemoryCardListPanel_Simple::OnCreateOrDeleteCard, this, McdMenuId_Create);
Bind(wxEVT_MENU, &MemoryCardListPanel_Simple::OnConvertCard, this, McdMenuId_Convert);
Bind(wxEVT_MENU, &MemoryCardListPanel_Simple::OnRenameFile, this, McdMenuId_Rename);
Bind(wxEVT_MENU, &MemoryCardListPanel_Simple::OnDuplicateFile, this, McdMenuId_Duplicate);
Bind(wxEVT_MENU, &MemoryCardListPanel_Simple::OnAssignUnassignFile, this, McdMenuId_AssignUnassign);
Bind(wxEVT_MENU, &MemoryCardListPanel_Simple::OnRefreshSelections, this, McdMenuId_RefreshList);
//because the wxEVT_LIST_ITEM_DESELECTED doesn't work (buttons stay enabled when clicking an empty area of the list),
// m_listview can send us an event that indicates a change at the list. Ugly, but works.
g_uglyPanel=this;
m_listview->setExternHandler(g_uglyFunc);
}
void Panels::MemoryCardListPanel_Simple::UpdateUI()
{
if( !m_listview ) return;
int sel = m_listview->GetFirstSelected();
m_button_Create->Enable();
if( wxNOT_FOUND == sel )
{
m_button_Create->SetLabel( _("Create ...") );
pxSetToolTip( m_button_Create, _("Create a new memory card." ));
// m_button_Mount->Disable();
m_button_Rename->Disable();
m_button_Duplicate->Disable();
m_button_AssignUnassign->Disable();
m_button_Convert->Disable();
return;
}
const McdSlotItem& card( GetCardForViewIndex(sel) );
m_button_Rename->Enable( card.IsPresent );
wxString renameTip = _("Rename this memory card ...");
pxSetToolTip( m_button_Rename, renameTip );
m_button_AssignUnassign->Enable( card.IsPresent );
m_button_AssignUnassign->SetLabel( card.Slot>=0 ? _("Eject") : _("Insert ...") );
wxString assignTip = (card.Slot>=0)?_("Eject the card from this port"):_("Insert this card to a port ...");
pxSetToolTip( m_button_AssignUnassign, assignTip );
m_button_Duplicate->Enable( card.IsPresent );
wxString dupTip = _("Create a duplicate of this memory card ...");
pxSetToolTip( m_button_Duplicate, dupTip );
m_button_Convert->Enable( card.IsPresent && card.IsFormatted && !card.IsPSX );
//m_button_Create->Enable( card.Slot>=0 || card.IsPresent);
m_button_Create->SetLabel( card.IsPresent ? _("Delete") : _("Create ...") );
if (card.IsPresent)
pxSetToolTip( m_button_Create, _("Permanently delete this memory card from disk (all contents are lost)"));
else if( card.Slot >= 0 )
pxSetToolTip( m_button_Create, _("Create a new memory card and assign it to this Port." ));
else
pxSetToolTip( m_button_Create, _("Create a new memory card." ));
/*
m_button_Mount->Enable( card.IsPresent && card.Slot>=0);
m_button_Mount->SetLabel( card.IsEnabled ? _("Disable Port") : _("Enable Port") );
pxSetToolTip( m_button_Mount,
card.IsEnabled
? _("Disable the selected PS2-Port (this memory card will be invisible to games/BIOS).")
: _("Enable the selected PS2-Port (games/BIOS will see this memory card).")
);
*/
}
void Panels::MemoryCardListPanel_Simple::Apply()
{
_parent::Apply();
int used=0;
Console.WriteLn( L"Apply Memory cards:" );
for( uint slot=0; slot<8; ++slot )
{
g_Conf->Mcd[slot].Type = m_Cards[slot].Type;
g_Conf->Mcd[slot].Enabled = m_Cards[slot].IsEnabled && m_Cards[slot].IsPresent;
if (m_Cards[slot].IsPresent)
g_Conf->Mcd[slot].Filename = m_Cards[slot].Filename;
else
g_Conf->Mcd[slot].Filename = L"";
if( g_Conf->Mcd[slot].Enabled )
{
used++;
Console.WriteLn( L"slot[%d]='%s'", slot, WX_STR(g_Conf->Mcd[slot].Filename.GetFullName()) );
}
}
if( !used )
Console.WriteLn( L"No active slots" );
SetForceMcdEjectTimeoutNow();
}
void Panels::MemoryCardListPanel_Simple::AppStatusEvent_OnSettingsApplied()
{
for( uint slot=0; slot<8; ++slot )
{
m_Cards[slot].IsEnabled = g_Conf->Mcd[slot].Enabled;
m_Cards[slot].Filename = g_Conf->Mcd[slot].Filename;
//automatically create the enabled but non-existing file such that it can be managed (else will get created anyway on boot)
wxString targetFile = (GetMcdPath() + m_Cards[slot].Filename.GetFullName()).GetFullPath();
if ( m_Cards[slot].IsEnabled && !( wxFileExists( targetFile ) || wxDirExists( targetFile ) ) )
{
wxString errMsg;
if (isValidNewFilename(m_Cards[slot].Filename.GetFullName(), GetMcdPath(), errMsg, 5))
{
if ( !Dialogs::CreateMemoryCardDialog::CreateIt(targetFile, 8, false) )
Console.Error( L"Automatic createion of MCD '%s' failed. Hope for the best...", WX_STR(targetFile) );
else
Console.WriteLn( L"memcard created: '%s'.", WX_STR(targetFile) );
}
else
{
Console.Error( L"memcard was enabled but had an invalid file name. Aborting automatic creation. Hope for the best... (%s)", WX_STR(errMsg) );
}
}
if ( !m_Cards[slot].IsEnabled || !( wxFileExists( targetFile ) || wxDirExists( targetFile ) ) )
{
m_Cards[slot].IsEnabled = false;
m_Cards[slot].IsPresent = false;
m_Cards[slot].Filename = L"";
}
}
DoRefresh();
_parent::AppStatusEvent_OnSettingsApplied();
}
//BUG: the next function is never reached because, for some reason, IsoDropTarget::OnDropFiles is called instead.
// Interestingly, IsoDropTarget::OnDropFiles actually "detects" a memory card file as a valid Audio-CD ISO... - avih
bool Panels::MemoryCardListPanel_Simple::OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames)
{
if( filenames.GetCount() == 1 && wxFileName(filenames[0]).IsDir() )
{
m_FolderPicker->SetPath( filenames[0] );
return true;
}
return false;
}
bool Panels::MemoryCardListPanel_Simple::ValidateEnumerationStatus()
{
if( m_listview ) m_listview->SetMcdProvider( NULL );
return false;
}
void Panels::MemoryCardListPanel_Simple::DoRefresh()
{
for( uint slot=0; slot<8; ++slot )
{
//if( FileMcd_IsMultitapSlot(slot) && !m_MultitapEnabled[FileMcd_GetMtapPort(slot)] )
// continue;
//wxFileName fullpath( m_FolderPicker->GetPath() + g_Conf->Mcd[slot].Filename.GetFullName() );
wxFileName fullpath = m_FolderPicker->GetPath() + m_Cards[slot].Filename.GetFullName();
EnumerateMemoryCard( m_Cards[slot], fullpath, m_FolderPicker->GetPath());
m_Cards[slot].Slot = slot;
}
ReadFilesAtMcdFolder();
if( m_listview ) m_listview->SetMcdProvider( this );
UpdateUI();
}
// =====================================================================================================
// MemoryCardListPanel_Simple (implementations)
// =====================================================================================================
void Panels::MemoryCardListPanel_Simple::UiCreateNewCard( McdSlotItem& card )
{//card can also be the filesystem placeholder. On that case, the changes
// made to it will be reverted on refresh, and we'll just have a new card at the folder.
if( card.IsPresent ){
Console.WriteLn("Error: Aborted: create mcd invoked but but a file is already associated.");
return;
}
Dialogs::CreateMemoryCardDialog dialog( this, m_FolderPicker->GetPath(), L"my memory card" );
wxWindowID result = dialog.ShowModal();
if (result != wxID_CANCEL)
{
card.IsEnabled = true;
card.Filename = dialog.result_createdMcdFilename;
card.IsPresent = true;
if ( card.Slot >= 0)
Console.WriteLn(L"setting new card to slot %u: '%s'", card.Slot, WX_STR(card.Filename.GetFullName()));
else
Console.WriteLn(L"Created a new unassigned card file: '%s'", WX_STR(card.Filename.GetFullName()) );
}
else
card.IsEnabled=false;
Apply();
RefreshSelections();
}
void Panels::MemoryCardListPanel_Simple::UiConvertCard( McdSlotItem& card ) {
if ( !card.IsPresent ) {
Console.WriteLn( "Error: Aborted: Convert mcd invoked but but a file is not associated." );
return;
}
AppConfig::McdOptions config;
config.Filename = card.Filename.GetFullName();
config.Enabled = card.IsEnabled;
config.Type = card.Type;
Dialogs::ConvertMemoryCardDialog dialog( this, m_FolderPicker->GetPath(), config );
wxWindowID result = dialog.ShowModal();
if ( result != wxID_CANCEL ) {
Apply();
RefreshSelections();
}
}
void Panels::MemoryCardListPanel_Simple::UiDeleteCard( McdSlotItem& card )
{
if( !card.IsPresent ){
Console.WriteLn("Error: Aborted: delete mcd invoked but but a file is not associated.");
return;
}
bool result = true;
if( card.IsFormatted )
{
wxString content;
content.Printf(
pxE( L"You are about to delete the formatted memory card '%s'. All data on this card will be lost! Are you absolutely and quite positively sure?"
), WX_STR(card.Filename.GetFullName())
);
result = Msgbox::YesNo( content, _("Delete memory file?") );
}
if( result )
{
wxFileName fullpath( m_FolderPicker->GetPath() + card.Filename.GetFullName());
card.IsEnabled=false;
Apply();
if ( fullpath.FileExists() ) {
wxRemoveFile( fullpath.GetFullPath() );
} else {
RemoveDirectory( fullpath.GetFullPath() );
}
RefreshSelections();
}
}
bool Panels::MemoryCardListPanel_Simple::UiDuplicateCard(McdSlotItem& src, McdSlotItem& dest)
{
wxDirName basepath = GetMcdPath();
if( !src.IsPresent )
{
Msgbox::Alert(_("Failed: Can only duplicate an existing card."), _("Duplicate memory card"));
return false;
}
if ( dest.IsPresent && dest.Slot!=-1 )
{
wxString content;
content.Printf(
pxE( L"Failed: Duplicate is only allowed to an empty PS2-Port or to the file system." )
);
Msgbox::Alert( content, _("Duplicate memory card") );
return false;
}
while (1)
{
wxString newFilename=L"";
newFilename = wxGetTextFromUser(_("Select a name for the duplicate\n( '.ps2' will be added automatically)"), _("Duplicate memory card"));
if( newFilename==L"" )
{
//Msgbox::Alert( _("Duplicate canceled"), _("Duplicate memory card") );
return false;
}
newFilename += L".ps2";
//check that the name is valid for a new file
wxString errMsg;
if( !isValidNewFilename( newFilename, basepath, errMsg, 5 ) )
{
wxString message;
message.Printf(_("Failed: %s"), WX_STR(errMsg));
Msgbox::Alert( message, _("Duplicate memory card") );
continue;
}
dest.Filename = newFilename;
break;
}
wxFileName srcfile( basepath + src.Filename);
wxFileName destfile( basepath + dest.Filename);
ScopedBusyCursor doh( Cursor_ReallyBusy );
if( !( ( srcfile.FileExists() && wxCopyFile( srcfile.GetFullPath(), destfile.GetFullPath(), true ) )
|| ( !srcfile.FileExists() && CopyDirectory( srcfile.GetFullPath(), destfile.GetFullPath() ) ) ) )
{
wxString heading;
heading.Printf( pxE( L"Failed: Destination memory card '%s' is in use." ),
WX_STR(dest.Filename.GetFullName()), dest.Slot
);
wxString content;
Msgbox::Alert( heading + L"\n\n" + content, _("Copy failed!") );
return false;
}
// Destination memcard isEnabled state is the same now as the source's
wxString success;
success.Printf(_("Memory card '%s' duplicated to '%s'."),
WX_STR(src.Filename.GetFullName()),
WX_STR(dest.Filename.GetFullName())
);
Msgbox::Alert(success, _("Success"));
dest.IsPresent=true;
dest.IsEnabled = true;
Apply();
DoRefresh();
return true;
}
void Panels::MemoryCardListPanel_Simple::UiRenameCard( McdSlotItem& card )
{
if( !card.IsPresent ){
Console.WriteLn("Error: Aborted: Rename mcd invoked but no file is associated.");
return;
}
const wxDirName basepath( m_listview->GetMcdProvider().GetMcdPath() );
wxString newFilename;
while (1){
wxString title;
title.Printf(_("Select a new name for the memory card '%s'\n( '.ps2' will be added automatically)"),
WX_STR(card.Filename.GetFullName())
);
newFilename = wxGetTextFromUser(title, _("Rename memory card"));
if( newFilename==L"" )
return;
newFilename += L".ps2";
//check that the name is valid for a new file
wxString errMsg;
if( !isValidNewFilename( newFilename, basepath, errMsg, 5 ) )
{
wxString message;
message.Printf(_("Error (%s)"), WX_STR(errMsg));
Msgbox::Alert( message, _("Rename memory card") );
continue;
}
break;
}
bool origEnabled=card.IsEnabled;
card.IsEnabled=false;
Apply();
if( !wxRenameFile( (basepath + card.Filename).GetFullPath(), (basepath + wxFileName(newFilename)).GetFullPath(), false ) )
{
card.IsEnabled=origEnabled;
Apply();
Msgbox::Alert( _("Error: Rename could not be completed.\n"), _("Rename memory card") );
return;
}
card.Filename = newFilename;
card.IsEnabled=origEnabled;
Apply();
RefreshSelections();
}
void Panels::MemoryCardListPanel_Simple::OnCreateOrDeleteCard(wxCommandEvent& evt)
{
int selectedViewIndex = m_listview->GetFirstSelected();
if( wxNOT_FOUND == selectedViewIndex )
selectedViewIndex = -1;//get filesystem placeholder, just create a new card at the filesystem.
McdSlotItem& card( GetCardForViewIndex(selectedViewIndex) );
if( card.IsPresent )
UiDeleteCard( card );
else
UiCreateNewCard( card );
}
void Panels::MemoryCardListPanel_Simple::OnConvertCard(wxCommandEvent& evt) {
int selectedViewIndex = m_listview->GetFirstSelected();
if ( wxNOT_FOUND == selectedViewIndex ) {
return;
}
McdSlotItem& card( GetCardForViewIndex( selectedViewIndex ) );
if ( card.IsPresent ) {
UiConvertCard( card );
}
}
//enable/disapbe port
/*
void Panels::MemoryCardListPanel_Simple::OnMountCard(wxCommandEvent& evt)
{
evt.Skip();
const int selectedViewIndex = m_listview->GetFirstSelected();
if( wxNOT_FOUND == selectedViewIndex ) return;
McdSlotItem& card( GetCardForViewIndex(selectedViewIndex) );
card.IsEnabled = !card.IsEnabled;
m_listview->RefreshItem(selectedViewIndex);
UpdateUI();
}
*/
/*
//text dialog: can be used for rename: wxGetTextFromUser - avih
void Panels::MemoryCardListPanel_Simple::OnRelocateCard(wxCommandEvent& evt)
{
evt.Skip();
const int slot = m_listview->GetFirstSelected();
if( wxNOT_FOUND == slot ) return;
// Issue a popup to the user that allows them to pick a new .PS2 file to serve as
// the new host memorycard file for the slot. The dialog has a number of warnings
// present to reiterate that this is an advanced operation that PCSX2 may not
// support very well (ie, might be buggy).
m_listview->RefreshItem(slot);
UpdateUI();
}
*/
// enter/double-click
void Panels::MemoryCardListPanel_Simple::OnItemActivated(wxListEvent& evt)
{
const int viewIndex = m_listview->GetFirstSelected();
if( wxNOT_FOUND == viewIndex ) return;
McdSlotItem& card( GetCardForViewIndex(viewIndex) );
if ( card.IsPresent )
UiRenameCard( card );
else if (card.Slot>=0)
UiCreateNewCard( card );// IsPresent==false can only happen for an internal slot (vs filename on the HD), so a card can be created.
}
void Panels::MemoryCardListPanel_Simple::OnDuplicateFile(wxCommandEvent& evt)
{
const int viewIndex = m_listview->GetFirstSelected();
if( wxNOT_FOUND == viewIndex ) return;
McdSlotItem& card( GetCardForViewIndex(viewIndex) );
pxAssert( card.IsPresent );
McdSlotItem dummy;
UiDuplicateCard(card, dummy);
}
wxString GetPortName(int slotIndex)
{
if (slotIndex==0 || slotIndex==1)
return pxsFmt(wxString(L" ") + _("Port-%u / Multitap-%u--Port-1"), FileMcd_GetMtapPort(slotIndex)+1, FileMcd_GetMtapPort(slotIndex)+1);
return pxsFmt(wxString(L" ")+_(" Multitap-%u--Port-%u"), FileMcd_GetMtapPort(slotIndex)+1, FileMcd_GetMtapSlot(slotIndex)+1 );
}
void Panels::MemoryCardListPanel_Simple::UiAssignUnassignFile(McdSlotItem &card)
{
pxAssert( card.IsPresent );
if( card.Slot >=0 )
{//eject
card.IsEnabled = false;
card.IsPresent = false;
card.Filename = L"";
DoRefresh();
}
else
{//insert into a (UI) selected slot
wxArrayString selections;
int i;
for (i=0; i< GetNumVisibleInternalSlots(); i++)
{
McdSlotItem& selCard = GetCardForViewIndex(i);
wxString sel = GetPortName( selCard.Slot ) + L" ( ";
if (selCard.IsPresent)
sel += selCard.Filename.GetFullName();
else
sel += _("Empty");
sel += L" )";
selections.Add(sel);
}
wxString title;
title.Printf(_("Select a target port for '%s'"), WX_STR(card.Filename.GetFullName()));
int res=wxGetSingleChoiceIndex(title, _("Insert card"), selections, this);
if( res<0 )
return;
McdSlotItem& target = GetCardForViewIndex(res);
bool en = target.IsPresent? target.IsEnabled : true;
RemoveCardFromSlot( card.Filename );
target.Filename = card.Filename;
target.IsPresent = true;
target.IsEnabled = en;
DoRefresh();
}
}
void Panels::MemoryCardListPanel_Simple::OnAssignUnassignFile(wxCommandEvent& evt)
{
const int viewIndex = m_listview->GetFirstSelected();
if( wxNOT_FOUND == viewIndex ) return;
McdSlotItem& card( GetCardForViewIndex(viewIndex) );
UiAssignUnassignFile(card);
}
void Panels::MemoryCardListPanel_Simple::OnRenameFile(wxCommandEvent& evt)
{
const int viewIndex = m_listview->GetFirstSelected();
if( wxNOT_FOUND == viewIndex ) return;
McdSlotItem& card( GetCardForViewIndex(viewIndex) );
UiRenameCard( card );
}
void Panels::MemoryCardListPanel_Simple::OnListDrag(wxListEvent& evt)
{
int selectionViewIndex = m_listview->GetFirstSelected();
if( selectionViewIndex < 0 ) return;
wxCustomDataObject my_data(drag_drop_format);