void Dlg_GameLibrary::ReloadGameListData()
{
	ClearTitles();

	TCHAR sROMDir[1024];
	GetDlgItemText(m_hDialogBox, IDC_RA_ROMDIR, sROMDir, 1024);

	mtx.lock();
	while (FilesToScan.size() > 0)
		FilesToScan.pop_front();
	mtx.unlock();

	bool bOK = ListFiles(Narrow(sROMDir), "*.bin", FilesToScan);
	bOK |= ListFiles(Narrow(sROMDir), "*.gen", FilesToScan);

	if (bOK)
	{
		std::thread scanner(&Dlg_GameLibrary::ThreadedScanProc);
		scanner.detach();
	}
}
예제 #2
0
void GxSystemInterfaceWin32::SetClipboardText(const GxString& text)
{
	if(!OpenClipboard(NULL)) return;

	std::wstring wstr;
	ToUTF16(wstr, text.Raw());
	GxList<char> cstr = Narrow(wstr.c_str());

	EmptyClipboard();
	HGLOBAL bufferHandle = GlobalAlloc(GMEM_DDESHARE, cstr.Size());
	char* buffer = (char*)GlobalLock(bufferHandle);
	if(buffer != NULL)
	{
		memcpy(buffer, cstr.Data(), cstr.Size());
		SetClipboardData(CF_TEXT, bufferHandle);
	}
	GlobalUnlock(bufferHandle);
	CloseClipboard();
}
BOOL Dlg_GameLibrary::LaunchSelected()
{
	HWND hList = GetDlgItem(m_hDialogBox, IDC_RA_LBX_GAMELIST);
	const int nSel = ListView_GetSelectionMark(hList);
	if (nSel != -1)
	{
		TCHAR buffer[1024];
		ListView_GetItemText(hList, nSel, 1, buffer, 1024);
		SetWindowText(GetDlgItem(m_hDialogBox, IDC_RA_GLIB_NAME), buffer);

		ListView_GetItemText(hList, nSel, 3, buffer, 1024);
		_RA_LoadROM(Narrow(buffer).c_str());

		return TRUE;
	}
	else
	{
		return FALSE;
	}
}
bool ListFiles(std::string path, std::string mask, std::deque<std::string>& rFileListOut)
{
	std::stack<std::string> directories;
	directories.push(path);

	while (!directories.empty())
	{
		path = directories.top();
		std::string spec = path + "\\" + mask;
		directories.pop();

		WIN32_FIND_DATA ffd;
		HANDLE hFind = FindFirstFile(NativeStr(spec).c_str(), &ffd);
		if (hFind == INVALID_HANDLE_VALUE)
			return false;

		do
		{
			std::string sFilename = Narrow(ffd.cFileName);
			if ((strcmp(sFilename.c_str(), ".") == 0) ||
				(strcmp(sFilename.c_str(), "..") == 0))
				continue;

			if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
				directories.push(path + "\\" + sFilename);
			else
				rFileListOut.push_front(path + "\\" + sFilename);
		} while (FindNextFile(hFind, &ffd) != 0);

		if (GetLastError() != ERROR_NO_MORE_FILES)
		{
			FindClose(hFind);
			return false;
		}

		FindClose(hFind);
		hFind = INVALID_HANDLE_VALUE;
	}

	return true;
}
예제 #5
0
std::string Dlg_MemBookmark::ImportDialog()
{
	std::string str;

	if ( g_pCurrentGameData->GetGameID() == 0 )
	{
		MessageBox( nullptr, _T("ROM not loaded: please load a ROM first!"), _T("Error!"), MB_OK );
		return str;
	}

	IFileOpenDialog* pDlg = nullptr;
	HRESULT hr = CoCreateInstance( CLSID_FileOpenDialog, NULL, CLSCTX_ALL, IID_IFileOpenDialog, reinterpret_cast<void**>( &pDlg ) );
	if ( hr == S_OK )
	{
		hr = pDlg->SetFileTypes( ARRAYSIZE( c_rgFileTypes ), c_rgFileTypes );
		if ( hr == S_OK )
		{
			hr = pDlg->Show( nullptr );
			if ( hr == S_OK )
			{
				IShellItem* pItem = nullptr;
				hr = pDlg->GetResult( &pItem );
				if ( hr == S_OK )
				{
					LPWSTR pStr = nullptr;
					hr = pItem->GetDisplayName( SIGDN_FILESYSPATH, &pStr );
					if ( hr == S_OK )
					{
						str = Narrow( pStr );
					}

					pItem->Release();
				}
			}
		}
		pDlg->Release();
	}

	return str;
}
예제 #6
0
void Dlg_MemBookmark::AddAddress()
{
	if ( g_pCurrentGameData->GetGameID() == 0 )
		return;

	MemBookmark* NewBookmark = new MemBookmark();

	// Fetch Memory Address from Memory Inspector
	TCHAR buffer[ 256 ];
	GetDlgItemText( g_MemoryDialog.GetHWND(), IDC_RA_WATCHING, buffer, 256 );
	unsigned int nAddr = strtol( Narrow( buffer ).c_str(), nullptr, 16 );
	NewBookmark->SetAddress( nAddr );

	// Check Data Type
	if ( SendDlgItemMessage( g_MemoryDialog.GetHWND(), IDC_RA_MEMVIEW8BIT, BM_GETCHECK, 0, 0 ) == BST_CHECKED )
		NewBookmark->SetType( 1 );
	else if ( SendDlgItemMessage( g_MemoryDialog.GetHWND(), IDC_RA_MEMVIEW16BIT, BM_GETCHECK, 0, 0 ) == BST_CHECKED )
		NewBookmark->SetType( 2 );
	else
		NewBookmark->SetType( 3 );

	// Get Memory Value
	NewBookmark->SetValue( GetMemory( nAddr, NewBookmark->Type() ) );
	NewBookmark->SetPrevious( NewBookmark->Value() );

	// Get Code Note and add as description
	const CodeNotes::CodeNoteObj* pSavedNote = g_MemoryDialog.Notes().FindCodeNote( nAddr );
	if ( ( pSavedNote != nullptr ) && ( pSavedNote->Note().length() > 0 ) )
		NewBookmark->SetDescription( Widen( pSavedNote->Note() ).c_str()  );

	// Add Bookmark to vector and map
	AddBookmark( NewBookmark );
	AddBookmarkMap( NewBookmark );

	PopulateList();
}
void Dlg_GameLibrary::ScanAndAddRomsRecursive(const std::string& sBaseDir)
{
	char sSearchDir[2048];
	sprintf_s(sSearchDir, 2048, "%s\\*.*", sBaseDir.c_str());

	WIN32_FIND_DATA ffd;
	HANDLE hFind = FindFirstFile(NativeStr(sSearchDir).c_str(), &ffd);
	if (hFind != INVALID_HANDLE_VALUE)
	{
		unsigned int ROM_MAX_SIZE = 6 * 1024 * 1024;
		unsigned char* sROMRawData = new unsigned char[ROM_MAX_SIZE];

		do
		{
			if (KEYDOWN(VK_ESCAPE))
				break;

			memset(sROMRawData, 0, ROM_MAX_SIZE);	//?!??

			const std::string sFilename = Narrow(ffd.cFileName);
			if (strcmp(sFilename.c_str(), ".") == 0 ||
				strcmp(sFilename.c_str(), "..") == 0)
			{
				//	Ignore 'this'
			}
			else if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
			{
				RA_LOG("Directory found: %s\n", ffd.cFileName);
				std::string sRecurseDir = sBaseDir + "\\" + sFilename.c_str();
				ScanAndAddRomsRecursive(sRecurseDir);
			}
			else
			{
				LARGE_INTEGER filesize;
				filesize.LowPart = ffd.nFileSizeLow;
				filesize.HighPart = ffd.nFileSizeHigh;
				if (filesize.QuadPart < 2048 || filesize.QuadPart > ROM_MAX_SIZE)
				{
					//	Ignore: wrong size
					RA_LOG("Ignoring %s, wrong size\n", sFilename.c_str());
				}
				else
				{
					//	Parse as ROM!
					RA_LOG("%s looks good: parsing!\n", sFilename.c_str());

					char sAbsFileDir[2048];
					sprintf_s(sAbsFileDir, 2048, "%s\\%s", sBaseDir.c_str(), sFilename.c_str());

					HANDLE hROMReader = CreateFile(NativeStr(sAbsFileDir).c_str(), GENERIC_READ, FILE_SHARE_READ,
						NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

					if (hROMReader != INVALID_HANDLE_VALUE)
					{
						BY_HANDLE_FILE_INFORMATION File_Inf;
						int nSize = 0;
						if (GetFileInformationByHandle(hROMReader, &File_Inf))
							nSize = (File_Inf.nFileSizeHigh << 16) + File_Inf.nFileSizeLow;

						DWORD nBytes = 0;
						BOOL bResult = ReadFile(hROMReader, sROMRawData, nSize, &nBytes, NULL);
						const std::string sHashOut = RAGenerateMD5(sROMRawData, nSize);

						if (m_GameHashLibrary.find(sHashOut) != m_GameHashLibrary.end())
						{
							const unsigned int nGameID = m_GameHashLibrary[std::string(sHashOut)];
							RA_LOG("Found one! Game ID %d (%s)", nGameID, m_GameTitlesLibrary[nGameID].c_str());

							const std::string& sGameTitle = m_GameTitlesLibrary[nGameID];
							AddTitle(sGameTitle, sAbsFileDir, nGameID);
							SetDlgItemText(m_hDialogBox, IDC_RA_GLIB_NAME, NativeStr(sGameTitle).c_str());
							InvalidateRect(m_hDialogBox, nullptr, TRUE);
						}

						CloseHandle(hROMReader);
					}
				}
			}
		} while (FindNextFile(hFind, &ffd) != 0);

		delete[](sROMRawData);
		sROMRawData = NULL;

		FindClose(hFind);
	}

	SetDlgItemText(m_hDialogBox, IDC_RA_SCANNERFOUNDINFO, TEXT("Scanning complete"));
}
INT_PTR CALLBACK Dlg_AchievementsReporter::AchievementsReporterProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
	switch( uMsg )
	{
		case WM_INITDIALOG:
		{
			HWND hList = GetDlgItem( hDlg, IDC_RA_REPORTBROKENACHIEVEMENTSLIST );
			SetupColumns( hList );

			for( size_t i = 0; i < g_pActiveAchievements->NumAchievements(); ++i )
				AddAchievementToListBox( hList, &g_pActiveAchievements->GetAchievement( i ) );

			ListView_SetExtendedListViewStyle( hList, LVS_EX_CHECKBOXES | LVS_EX_HEADERDRAGDROP );
			SetDlgItemText( hDlg, IDC_RA_BROKENACH_BUGREPORTER, Widen( RAUsers::LocalUser().Username() ).c_str() );
		}
		return FALSE;

	case WM_COMMAND:
		switch( LOWORD( wParam ) )
		{
		case IDOK:
		{
			HWND hList = GetDlgItem( hDlg, IDC_RA_REPORTBROKENACHIEVEMENTSLIST );

			const bool bProblem1Sel = ( IsDlgButtonChecked( hDlg, IDC_RA_PROBLEMTYPE1 ) == BST_CHECKED );
			const bool bProblem2Sel = ( IsDlgButtonChecked( hDlg, IDC_RA_PROBLEMTYPE2 ) == BST_CHECKED );

			if( ( bProblem1Sel == false ) && ( bProblem2Sel == false ) )
			{
				MessageBox( nullptr, L"Please select a problem type.", L"Warning", MB_ICONWARNING );
				return FALSE;
			}

			int nProblemType = bProblem1Sel ? 1 : bProblem2Sel ? 2 : 0;	// 0==?
			const char* sProblemTypeNice = PROBLEM_STR[ nProblemType ];

			char sBuggedIDs[ 1024 ];
			sprintf_s( sBuggedIDs, 1024, "" );

			int nReportCount = 0;

			const size_t nListSize = ListView_GetItemCount( hList );
			for( size_t i = 0; i < nListSize; ++i )
			{
				if( ListView_GetCheckState( hList, i ) != 0 )
				{
					//	NASTY big assumption here...
					char buffer[ 1024 ];
					sprintf_s( buffer, 1024, "%d,", g_pActiveAchievements->GetAchievement( i ).ID() );
					strcat_s( sBuggedIDs, 1024, buffer );

					//ListView_GetItem( hList );	
					nReportCount++;
				}
			}

			if( nReportCount > 5 )
			{
				if( MessageBox( nullptr, L"You have over 5 achievements selected. Is this OK?", L"Warning", MB_YESNO ) == IDNO )
					return FALSE;
			}

			wchar_t sBugReportCommentWide[ 4096 ];
			GetDlgItemText( hDlg, IDC_RA_BROKENACHIEVEMENTREPORTCOMMENT, sBugReportCommentWide, 4096 );
			std::string sBugReportComment = Narrow( sBugReportCommentWide );

			char sBugReportInFull[ 8192 ];
			sprintf_s( sBugReportInFull, 8192,
					"--New Bug Report--\n"
					"\n"
					"Game: %s\n"
					"Achievement IDs: %s\n"
					"Problem: %s\n"
					"Reporter: %s\n"
					"ROM Checksum: %s\n"
					"\n"
					"Comment: %s\n"
					"\n"
					"Is this OK?",
					CoreAchievements->GameTitle().c_str(),
					sBuggedIDs,
					sProblemTypeNice,
					RAUsers::LocalUser().Username().c_str(),
					g_sCurrentROMMD5.c_str(),
					sBugReportComment.c_str() );

			if( MessageBox( nullptr, Widen( sBugReportInFull ).c_str(), L"Summary", MB_YESNO ) == IDNO )
				return FALSE;

			PostArgs args;
			args[ 'u' ] = RAUsers::LocalUser().Username();
			args[ 't' ] = RAUsers::LocalUser().Token();
			args[ 'i' ] = sBuggedIDs;
			args[ 'p' ] = std::to_string( nProblemType );
			args[ 'n' ] = sBugReportComment.c_str();
			args[ 'm' ] = g_sCurrentROMMD5;

			Document doc;
			if( RAWeb::DoBlockingRequest( RequestSubmitTicket, args, doc ) )
			{
				if( doc[ "Success" ].GetBool() )
				{
					char buffer[ 2048 ];
					sprintf_s( buffer, 2048, "Submitted OK!\n"
							"\n"
							"Thankyou for reporting that bug(s), and sorry it hasn't worked correctly.\n"
							"\n"
							"The development team will investigate this bug as soon as possible\n"
							"and we will send you a message on RetroAchievements.org\n"
							"as soon as we have a solution.\n"
							"\n"
							"Thanks again!" );

					MessageBox( hDlg, Widen( buffer ).c_str(), L"Success!", MB_OK );
					EndDialog( hDlg, TRUE );
					return TRUE;
				}
				else
				{
					char buffer[ 2048 ];
					sprintf_s( buffer, 2048,
							"Failed!\n"
							"\n"
							"Response From Server:\n"
							"\n"
							"Error code: %d", doc.GetParseError() );
					MessageBox( hDlg, Widen( buffer ).c_str(), L"Error from server!", MB_OK );
					return FALSE;
				}
			}
			else
			{
				MessageBox( hDlg,
							L"Failed!\n"
							L"\n"
							L"Cannot reach server... are you online?\n"
							L"\n",
							L"Error!", MB_OK );
				return FALSE;
			}
		}
		break;

		case IDCANCEL:
			EndDialog( hDlg, TRUE );
			return TRUE;
		}
		return FALSE;

	case WM_CLOSE:
		EndDialog( hDlg, FALSE );
		return TRUE;

	default:
		return FALSE;
	}
}
예제 #9
0
void Dlg_MemBookmark::ExportJSON()
{
	if ( g_pCurrentGameData->GetGameID() == 0 )
	{
		MessageBox( nullptr, _T("ROM not loaded: please load a ROM first!"), _T("Error!"), MB_OK );
		return;
	}

	if ( m_vBookmarks.size() == 0)
	{
		MessageBox( nullptr, _T("No bookmarks to save: please create a bookmark before attempting to save."), _T("Error!"), MB_OK );
		return;
	}

	std::string defaultDir = RA_DIR_BOOKMARKS;
	defaultDir.erase ( 0, 2 ); // Removes the characters (".\\")
	defaultDir = g_sHomeDir + defaultDir;

	IFileSaveDialog* pDlg = nullptr;
	HRESULT hr = CoCreateInstance( CLSID_FileSaveDialog, NULL, CLSCTX_ALL, IID_IFileSaveDialog, reinterpret_cast<void**>( &pDlg ) );
	if ( hr == S_OK )
	{
		hr = pDlg->SetFileTypes( ARRAYSIZE( c_rgFileTypes ), c_rgFileTypes );
		if ( hr == S_OK )
		{
			char defaultFileName[ 512 ];
			sprintf_s ( defaultFileName, 512, "%s-Bookmarks.txt", std::to_string( g_pCurrentGameData->GetGameID() ).c_str() );
			hr = pDlg->SetFileName( Widen( defaultFileName ).c_str() );
			if ( hr == S_OK )
			{
				PIDLIST_ABSOLUTE pidl;
				hr = SHParseDisplayName( Widen( defaultDir ).c_str(), NULL, &pidl, SFGAO_FOLDER, 0 );
				if ( hr == S_OK )
				{
					IShellItem* pItem = nullptr;
					SHCreateShellItem( NULL, NULL, pidl, &pItem );
					hr = pDlg->SetDefaultFolder( pItem );
					if ( hr == S_OK )
					{
						pDlg->SetDefaultExtension( L"txt" );
						hr = pDlg->Show( nullptr );
						if ( hr == S_OK )
						{

							hr = pDlg->GetResult( &pItem );
							if ( hr == S_OK )
							{
								LPWSTR pStr = nullptr;
								hr = pItem->GetDisplayName( SIGDN_FILESYSPATH, &pStr );
								if ( hr == S_OK )
								{
									Document doc;
									Document::AllocatorType& allocator = doc.GetAllocator();
									doc.SetObject();

									Value bookmarks( kArrayType );
									for ( MemBookmark* bookmark : m_vBookmarks )
									{
										Value item( kObjectType );
										char buffer[ 256 ];
										sprintf_s( buffer, Narrow( bookmark->Description() ).c_str(), sizeof( buffer ) );
										Value s( buffer, allocator );

										item.AddMember( "Description", s, allocator );
										item.AddMember( "Address", bookmark->Address(), allocator );
										item.AddMember( "Type", bookmark->Type(), allocator );
										item.AddMember( "Decimal", bookmark->Decimal(), allocator );
										bookmarks.PushBack( item, allocator );
									}
									doc.AddMember( "Bookmarks", bookmarks, allocator );

									_WriteBufferToFile( Narrow( pStr ), doc );
								}

								pItem->Release();
								ILFree( pidl );
							}
						}
					}
				}
			}
		}
		pDlg->Release();
	}
}
예제 #10
0
파일: Common.cpp 프로젝트: botanegg/gpsvp
	int Guess(int intDegree)
	{
		int res = table[Narrow(intDegree)];
		return res;
	}