Example #1
0
static ff::String GetClrVersion(ICLRMetaHost *metaHost, ff::StringRef versionOrAssembly)
{
	ff::String version;
	assertRetVal(versionOrAssembly.size(), version);

	if (!_wcsicmp(ff::GetPathExtension(versionOrAssembly).c_str(), L"dll"))
	{
		ff::String assembly = ff::GetExecutablePath();
		ff::StripPathTail(assembly);
		ff::AppendPathTail(assembly, versionOrAssembly);

		if (ff::FileExists(assembly))
		{
			wchar_t versionBuf[32];
			DWORD count = _countof(versionBuf);
			assertRetVal(SUCCEEDED(metaHost->GetVersionFromFile(assembly.c_str(), versionBuf, &count)), version);
			version = versionBuf;
		}
		else
		{
			assertSz(false, ff::String::format_new(L"Managed DLL doesn't exist: %s", assembly.c_str()).c_str());
		}
	}
	else if (versionOrAssembly[0] == 'v')
	{
		version = versionOrAssembly;
	}
	else
	{
		assertRetVal(false, version);
	}

	return version;
}
Example #2
0
FILETIME ff::GetFileAccessedTime(StringRef path)
{
	WIN32_FIND_DATA data;

	if (FileExists(path, &data))
	{
		return data.ftLastAccessTime;
	}

	assertSz(false, L"File doesn't exist");

	FILETIME dtm = { 0, 0 };
	return dtm;
}
void ff::AtProgramShutdown(std::function<void()> func)
{
    assertRet(s_processGlobals != nullptr);

    if (s_processGlobals->IsShuttingDown())
    {
        assertSz(false, L"Why register a program shutdown function during shutdown?");
        func();
    }
    else
    {
        s_processGlobals->AtShutdown(func);
    }
}
Example #4
0
ff::String ff::CreateTempFile(StringRef base, StringRef extension)
{
	LockMutex crit(GCS_FILE_UTIL);

	// STATIC_DATA (pod)
	static UINT nUnique = 0;
	const int maxTries = 1000;
	String szFinal;

	static StaticString defaultBase(L"TempFile");
	static StaticString defaultExt(L"tmp");

	String szBase      = base.size() ? szBase : defaultBase;
	String szExtension = extension.size() ? szExtension : defaultExt;

	for (int nTry = 0; nTry < maxTries; nTry++, nUnique++)
	{
		wchar_t szUnique[20];
		_snwprintf_s(szUnique, _countof(szUnique), _TRUNCATE, L"%u", nUnique);

		ff::String szTry = GetTempDirectory();
		AppendPathTail(szTry, szBase);
		szTry += szUnique;
		szTry += L".";
		szTry += szExtension;

		if (!FileExists(szTry))
		{
			szFinal = szTry;
			break;
		}
	}

	if (szFinal.size())
	{
		nUnique++;

		// Create the file to reserve it
		File file;
		if (!file.OpenWrite(szFinal))
		{
			szFinal.empty();
		}
	}

	assertSz(szFinal.size(), L"Can't create a file in the temp folder");

	return szFinal;
}