Esempio n. 1
0
void CConfigMain::ChooseMemcardPath(std::string& strMemcard, bool isSlotA)
{
	std::string filename = WxStrToStr(wxFileSelector(
		_("Choose a file to open"),
		StrToWxStr(File::GetUserPath(D_GCUSER_IDX)),
		isSlotA ? GC_MEMCARDA : GC_MEMCARDB,
		wxEmptyString,
		_("GameCube Memory Cards (*.raw,*.gcp)") + "|*.raw;*.gcp"));

	if (!filename.empty())
	{
		if (File::Exists(filename))
		{
			GCMemcard memorycard(filename);
			if (!memorycard.IsValid())
			{
				PanicAlertT("Cannot use that file as a memory card.\n%s\n" \
							"is not a valid gamecube memory card file", filename.c_str());
				return;
			}
		}
		#ifdef _WIN32
			if (!strncmp(File::GetExeDirectory().c_str(), filename.c_str(), File::GetExeDirectory().size()))
			{
				// If the Exe Directory Matches the prefix of the filename, we still need to verify
				// that the next character is a directory separator character, otherwise we may create an invalid path
				char next_char = filename.at(File::GetExeDirectory().size())+1;
				if (next_char == '/' || next_char == '\\')
				{
					filename.erase(0, File::GetExeDirectory().size() +1);
					filename = "./" + filename;
				}
			}
		#endif

		// also check that the path isn't used for the other memcard...
		if (filename.compare(isSlotA ? SConfig::GetInstance().m_strMemoryCardB
			: SConfig::GetInstance().m_strMemoryCardA) != 0)
		{
			strMemcard = filename;

			if (Core::GetState() != Core::CORE_UNINITIALIZED)
			{
				// Change memcard to the new file
				ExpansionInterface::ChangeDevice(
					isSlotA ? 0 : 1, // SlotA: channel 0, SlotB channel 1
					EXIDEVICE_MEMORYCARD,
					0); // SP1 is device 2, slots are device 0
			}
		}
		else
		{
			PanicAlertT("Cannot use that file as a memory card.\n" \
					"Are you trying to use the same file in both slots?");
		}
	}
}
Esempio n. 2
0
void GameCubeConfigPane::ChooseSlotPath(bool is_slot_a, TEXIDevices device_type)
{
	bool memcard = (device_type == EXIDEVICE_MEMORYCARD);
	std::string path;
	std::string cardname;
	std::string ext;
	std::string pathA = SConfig::GetInstance().m_strMemoryCardA;
	std::string pathB = SConfig::GetInstance().m_strMemoryCardB;
	if (!memcard)
	{
		pathA = SConfig::GetInstance().m_strGbaCartA;
		pathB = SConfig::GetInstance().m_strGbaCartB;
	}
	SplitPath(is_slot_a ? pathA : pathB, &path, &cardname, &ext);
	std::string filename = WxStrToStr(wxFileSelector(
		_("Choose a file to open"), StrToWxStr(path), StrToWxStr(cardname), StrToWxStr(ext),
		memcard ? _("GameCube Memory Cards (*.raw,*.gcp)") + "|*.raw;*.gcp" :
		_("Game Boy Advance Carts (*.gba)") + "|*.gba"));

	if (!filename.empty())
	{
		if (File::Exists(filename))
		{
			if (memcard)
			{
				GCMemcard memorycard(filename);
				if (!memorycard.IsValid())
				{
					WxUtils::ShowErrorDialog(wxString::Format(_("Cannot use that file as a memory card.\n%s\n"
						"is not a valid GameCube memory card file"),
						filename.c_str()));
					return;
				}
			}
		}

		wxFileName newFilename(filename);
		newFilename.MakeAbsolute();
		filename = newFilename.GetFullPath();

#ifdef _WIN32
		// If the Memory Card file is within the Exe dir, we can assume that the user wants it to be
		// stored relative
		// to the executable, so it stays set correctly when the probably portable Exe dir is moved.
		// TODO: Replace this with a cleaner, non-wx solution once std::filesystem is standard
		std::string exeDir = File::GetExeDirectory() + '\\';
		if (wxString(filename).Lower().StartsWith(wxString(exeDir).Lower()))
			filename.erase(0, exeDir.size());

		std::replace(filename.begin(), filename.end(), '\\', '/');
#endif

		// also check that the path isn't used for the other memcard...
		wxFileName otherFilename(is_slot_a ? pathB : pathA);
		otherFilename.MakeAbsolute();
		if (newFilename.GetFullPath().compare(otherFilename.GetFullPath()) != 0)
		{
			if (memcard)
			{
				if (is_slot_a)
					SConfig::GetInstance().m_strMemoryCardA = filename;
				else
					SConfig::GetInstance().m_strMemoryCardB = filename;
			}
			else
			{
				if (is_slot_a)
					SConfig::GetInstance().m_strGbaCartA = filename;
				else
					SConfig::GetInstance().m_strGbaCartB = filename;
			}

			if (Core::IsRunning())
			{
				// Change memcard to the new file
				ExpansionInterface::ChangeDevice(is_slot_a ? 0 : 1,  // SlotA: channel 0, SlotB channel 1
					device_type,
					0);  // SP1 is device 2, slots are device 0
			}
		}
		else
		{
			WxUtils::ShowErrorDialog(_("Are you trying to use the same file in both slots?"));
		}
	}
}