void CMemcardManager::CopyDeleteClick(wxCommandEvent& event)
{
	int index_A = m_MemcardList[SLOT_A]->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
	int index_B = m_MemcardList[SLOT_B]->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
	int slot = SLOT_B;
	int slot2 = SLOT_A;
	std::string fileName2("");

	if (index_A != wxNOT_FOUND && page[SLOT_A]) index_A += itemsPerPage * page[SLOT_A];
	if (index_B != wxNOT_FOUND && page[SLOT_B]) index_B += itemsPerPage * page[SLOT_B];

	int index = index_B;
	switch (event.GetId())
	{
	case ID_COPYFROM_B:
		slot = SLOT_A;
		slot2 = SLOT_B;
	case ID_COPYFROM_A:
		index = slot2 ? index_B : index_A;
		index = memoryCard[slot2]->GetFileIndex(index);
		if ((index != wxNOT_FOUND))
		{
			CopyDeleteSwitch(memoryCard[slot]->CopyFrom(*memoryCard[slot2], index), slot);
		}
		break;
	case ID_FIXCHECKSUM_A:
		slot = SLOT_A;
	case ID_FIXCHECKSUM_B:
		if (memoryCard[slot]->FixChecksums() && memoryCard[slot]->Save())
		{
			SuccessAlertT("The checksum was successfully fixed");
		}
		else
		{
			PanicAlertT(E_SAVEFAILED);
		}
		break;
	case ID_CONVERTTOGCI:
		fileName2 = "convert";
	case ID_SAVEIMPORT_A:
		slot = SLOT_A;
	case ID_SAVEIMPORT_B:
	{
		wxString fileName = wxFileSelector(
			_("Select a save file to import"),
			(strcmp(DefaultIOPath.c_str(), "/Users/GC") == 0)
				? StrToWxStr("")
				: StrToWxStr(DefaultIOPath),
			wxEmptyString, wxEmptyString,
			_("GameCube Savegame files(*.gci;*.gcs;*.sav)") + wxString("|*.gci;*.gcs;*.sav|") +
			_("Native GCI files(*.gci)") + wxString("|*.gci|") +
			_("MadCatz Gameshark files(*.gcs)") + wxString("|*.gcs|") +
			_("Datel MaxDrive/Pro files(*.sav)") + wxString("|*.sav"),
			wxFD_OPEN | wxFD_FILE_MUST_EXIST, this);
		if (!fileName.empty() && !fileName2.empty())
		{
			wxString temp2 = wxFileSelector(_("Save GCI as..."),
				wxEmptyString, wxEmptyString, ".gci",
				_("GCI File(*.gci)") + wxString("|*.gci"),
				wxFD_OVERWRITE_PROMPT|wxFD_SAVE, this);

			if (temp2.empty())
				break;

			fileName2 = WxStrToStr(temp2);
		}
		if (fileName.length() > 0)
		{
			CopyDeleteSwitch(memoryCard[slot]->ImportGci(WxStrToStr(fileName), fileName2), slot);
		}
	}
	break;
	case ID_SAVEEXPORT_A:
		slot=SLOT_A;
		index = index_A;
	case ID_SAVEEXPORT_B:
		index = memoryCard[slot]->GetFileIndex(index);
		if (index != wxNOT_FOUND)
		{
			std::string gciFilename;
			if (!memoryCard[slot]->GCI_FileName(index, gciFilename))
			{
				PanicAlertT("Invalid index");
				return;
			}
			wxString fileName = wxFileSelector(
				_("Export save as..."),
				StrToWxStr(DefaultIOPath),
				StrToWxStr(gciFilename), ".gci",
				_("Native GCI files(*.gci)") + wxString("|*.gci|") +
				_("MadCatz Gameshark files(*.gcs)") + wxString("|*.gcs|") +
				_("Datel MaxDrive/Pro files(*.sav)") + wxString("|*.sav"),
				wxFD_OVERWRITE_PROMPT|wxFD_SAVE, this);

			if (fileName.length() > 0)
			{
				if (!CopyDeleteSwitch(memoryCard[slot]->ExportGci(index, WxStrToStr(fileName), ""), -1))
				{
					File::Delete(WxStrToStr(fileName));
				}
			}
		}
		break;
	case ID_EXPORTALL_A:
		slot=SLOT_A;
	case ID_EXPORTALL_B:
	{
		std::string path1, path2, mpath;
		mpath = WxStrToStr(m_MemcardPath[slot]->GetPath());
		SplitPath(mpath, &path1, &path2, nullptr);
		path1 += path2;
		File::CreateDir(path1);
		if (PanicYesNoT("Warning: This will overwrite any existing saves that are in the folder:\n"
		                "%s\nand have the same name as a file on your memcard\nContinue?", path1.c_str()))
		for (int i = 0; i < DIRLEN; i++)
		{
			CopyDeleteSwitch(memoryCard[slot]->ExportGci(i, "", path1), -1);
		}
		break;
	}
	case ID_DELETE_A:
		slot = SLOT_A;
		index = index_A;
	case ID_DELETE_B:
		index = memoryCard[slot]->GetFileIndex(index);
		if (index != wxNOT_FOUND)
		{
			CopyDeleteSwitch(memoryCard[slot]->RemoveFile(index), slot);
		}
		break;
	}
}
Esempio n. 2
0
void CMemcardManager::CopyDeleteClick(wxCommandEvent& event)
{
	int index_A = m_MemcardList[SLOT_A]->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
	int index_B = m_MemcardList[SLOT_B]->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
	int slot = SLOT_B;
	int slot2 = SLOT_A;
	int index = index_B;
	std::string fileName2("");

	if (index_A != wxNOT_FOUND && page[SLOT_A]) index_A += itemsPerPage * page[SLOT_A];
	if (index_B != wxNOT_FOUND && page[SLOT_B]) index_B += itemsPerPage * page[SLOT_B];

	switch (event.GetId())
	{
	case ID_COPYFROM_B:
		slot = SLOT_A;
		slot2 = SLOT_B;
	case ID_COPYFROM_A:
		index = slot2 ? index_B : index_A;
		if ((index != wxNOT_FOUND))
		{
			CopyDeleteSwitch(memoryCard[slot]->CopyFrom(*memoryCard[slot2], index), slot);
		}
		break;
	case ID_FIXCHECKSUM_A:
		slot = SLOT_A;
	case ID_FIXCHECKSUM_B:
		if (memoryCard[slot]->FixChecksums() && memoryCard[slot]->Save())
		{
			SuccessAlertT("The checksum was successfully fixed");
		}
		else PanicAlert(E_SAVEFAILED);
		break; 
	case ID_CONVERTTOGCI:
		fileName2 = "convert";
	case ID_SAVEIMPORT_A:
		slot = SLOT_A;
	case ID_SAVEIMPORT_B:
	{
		wxString fileName = wxFileSelector(
			_("Select a save file to import"),
			(strcmp(DefaultIOPath.c_str(), "/Users/GC") == 0)
				? wxString::FromAscii("")
				: wxString::From8BitData(DefaultIOPath.c_str()),
			wxEmptyString, wxEmptyString,
			_("Native GCI files(*.gci)") + wxString(wxT("|*.gci|")) +
			_("MadCatz Gameshark files(*.gcs)") + wxString(wxT("|*.gcs|")) +
			_("Datel MaxDrive/Pro files(*.sav)") + wxString(wxT("|*.sav")),
			wxFD_OPEN | wxFD_FILE_MUST_EXIST);
		if (!fileName.empty() && !fileName2.empty())
		{
			wxString temp2 = wxFileSelector(_("Save GCI as..."),
				wxEmptyString, wxEmptyString, wxT(".gci"),
				_("GCI File(*.gci)") + wxString(_T("|*.gci")),
				wxFD_OVERWRITE_PROMPT|wxFD_SAVE);
			if (temp2.empty()) break;
			fileName2 = temp2.mb_str();
		}
		if (fileName.length() > 0)
		{
			CopyDeleteSwitch(memoryCard[slot]->ImportGci(fileName.mb_str(), fileName2), slot);
		}
	}
	break;
	case ID_SAVEEXPORT_A:
		slot=SLOT_A;
		index = index_A;
	case ID_SAVEEXPORT_B:
		if (index != wxNOT_FOUND)
		{
			char tempC[10 + DENTRY_STRLEN],
				 tempC2[DENTRY_STRLEN];
			memoryCard[slot]->DEntry_GameCode(index,tempC);
			memoryCard[slot]->DEntry_FileName(index,tempC2);
			sprintf(tempC, "%s_%s.gci", tempC, tempC2);
			wxString fileName = wxFileSelector(
				_("Export save as..."),
				wxString::From8BitData(DefaultIOPath.c_str()),
				wxString::From8BitData(tempC), wxT(".gci"),
				_("Native GCI files(*.gci)") + wxString(wxT("|*.gci|")) +
				_("MadCatz Gameshark files(*.gcs)") + wxString(wxT("|*.gcs|")) +
				_("Datel MaxDrive/Pro files(*.sav)") + wxString(wxT("|*.sav")),
				wxFD_OVERWRITE_PROMPT|wxFD_SAVE);

			if (fileName.length() > 0)
			{
				if (!CopyDeleteSwitch(memoryCard[slot]->ExportGci(index, fileName.mb_str(), NULL), -1))
				{
					File::Delete(std::string(fileName.mb_str()));
				}
			}
		}
		break;
	case ID_EXPORTALL_A:
		slot=SLOT_A;
	case ID_EXPORTALL_B:
	{
		std::string path1, path2, mpath;
		mpath = m_MemcardPath[slot]->GetPath().mb_str();
		SplitPath(mpath, &path1, &path2, NULL);
		path1 += path2;
		File::CreateDir(path1);
		if(PanicYesNoT("Warning: This will overwrite any existing saves that are in the folder:\n"
					"%s\nand have the same name as a file on your memcard\nContinue?", path1.c_str()))
		for (int i = 0; i < DIRLEN; i++)
		{
			CopyDeleteSwitch(memoryCard[slot]->ExportGci(i, ".", &path1), -1);
		}
		break;
	}
	case ID_DELETE_A:
		slot = SLOT_A;
		index = index_A;
	case ID_DELETE_B:
		if (index != wxNOT_FOUND)
		{
			CopyDeleteSwitch(memoryCard[slot]->RemoveFile(index), slot);
		}
		break;
	}
}