Пример #1
0
static void DirWatcher_Signal(PDIRWATCHER pWatcher, struct DirWatcherEntry *pEntry)
{
	LPSTR pszFileName;
	LPSTR pszFullFileName;
	BOOL bPause = 0;
	HANDLE hFile;
	int nTries = 0;
	TCHAR* t_filename;

	{
		int nLength;
		nLength = WideCharToMultiByte(CP_ACP, 0, pEntry->u.notify.FileName, -1, NULL, 0, NULL, NULL);
		pszFileName = (LPSTR) alloca(nLength * sizeof(*pszFileName));
		WideCharToMultiByte(CP_ACP, 0, pEntry->u.notify.FileName, -1, pszFileName, nLength, NULL, NULL);
	}

	// get the full path to this new file
	pszFullFileName = (LPSTR) alloca(strlen(pEntry->szDirPath) + strlen(pszFileName) + 2);
	strcpy(pszFullFileName, pEntry->szDirPath);
	strcat(pszFullFileName, "\\");
	strcat(pszFullFileName, pszFileName);

	// attempt to busy wait until any result other than ERROR_SHARING_VIOLATION
	// is generated
	nTries = 100;
	do
	{
		hFile = win_create_file_utf8(pszFullFileName, GENERIC_READ,
			FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
		if (hFile != INVALID_HANDLE_VALUE)
			CloseHandle(hFile);

		bPause = (nTries--) && (hFile == INVALID_HANDLE_VALUE)
			&& (GetLastError() == ERROR_SHARING_VIOLATION);
		if (bPause)
			Sleep(10);
	}
	while(bPause);

	// send the message (assuming that we have a target)
	if (pWatcher->hwndTarget)
	{
		t_filename = ui_wstring_from_utf8(pszFileName);
		if( !t_filename )
			return;
		SendMessage(pWatcher->hwndTarget,
			pWatcher->nMessage,
			(pEntry->nIndex << 16) | (pEntry->nSubIndex << 0),
			(LPARAM)(LPCTSTR) win_tstring_strdup(t_filename));
		free(t_filename);
	}

	DirWatcher_SetupWatch(pWatcher, pEntry);
}
Пример #2
0
static void DirInfo_SetDir(tDirInfo *pInfo, int nType, int nItem, LPCTSTR pText)
{
	TCHAR *t_s;
	TCHAR *t_pOldText;

	if (IsMultiDir(nType))
	{
		assert(nItem >= 0);
		_tcscpy(DirInfo_Path(pInfo, nType, nItem), pText);
		DirInfo_SetModified(pInfo, nType, TRUE);
	}
	else
	{
		t_s = win_tstring_strdup(pText);
		if (!t_s)
			return;
		t_pOldText = pInfo[nType].m_tDirectory;
		if (t_pOldText)
			osd_free(t_pOldText);
		pInfo[nType].m_tDirectory = t_s;
	}
}
Пример #3
0
static void CLIB_DECL DetailsPrintf(const char *fmt, ...)
{
	HWND	hEdit;
	va_list marker;
	char	buffer[2000];
	TCHAR*  t_s;
	int		textLength;

	//RS 20030613 Different Ids for Property Page and Dialog
	// so see which one's currently instantiated
	hEdit = GetDlgItem(hAudit, IDC_AUDIT_DETAILS);
	if (hEdit ==  NULL)
		hEdit = GetDlgItem(hAudit, IDC_AUDIT_DETAILS_PROP);
	
	if (hEdit == NULL)
	{
		dprintf("audit detailsprintf() can't find any audit control\n");
		return;
	}

	va_start(marker, fmt);
	
	vsprintf(buffer, fmt, marker);
	
	va_end(marker);

	t_s = tstring_from_utf8(ConvertToWindowsNewlines(buffer));
	if( !t_s || _tcscmp(TEXT(""), t_s) == 0)
		return;

	textLength = Edit_GetTextLength(hEdit);
	Edit_SetSel(hEdit, textLength, textLength);
	SendMessage( hEdit, EM_REPLACESEL, FALSE, (WPARAM)(LPCTSTR)win_tstring_strdup(t_s) );
	
	osd_free(t_s);
}
Пример #4
0
static BOOL RamPopulateControl(datamap *map, HWND dialog, HWND control, windows_options *opts, const char *option_name)
{
	int i, current_index, driver_index;
	const game_driver *gamedrv;
	UINT32 ram, current_ram;
	const char *this_ram_string;
	TCHAR* t_ramstring;
	const device_t *device;

	// identify the driver
	driver_index = PropertiesCurrentGame(dialog);
	gamedrv = &driver_list::driver(driver_index);

	// clear out the combo box
	(void)ComboBox_ResetContent(control);

	// allocate the machine config
	machine_config cfg(*gamedrv,*opts);

	// identify how many options that we have
	device = cfg.devicelist().first(RAM);

	EnableWindow(control, (device != NULL));
	i = 0;
	// we can only do something meaningful if there is more than one option
	if (device != NULL)
	{
		ram_config *config = (ram_config *)downcast<const legacy_device_base *>(device)->inline_config();

		// identify the current amount of RAM
		this_ram_string = opts->value(OPTION_RAMSIZE);
		current_ram = (this_ram_string != NULL) ? ram_parse_string(this_ram_string) : 0;
		if (current_ram == 0)
			current_ram = ram_parse_string(config->default_size);

		// by default, assume index 0
		current_index = 0;

		{
			ram = ram_parse_string(config->default_size);
			t_ramstring = tstring_from_utf8(config->default_size);
			if( !t_ramstring )
				return FALSE;

			(void)ComboBox_InsertString(control, i, win_tstring_strdup(t_ramstring));
			(void)ComboBox_SetItemData(control, i, ram);

			osd_free(t_ramstring);
		}
		if (config->extra_options != NULL)
		{
			int j;
			int size = strlen(config->extra_options);
			char * const s = mame_strdup(config->extra_options);
			char * const e = s + size;
			char *p = s;
			for (j=0;j<size;j++) {
				if (p[j]==',') p[j]=0;
			}

			/* try to parse each option */
			while(p <= e)
			{
				i++;
				// identify this option
				ram = ram_parse_string(p);

				this_ram_string = p;

				t_ramstring = tstring_from_utf8(this_ram_string);
				if( !t_ramstring )
					return FALSE;

				// add this option to the combo box
				(void)ComboBox_InsertString(control, i, win_tstring_strdup(t_ramstring));
				(void)ComboBox_SetItemData(control, i, ram);

				osd_free(t_ramstring);

				// is this the current option?  record the index if so
				if (ram == current_ram)
					current_index = i;

				p+= strlen(p);
				if (p == e)
					break;

				p += 1;
			}

			osd_free(s);
		}

		// set the combo box
		(void)ComboBox_SetCurSel(control, current_index);
	}
	return TRUE;
}
Пример #5
0
static BOOL Directories_OnInitDialog(HWND hDlg, HWND hwndFocus, LPARAM lParam)
{
	RECT		rectClient;
	LVCOLUMN	LVCol;
	int 		i;
	int			nDirInfoCount;
	LPCSTR		s;
	TCHAR       *token;
	TCHAR       buf[MAX_PATH * MAX_DIRS];
	TCHAR*      t_s = NULL;
	HRESULT 	res;

	/* count how many dirinfos there are */
	nDirInfoCount = 0;
	while(g_directoryInfo[nDirInfoCount].lpName)
		nDirInfoCount++;

	g_pDirInfo = (tDirInfo *) malloc(sizeof(tDirInfo) * nDirInfoCount);
	if (!g_pDirInfo) /* bummer */
		goto error;
	memset(g_pDirInfo, 0, sizeof(tDirInfo) * nDirInfoCount);

	for (i = nDirInfoCount - 1; i >= 0; i--)
	{
		t_s = tstring_from_utf8(g_directoryInfo[i].lpName);
		if( !t_s )
			return FALSE;
		(void)ComboBox_InsertString(GetDlgItem(hDlg, IDC_DIR_COMBO), 0, win_tstring_strdup(t_s));
		osd_free(t_s);
		t_s = NULL;
	}

	(void)ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_DIR_COMBO), 0);

	GetClientRect(GetDlgItem(hDlg, IDC_DIR_LIST), &rectClient);

	memset(&LVCol, 0, sizeof(LVCOLUMN));
	LVCol.mask	  = LVCF_WIDTH;
	LVCol.cx	  = rectClient.right - rectClient.left - GetSystemMetrics(SM_CXHSCROLL);
	
	res = ListView_InsertColumn(GetDlgItem(hDlg, IDC_DIR_LIST), 0, &LVCol);

	/* Keep a temporary copy of the directory strings in g_pDirInfo. */
	for (i = 0; i < nDirInfoCount; i++)
	{
		s = g_directoryInfo[i].pfnGetTheseDirs();
		t_s = tstring_from_utf8(s);
		if( !t_s )
			return FALSE;
		if (g_directoryInfo[i].bMulti)
		{
			/* Copy the string to our own buffer so that we can mutilate it */
			_tcscpy(buf, t_s);

			g_pDirInfo[i].m_Path = (tPath*)malloc(sizeof(tPath));
			if (!g_pDirInfo[i].m_Path)
				goto error;

			g_pDirInfo[i].m_Path->m_NumDirectories = 0;
			token = _tcstok(buf, TEXT(";"));
			while ((DirInfo_NumDir(g_pDirInfo, i) < MAX_DIRS) && token)
			{
				_tcscpy(DirInfo_Path(g_pDirInfo, i, DirInfo_NumDir(g_pDirInfo, i)), token);
				DirInfo_NumDir(g_pDirInfo, i)++;
				token = _tcstok(NULL, TEXT(";"));
			}
			DirInfo_SetModified(g_pDirInfo, i, FALSE);
		}
		else
		{
			DirInfo_SetDir(g_pDirInfo, i, -1, t_s);
		}
		osd_free(t_s);
		t_s = NULL;
	}

	UpdateDirectoryList(hDlg);
	return TRUE;

error:
	if( t_s )
		osd_free(t_s);
	Directories_OnDestroy(hDlg);
	EndDialog(hDlg, -1);
	return FALSE;
}