Ejemplo n.º 1
0
static pascal Boolean NavOpenFilterProc(AEDesc *item, void *info, NavCallBackUserData callBackUD, NavFilterModes filterMode)
{
   OSStatus status;
   Boolean outCanOpenAsMovie;
   Boolean canViewItem = false;

   if (!item->descriptorType == typeFSRef) return false;
   if (((NavFileOrFolderInfo*)info)->isFolder == true) return true;

   FSRef fsRef;
   status = AEGetDescData(item, &fsRef, sizeof(fsRef));
   if (status != noErr) throw PianoGameError(WSTRING(L"Couldn't get item description.  Error code: " << static_cast<int>(status)));

   const static int BufferSize(1024);
   char path_buffer[BufferSize];
   status = FSRefMakePath(&fsRef, (UInt8*)path_buffer, BufferSize);
   if (status != noErr) throw PianoGameError(WSTRING(L"Couldn't get file path.  Error code: " << static_cast<int>(status)));

   std::string path(path_buffer);
   if (path.length() < 5) return false;
   
   std::string path_lower(StringLower<std::string>(path));
   
   bool allowed = false;
   const static std::string allowed1(".mid");
   const static std::string allowed2(".midi");
   allowed = allowed || (path_lower.substr(path_lower.length() - allowed1.length()) == allowed1);
   allowed = allowed || (path_lower.substr(path_lower.length() - allowed2.length()) == allowed2);

   return allowed;
}
Ejemplo n.º 2
0
void TrackSelectionState::Draw(Renderer &renderer) const
{
   Layout::DrawTitle(renderer, L"Choose Tracks To Play");

   Layout::DrawHorizontalRule(renderer, GetStateWidth(), Layout::ScreenMarginY);
   Layout::DrawHorizontalRule(renderer, GetStateWidth(), GetStateHeight() - Layout::ScreenMarginY);

   Layout::DrawButton(renderer, m_continue_button, GetTexture(ButtonPlaySong));
   Layout::DrawButton(renderer, m_back_button, GetTexture(ButtonBackToTitle));

   // Write our page count on the screen
   TextWriter pagination(GetStateWidth()/2, GetStateHeight() - Layout::SmallFontSize - 30, renderer, true, Layout::ButtonFontSize);
   pagination << Text(WSTRING(L"Page " << (m_current_page+1) << L" of " << m_page_count << L" (arrow keys change page)"), Gray);

   TextWriter tooltip(GetStateWidth()/2, GetStateHeight() - Layout::SmallFontSize - 54, renderer, true, Layout::ButtonFontSize);
   tooltip << m_tooltip;

   Tga *buttons = GetTexture(InterfaceButtons);
   Tga *box = GetTexture(TrackPanel);

   // Draw each track tile on the current page
   size_t start = m_current_page * m_tiles_per_page;
   size_t end = std::min( static_cast<size_t>((m_current_page+1) * m_tiles_per_page), m_track_tiles.size() );
   for (size_t i = start; i < end; ++i)
   {
      m_track_tiles[i].Draw(renderer, m_state.midi, buttons, box);
   }
}
Ejemplo n.º 3
0
BOOL CED6AsDecompiler::DecompilerFile(LPWSTR pszAsFileName, LPWSTR pszOutput /* = NULL */)
{
    LONG Status;
    WCHAR szOutput[MAX_PATH];
    CFileDisk file;

    Reset();

    if (!file.Open(pszAsFileName))
        return FALSE;

    m_AsInfo.BufferSize = file.GetSize();
    m_AsInfo.pbAsBuffer = (PBYTE)m_mem.Alloc(m_AsInfo.BufferSize);
    if (m_AsInfo.pbAsBuffer == NULL)
        return FALSE;

    if (!file.Read(m_AsInfo.pbAsBuffer))
        return FALSE;

    Status = DecompilerFile(&m_AsInfo);
    if (Status != ASDECL_ERROR_UNKNOWN_INSTRUCTION)
        AS_IF_FAIL_RETURN(Status);

    if (pszOutput == NULL)
    {
        LPWSTR pszExtension;

        pszExtension = findextw(pszAsFileName);
        if (!StrICompareW(pszExtension, WSTRING(NAME_DEFAULT_EXTENSION)))
            pszExtension += countof(WSTRING(NAME_DEFAULT_EXTENSION)) - 1;

        lstrcpyW(szOutput, pszAsFileName);
        pszExtension = szOutput + (pszExtension - pszAsFileName);
        lstrcpyW(pszExtension, WSTRING(NAME_DEFAULT_EXTENSION));
        pszOutput = szOutput;
    }

    Status = DumpToFile(&m_AsInfo, pszAsFileName, pszOutput);

    return Status;
}
Ejemplo n.º 4
0
void SetConEmuWorkEnvVar(HMODULE hConEmuCD)
{
	wchar_t szPath[MAX_PATH*2] = L"";
	GetCurrentDirectory(countof(szPath), szPath);
	SetEnvironmentVariable(ENV_CONEMUWORKDIR_VAR_W, szPath);

	wchar_t szDrive[MAX_PATH];
	SetEnvironmentVariable(ENV_CONEMUWORKDRIVE_VAR_W, GetDrive(szPath, szDrive, countof(szDrive)));
	GetModuleFileName(hConEmuCD, szPath, countof(szPath));
	SetEnvironmentVariable(ENV_CONEMUDRIVE_VAR_W, GetDrive(szPath, szDrive, countof(szDrive)));

	// Same as gpConEmu->ms_ConEmuBuild
	wchar_t szVer4[8] = L""; lstrcpyn(szVer4, WSTRING(MVV_4a), countof(szVer4));
	msprintf(szDrive, countof(szDrive), L"%02u%02u%02u%s%s",
		(MVV_1%100), MVV_2, MVV_3, szVer4[0]&&szVer4[1]?L"-":L"", szVer4);
	SetEnvironmentVariable(ENV_CONEMU_BUILD_W, szDrive);
}
Ejemplo n.º 5
0
void ExchndlSetup(const char *packageVersion)
{
# if defined(WZ_CC_MINGW)
	wchar_t miniDumpPath[PATH_MAX] = {'\0'};

#ifdef HAVE_BFD
	bfd_init();
#endif /* HAVE_BFD */

	// Install the unhandled exception filter function
	prevExceptionFilter = SetUnhandledExceptionFilter(TopLevelExceptionFilter);

	// Retrieve the current version
	formattedVersionString = strdup(packageVersion);

	// Because of UAC on vista / win7 we use this to write our dumps to (unless we override it via OverrideRPTDirectory())
	// NOTE: CSIDL_PERSONAL =  C:\Users\user name\Documents
	if ( SUCCEEDED( SHGetFolderPathW( NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, miniDumpPath ) ))
	{
		PathAppendW( miniDumpPath, WSTRING(WZ_WRITEDIR));
		PathAppendW( miniDumpPath, L"\\logs" );

		if( !PathFileExistsW( miniDumpPath ) )
		{
			if( ERROR_SUCCESS != SHCreateDirectoryExW( NULL, miniDumpPath, NULL ) )
			{
				wcscpy(miniDumpPath, L"c:\\temp");
			}
		}
	}
	else
	{	// should never fail, but if it does, we fall back to this
		wcscpy(miniDumpPath, L"c:\\temp");
	}

	wcscat(szLogFileName, L"Warzone2100.RPT");
	wcscat(miniDumpPath, L"\\");
	wcscat(miniDumpPath,szLogFileName);
	wcscpy(szLogFileName, miniDumpPath);

	atexit(ExchndlShutdown);
#endif
}
Ejemplo n.º 6
0
CINFILTRATE_EXIT_CODES PrepareHookModule(wchar_t (&szModule)[MAX_PATH+16])
{
	CINFILTRATE_EXIT_CODES iRc = CIR_GeneralError/*-1*/;
	wchar_t szNewPath[MAX_PATH+16] = {}, szAddName[40] = {};
	wchar_t szMinor[8] = L""; lstrcpyn(szMinor, WSTRING(MVV_4a), countof(szMinor));
	INT_PTR nLen = 0;
	bool bAlreadyExists = false;

	// Copy szModule to CSIDL_LOCAL_APPDATA and return new path
	HRESULT hr = SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, 0/*SHGFP_TYPE_CURRENT*/, szNewPath);
	if ((hr != S_OK) || !*szNewPath)
	{
		iRc = CIR_SHGetFolderPath/*-251*/;
		goto wrap;
	}

	_wsprintf(szAddName, SKIPLEN(countof(szAddName))
		L"\\" CEDEFTERMDLLFORMAT /*L"ConEmuHk%s.%02u%02u%02u%s.dll"*/,
		WIN3264TEST(L"",L"64"), MVV_1, MVV_2, MVV_3, szMinor);

	nLen = lstrlen(szNewPath);
	if (szNewPath[nLen-1] != L'\\')
	{
		szNewPath[nLen++] = L'\\'; szNewPath[nLen] = 0;
	}

	if ((nLen + lstrlen(szAddName) + 8) >= countof(szNewPath))
	{
		iRc = CIR_TooLongTempPath/*-252*/;
		goto wrap;
	}

	wcscat_c(szNewPath, L"ConEmu");
	if (!DirectoryExists(szNewPath))
	{
		if (!CreateDirectory(szNewPath, NULL))
		{
			iRc = CIR_CreateTempDirectory/*-253*/;
			goto wrap;
		}
	}

	wcscat_c(szNewPath, szAddName);

	if ((bAlreadyExists = FileExists(szNewPath)) && FileCompare(szNewPath, szModule))
	{
		// OK, file exists and match the required
	}
	else
	{
		if (bAlreadyExists)
		{
			_ASSERTE(FALSE && "Continue to overwrite existing ConEmuHk in AppLocal");

			// Try to delete or rename old version
			if (!DeleteFile(szNewPath))
			{
				//SYSTEMTIME st; GetLocalTime(&st);
				wchar_t szBakPath[MAX_PATH+32]; wcscpy_c(szBakPath, szNewPath);
				wchar_t* pszExt = (wchar_t*)PointToExt(szBakPath);
				msprintf(pszExt, 16, L".%u.dll", GetTickCount());
				DeleteFile(szBakPath);
				MoveFile(szNewPath, szBakPath);
			}
		}

		if (!CopyFile(szModule, szNewPath, FALSE))
		{
			iRc = CIR_CopyHooksFile/*-254*/;
			goto wrap;
		}
	}

	wcscpy_c(szModule, szNewPath);
	iRc = CIR_OK/*0*/;
