Example #1
0
UniConvert::UniConvert(char * pszCmdLine)
{
	AssertPsz(pszCmdLine);
	memset(m_szFiles, 0, sizeof(m_szFiles));
	m_fSilent = false;
	ParseCommandLine(pszCmdLine);
}
Example #2
0
/*----------------------------------------------------------------------------------------------
	This method opens the given file according to the given mode settings.
	NOTE: This now creates a file if it doesn't already exist, but opens it if it does exist,
		  if STGM_READWRITE alone is set.
		@param pszFile Name (or path) of the desired file
		@param grfstgm Combination of flags kfstgmXxxx from enum in FileStrm.h
----------------------------------------------------------------------------------------------*/
void FileStream::Init(LPCOLESTR pszFile, int grfstgm)
{
	// To access another file this stream should be closed and another created.
	AssertPsz(pszFile);
	Assert(*pszFile);
	Assert(!m_hfile);

	HANDLE hfile = 0;
	DWORD dwDesiredAccess = 0;
	DWORD dwShareMode;
	DWORD dwCreationDisposition = 0;

	// Set the dwShareMode parameter.
	if (grfstgm & kfstgmShareDenyNone)
		dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
	else if (grfstgm & kfstgmShareDenyRead)
		dwShareMode = FILE_SHARE_WRITE;
	else if (grfstgm & kfstgmShareExclusive)
		dwShareMode = 0;
	else
		dwShareMode = FILE_SHARE_READ;

	if (grfstgm & kfstgmReadWrite)
		dwDesiredAccess = GENERIC_READ | GENERIC_WRITE;
	else if (grfstgm & kfstgmWrite)
		dwDesiredAccess = GENERIC_WRITE;
	else
		dwDesiredAccess = GENERIC_READ;

	if (dwDesiredAccess & GENERIC_WRITE)
	{
		if (grfstgm & kfstgmCreate)
			dwCreationDisposition = CREATE_ALWAYS;
		else if (grfstgm & kfstgmReadWrite)
			dwCreationDisposition = OPEN_ALWAYS;	// Allows writing to existing file.
		else
			dwCreationDisposition = CREATE_NEW;
	}
	else
		dwCreationDisposition = OPEN_EXISTING;
	hfile = ::CreateFileW(pszFile, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition,
		FILE_ATTRIBUTE_NORMAL, NULL);
	if (hfile == INVALID_HANDLE_VALUE)
	{
		HRESULT hr = (HRESULT)::GetLastError();
		int stid = ErrorStringId(hr);
		StrUni stuRes(stid);
		StrUni stuMsg;
		stuMsg.Format(L"%s%n%s", stuRes.Chars(), pszFile);
		ThrowHr(hr, stuMsg.Chars());	// Caller should handle. (This is not a COM method).
	}

	m_hfile = hfile;
	m_staPath = pszFile;
	m_grfstgm = grfstgm;  // Store the access mode for the stat method.
}
Example #3
0
/*----------------------------------------------------------------------------------------------
	Static method to create a new FileStream object, opening the specified file in the
	specified mode.
		@param pszFile Name (or path) of the desired file (LPCSTR)
		@param grfstgm Combination of flags kfstgmXxxx from enum in FileStrm.h
		@return The associated IStream interface pointer if successful (third parameter).
----------------------------------------------------------------------------------------------*/
void FileStream::Create(LPCSTR pszFile, int grfstgm, IStream ** ppstrm)
{
	AssertPsz(pszFile);
	AssertPtr(ppstrm);
	Assert(!*ppstrm);

	StrUniBufPath stubp(pszFile);	// converts from ANSI string to Unicode string
	if (stubp.Overflow())
		ThrowHr(WarnHr(STG_E_INVALIDPARAMETER));
	Create(stubp.Chars(), grfstgm, ppstrm);
}
Example #4
0
/*----------------------------------------------------------------------------------------------
	Static method to create a new FileStream object, opening the specified file in the
	specified mode.
		@param pszFile Name (or path) of the desired file (LPCOLESTR)
		@param grfstgm Combination of flags kfstgmXxxx from enum in FileStrm.h
		@return The associated IStream interface pointer if successful (third parameter).
----------------------------------------------------------------------------------------------*/
void FileStream::Create(LPCOLESTR pszFile, int grfstgm, IStream ** ppstrm)
{
	AssertPsz(pszFile);
	AssertPtr(ppstrm);
	Assert(!*ppstrm);

	ComSmartPtr<FileStream> qfist;
	qfist.Attach(NewObj FileStream);
	qfist->Init(pszFile, grfstgm);
	*ppstrm = qfist.Detach();
}
Example #5
0
/*----------------------------------------------------------------------------------------------
	Open a key, which is the name of a Graphite font, and return a handle to it.

	@param pszFontKey		- the name of the font
	@param pszStyle			- regular, bold, italic, bolditalic;
								ignored here--caller opens string value
	@param at				- access
	@param phkey			- handle to return
----------------------------------------------------------------------------------------------*/
bool GrUtil::OpenFontKey(const utf16 * pszFontKey, const utf16 * pszStyle,
		AccessType at, HKEY * phkey)
{
	AssertPsz((const wchar_t*)pszFontKey);
	AssertPsz((const wchar_t*)pszStyle);
	AssertPtr(phkey);

//#ifdef GR_FW
//	StrApp str;
//	str.Format(_T("Software\\SIL\\GraphiteFonts\\%s"), pszFontKey);
//#else
	OLECHAR str[260];
	_stprintf_s(str, _T("Software\\SIL\\GraphiteFonts\\%s"), (wchar_t*)pszFontKey);
//#endif

	if (at == katRead)
		return ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, str, 0, at, phkey) == ERROR_SUCCESS;
	return ::RegCreateKeyEx(HKEY_LOCAL_MACHINE, str, 0, NULL, 0, at, NULL, phkey,
		NULL) == ERROR_SUCCESS;
}
Example #6
0
/*----------------------------------------------------------------------------------------------
	OnHelp shows the help page for the dialog (if there is one).
----------------------------------------------------------------------------------------------*/
bool RnAnthroListDlg::OnHelp()
{
	AssertPsz(m_pszHelpUrl);
	if (m_strHelpFilename.Length())
	{
		StrAppBufPath strbpHelp;
		strbpHelp.Format(_T("%s::/%s"), m_strHelpFilename.Chars(), m_pszHelpUrl);
		HtmlHelp(::GetDesktopWindow(), strbpHelp.Chars(), HH_DISPLAY_TOPIC, NULL);
		return true;
	}
	return false;
}
Example #7
0
/*----------------------------------------------------------------------------------------------
	Return the file name (including path) of the given Graphite font.

	@param pszFontKey			- name of font
	@param strStyle				- regular, bold, italic, bolditalic
	@param strRetFile			- file name to return
----------------------------------------------------------------------------------------------*/
bool GrUtil::GetFontFile(const utf16 * pszFontKey, const utf16 * pszStyle,
	std::wstring & strRetFile)
{
	AssertPsz((const wchar_t*)pszFontKey);
	AssertPsz((const wchar_t*)pszStyle);

	RegKey hkey;
	if (OpenFontKey(pszFontKey, pszStyle, katRead, &hkey))
	{
		OLECHAR rgch[MAX_PATH];
		DWORD cb = isizeof(rgch);
		DWORD dwT;
		if (::RegQueryValueEx(hkey, (LPCWSTR)pszStyle, NULL, &dwT, (byte *)rgch, &cb) == ERROR_SUCCESS)
		{
			Assert(dwT == REG_SZ);
			strRetFile = rgch;
			return true;
		}
	}
	return false;
}
Example #8
0
UniConvert::ParseCommandLine(char * pszCmdLine)
{
	AssertPsz(pszCmdLine);
	char * prgchPos = strtok(pszCmdLine, kpszWhiteSpace);

	// Set default error log
	strcpy(m_szFiles[kfoErrorLog], "UniConvert.log");

	while (prgchPos)
	{
		if (*prgchPos == '-')
		{
			char ch = *(++prgchPos);
			prgchPos = strtok(NULL, kpszWhiteSpace);
			switch (ch)
			{
			case 'c':
				strncpy(m_szFiles[kfoControlFile], prgchPos, MAX_PATH);
				break;

			case 'e':
				strncpy(m_szFiles[kfoErrorLog], prgchPos, MAX_PATH);
				break;

			case 'o':
				strncpy(m_szFiles[kfoOutputFile], prgchPos, MAX_PATH);
				break;

			case 's':
				m_fSilent = true;
				continue;

			default:
				{
					char szMessage[] =
						 "Usage: UniConvert -c control.txt [-e error.txt] -o output.txt input.txt\n\n"
						 "   -c\tGives a control file that specifies input and output formats and\n"
						 "\tcontains a list of encodings with corresponding mapping files.\n"
						 "   -e\tOptionally specifies a file for error reports during conversion.\n"
						 "\tIt defaults to UniConvert.log.\n"
						 "   -o\tSpecifies the output file.\n";
					MessageBox(NULL, szMessage, "Unicovert", MB_OK | MB_ICONINFORMATION);
					ExitProcess(0);
				}
			}
		}
		else
		{
			strncpy(m_szFiles[kfoInputFile], prgchPos, MAX_PATH);
		}
		prgchPos = strtok(NULL, kpszWhiteSpace);
	}
}
Example #9
0
/*----------------------------------------------------------------------------------------------
	WinMain for an exe server.
----------------------------------------------------------------------------------------------*/
int ModuleEntry::WinMain(HINSTANCE hinst, HINSTANCE hinstPrev, LPSTR pszCmdLine,
	int nShowCmd)
{
	AssertPsz(pszCmdLine);
	Assert(!hinstPrev);

	// Initialize COM
	HRESULT hr = OleInitialize(NULL);
	s_qdobjClipboard.Clear();

	if (FAILED(hr))
	{
		WarnHr(hr);
		// REVIEW DarrellZ: Should we alert the user?
		return 0;
	}

	s_hmod = hinst;
	s_tid = ::GetCurrentThreadId();

	int nRet = 0;
	bool fRun = true;

	// Look through the command line to see if the EXE server should be registered or
	// unregistered. If it should, quit the EXE server after performing the appropriate action.
	if (*pszCmdLine == '-' || *pszCmdLine == '/')
	{
		if (_stricmp(pszCmdLine + 1, "UnregServer") == 0)
		{
			hr = ModuleEntry::ModuleUnregisterServer();
			fRun = false;
		}
		else if (_stricmp(pszCmdLine + 1, "RegServer") == 0)
		{
			hr = ModuleEntry::ModuleRegisterServer();
			fRun = false;
		}
		else if (_stricmp(pszCmdLine + 1, "RegRedirect") == 0)
		{
			// Used only during creation of installer:
			OverrideRegistryKeys();
			hr = ModuleEntry::ModuleRegisterServer();
			return true;
		}
	}

	if (fRun)
	{
		hr = ModuleEntry::ModuleProcessAttach();
		WarnHr(hr);

		// NealA: I am working on this for UNICODE support
		// if not removed by 12-2002 please remove these comments
		// StrApp strCmdLine = pszCmdLine;
		nRet = Run(hinst, pszCmdLine, nShowCmd);

		hr = ModuleEntry::ModuleProcessDetach();
		WarnHr(hr);
		// Check for memory leaks in the main program.
		_CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF);
	}
	else
	{
		WarnHr(hr);
	}

	// Uninitialize COM, first shutting down the clipboard.
	if (s_qdobjClipboard.Ptr())
	{
		hr = OleIsCurrentClipboard(s_qdobjClipboard.Ptr());
		WarnHr(hr);
		if (hr == S_OK)
		{
			WarnHr(OleFlushClipboard());
		}
		s_qdobjClipboard.Clear();
	}
	OleUninitialize();

	return nRet;
}
Example #10
0
/*----------------------------------------------------------------------------------------------
	Call in starting up an MFC EXE, passing the command line.
	Returns true if program was invoked just to register server. This means you should quit
	without ever showing your main window.
----------------------------------------------------------------------------------------------*/
bool ModuleEntry::Startup(HINSTANCE hinst, LPSTR pszCmdLine)
{
	AssertPsz(pszCmdLine);

	// Initialize COM
	HRESULT hr = OleInitialize(NULL);
	s_qdobjClipboard.Clear();

	if (FAILED(hr))
	{
		WarnHr(hr);
		// REVIEW DarrellZ (JohnT): Should we alert the user? Probably, the app is going to quit
		return true;
	}

	s_hmod = hinst;
	s_tid = ::GetCurrentThreadId();

	// Look through the command line to see if the EXE server should be registered or
	// unregistered. If it should, quit the EXE server after performing the appropriate action.
	if (*pszCmdLine == '-' || *pszCmdLine == '/')
	{
		if (stricmp(pszCmdLine + 1, "UnregServer") == 0)
		{
			hr = ModuleEntry::ModuleUnregisterServer();
			return true;
		}
		else if (stricmp(pszCmdLine + 1, "RegServer") == 0)
		{
			hr = ModuleEntry::ModuleRegisterServer();
			return true;
		}
		else if (stricmp(pszCmdLine + 1, "RegRedirect") == 0)
		{
			// Used only during creation of installer:
			OverrideRegistryKeys();
			hr = ModuleEntry::ModuleRegisterServer();
			return true;
		}
	}

	ModuleEntry * pme;

	for (pme = s_pmeFirst; pme; pme = pme->m_pobjNext)
	{
		try
		{
			pme->ProcessAttach();
		}
		catch (const Throwable & thr)
		{
			hr = thr.Error();
		}
		catch (...)
		{
			hr = WarnHr(E_FAIL);
		}
		WarnHr(hr);
	}
	return false;
}
Example #11
0
DEFINE_THIS_FILE
//:End Ignore

