本文整理汇总了C++中CAutoFile::IsValid方法的典型用法代码示例。如果您正苦于以下问题:C++ CAutoFile::IsValid方法的具体用法?C++ CAutoFile::IsValid怎么用?C++ CAutoFile::IsValid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CAutoFile
的用法示例。
在下文中一共展示了CAutoFile::IsValid方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sizeof
TEST(UpdateCrypto, Binary)
{
CAutoTempDir tempdir;
CString testFile = tempdir.GetTempDir() + L"\\test.bin";
unsigned char binaryFile[99] = // based on link.png
{
0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, 0x00, 0x0D, 0x49, 0x48, 0x44, 0x52,
0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08, 0x01, 0x03, 0x00, 0x00, 0x00, 0xFE, 0xC1, 0x2C,
0xC8, 0x00, 0x00, 0x00, 0x06, 0x50, 0x4C, 0x54, 0x45, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xA5,
0xD9, 0x9F, 0xDD, 0x00, 0x00, 0x00, 0x18, 0x49, 0x44, 0x41, 0x54, 0x78, 0x5E, 0x63, 0xF8, 0xC0,
0xF0, 0x87, 0xE1, 0x17, 0x83, 0x18, 0x43, 0x3E, 0x43, 0x38, 0x43, 0x39, 0x03, 0x3B, 0x00, 0x2C,
0x98, 0x04, 0x41, 0xFA, 0xEC, 0xE7, 0x75, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4E, 0x44, 0xAE,
0x42, 0x60, 0x82,
};
CAutoFile file = ::CreateFile(testFile, GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
ASSERT_TRUE(file.IsValid());
DWORD written = 0;
EXPECT_TRUE(::WriteFile(file, binaryFile, sizeof(binaryFile), &written, nullptr));
EXPECT_EQ(sizeof(binaryFile), written);
EXPECT_TRUE(file.CloseHandle());
CString testFileSignature = testFile + _T(".rsa.asc");
EXPECT_TRUE(CStringUtils::WriteStringToTextFile((LPCTSTR)testFileSignature, L"-----BEGIN PGP SIGNATURE-----\nVersion: GnuPG v2\n\niQIcBAABCgAGBQJVxPvgAAoJEPfxez+d2VOerKsP/iQlt4S20LdUknT5udD8fFpT\nEFhZDPTXMRWkd8OhCLxa+t5b/ijyxFKWNz808Q7BDQcQoOQtC19NDvVmAcfqXflt\nR4Z+ugCG/lqP+3y0xBrL9m4UT9fNzQCiUY8Xpaih+6riLGnXVVpUe29BgVZppEWn\nMG9RVXpXwC+M3VQ0yQWu1F2Yy5OjdH4Ww5kpluoseZMOPhT6VaSfXeyQmg2DrBbw\nUfVV+w718noZ5znDH9MiD5y+sd4o7vqN2YFdg6FNvTjHyha39aFV8UCpPX1lH9ME\nN9v1vt5IWGCWL0zsZ6umHqibGG3Q2S3mlqktFhKJGWci+Swy4cNMpXDHIKY6e5v7\nxPIP92djyFtbjdixcSqBaYFC/Dd0KuCa1eYmyi2KxzUP29rZ+EHWoazfbeL1Y2Pu\nkSBrVFv64j0URzSMxUpJMqYXZRC5QW7vdbVwHGAPzoS+0rBBddwfSKteBQjagcHA\nkLk3sAIZNj1JaP5dcGL2K4Wxlaae0WgwI48lZSBMoL8SaInQvcKq9iL64xfpU+FU\nG0mzbidvTfZpyEU3eeSNiFi+6z4XLQ3NUFxsOr5jEPVKvgRoPljhJ4nCx034KQRQ\nHbVF9KYgMJSroKN9bNi/UFkC45Pc4wVov/XyH82XCVS30Du4hsVXsTdAiiXb3i6w\nkrWIJWYRxx76XGtQoHrR\n=PlFQ\n-----END PGP SIGNATURE-----"));
EXPECT_EQ(0, VerifyIntegrity(testFile, testFileSignature, nullptr));
// signature is shorter than pubkey; did not work w/o commit 941c103c00e48b0ffe592ab4d87d40ff48f899f6
EXPECT_TRUE(CStringUtils::WriteStringToTextFile((LPCTSTR)testFileSignature, L"-----BEGIN PGP SIGNATURE-----\nVersion: GnuPG v2\n\niQIbBAABCgAGBQJVxQQOAAoJEPfxez+d2VOe7GoP+KflvYJVpNXSwnteXyDc1zTo\nJAyAJFtW6mgqCLrN6KoMrncEvd0cHrD07hT5mxULkbP6zy9fGaFYF0gHO0mOqErF\nIIbDcpPTWooJWUHMbnuQjf2I0x70Cr8ikycZQ7uDg7scZx7E8EIwHOJX60dcfdVX\nK1SQ+c+VIvo1uxL1PndloACaeINz6rL0Pj504lVDJaaGBvzdAV6KEIcjjm+Jb4r0\n6CYEntmt1i3Mc8FM6Xp1QfGtJqp4ogjv6o89hvtaBBLihB54EVQn66/2qIjdhX8W\nkdqJE6+pmFTfuD02XNECwl6stDIZcxXCw6EE87/1hdHip8oW9enIVTxKWB3fUWHl\n236eE2qb8zAN/WWGx/2Cvi6ctyosy9Cc/1hopnmV0KgZFfmDJWw0lISlC/3ZYWEe\nQFiXs5FPzLwfKnkq4REpoOKKfbZNk329J2iLFnwrF0mlL4vUZ1m26BBBk6lhm41J\nnjOSFWhJG/AqBbR5DqdJfXMqnxpfVZfaE5cry2rhjI4mfzw0xzrgvL4M9FZ7R9F8\njVHAV11CMqtp/7gMHXu6ljkTEBBQ7cgbU5DEAwfWddaJF+R30jmNSVliN2JW2FAk\nIbE8yV+uPiyXebn49CmRzkOWOAZqx+DShqriXGam37qjhdys147wPMMiwk8lZKjP\n4V66gTFw45UvBpophyg=\n=0bmW\n-----END PGP SIGNATURE-----"));
EXPECT_EQ(0, VerifyIntegrity(testFile, testFileSignature, nullptr));
}
示例2: Execute
bool SyncCommand::Execute()
{
bool bRet = false;
CRegString rSyncPath(L"Software\\TortoiseSVN\\SyncPath");
CTSVNPath syncPath = CTSVNPath(CString(rSyncPath));
CTSVNPath syncFolder = syncPath;
CRegDWORD regCount(L"Software\\TortoiseSVN\\SyncCounter");
CRegDWORD regSyncAuth(L"Software\\TortoiseSVN\\SyncAuth");
bool bSyncAuth = DWORD(regSyncAuth) != 0;
if (!cmdLinePath.IsEmpty())
syncPath = cmdLinePath;
if (syncPath.IsEmpty() && !parser.HasKey(L"askforpath"))
{
return false;
}
syncPath.AppendPathString(L"tsvnsync.tsex");
BOOL bWithLocals = FALSE;
if (parser.HasKey(L"askforpath"))
{
// ask for the path first, then for the password
// this is used for a manual import/export
CString path;
bool bGotPath = FileOpenSave(path, bWithLocals, !!parser.HasKey(L"load"), GetExplorerHWND());
if (bGotPath)
{
syncPath = CTSVNPath(path);
if (!parser.HasKey(L"load") && syncPath.GetFileExtension().IsEmpty())
syncPath.AppendRawString(L".tsex");
}
else
return false;
}
CSimpleIni iniFile;
iniFile.SetMultiLine(true);
SVNAuthData authData;
CAutoRegKey hMainKey;
RegOpenKeyEx(HKEY_CURRENT_USER, L"Software\\TortoiseSVN", 0, KEY_READ, hMainKey.GetPointer());
FILETIME filetime = { 0 };
RegQueryInfoKey(hMainKey, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &filetime);
bool bCloudIsNewer = false;
if (!parser.HasKey(L"save"))
{
// open the file in read mode
CAutoFile hFile = CreateFile(syncPath.GetWinPathString(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile.IsValid())
{
// load the file
LARGE_INTEGER fsize = { 0 };
if (GetFileSizeEx(hFile, &fsize))
{
auto filebuf = std::make_unique<char[]>(DWORD(fsize.QuadPart));
DWORD bytesread = 0;
if (ReadFile(hFile, filebuf.get(), DWORD(fsize.QuadPart), &bytesread, NULL))
{
// decrypt the file contents
std::string encrypted;
if (bytesread > 0)
encrypted = std::string(filebuf.get(), bytesread);
CRegString regPW(L"Software\\TortoiseSVN\\SyncPW");
CString password;
if (parser.HasKey(L"askforpath") && parser.HasKey(L"load"))
{
INT_PTR dlgret = 0;
bool bPasswordMatches = true;
do
{
bPasswordMatches = true;
CPasswordDlg passDlg(CWnd::FromHandle(GetExplorerHWND()));
passDlg.m_bForSave = !!parser.HasKey(L"save");
dlgret = passDlg.DoModal();
password = passDlg.m_sPW1;
if ((dlgret == IDOK) && (parser.HasKey(L"load")))
{
std::string passworda = CUnicodeUtils::StdGetUTF8((LPCWSTR)password);
std::string decrypted = CStringUtils::Decrypt(encrypted, passworda);
if ((decrypted.size() < 3) || (decrypted.substr(0, 3) != "***"))
{
bPasswordMatches = false;
}
}
} while ((dlgret == IDOK) && !bPasswordMatches);
if (dlgret != IDOK)
return false;
}
else
{
auto passwordbuf = CStringUtils::Decrypt(CString(regPW));
if (passwordbuf.get())
{
password = passwordbuf.get();
}
else
{
// password does not match or it couldn't be read from
// the registry!
//.........这里部分代码省略.........