wrap:
	return iRc;
}
Ejemplo n.º 7
0
bool InitDefTerm()
{
	bool lbRc = true;

	wchar_t szInfo[MAX_PATH*2];
	msprintf(szInfo, countof(szInfo), L"!!! TH32CS_SNAPMODULE, TID=%u, InitDefaultTerm\n", GetCurrentThreadId());
	DebugStr(szInfo); // Don't call DefTermLogString here - gpDefTerm was not initialized yet

	_ASSERTEX(gpDefTerm==NULL);
	gpDefTerm = new CDefTermHk();
	if (!gpDefTerm)
	{
		_ASSERTEX(gpDefTerm!=NULL);
		return false;
	}

	//_ASSERTE(FALSE && "InitDefaultTerm");

	// При обновлении ConEmu может обновиться и ConEmuHk.dll
	// Но в процессы с "DefTerm" грузится копия dll-ки, поэтому
	// после обновления в уже хукнутый процесс загружается
	// вторая "ConEmuHk.YYMMDD.dll", а старую при этом нужно
	// выгрузить. Этим и займемся.
	HMODULE hPrevHooks = NULL;
	_ASSERTEX(gnSelfPID!=0 && ghOurModule!=NULL);
	HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, gnSelfPID);
	if (hSnap != INVALID_HANDLE_VALUE)
	{
		MODULEENTRY32 mi = {sizeof(mi)};
		//wchar_t szOurName[MAX_PATH] = L"";
		//GetModuleFileName(ghOurModule, szOurName, MAX_PATH);
		wchar_t szMinor[8] = L""; lstrcpyn(szMinor, WSTRING(MVV_4a), countof(szMinor));
		wchar_t szAddName[40];
		msprintf(szAddName, countof(szAddName),
			CEDEFTERMDLLFORMAT /*L"ConEmuHk%s.%02u%02u%02u%s.dll"*/,
			WIN3264TEST(L"",L"64"), MVV_1, MVV_2, MVV_3, szMinor);
		//LPCWSTR pszOurName = PointToName(szOurName);
		wchar_t* pszDot = wcschr(szAddName, L'.');
		wchar_t szCheckName[MAX_PATH+1];

		if (pszDot && Module32First(hSnap, &mi))
		{
			pszDot[1] = 0; // Need to check only name, without version number
			int nCurLen = lstrlen(szAddName);
			do {
				if (mi.hModule == ghOurModule)
					continue;
				lstrcpyn(szCheckName, PointToName(mi.szExePath), nCurLen+1);
				if (lstrcmpi(szCheckName, szAddName) == 0)
				{
					msprintf(szInfo, countof(szInfo),
						L"Prevous ConEmuHk module found at address " WIN3264TEST(L"0x%08X",L"0x%X%08X") L": %s",
						WIN3264WSPRINT(mi.hModule), mi.szExePath);
					DefTermLogString(szInfo);

					hPrevHooks = mi.hModule;
					break; // Prev (old version) instance found!
				}
			} while (Module32Next(hSnap, &mi));
		}

		CloseHandle(hSnap);
	}

	// Old library was found, unload it before continue
	if (hPrevHooks)
	{
		DefTermLogString(L"Trying to unload previous ConEmuHk module");
		if (!FreeLibrary(hPrevHooks))
		{
			lbRc = false;
			gpDefTerm->DisplayLastError(L"Unloading failed", GetLastError());
		}
		else
		{
			DefTermLogString(L"Unloading succeeded");
		}
	}

	// For Visual Studio check all spawned processes (children of gnSelfPID), find *.vshost.exe
	if (gbIsVStudio)
	{
		//_ASSERTEX(FALSE && "Continue to find existing *.vshost.exe");
		HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
		if (hSnap != INVALID_HANDLE_VALUE)
		{
			PROCESSENTRY32 pe = {sizeof(pe)};
			if (Process32First(hSnap, &pe)) do
			{
				if (pe.th32ParentProcessID == gnSelfPID)
				{
					if (IsVsNetHostExe(pe.szExeFile)) // *.vshost.exe
					{
						// Found! Hook it!
						DefTermLogString(L"Child VsNetHost found, hooking");
						gpDefTerm->StartDefTermHooker(pe.th32ProcessID);
						break;
					}
				}
			} while (Process32Next(hSnap, &pe));
			CloseHandle(hSnap);
		}
	}

	DefTermLogString(L"InitDefaultTerm finished, calling StartDefTerm");

	gpDefTerm->StartDefTerm();

	return lbRc;
}
Ejemplo n.º 8
0
int MyAssertProc(const wchar_t* pszFile, int nLine, const wchar_t* pszTest, bool abNoPipe)
{
	#if defined(AssertHooksUnlocker)
	AssertHooksUnlocker;
	#endif

	#ifdef _DEBUG
	static bool lbSkip = false;
	if (lbSkip)
		return 1;
	#endif

	MyAssertDumpToFile(pszFile, nLine, pszTest);

	HANDLE hHeap = GetProcessHeap();
	MyAssertInfo* pa = (MyAssertInfo*)HeapAlloc(hHeap, HEAP_ZERO_MEMORY, sizeof(MyAssertInfo));
	if (!pa)
		return -1;
	wchar_t *szExeName = (wchar_t*)HeapAlloc(hHeap, HEAP_ZERO_MEMORY, (MAX_PATH+1)*sizeof(wchar_t));
	if (szExeName && !GetModuleFileNameW(NULL, szExeName, MAX_PATH+1)) szExeName[0] = 0;
	pa->bNoPipe = abNoPipe;
	msprintf(pa->szTitle, countof(pa->szTitle), L"CEAssert PID=%u TID=%u", GetCurrentProcessId(), GetCurrentThreadId());
	wchar_t szVer4[2] = WSTRING(MVV_4a);
	msprintf(pa->szDebugInfo, countof(pa->szDebugInfo), L"Assertion in %s [%02u%02u%02u%s]\n%s\n\n%s: %i\n\nPress 'Retry' to trap.",
	                szExeName ? szExeName : L"<HeapAllocFailed>",
					MVV_1, MVV_2, MVV_3, szVer4,
					pszTest ? pszTest : L"", pszFile, nLine);
	DWORD dwCode = 0;

	if (gAllowAssertThread == am_Thread)
	{
		DWORD dwTID;
		HANDLE hThread = CreateThread(NULL, 0, MyAssertThread, pa, 0, &dwTID);

		if (hThread == NULL)
		{
			dwCode = IDRETRY;
			goto wrap;
		}

		WaitForSingleObject(hThread, INFINITE);
		GetExitCodeThread(hThread, &dwCode);
		CloseHandle(hThread);
		goto wrap;
	}
	
#ifdef ASSERT_PIPE_ALLOWED
#ifdef _DEBUG
	if (!abNoPipe && (gAllowAssertThread == am_Pipe))
	{
		HWND hConWnd = GetConEmuHWND(2);
		HWND hGuiWnd = ghConEmuWnd;

		// -- искать - нельзя. Если мы НЕ в ConEmu - нельзя стучаться в другие копии!!!
		//#ifndef CONEMU_MINIMAL
		//if (hGuiWnd == NULL)
		//{
		//	hGuiWnd = FindWindowEx(NULL, NULL, VirtualConsoleClassMain, NULL);
		//}
		//#endif

		if (hGuiWnd && gnInMyAssertTrap <= 0)
		{
			InterlockedIncrement(&gnInMyAssertTrap);
			InterlockedIncrement(&gnInMyAssertPipe);
			gnInMyAssertThread = GetCurrentThreadId();
			ResetEvent(ghInMyAssertTrap);
			
			dwCode = GuiMessageBox(abNoPipe ? NULL : hGuiWnd, pa->szDebugInfo, pa->szTitle, MB_SETFOREGROUND|MB_SYSTEMMODAL|MB_RETRYCANCEL);
			InterlockedDecrement(&gnInMyAssertTrap);
			InterlockedDecrement(&gnInMyAssertPipe);
			SetEvent(ghInMyAssertTrap);
			gnInMyAssertThread = 0;
			goto wrap;
		}
	}

	while (gnInMyAssertPipe>0 && (gnInMyAssertThread != GetCurrentThreadId()))
	{
		Sleep(250);
	}
#endif
#endif

	// В консольных приложениях попытка запустить CreateThread(MyAssertThread) может зависать
	dwCode = MyAssertThread(pa);

wrap:
	if (pa)
		HeapFree(hHeap, 0, pa);
	if (szExeName)
		HeapFree(hHeap, 0, szExeName);
	return (dwCode == IDRETRY) ? -1 : 1;
}
Ejemplo n.º 9
0
LONG CED6AsDecompiler::CreateDefinition(LPWSTR pszAsFile, LPSTR Buffer)
{
    WCHAR szPath[MAX_PATH];
    LPWSTR pszFileName;

    lstrcpyW(szPath, pszAsFile);
    pszFileName = findnamew(szPath);
    if (pszFileName != szPath)
        *pszFileName = 0;

    lstrcpyW(pszFileName, WSTRING(NAME_DEFINITION_FILE));
    if (IsPathExistsW(szPath))
        return ASDECL_ERROR_SUCCESS;

    LONG                        Status;
    CFileDisk                   file;
    ED6_AS_INSTRUCTION_MAP     *pMap;
    ED6_INSTRUCTION_PARAM_DESC *pDesc;
    CHAR szParamLengthTable[] = { 'b', 's', 't', 'i' };

    if (!file.Create(szPath))
        return ASDECL_ERROR_CREATE_FILE;

    WriteScr(
        "@_DEFI 4\n"
        "@_DEFF 4\n"
        "@_IGNORECASE\n"
        "\n"
    );

    pMap = g_InstructionMap;
    for (ULONG Count = countof(g_InstructionMap); Count; ++pMap, --Count)
    {
        if (pMap->pszName != NULL)
        {
            WriteScr("@%s [%02X]\n", pMap->pszName, pMap->Instruction);
        }
        else
        {
//            WriteScr("@%s%X [%02X]\n", NAME_DEFAULT_INSTRUCTION_PREFIX, pMap->Instruction, pMap->Instruction);
        }

        pDesc = pMap->pParamDesc;
        for (ULONG DescCount = pMap->DescCount; DescCount; pDesc++, --DescCount)
        {
            if (pDesc->pszDescription == NULL)
                continue;
#if 0
            if (pDesc->Length > 4)
            {
                PBYTE  pbBuffer;
                WriteScr("    @%s [", pDesc->pszDescription);
                pbBuffer = (PBYTE)&pDesc->Value;
                for (ULONG Length = pDesc->Length; ; )
                {
                    WriteScr("%02X", *pbBuffer++);
                    if (--Length == 0)
                        break;
                    WriteScr(" ");
                }
                WriteScr("]\n");
            }
            else
#endif
            {
                WriteScr(
                    "    @%s 0x%X:%c\n",
                    pDesc->pszDescription,
                    pDesc->Value,
                    szParamLengthTable[pDesc->Length - 1]
                );
            }
        }
    }

    WriteScr("\n");
    pMap = g_InstructionMap;
    for (ULONG Count = countof(g_InstructionMap); Count; ++pMap, --Count)
    {
        WriteScr("@%s%X [%02X]\n", NAME_DEFAULT_INSTRUCTION_PREFIX, pMap->Instruction, pMap->Instruction);
    }

    return 0;
}
Ejemplo n.º 10
0
void ExchndlSetup(const char *packageVersion)
{
# if defined(WZ_CC_MINGW)
	wchar_t miniDumpPath[PATH_MAX] = {'\0'};
	DWORD dwRetVal = 0;
#ifdef HAVE_BFD
	bfd_init();
#endif /* HAVE_BFD */

	// Install the unhandled exception filter function
	prevExceptionFilter = SetUnhandledExceptionFilter(TopLevelExceptionFilter);

	// Retrieve the current version
	formattedVersionString = strdup(packageVersion);
#ifndef WZ_PORTABLE
	// Because of UAC on vista / win7 we use this to write our dumps to (unless we override it via OverrideRPTDirectory())
	// NOTE: CSIDL_PERSONAL =  C:\Users\user name\Documents
	if ( SUCCEEDED( SHGetFolderPathW( NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, miniDumpPath ) ))
	{
		PathAppendW( miniDumpPath, WSTRING(WZ_WRITEDIR));
		PathAppendW( miniDumpPath, L"\\logs" );

		if( !PathFileExistsW( miniDumpPath ) )
		{
			if( ERROR_SUCCESS != SHCreateDirectoryExW( NULL, miniDumpPath, NULL ) )
			{
				//last attempt to get a path
				dwRetVal = GetTempPathW(PATH_MAX, miniDumpPath);
				if (dwRetVal > MAX_PATH || (dwRetVal == 0))
				{
					MessageBox((HWND)MB_ICONEXCLAMATION, "Could not created a temporary directory!\nProgram will now exit." , _T("Error"), MB_OK);
					exit(1);
				}
			}
		}
	}
#else
	// we use where they installed it on, since this is a removeable drive (most likely), we will use where the program is located in.
	if (dwRetVal = GetCurrentDirectoryW(MAX_PATH, miniDumpPath))
	{
		if(dwRetVal > MAX_PATH)
		{
			MessageBox((HWND)MB_ICONEXCLAMATION, "Buffer exceeds maximum path to create directory.  Exiting.", _T("Error"), MB_OK);
			exit(1);
		}
		PathAppendW( miniDumpPath, WSTRING(WZ_WRITEDIR));
		PathAppendW( miniDumpPath, L"\\logs" );
	}
#endif
	else
	{	// should never fail, but if it does, we fall back to this
		dwRetVal = GetTempPathW(PATH_MAX, miniDumpPath);
		if (dwRetVal > MAX_PATH || (dwRetVal == 0))
		{
			MessageBox((HWND)MB_ICONEXCLAMATION, "Could not created a temporary directory!\nProgram will now exit." , _T("Error!"), MB_OK);
			exit(1);
		}
	}

	wcscat(szLogFileName, L"Warzone2100.RPT");
	wcscat(miniDumpPath, L"\\");
	wcscat(miniDumpPath,szLogFileName);
	wcscpy(szLogFileName, miniDumpPath);

	atexit(ExchndlShutdown);
#endif
}
Ejemplo n.º 11
0
char *nl_langinfo_l(nl_item item, locale_t locale) {
  switch (item) {
    case CODESET:
      return (char *)locale->ctype->codeset;
#define STRING(item, category, field) \
  case item:                          \
    return (char *)COMPILE_STRING(locale, category, field)
#define WSTRING(item, category, field) \
  case item:                           \
    return (char *)COMPILE_WSTRING(locale, category, field)
      WSTRING(D_T_FMT, time, d_t_fmt);
      WSTRING(D_FMT, time, d_fmt);
      WSTRING(T_FMT, time, t_fmt);
      WSTRING(T_FMT_AMPM, time, t_fmt_ampm);
      WSTRING(AM_STR, time, am_str);
      WSTRING(PM_STR, time, pm_str);
      WSTRING(DAY_1, time, day[0]);
      WSTRING(DAY_2, time, day[1]);
      WSTRING(DAY_3, time, day[2]);
      WSTRING(DAY_4, time, day[3]);
      WSTRING(DAY_5, time, day[4]);
      WSTRING(DAY_6, time, day[5]);
      WSTRING(DAY_7, time, day[6]);
      WSTRING(ABDAY_1, time, abday[0]);
      WSTRING(ABDAY_2, time, abday[1]);
      WSTRING(ABDAY_3, time, abday[2]);
      WSTRING(ABDAY_4, time, abday[3]);
      WSTRING(ABDAY_5, time, abday[4]);
      WSTRING(ABDAY_6, time, abday[5]);
      WSTRING(ABDAY_7, time, abday[6]);
      WSTRING(MON_1, time, mon[0]);
      WSTRING(MON_2, time, mon[1]);
      WSTRING(MON_3, time, mon[2]);
      WSTRING(MON_4, time, mon[3]);
      WSTRING(MON_5, time, mon[4]);
      WSTRING(MON_6, time, mon[5]);
      WSTRING(MON_7, time, mon[6]);
      WSTRING(MON_8, time, mon[7]);
      WSTRING(MON_9, time, mon[8]);
      WSTRING(MON_10, time, mon[9]);
      WSTRING(MON_11, time, mon[10]);
      WSTRING(MON_12, time, mon[11]);
      WSTRING(ABMON_1, time, abmon[0]);
      WSTRING(ABMON_2, time, abmon[1]);
      WSTRING(ABMON_3, time, abmon[2]);
      WSTRING(ABMON_4, time, abmon[3]);
      WSTRING(ABMON_5, time, abmon[4]);
      WSTRING(ABMON_6, time, abmon[5]);
      WSTRING(ABMON_7, time, abmon[6]);
      WSTRING(ABMON_8, time, abmon[7]);
      WSTRING(ABMON_9, time, abmon[8]);
      WSTRING(ABMON_10, time, abmon[9]);
      WSTRING(ABMON_11, time, abmon[10]);
      WSTRING(ABMON_12, time, abmon[11]);
      WSTRING(ERA, time, era);
      WSTRING(ERA_D_FMT, time, era_d_fmt);
      WSTRING(ERA_D_T_FMT, time, era_d_t_fmt);
      WSTRING(ERA_T_FMT, time, era_t_fmt);
      WSTRING(ALT_DIGITS, time, alt_digits);
      WSTRING(RADIXCHAR, numeric, decimal_point);
      WSTRING(THOUSEP, numeric, thousands_sep);
      STRING(YESEXPR, messages, yesexpr);
      STRING(NOEXPR, messages, noexpr);
#undef STRING
#undef WSTRING
    case CRNCYSTR: {
      // CRNCYSTR should return the currency symbol used by the locale,
      // preceded by a character indicating where the currency symbol
      // should be placed.
      //
      // Instead of storing it separately, we can derive it from several
      // existing properties.

      struct lc_compiled *compiled = __locale_get_compiled(locale);
      if (compiled == NULL)
        return NULL;

      // Return an already existing copy if available.
      char *old_crncystr = atomic_load(&compiled->crncystr);
      if (old_crncystr != NULL)
        return (char *)old_crncystr;

      // String only makes sense if there is a currency symbol and its
      // placement is uniform.
      const struct lc_monetary *monetary = locale->monetary;
      const wchar_t *currency_symbol = monetary->currency_symbol;
      if (currency_symbol == NULL || *currency_symbol == '\0' ||
          monetary->p_cs_precedes != monetary->n_cs_precedes)
        return (char *)"";

      // Determine the character preceding the currency symbol,
      // indicating the position.
      char precedes = monetary->p_cs_precedes;
      char position;
      if (precedes == CHAR_MAX) {
        if (wcscmp(currency_symbol, monetary->mon_decimal_point) != 0)
          return (char *)"";
        position = '.';
      } else {
        position = precedes ? '-' : '+';
      }

      // Generate new string.
      char *new_crncystr;
      if (asprintf_l(&new_crncystr, locale, "%c%ls", position,
                     currency_symbol) == -1)
        return (char *)"";

      // Store the new copy and return it.
      if (!atomic_compare_exchange_strong(&compiled->crncystr, &old_crncystr,
                                          new_crncystr)) {
        // Race condition. Another thread created a copy at the same time.
        free(new_crncystr);
        return old_crncystr;
      }
      return new_crncystr;
    }
    default:
      return (char *)"";
  }
}
Ejemplo n.º 12
0
TextWriter::TextWriter(int in_x, int in_y, Renderer &in_renderer, bool in_centered, int in_size, std::wstring fontname) :
x(in_x), y(in_y), size(in_size), original_x(0), last_line_height(0), centered(in_centered), renderer(in_renderer)
{
   x += renderer.m_xoffset;
   original_x = x;

   y += renderer.m_yoffset;

#ifdef WIN32

   Context c = renderer.m_context;
   point_size = MulDiv(size, GetDeviceCaps(c, LOGPIXELSY), 72);

   HFONT font = 0;
   if (font_size_lookup[in_size] == 0)
   {
      // Set up the LOGFONT structure
      LOGFONT logical_font;
      logical_font.lfHeight = get_point_size();
      logical_font.lfWidth = 0;
      logical_font.lfEscapement = 0;
      logical_font.lfOrientation = 0;
      logical_font.lfWeight = FW_NORMAL;
      logical_font.lfItalic = false;
      logical_font.lfUnderline = false;
      logical_font.lfStrikeOut = false;
      logical_font.lfCharSet = ANSI_CHARSET;
      logical_font.lfOutPrecision = OUT_DEFAULT_PRECIS;
      logical_font.lfClipPrecision = CLIP_DEFAULT_PRECIS;
      logical_font.lfQuality = PROOF_QUALITY;
      logical_font.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
      lstrcpy(logical_font.lfFaceName, fontname.c_str()); 

      font = CreateFontIndirect(&logical_font);

      HFONT previous_font = (HFONT)SelectObject(c, font);

      wglUseFontBitmaps(c, 0, 128, next_call_list_start);
      font_size_lookup[in_size] = next_call_list_start;
      font_handle_lookup[in_size] = font;
      next_call_list_start += 130;

      SelectObject(c, previous_font);
   }

#else

   // TODO: is this sufficient?
   point_size = size;

   if (font_size_lookup[size] == 0)
   {
      int list_start = glGenLists(128);

      // MACNOTE: Force Trebuchet MS.  It's what we mostly use anyway, but
      // I want to be sure they have it.
      const CFStringRef font_name = CFSTR("Trebuchet MS");
      
      ATSFontFamilyRef font = ATSFontFamilyFindFromName(font_name, kATSOptionFlagsDefault);
      if (!font) throw PianoGameError(WSTRING(L"Couldn't get ATSFontFamilyRef for font '" << WideFromMacString(font_name) << L"'."));         
      
      AGLContext context = aglGetCurrentContext();
      if (!context) throw PianoGameError(L"Couldn't retrieve OpenGL context while creating font.");         
      
      GLboolean ret = aglUseFont(context, font, normal, size, 0, 128, list_start);
      if (ret == GL_FALSE) throw PianoGameError(WSTRING(L"aglUseFont() call failed with error code: " << aglGetError()));
      
      font_size_lookup[size] = list_start;


      // Create the ATSU style object that we'll use for calculating text extents and store it for later.
      ATSUStyle style;

      OSStatus status = ATSUCreateStyle(&style);
      if (status != noErr) throw PianoGameError(WSTRING(L"Couldn't create ATSU style.  Error code: " << static_cast<int>(status)));

      Fixed fixed_size = Long2Fix(size);
      
      ATSUAttributeTag tags[] = { kATSUSizeTag };
      ByteCount sizes[] = { sizeof(Fixed) };
      ATSUAttributeValuePtr values[] = { &fixed_size };
      status = ATSUSetAttributes(style, sizeof(sizes) / sizeof(ByteCount), tags, sizes, values);
      if (status != noErr) throw PianoGameError(WSTRING(L"Couldn't set ATSU style attributes.  Error code: " << static_cast<int>(status)));
      
      atsu_style_lookup[size] = style;      
   }

#endif

}
Ejemplo n.º 13
0
void Text::calculate_position_and_advance_cursor(TextWriter &tw, int *out_x, int *out_y) const
{
#ifdef WIN32

   const long options = DT_LEFT | DT_NOPREFIX;

   Context c = tw.renderer.m_context;
   int previous_map_mode = SetMapMode(c, MM_TEXT);

   HFONT font = font_handle_lookup[tw.size];

   // Create the font we want to use, and swap it out with
   // whatever is currently in there, along with our color
   HFONT previous_font = (HFONT)SelectObject(c, font);

   // Call DrawText to find out how large our text is
   RECT drawing_rect = { tw.x, tw.y, 0, 0 };
   tw.last_line_height = DrawText(c, m_text.c_str(), int(m_text.length()), &drawing_rect, options | DT_CALCRECT);

   // Return the hdc settings to their previous setting
   SelectObject(c, previous_font);
   SetMapMode(c, previous_map_mode);

#else

   // Convert passed-in text to Unicode
   CFStringRef cftext = MacStringFromWide(m_text, true).get();
   CFDataRef unitext = CFStringCreateExternalRepresentation(kCFAllocatorDefault, cftext, kCFStringEncodingUnicode, 0);
   if (!unitext) throw PianoGameError(WSTRING(L"Couldn't convert string to unicode: '" << m_text << L"'"));
   CFRelease(cftext);

   // Create an ATSU layout
   ATSUTextLayout layout;
   const UniCharCount run_length = kATSUToTextEnd;
   OSStatus status = ATSUCreateTextLayoutWithTextPtr((ConstUniCharArrayPtr)CFDataGetBytePtr(unitext), kATSUFromTextBeginning, kATSUToTextEnd, CFDataGetLength(unitext) / 2, 1, &run_length, &atsu_style_lookup[tw.size], &layout);
   if (status != noErr) throw PianoGameError(WSTRING(L"Couldn't create ATSU text layout for string: '" << m_text << L"', Error code: " << static_cast<int>(status)));

   // Measure the size of the resulting text
   Rect drawing_rect = { 0, 0, 0, 0 };
   
   ATSUTextMeasurement before = 0;
   ATSUTextMeasurement after = 0;
   ATSUTextMeasurement ascent = 0;
   ATSUTextMeasurement descent = 0;
   
   status = ATSUGetUnjustifiedBounds(layout, 0, kATSUToTextEnd, &before, &after, &ascent, &descent);
   if (status != noErr) throw PianoGameError(WSTRING(L"Couldn't get unjustified bounds for text layout for string: '" << m_text << L"', Error code: " << static_cast<int>(status)));

   // NOTE: the +1 here is completely arbitrary and seemed to place the text better.
   // It may just be a difference between the Windows and Mac text placement systems.
   drawing_rect.top += tw.y + 1;
   drawing_rect.left += tw.x + FixRound(before);
   drawing_rect.right += tw.x + FixRound(after);

   // Not used.
   drawing_rect.bottom = 0;

   // Clean-up
	ATSUDisposeTextLayout(layout);
   CFRelease(unitext);

#endif

   // Update the text-writer with post-draw coordinates
   if (tw.centered) drawing_rect.left -= (drawing_rect.right - drawing_rect.left) / 2;
   if (!tw.centered) tw.x += drawing_rect.right - drawing_rect.left;

   // Tell the draw function where to put the text
   *out_x = drawing_rect.left;
   *out_y = drawing_rect.top;
}
Ejemplo n.º 14
0
// !SMT!-UI
void UserInfoSimple::addSummaryMenu()
{
	// TODO: move obtain information about the user in the UserManager
	if (!getUser())
		return;
		
	CWaitCursor l_cursor_wait; //-V808
	
	UserInfoGuiTraits::userSummaryMenu.InsertSeparatorLast(getUser()->getLastNickT());
	
	ClientManager::UserParams l_params;
	if (ClientManager::getUserParams(getUser(), l_params))
	{
		tstring userInfo = TSTRING(SLOTS) + _T(": ") + Util::toStringW(l_params.m_slots) + _T(", ") + TSTRING(SHARED) + _T(": ") + Util::formatBytesW(l_params.m_bytesShared);
		
		if (l_params.m_limit)
		{
			userInfo += _T(", ") + TSTRING(SPEED_LIMIT) + _T(": ") + Util::formatBytesW(l_params.m_limit) + _T('/') + WSTRING(SEC);
		}
		
		UserInfoGuiTraits::userSummaryMenu.AppendMenu(MF_STRING | MF_DISABLED, IDC_NONE, userInfo.c_str());
		
		const time_t slot = UploadManager::getReservedSlotTime(getUser());
		if (slot)
		{
			const tstring note = TSTRING(EXTRA_SLOT_TIMEOUT) + _T(": ") + Util::formatSecondsW((slot - GET_TICK()) / 1000);
			UserInfoGuiTraits::userSummaryMenu.AppendMenu(MF_STRING | MF_DISABLED, IDC_NONE, note.c_str());
		}
		
		if (!l_params.m_ip.empty())
		{
			UserInfoGuiTraits::userSummaryMenu.AppendMenu(MF_STRING | MF_DISABLED, IDC_NONE, l_params.getTagIP().c_str());
			
			const Util::CustomNetworkIndex l_location = Util::getIpCountry(l_params.m_ip, true); // Не обращаемся в базу данных
			const tstring loc = TSTRING(COUNTRY) + _T(": ") + l_location.getCountry() + _T(", ") + l_location.getDescription();
			UserInfoGuiTraits::userSummaryMenu.AppendMenu(MF_STRING | MF_DISABLED, IDC_NONE, loc.c_str());
			
			HubFrame::addDupeUsersToSummaryMenu(l_params);
		}
		else
		{
			UserInfoGuiTraits::userSummaryMenu.AppendMenu(MF_STRING | MF_DISABLED, IDC_NONE, l_params.getTagIP().c_str());
			HubFrame::addDupeUsersToSummaryMenu(l_params);
		}
	}
	
	//UserInfoGuiTraits::userSummaryMenu.AppendMenu(MF_SEPARATOR);
	
	bool caption = false;
	{
		UploadManager::LockInstanceQueue lockedInstance;
		const auto& users = lockedInstance->getUploadQueueL();
		for (auto uit = users.cbegin(); uit != users.cend(); ++uit)
		{
			if (uit->getUser() == getUser())
			{
				uint8_t l_count_menu = 0; // [+]PPA
				for (auto i = uit->m_waiting_files.cbegin(); i != uit->m_waiting_files.cend(); ++i)
				{
					if (!caption)
					{
						UserInfoGuiTraits::userSummaryMenu.InsertSeparatorLast(TSTRING(USER_WAIT_MENU));
						caption = true;
					}
					const tstring note =
					    _T('[') +
					    Util::toStringW((double)(*i)->getPos() * 100.0 / (double)(*i)->getSize()) +
					    _T("% ") +
					    Util::formatSecondsW(GET_TIME() - (*i)->getTime()) +
					    _T("]\t") +
					    Text::toT((*i)->getFile());
					UserInfoGuiTraits::userSummaryMenu.AppendMenu(MF_STRING | MF_DISABLED, IDC_NONE, note.c_str());
					if (l_count_menu++ == 10) //[+]PPA
					{
						UserInfoGuiTraits::userSummaryMenu.AppendMenu(MF_STRING | MF_DISABLED, IDC_NONE, _T("..."));
						break;
					}
				}
			}
		}
	}
	caption = false;
	{
		uint8_t l_count_menu = 0; // [+]PPA
		RLock(*QueueItem::g_cs);
		QueueManager::LockFileQueueShared l_fileQueue;
		const auto& downloads = l_fileQueue.getQueueL();
		for (auto j = downloads.cbegin(); j != downloads.cend(); ++j)
		{
			const QueueItemPtr& aQI = j->second;
			const bool src = aQI->isSourceL(getUser());
			bool badsrc = false;
			if (!src)
			{
				badsrc = aQI->isBadSourceL(getUser());
			}
			if (src || badsrc)
			{
				if (!caption)
				{
					UserInfoGuiTraits::userSummaryMenu.InsertSeparatorLast(TSTRING(NEED_USER_FILES_MENU));
					caption = true;
				}
				tstring note = Text::toT(aQI->getTarget());
				if (aQI->getSize() > 0)
				{
					note += tstring(_T("\t(")) + Util::toStringW((double)aQI->getDownloadedBytes() * 100.0 / (double)aQI->getSize()) + tstring(_T("%)"));
				}
				const UINT flags = MF_STRING | MF_DISABLED | (badsrc ? MF_GRAYED : 0);
				UserInfoGuiTraits::userSummaryMenu.AppendMenu(flags, IDC_NONE, note.c_str());
				if (l_count_menu++ == 10) //[+]PPA
				{
					UserInfoGuiTraits::userSummaryMenu.AppendMenu(MF_STRING | MF_DISABLED, IDC_NONE, _T("..."));
					break;
				}
			}
		}
	}
}
Ejemplo n.º 15
0
LRESULT StatsFrame::onPaint(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
	if (GetUpdateRect(NULL))
	{
		CPaintDC dc(m_hWnd);
		CRect rc(dc.m_ps.rcPaint);
//[-]PPA        dcdebug("Update: %d, %d, %d, %d\n", rc.left, rc.top, rc.right, rc.bottom);

		dc.SelectBrush(m_backgr);
		dc.BitBlt(rc.left, rc.top, rc.Width(), rc.Height(), NULL, 0, 0, PATCOPY);
		
		CRect clientRC;
		GetClientRect(clientRC);
		
		dc.SetTextColor(Colors::g_textColor);
		dc.SetBkColor(Colors::g_bgColor);
		
		{
			CSelectPen l_pen(dc, m_foregr); //-V808
			{
				CSelectFont l_font(dc, Fonts::g_font); //-V808
				const int lines = g_height / (Fonts::g_fontHeight * LINE_HEIGHT);
				const int lheight = g_height / (lines + 1);
				
				for (int i = 0; i < lines; ++i)
				{
					int ypos = lheight * (i + 1);
					if (ypos > Fonts::g_fontHeight + 2)
					{
						dc.MoveTo(rc.left, ypos);
						dc.LineTo(rc.right, ypos);
					}
					
					if (rc.left <= twidth)
					{
					
						ypos -= Fonts::g_fontHeight + 2;
						if (ypos < 0)
							ypos = 0;
						if (g_height == 0)
							g_height = 1;
						const tstring txt = Util::formatBytesW(m_max * (g_height - ypos) / g_height) + _T('/') + WSTRING(S);
						const int tw = WinUtil::getTextWidth(txt, dc);
						if (tw + 2 > twidth)
							twidth = tw + 2;
						dc.TextOut(1, ypos, txt.c_str());
					}
				}
			}
			if (rc.left < twidth)
			{
				const tstring txt = Util::formatBytesW(m_max) + _T('/') + WSTRING(S);
				int tw = WinUtil::getTextWidth(txt, dc);
				if (tw + 2 > twidth)
					twidth = tw + 2;
				dc.TextOut(1, 1, txt.c_str());
			}
		}
		{
			CSelectPen l_pen(dc, m_UploadSocketPen); //-V808
			drawLine(dc, m_UpSockets, rc, clientRC);
		}
		
		{
			CSelectPen l_pen(dc, m_DownloadSocketPen); //-V808
			drawLine(dc, m_DownSockets, rc, clientRC);
		}
		// [+]IRainman
		{
			CSelectPen l_pen(dc, m_UploadsPen); //-V808
			drawLine(dc, m_Uploads, rc, clientRC);
		}
		{
			CSelectPen l_pen(dc, m_DownloadsPen); //-V808
			drawLine(dc, m_Downloads, rc, clientRC);
		}
		// [~]IRainman
	}
	return 0;
}
Ejemplo n.º 16
0
void RequestMidiFilename(std::wstring *returned_filename, std::wstring *returned_file_title)
{
   // Grab the filename of the last song we played
   // and pre-load it into the open dialog
   wstring last_filename = UserSetting::Get(L"Last File", L"");

   const static int BufferSize = 512;
   wchar_t filename[BufferSize] = L"";
   wchar_t filetitle[BufferSize] = L"";

#ifdef WIN32
   // Try to populate our "File Open" box with the last file selected
   if (StringCbCopyW(filename, BufferSize, last_filename.c_str()) == STRSAFE_E_INSUFFICIENT_BUFFER)
   {
      // If there wasn't a last file, default to the built-in Music directory
      filename[0] = L'\0';
   }

   wstring default_dir;
   bool default_directory = false;
   if (last_filename.length() == 0)
   {
      default_directory = true;
      default_dir = UserSetting::Get(L"Default Music Directory", L"");

      if (!SetCurrentDirectory(default_dir.c_str()))
      {
         // LOGTODO!
         // This is non-critical.  No action required.
      }
   }

   OPENFILENAME ofn;
   ZeroMemory(&ofn, sizeof(OPENFILENAME));
   ofn.lStructSize =     sizeof(OPENFILENAME);
   ofn.hwndOwner =       0;
   ofn.lpstrTitle =      L"Piano Game: Choose a MIDI song to play";
   ofn.lpstrFilter =     L"MIDI Files (*.mid)\0*.mid;*.midi\0All Files (*.*)\0*.*\0";
   ofn.lpstrFile =       filename;
   ofn.nMaxFile =        BufferSize;
   ofn.lpstrFileTitle =  filetitle;
   ofn.lpstrInitialDir = default_dir.c_str();
   ofn.nMaxFileTitle =   BufferSize;
   ofn.lpstrDefExt =     L"mid";
   ofn.Flags =           OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST;

   if (GetOpenFileName(&ofn))
   {
      std::wstring filename = WSTRING(ofn.lpstrFile);

      SetLastMidiFilename(filename);

      if (returned_file_title) *returned_file_title = WSTRING(filetitle);
      if (returned_filename) *returned_filename = filename;
      return;
   }

   if (returned_file_title) *returned_file_title = L"";
   if (returned_filename) *returned_filename = L"";

#else
   
   OSStatus status;
   
   NavDialogCreationOptions options;
   status  = NavGetDefaultDialogCreationOptions(&options);
   if (status != noErr) throw PianoGameError(WSTRING(L"Couldn't create dialog options.  Error code: " << static_cast<int>(status)));
   
   options.windowTitle = CFSTR("Piano Game: Choose a MIDI song to play");
   
   // TODO: Should clean this up at shut-down
   static NavObjectFilterUPP navFilterUPP(0);
   if (navFilterUPP == 0) navFilterUPP = NewNavObjectFilterUPP(NavOpenFilterProc);
   
   NavDialogRef navDialog(0);
   status = NavCreateChooseFileDialog(&options, 0, 0, 0, navFilterUPP, 0, &navDialog);
   if (status != noErr) throw PianoGameError(WSTRING(L"Couldn't create open dialog.  Error code: " << static_cast<int>(status)));
   
   status = NavDialogRun(navDialog);
   if (status != noErr) throw PianoGameError(WSTRING(L"Couldn't run open dialog.  Error code: " << static_cast<int>(status)));
   
   NavReplyRecord navReply;
   status = NavDialogGetReply(navDialog, &navReply);

   if (status == userCanceledErr || !navReply.validRecord)
   {
      NavDisposeReply(&navReply);

      if (returned_file_title) *returned_file_title = L"";
      if (returned_filename) *returned_filename = L"";
      return;
   }
   
   long item_count = 0;
   status = AECountItems(&navReply.selection, &item_count);
   if (status != noErr) throw PianoGameError(WSTRING(L"Couldn't count resulting items from open dialog.  Error code: " << static_cast<int>(status)));
      
   for (long i = 1; i <= item_count; i++)
   {
      FSRef fsRef;
      status = AEGetNthPtr(&navReply.selection, i, typeFSRef, 0, 0, &fsRef, sizeof(FSRef), 0);
      if (status != noErr) throw PianoGameError(WSTRING(L"Couldn't get FSRef pointer from open dialog.  Error code: " << static_cast<int>(status)));

      CFStringRef file_title;
      status = LSCopyDisplayNameForRef( &fsRef, &file_title );
      if (status != noErr) throw PianoGameError(WSTRING(L"Couldn't get file title.  Error code: " << static_cast<int>(status)));
      
      const static int BufferSize(1024);
      char path_buffer[BufferSize];
      status = FSRefMakePath(&fsRef, (UInt8*)path_buffer, BufferSize);
      if (status != noErr) throw PianoGameError(WSTRING(L"Couldn't get file path.  Error code: " << static_cast<int>(status)));
      
      std::string narrow_path(path_buffer);
      std::wstring filepath(narrow_path.begin(), narrow_path.end());
      
      if (returned_file_title) *returned_file_title = WideFromMacString(file_title);
      if (returned_filename) *returned_filename = filepath;
      
      CFRelease(file_title);
   }
   
   NavDisposeReply(&navReply);
   
#endif
}
Ejemplo n.º 17
0
/** Product minor version */
const int product_minor_version = VERSION_MINOR;

/** Product version string */
const char product_version[] = VERSION;

/** Product name string */
const char product_name[] = PRODUCT_NAME;

/** Product short name string */
const char product_short_name[] = PRODUCT_SHORT_NAME;

/** Build name string */
const char build_name[] = BUILD_NAME;

/** Wide-character product version string */
const wchar_t product_wversion[] = WSTRING ( VERSION );

/** Wide-character product name string */
const wchar_t product_wname[] = WSTRING ( PRODUCT_NAME );

/** Wide-character product short name string */
const wchar_t product_short_wname[] = WSTRING ( PRODUCT_SHORT_NAME );

/** Wide-character build name string */
const wchar_t build_wname[] = WSTRING ( BUILD_NAME );

/** Copy of build name string within ".prefix" */
const char build_name_prefix[] __attribute__ (( section ( ".prefix.name" ) ))
	= BUILD_NAME;