//:>********************************************************************************************
//:>	AfWnd methods.
//:>********************************************************************************************

/*----------------------------------------------------------------------------------------------
	Register this window class.  This is a static method.

	@param pszName The window class name.
	@param grfwcs Window class style flags (CS_HREDRAW, CS_NOCLOSE, ...)
	@param ridCrs Resource ID for the window class cursor, or 0.
	@param ridMenu Resource ID for the window class menu, or 0.
	@param clrBack Background color for the window class.
	@param ridIcon Resource ID for the window class icon, or 0.
	@param ridIconSmall Resource ID for the window class small icon, or 0.
----------------------------------------------------------------------------------------------*/
void AfWnd::RegisterClass(Pcsz pszName, int grfwcs, int ridCrs, int ridMenu, int clrBack,
	int ridIcon, int ridIconSmall)
{
	AssertPsz(pszName);
	Assert(!(ridCrs & 0xFFFF0000));
	Assert(!(ridMenu & 0xFFFF0000));
	Assert(clrBack == -1 || !(clrBack & 0xFFFF0000));
	Assert(!(ridIcon & 0xFFFF0000));
	Assert(!(ridIconSmall & 0xFFFF0000));

	WNDCLASSEX wcx;
	HINSTANCE hinst = ModuleEntry::GetModuleHandle();

	ClearItems(&wcx, 1);
	wcx.cbSize = isizeof(wcx);
	wcx.style = grfwcs;
	wcx.lpfnWndProc = &AfWnd::WndProc;
	wcx.cbClsExtra = 0;

	// REVIEW ShonK: For dialogs this needs to be DLGWINDOWEXTRA. Will we ever register
	// dialog classes? Probably not.
	wcx.cbWndExtra = 0;

	wcx.hInstance = hinst;

	// REVIEW ShonK: Determine whether to pass NULL or hinst in LoadIcon calls.
	wcx.hIcon = ridIcon ? ::LoadIcon(hinst, MAKEINTRESOURCE(ridIcon)) : NULL;
	wcx.hCursor = ridCrs ? ::LoadCursor(NULL, MAKEINTRESOURCE(ridCrs)) : NULL;
	// REVIEW ShonK: Do we not want to disallow a brush to be passed in clrBack?
	// hbrBackground in WNDCLASSEX allows a brush if it is not one a fixed number of
	// system colors. For context help we want COLOR_INFOBK which is not listed as
	// one of the valid colors. However, this along with the assert above, fails if
	// we try to pass a brush with COLOR_INFOBK, although this should be acceptable to
	// WNDCLASSEX. It ends up that we can pass COLOR_INFOBK to this method directly, and
	// it works OK. Will any color work using this approach, or should we allow a brush
	// to be consistent with WNDCLASSEX?
	// wcx.hbrBackground = (uint)clrBack < (uint)30 ? (HBRUSH)(clrBack + 1) : (HBRUSH)clrBack;
	wcx.hbrBackground = clrBack >= 0 ? (HBRUSH)(clrBack + 1) : NULL;
	wcx.lpszMenuName = MAKEINTRESOURCE(ridMenu);
	wcx.lpszClassName = pszName;
	wcx.hIconSm = ridIconSmall ? ::LoadIcon(hinst, MAKEINTRESOURCE(ridIconSmall)) : NULL;

	if (!::RegisterClassEx(&wcx))
	{
		// we try to avoid this, but it can happen with opening/closing multiple projects and
		// multiple dialogs.
		DWORD dw = ::GetLastError();
		if (dw == ERROR_CLASS_ALREADY_EXISTS)
			return;
		AssertMsg(false, "Registering window class failed.");
		ThrowHr(WarnHr(E_UNEXPECTED));
	}
}
Example #12
0
/*----------------------------------------------------------------------------------------------
	This method opens the given file according to the given mode settings.
	NOTE: This now creates a file if it doesn't already exist, but opens it if it does exist,
		  if STGM_READWRITE alone is set.
	NOTE: STGM_SHARE_* flags are ignored on Linux, files are always 'shared'
		@param pszFile Name (or path) of the desired file
		@param grfstgm Combination of flags kfstgmXxxx from enum in FileStrm.h
----------------------------------------------------------------------------------------------*/
void FileStream::Init(LPCOLESTR pszFile, int grfstgm)
{
	/* TODO: To access another file this stream should be closed and another created.
	 */
	AssertPsz(pszFile);
	Assert(*pszFile);
#if WIN32
	Assert(!m_hfile);

	HANDLE hfile = 0;
	DWORD dwDesiredAccess = 0;
	DWORD dwShareMode;
	DWORD dwCreationDisposition = 0;

	// Set the dwShareMode parameter.
	if (grfstgm & kfstgmShareDenyNone)
		dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
	else if (grfstgm & kfstgmShareDenyRead)
		dwShareMode = FILE_SHARE_WRITE;
	else if (grfstgm & kfstgmShareExclusive)
		dwShareMode = 0;
	else
		dwShareMode = FILE_SHARE_READ;

	if (grfstgm & kfstgmReadWrite)
		dwDesiredAccess = GENERIC_READ | GENERIC_WRITE;
	else if (grfstgm & kfstgmWrite)
		dwDesiredAccess = GENERIC_WRITE;
	else
		dwDesiredAccess = GENERIC_READ;

	if (dwDesiredAccess & GENERIC_WRITE)
	{
		if (grfstgm & kfstgmCreate)
			dwCreationDisposition = CREATE_ALWAYS;
		else if (grfstgm & kfstgmReadWrite)
			dwCreationDisposition = OPEN_ALWAYS;	// Allows writing to existing file.
		else
			dwCreationDisposition = CREATE_NEW;
	}
	else
		dwCreationDisposition = OPEN_EXISTING;
	hfile = ::CreateFileW(pszFile, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition,
		FILE_ATTRIBUTE_NORMAL, NULL);
	if (hfile == INVALID_HANDLE_VALUE)
	{
		HRESULT hr = (HRESULT)::GetLastError();
		int stid = ErrorStringId(hr);
		StrUni stuRes(stid);
		StrUni stuMsg;
		stuMsg.Format(L"%s%n%s", stuRes.Chars(), pszFile);
		ThrowHr(hr, stuMsg.Chars());	// Caller should handle. (This is not a COM method).
	}

	m_hfile = hfile;
	m_staPath = pszFile;
	m_grfstgm = grfstgm;  // Store the access mode for the stat method.
#else
	Assert(m_file < 0);

	int file = -1;
	int flags = 0;
	mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;

	//std::cout << kfstgmReadWrite << ", " << kfstgmRead << ", " << kfstgmWrite << ", " << kfstgmCreate << std::endl;
	//std::cout << O_RDWR << ", " << O_RDONLY << ", " << O_WRONLY << ", " << O_CREAT << std::endl;

	if (grfstgm & kfstgmReadWrite) {
		flags |= O_RDWR;
	}
	else if (grfstgm & kfstgmWrite) {
		flags |= O_WRONLY;
	}
	else {
		flags |= O_RDONLY;
	}

	if (grfstgm & kfstgmCreate) {
		flags |= O_CREAT;
	}

	if (grfstgm == kfstgmReadWrite) {
		flags |= O_CREAT;
	}

	if (flags & O_WRONLY | flags & O_RDWR)
	{
		if (grfstgm & kfstgmCreate)
			flags |= O_TRUNC;
		else if (grfstgm & kfstgmReadWrite)
			flags |= O_CREAT;
		else
			flags |= O_CREAT | O_EXCL;
	}

	m_staPath = pszFile;

	file = open(m_staPath, flags, mode);
	if (file < 0) {
		//File open failed, throw error
		ThrowHr(ERROR_OPEN_FAILED);
	}

	m_flags = flags;
	m_file = file;
#endif
}