diff src/win32/MovieOpen.cpp @ 1:f9f4f1b99eed

importing src directory
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:31:27 -0600
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/win32/MovieOpen.cpp	Sat Mar 03 10:31:27 2012 -0600
     1.3 @@ -0,0 +1,532 @@
     1.4 +// MovieOpen.cpp : implementation file
     1.5 +//
     1.6 +
     1.7 +#include "stdafx.h"
     1.8 +#include "resource.h"
     1.9 +#include "MovieOpen.h"
    1.10 +#include "MainWnd.h"
    1.11 +#include "FileDlg.h"
    1.12 +#include "WinResUtil.h"
    1.13 +#include "WinMiscUtil.h"
    1.14 +#include "VBA.h"
    1.15 +
    1.16 +#include "../gba/GBA.h"
    1.17 +#include "../gb/gbGlobals.h"
    1.18 +#include "../common/Util.h"
    1.19 +#include "7zip/OpenArchive.h"
    1.20 +
    1.21 +// MovieOpen dialog
    1.22 +
    1.23 +IMPLEMENT_DYNAMIC(MovieOpen, CDialog)
    1.24 +MovieOpen::MovieOpen(CWnd *pParent /*=NULL*/)
    1.25 +	: CDialog(MovieOpen::IDD, pParent)
    1.26 +{}
    1.27 +
    1.28 +MovieOpen::~MovieOpen()
    1.29 +{
    1.30 +	SetArchiveParentHWND(NULL);
    1.31 +}
    1.32 +
    1.33 +BOOL MovieOpen::OnInitDialog()
    1.34 +{
    1.35 +	CDialog::OnInitDialog();
    1.36 +
    1.37 +	pauseFrame = 0;
    1.38 +	ZeroMemory(&movieInfo, sizeof SMovie);
    1.39 +
    1.40 +	SetArchiveParentHWND(GetSafeHwnd());
    1.41 +
    1.42 +	GetDlgItem(IDC_CHECK_HIDEBORDER)->ShowWindow(FALSE);
    1.43 +	GetDlgItem(IDC_LABEL_WARNING1)->SetWindowText("");
    1.44 +	GetDlgItem(IDC_LABEL_WARNING2)->SetWindowText("");
    1.45 +	GetDlgItem(IDC_EDIT_PAUSEFRAME)->SetWindowText("");
    1.46 +	GetDlgItem(IDC_EDIT_PAUSEFRAME)->EnableWindow(FALSE);
    1.47 +	GetDlgItem(IDC_CHECK_PAUSEFRAME)->EnableWindow(FALSE);
    1.48 +
    1.49 +	CheckDlgButton(IDC_READONLY, TRUE);
    1.50 +	m_editDescription.SetReadOnly(theApp.movieReadOnly);
    1.51 +
    1.52 +	m_editFilename.LimitText(_MAX_PATH);
    1.53 +	m_editAuthor.LimitText(MOVIE_METADATA_AUTHOR_SIZE);
    1.54 +	m_editDescription.LimitText(MOVIE_METADATA_SIZE - MOVIE_METADATA_AUTHOR_SIZE);
    1.55 +	m_editPauseFrame.LimitText(8);
    1.56 +
    1.57 +	// convert the ROM filename into a default movie name
    1.58 +	CString movieName = winGetDestFilename(theApp.gameFilename, IDS_MOVIE_DIR, ".vbm");
    1.59 +
    1.60 +	GetDlgItem(IDC_MOVIE_FILENAME)->SetWindowText(movieName);
    1.61 +
    1.62 +	// scroll to show the rightmost side of the movie filename
    1.63 +	((CEdit *)GetDlgItem(IDC_MOVIE_FILENAME))->SetSel((DWORD)(movieName.GetLength() - 1), FALSE);
    1.64 +
    1.65 +	OnBnClickedMovieRefresh();
    1.66 +
    1.67 +	return TRUE; // return TRUE unless you set the focus to a control
    1.68 +	// EXCEPTION: OCX Property Pages should return FALSE
    1.69 +}
    1.70 +
    1.71 +void MovieOpen::DoDataExchange(CDataExchange *pDX)
    1.72 +{
    1.73 +	CDialog::DoDataExchange(pDX);
    1.74 +	//{{AFX_DATA_MAP(MovieCreate)
    1.75 +	DDX_Control(pDX, IDC_EDIT_AUTHOR, m_editAuthor);
    1.76 +	DDX_Control(pDX, IDC_EDIT_DESCRIPTION, m_editDescription);
    1.77 +	DDX_Control(pDX, IDC_MOVIE_FILENAME, m_editFilename);
    1.78 +	DDX_Control(pDX, IDC_EDIT_PAUSEFRAME, m_editPauseFrame);
    1.79 +	//}}AFX_DATA_MAP
    1.80 +}
    1.81 +
    1.82 +BEGIN_MESSAGE_MAP(MovieOpen, CDialog)
    1.83 +ON_BN_CLICKED(IDC_BROWSE, OnBnClickedBrowse)
    1.84 +ON_BN_CLICKED(IDOK, OnBnClickedOk)
    1.85 +ON_BN_CLICKED(IDCANCEL, OnBnClickedCancel)
    1.86 +ON_BN_CLICKED(IDC_MOVIE_REFRESH, OnBnClickedMovieRefresh)
    1.87 +ON_BN_CLICKED(IDC_READONLY, OnBnClickedReadonly)
    1.88 +ON_BN_CLICKED(IDC_CHECK_PAUSEFRAME, OnBnClickedCheckPauseframe)
    1.89 +ON_BN_CLICKED(IDC_CHECK_HIDEBORDER, OnBnClickedHideborder)
    1.90 +ON_EN_CHANGE(IDC_MOVIE_FILENAME, OnEnChangeMovieFilename)
    1.91 +END_MESSAGE_MAP()
    1.92 +
    1.93 +// MovieOpen message handlers
    1.94 +
    1.95 +// FIXME: file-scope-global
    1.96 +static bool shouldReopenBrowse = false;
    1.97 +
    1.98 +void MovieOpen::OnBnClickedBrowse()
    1.99 +{
   1.100 +	theApp.winCheckFullscreen();    // FIXME: necessary or not?
   1.101 +
   1.102 +	LPCTSTR exts[] = { ".vbm", NULL };
   1.103 +
   1.104 +	CString filter = winResLoadFilter(IDS_FILTER_MOVIE);
   1.105 +	CString title  = winResLoadString(IDS_SELECT_MOVIE_NAME);
   1.106 +
   1.107 +	CString movieName = winGetDestFilename(theApp.gameFilename, IDS_MOVIE_DIR, exts[0]);
   1.108 +	CString movieDir  = winGetDestDir(IDS_MOVIE_DIR);
   1.109 +
   1.110 +	FileDlg dlg(this, movieName, filter, 1, "VBM", exts, movieDir, title, false, true);
   1.111 +
   1.112 +	do
   1.113 +	{
   1.114 +		shouldReopenBrowse = false;
   1.115 +
   1.116 +		if (dlg.DoModal() == IDCANCEL)
   1.117 +		{
   1.118 +			return;
   1.119 +		}
   1.120 +
   1.121 +		movieName = dlg.GetPathName();
   1.122 +
   1.123 +		GetDlgItem(IDC_MOVIE_FILENAME)->SetWindowText(movieName);
   1.124 +
   1.125 +		// SetWindowText calls OnEnChangeMovieFilename which calls OnBnClickedMovieRefresh
   1.126 +		// so this extra call to OnBnClickedMovieRefresh is bad
   1.127 +		//OnBnClickedMovieRefresh();
   1.128 +	}
   1.129 +	while (shouldReopenBrowse);
   1.130 +
   1.131 +	// scroll to show the rightmost side of the movie filename
   1.132 +	((CEdit *)GetDlgItem(IDC_MOVIE_FILENAME))->SetSel((DWORD)(movieName.GetLength() - 1), FALSE);
   1.133 +}
   1.134 +
   1.135 +// some extensions that might commonly be near emulation-related files that we almost certainly can't open, or at least not
   1.136 +// directly.
   1.137 +// also includes definitely non-movie extensions we know about, since we only use this variable in a movie opening function.
   1.138 +// we do this by exclusion instead of inclusion because we don't want to exclude extensions used for any archive files, even
   1.139 +// extensionless or unusually-named archives.
   1.140 +static const char *s_movieIgnoreExtensions [] = {
   1.141 +	"gba", "gbc", "gb",	 "sgb",	 "cgb",	 "bin", "agb", "bios", "mb",   "elf",	"sgm",	"clt",	 "dat",	 "gbs",	 "gcf", "spc",
   1.142 +	"xpc", "pal", "act", "dmp",	 "avi",	 "ini", "txt", "nfo",  "htm",  "html",	"jpg",	"jpeg",	 "png",	 "bmp",	 "gif", "mp3",
   1.143 +	"wav", "lnk", "exe", "bat",	 "sav",	 "luasav"
   1.144 +};
   1.145 +
   1.146 +void MovieOpen::OnBnClickedMovieRefresh()
   1.147 +{
   1.148 +	static int recursionDepth = 0;
   1.149 +	if (recursionDepth > 0)
   1.150 +		return;
   1.151 +	struct Scope {Scope(){ ++ recursionDepth; } ~Scope(){ --recursionDepth; }} scope;
   1.152 +
   1.153 +	CString tempName;
   1.154 +	GetDlgItem(IDC_MOVIE_FILENAME)->GetWindowText(tempName);
   1.155 +
   1.156 +#if 1
   1.157 +	// use ObtainFile to support opening files within archives (.7z, .rar, .zip, .zip.rar.7z, etc.)
   1.158 +
   1.159 +	if (movieLogicalName.GetLength() > 2048) movieLogicalName.Truncate(2048);
   1.160 +
   1.161 +	char LogicalName[2048], PhysicalName[2048];
   1.162 +	if (ObtainFile(tempName, LogicalName, PhysicalName, "mov", s_movieIgnoreExtensions,
   1.163 +	               sizeof(s_movieIgnoreExtensions) / sizeof(*s_movieIgnoreExtensions)))
   1.164 +	{
   1.165 +		if (tempName != LogicalName)
   1.166 +		{
   1.167 +			int selStart = 0, selEnd = 0;
   1.168 +			((CEdit *)GetDlgItem(IDC_MOVIE_FILENAME))->GetSel(selStart, selEnd);
   1.169 +
   1.170 +			GetDlgItem(IDC_MOVIE_FILENAME)->SetWindowText(LogicalName);
   1.171 +
   1.172 +			((CEdit *)GetDlgItem(IDC_MOVIE_FILENAME))->SetSel(selStart, selEnd, FALSE);
   1.173 +		}
   1.174 +		moviePhysicalName = PhysicalName;
   1.175 +		movieLogicalName  = LogicalName;
   1.176 +		ReleaseTempFileCategory("mov", PhysicalName);
   1.177 +	}
   1.178 +	else
   1.179 +	{
   1.180 +		shouldReopenBrowse = true;
   1.181 +		return;
   1.182 +	}
   1.183 +#else
   1.184 +	// old version that only supports uncompressed movies
   1.185 +	moviePhysicalName = tempName;
   1.186 +	movieLogicalName  = tempName;
   1.187 +#endif
   1.188 +
   1.189 +	if (VBAMovieGetInfo(moviePhysicalName, &movieInfo) == MOVIE_SUCCESS)
   1.190 +	{
   1.191 +		if (movieInfo.readOnly)
   1.192 +		{
   1.193 +			CheckDlgButton(IDC_READONLY, TRUE);
   1.194 +			m_editDescription.SetReadOnly(TRUE);
   1.195 +		}
   1.196 +
   1.197 +		char buffer[MOVIE_METADATA_SIZE];
   1.198 +
   1.199 +		strncpy(buffer, movieInfo.authorInfo, MOVIE_METADATA_AUTHOR_SIZE);
   1.200 +		buffer[MOVIE_METADATA_AUTHOR_SIZE - 1] = '\0';
   1.201 +		GetDlgItem(IDC_EDIT_AUTHOR)->SetWindowText(buffer);
   1.202 +
   1.203 +		strncpy(buffer, movieInfo.authorInfo + MOVIE_METADATA_AUTHOR_SIZE, MOVIE_METADATA_SIZE - MOVIE_METADATA_AUTHOR_SIZE);
   1.204 +		buffer[MOVIE_METADATA_SIZE - MOVIE_METADATA_AUTHOR_SIZE - 1] = '\0';
   1.205 +		GetDlgItem(IDC_EDIT_DESCRIPTION)->SetWindowText(buffer);
   1.206 +
   1.207 +		int option = 2;
   1.208 +		if (movieInfo.header.startFlags & MOVIE_START_FROM_SRAM)
   1.209 +			option = 1;
   1.210 +		if (movieInfo.header.startFlags & MOVIE_START_FROM_SNAPSHOT)
   1.211 +			option = 0;
   1.212 +		CheckRadioButton(IDC_RECNOW, IDC_RECSTART, IDC_RECNOW + option);
   1.213 +
   1.214 +		option = 3;
   1.215 +		if (movieInfo.header.typeFlags & MOVIE_TYPE_SGB)
   1.216 +			option = 2;
   1.217 +		if (movieInfo.header.typeFlags & MOVIE_TYPE_GBC)
   1.218 +			option = 1;
   1.219 +		if (movieInfo.header.typeFlags & MOVIE_TYPE_GBA)
   1.220 +			option = 0;
   1.221 +		CheckRadioButton(IDC_REC_GBA, IDC_REC_GB, IDC_REC_GBA + option);
   1.222 +
   1.223 +		GetDlgItem(IDC_CHECK_HIDEBORDER)->ShowWindow(option == 2 ? TRUE : FALSE);
   1.224 +
   1.225 +		if (movieInfo.header.typeFlags & MOVIE_TYPE_GBA)
   1.226 +		{
   1.227 +			if (movieInfo.header.optionFlags & MOVIE_SETTING_USEBIOSFILE)
   1.228 +			{
   1.229 +				if (movieInfo.header.optionFlags & MOVIE_SETTING_SKIPBIOSFILE)
   1.230 +					option = 2;
   1.231 +				else
   1.232 +					option = 3;
   1.233 +			}
   1.234 +			else
   1.235 +				option = 1;
   1.236 +		}
   1.237 +		else
   1.238 +			option = 0;
   1.239 +
   1.240 +		CheckRadioButton(IDC_REC_NOBIOS, IDC_REC_GBABIOSINTRO, IDC_REC_NOBIOS + option);
   1.241 +
   1.242 +		{
   1.243 +			char * p;
   1.244 +			time_t ttime = (time_t)movieInfo.header.uid;
   1.245 +			strncpy(buffer, ctime(&ttime), 127);
   1.246 +			buffer[127] = '\0';
   1.247 +			if ((p = strrchr(buffer, '\n')))
   1.248 +				*p = '\0';
   1.249 +			GetDlgItem(IDC_LABEL_DATE)->SetWindowText(buffer);
   1.250 +
   1.251 +			uint32 div	   = 60;
   1.252 +			uint32 l	   = (movieInfo.header.length_frames + (div >> 1)) / div;
   1.253 +			uint32 seconds = l % 60;
   1.254 +			l /= 60;
   1.255 +			uint32 minutes = l % 60;
   1.256 +			l /= 60;
   1.257 +			uint32 hours = l % 60;
   1.258 +			sprintf(buffer, "%02d:%02d:%02d", hours, minutes, seconds);
   1.259 +			GetDlgItem(IDC_LABEL_LENGTH)->SetWindowText(buffer);
   1.260 +			sprintf(buffer, "%ld", movieInfo.header.length_frames);
   1.261 +			GetDlgItem(IDC_LABEL_FRAMES)->SetWindowText(buffer);
   1.262 +			sprintf(buffer, "%ld", movieInfo.header.rerecord_count);
   1.263 +			GetDlgItem(IDC_LABEL_RERECORD)->SetWindowText(buffer);
   1.264 +		}
   1.265 +
   1.266 +		{
   1.267 +			char warning1 [1024], warning2 [1024], buffer [1024];
   1.268 +
   1.269 +			strcpy(warning1, "");
   1.270 +			strcpy(warning2, "");
   1.271 +
   1.272 +			char   romTitle [12];
   1.273 +			uint32 romGameCode;
   1.274 +			uint16 checksum;
   1.275 +			uint8  crc;
   1.276 +
   1.277 +			VBAMovieGetRomInfo(movieInfo, romTitle, romGameCode, checksum, crc);
   1.278 +
   1.279 +			// rather than treat these as warnings, might as well always show the info in the dialog (it's probably more
   1.280 +			// informative and reassuring)
   1.281 +///			if (strncmp(movieInfo.header.romTitle,romTitle,12) != 0)
   1.282 +			{
   1.283 +				char str [13];
   1.284 +				strncpy(str, movieInfo.header.romTitle, 12);
   1.285 +				str[12] = '\0';
   1.286 +				sprintf(buffer, "title=%s  ", str);
   1.287 +				strcat(warning1, buffer);
   1.288 +
   1.289 +				strncpy(str, romTitle, 12);
   1.290 +				str[12] = '\0';
   1.291 +				sprintf(buffer, "title=%s  ", str);
   1.292 +				strcat(warning2, buffer);
   1.293 +			}
   1.294 +///			if (((movieInfo.header.typeFlags & MOVIE_TYPE_GBA)!=0) != (systemCartridgeType == 0))
   1.295 +			{
   1.296 +				sprintf(buffer, "type=%s  ",
   1.297 +				        (movieInfo.header.typeFlags & MOVIE_TYPE_GBA) ? "GBA" : (movieInfo.header.typeFlags &
   1.298 +				                                                                 MOVIE_TYPE_GBC) ? "GBC" : (movieInfo.header.
   1.299 +				                                                                                            typeFlags &
   1.300 +				                                                                                            MOVIE_TYPE_SGB) ? "SGB" : "GB");
   1.301 +				strcat(warning1, buffer);
   1.302 +
   1.303 +				sprintf(buffer, "type=%s  ", systemCartridgeType ==
   1.304 +				        0 ? "GBA" : (gbRom[0x143] & 0x80 ? "GBC" : (gbRom[0x146] == 0x03 ? "SGB" : "GB")));
   1.305 +				strcat(warning2, buffer);
   1.306 +			}
   1.307 +///			if (movieInfo.header.romCRC != crc)
   1.308 +			{
   1.309 +				sprintf(buffer, "crc=%02x  ", movieInfo.header.romCRC);
   1.310 +				strcat(warning1, buffer);
   1.311 +
   1.312 +				sprintf(buffer, "crc=%02x  ", crc);
   1.313 +				strcat(warning2, buffer);
   1.314 +			}
   1.315 +///			if (movieInfo.header.romGameCode != romGameCode)
   1.316 +			{
   1.317 +				char code [5];
   1.318 +				if (movieInfo.header.typeFlags & MOVIE_TYPE_GBA)
   1.319 +				{
   1.320 +					memcpy(code, &movieInfo.header.romGameCode, 4);
   1.321 +					code[4] = '\0';
   1.322 +					sprintf(buffer, "code=%s  ", code);
   1.323 +					strcat(warning1, buffer);
   1.324 +				}
   1.325 +
   1.326 +				if (systemCartridgeType == 0)
   1.327 +				{
   1.328 +					memcpy(code, &romGameCode, 4);
   1.329 +					code[4] = '\0';
   1.330 +					sprintf(buffer, "code=%s  ", code);
   1.331 +					strcat(warning2, buffer);
   1.332 +				}
   1.333 +			}
   1.334 +///			if (movieInfo.header.romOrBiosChecksum != checksum && !((movieInfo.header.optionFlags &
   1.335 +// MOVIE_SETTING_USEBIOSFILE)==0
   1.336 +// && checksum==0))
   1.337 +			{
   1.338 +				sprintf(buffer,
   1.339 +				        movieInfo.header.typeFlags &
   1.340 +				        MOVIE_TYPE_GBA ? ((movieInfo.header.optionFlags & MOVIE_SETTING_USEBIOSFILE) ==
   1.341 +				                          0 ? "(bios=none)  " : "(bios=%04x)  ") : "check=%04x  ",
   1.342 +				        movieInfo.header.romOrBiosChecksum);
   1.343 +				strcat(warning1, buffer);
   1.344 +
   1.345 +				sprintf(buffer,
   1.346 +				        checksum == 0 ? "(bios=none)  " : systemCartridgeType == 0 ? "(bios=%04x)  " : "check=%04x  ",
   1.347 +				        checksum);
   1.348 +				strcat(warning2, buffer);
   1.349 +			}
   1.350 +
   1.351 +			if (strlen(warning1) > 0)
   1.352 +			{
   1.353 +				sprintf(buffer, "Movie ROM: %s", warning1);
   1.354 +				GetDlgItem(IDC_LABEL_WARNING1)->SetWindowText(buffer);
   1.355 +
   1.356 +				sprintf(buffer, "Your ROM: %s", warning2);
   1.357 +
   1.358 +				//if(movieInfo.header.romCRC != crc
   1.359 +				//|| strncmp(movieInfo.header.romTitle,romTitle,12) != 0
   1.360 +				//|| movieInfo.header.romOrBiosChecksum != checksum && !((movieInfo.header.optionFlags &
   1.361 +				// MOVIE_SETTING_USEBIOSFILE)==0 && checksum==0))
   1.362 +				//	strcat(buffer, "<-- MISMATCH");
   1.363 +
   1.364 +				GetDlgItem(IDC_LABEL_WARNING2)->SetWindowText(buffer);
   1.365 +			}
   1.366 +			else
   1.367 +			{
   1.368 +				GetDlgItem(IDC_LABEL_WARNING1)->SetWindowText("(No problems detected)");
   1.369 +				GetDlgItem(IDC_LABEL_WARNING2)->SetWindowText(" ");
   1.370 +			}
   1.371 +		}
   1.372 +		GetDlgItem(IDC_CHECK_PAUSEFRAME)->EnableWindow(TRUE);
   1.373 +	}
   1.374 +	else
   1.375 +	{
   1.376 +		GetDlgItem(IDC_LABEL_DATE)->SetWindowText(" ");
   1.377 +		GetDlgItem(IDC_LABEL_LENGTH)->SetWindowText(" ");
   1.378 +		GetDlgItem(IDC_LABEL_FRAMES)->SetWindowText(" ");
   1.379 +		GetDlgItem(IDC_LABEL_RERECORD)->SetWindowText(" ");
   1.380 +		GetDlgItem(IDC_EDIT_AUTHOR)->SetWindowText(" ");
   1.381 +		GetDlgItem(IDC_EDIT_DESCRIPTION)->SetWindowText(" ");
   1.382 +		GetDlgItem(IDC_LABEL_WARNING1)->SetWindowText(" ");
   1.383 +		GetDlgItem(IDC_LABEL_WARNING2)->SetWindowText(" ");
   1.384 +
   1.385 +		GetDlgItem(IDC_EDIT_PAUSEFRAME)->SetWindowText("");
   1.386 +		GetDlgItem(IDC_EDIT_PAUSEFRAME)->EnableWindow(FALSE);
   1.387 +		GetDlgItem(IDC_CHECK_PAUSEFRAME)->EnableWindow(FALSE);
   1.388 +		CheckDlgButton(IDC_CHECK_PAUSEFRAME, FALSE);
   1.389 +/*
   1.390 +        /// FIXME: how to un-check all the radio buttons?
   1.391 +        CheckRadioButton(IDC_RECNOW, IDC_RECSTART, -1);
   1.392 +        CheckRadioButton(IDC_REC_GBA, IDC_REC_GB, -1);
   1.393 +        CheckRadioButton(IDC_REC_NOBIOS, IDC_REC_GBABIOSINTRO, -1);*/
   1.394 +	}
   1.395 +}
   1.396 +
   1.397 +BOOL MovieOpen::OnWndMsg(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT *res)
   1.398 +{
   1.399 +	switch (msg)
   1.400 +	{
   1.401 +	case WM_CTLCOLORSTATIC:
   1.402 +	{
   1.403 +		//HWND hwndDlg = GetSafeHwnd();
   1.404 +		HWND warnDlg = NULL;
   1.405 +		GetDlgItem(IDC_LABEL_WARNING2, &warnDlg);
   1.406 +
   1.407 +		if ((HWND)lParam == warnDlg)
   1.408 +		{
   1.409 +			char   romTitle [12];
   1.410 +			uint32 romGameCode;
   1.411 +			uint16 checksum;
   1.412 +			uint8  crc;
   1.413 +
   1.414 +			VBAMovieGetRomInfo(movieInfo, romTitle, romGameCode, checksum, crc);
   1.415 +
   1.416 +			if (movieInfo.header.romCRC != crc
   1.417 +			    || strncmp(movieInfo.header.romTitle, romTitle, 12) != 0
   1.418 +			    || movieInfo.header.romOrBiosChecksum != checksum
   1.419 +			    && !((movieInfo.header.optionFlags & MOVIE_SETTING_USEBIOSFILE) == 0 && checksum == 0))
   1.420 +			{
   1.421 +				// draw the md5 sum in red if it's different from the md5 of the rom used in the replay
   1.422 +				HDC hdcStatic = (HDC)wParam;
   1.423 +				SetTextColor(hdcStatic, RGB(255, 0, 0));      // use red for a mismatch
   1.424 +
   1.425 +				// I'm not sure why this doesn't work to make the background transparent... it turns white anyway
   1.426 +				SetBkMode(hdcStatic, TRANSPARENT);
   1.427 +				return (LONG)GetStockObject(NULL_BRUSH);
   1.428 +			}
   1.429 +		}
   1.430 +		return FALSE;
   1.431 +	}
   1.432 +	}
   1.433 +	return CDialog::OnWndMsg(msg, wParam, lParam, res);
   1.434 +}
   1.435 +
   1.436 +void MovieOpen::OnBnClickedOk()
   1.437 +{
   1.438 +	bool useBIOSFile = (movieInfo.header.optionFlags & MOVIE_SETTING_USEBIOSFILE) != 0;
   1.439 +	if (useBIOSFile)
   1.440 +	{
   1.441 +		extern bool systemLoadBIOS(const char *biosFileName, bool useBiosFile);
   1.442 +		if (!systemLoadBIOS(theApp.biosFileName, useBIOSFile))
   1.443 +		{
   1.444 +			systemMessage(0, "This movie requires a valid GBA BIOS file to play.\nPlease locate a BIOS file.");
   1.445 +			((MainWnd *)theApp.m_pMainWnd)->OnOptionsEmulatorSelectbiosfile();
   1.446 +			if (!systemLoadBIOS(theApp.biosFileName, useBIOSFile))
   1.447 +			{
   1.448 +				systemMessage(0, "\"%s\" is not a valid BIOS file; cannot play movie without one.", theApp.biosFileName);
   1.449 +				return;
   1.450 +			}
   1.451 +		}
   1.452 +	}
   1.453 +
   1.454 +	int code = VBAMovieOpen(moviePhysicalName, IsDlgButtonChecked(IDC_READONLY) != FALSE);
   1.455 +
   1.456 +	if (code != MOVIE_SUCCESS)
   1.457 +	{
   1.458 +		if (code == MOVIE_FILE_NOT_FOUND)
   1.459 +			systemMessage(0, "Could not find movie file \"%s\".", (const char *)movieLogicalName);
   1.460 +		else if (code == MOVIE_WRONG_FORMAT)
   1.461 +			systemMessage(0, "Movie file \"%s\" is not in proper VBM format.", (const char *)movieLogicalName);
   1.462 +		else if (code == MOVIE_WRONG_VERSION)
   1.463 +			systemMessage(0, "Movie file \"%s\" is not a supported version.", (const char *)movieLogicalName);
   1.464 +		else
   1.465 +			systemMessage(0, "Failed to open movie \"%s\".", (const char *)movieLogicalName);
   1.466 +		return;
   1.467 +	}
   1.468 +	else
   1.469 +	{
   1.470 +		// get author and movie info from the edit fields (the description might change):
   1.471 +		char info[MOVIE_METADATA_SIZE], buffer[MOVIE_METADATA_SIZE];
   1.472 +
   1.473 +		GetDlgItem(IDC_EDIT_AUTHOR)->GetWindowText(buffer, MOVIE_METADATA_AUTHOR_SIZE);
   1.474 +		strncpy(info, buffer, MOVIE_METADATA_AUTHOR_SIZE);
   1.475 +		info[MOVIE_METADATA_AUTHOR_SIZE - 1] = '\0';
   1.476 +
   1.477 +		GetDlgItem(IDC_EDIT_DESCRIPTION)->GetWindowText(buffer, MOVIE_METADATA_SIZE - MOVIE_METADATA_AUTHOR_SIZE);
   1.478 +		strncpy(info + MOVIE_METADATA_AUTHOR_SIZE, buffer, MOVIE_METADATA_SIZE - MOVIE_METADATA_AUTHOR_SIZE);
   1.479 +		info[MOVIE_METADATA_SIZE - 1] = '\0';
   1.480 +
   1.481 +		VBAMovieSetMetadata(info);
   1.482 +	}
   1.483 +
   1.484 +	if (IsDlgButtonChecked(IDC_CHECK_PAUSEFRAME))
   1.485 +	{
   1.486 +		char buffer [9];
   1.487 +		GetDlgItem(IDC_EDIT_PAUSEFRAME)->GetWindowText(buffer, 8);
   1.488 +		buffer[8] = '\0';
   1.489 +
   1.490 +		int pauseFrame = atoi(buffer);
   1.491 +		if (pauseFrame >= 0)
   1.492 +			VBAMovieSetPauseAt(pauseFrame);
   1.493 +	}
   1.494 +
   1.495 +	OnOK();
   1.496 +}
   1.497 +
   1.498 +void MovieOpen::OnBnClickedCancel()
   1.499 +{
   1.500 +	OnCancel();
   1.501 +}
   1.502 +
   1.503 +void MovieOpen::OnBnClickedReadonly()
   1.504 +{
   1.505 +	theApp.movieReadOnly = IsDlgButtonChecked(IDC_READONLY) != 0;
   1.506 +	m_editDescription.SetReadOnly(theApp.movieReadOnly);
   1.507 +	OnBnClickedMovieRefresh();
   1.508 +}
   1.509 +
   1.510 +void MovieOpen::OnBnClickedCheckPauseframe()
   1.511 +{
   1.512 +	if (IsDlgButtonChecked(IDC_CHECK_PAUSEFRAME))
   1.513 +	{
   1.514 +		char buffer [8];
   1.515 +		_itoa(movieInfo.header.length_frames, buffer, 10);
   1.516 +		GetDlgItem(IDC_EDIT_PAUSEFRAME)->SetWindowText(buffer);
   1.517 +		GetDlgItem(IDC_EDIT_PAUSEFRAME)->EnableWindow(TRUE);
   1.518 +	}
   1.519 +	else
   1.520 +	{
   1.521 +		GetDlgItem(IDC_EDIT_PAUSEFRAME)->SetWindowText("");
   1.522 +		GetDlgItem(IDC_EDIT_PAUSEFRAME)->EnableWindow(FALSE);
   1.523 +	}
   1.524 +}
   1.525 +
   1.526 +void MovieOpen::OnBnClickedHideborder()
   1.527 +{
   1.528 +	theApp.hideMovieBorder = IsDlgButtonChecked(IDC_CHECK_HIDEBORDER) != 0;
   1.529 +}
   1.530 +
   1.531 +void MovieOpen::OnEnChangeMovieFilename()
   1.532 +{
   1.533 +	OnBnClickedMovieRefresh();
   1.534 +}
   1.535 +