-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFileCreators.cpp
69 lines (53 loc) · 1.59 KB
/
FileCreators.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "FileCreators.h"
#include "Utils.h"
#include "WINEXCLUDE.H"
#include <windows.h>
#include <tchar.h>
#include <cstdio>
#include <memory>
#include <fstream>
#include <iostream>
///////////////////////////////////////////////////////////////////////////////
// StdioFileCreator
bool StdioFileCreator::Create(TGenFunc func)
{
FILE_unique_ptr pOutputFilePtr = make_fopen(m_strFile.c_str(), L"wb");
if (!pOutputFilePtr)
return false;
std::unique_ptr<char[]> outBuf(new char[m_blockSizeInBytes]);
// allocate proper size at the beginning...
size_t bytesWritten = 0;
size_t blockCount = 0;
while (bytesWritten < m_sizeInBytes)
{
func(outBuf.get(), m_blockSizeInBytes);
const auto numWritten = fwrite(outBuf.get(), sizeof(char), m_blockSizeInBytes, pOutputFilePtr.get());
if (numWritten < m_blockSizeInBytes)
{
printf("Problem in writing the file!\n");
break;
}
bytesWritten+=m_blockSizeInBytes;
blockCount++;
}
std::wcout << L"File " << m_strFile << L" created with " << bytesWritten << L" bytes written (" << (bytesWritten>>20) << L" MB), " << blockCount << L" blocks\n";
return true;
}
///////////////////////////////////////////////////////////////////////////////
// IoStreamFileCreator
bool IoStreamFileCreator::Create(TGenFunc )
{
return false;
}
///////////////////////////////////////////////////////////////////////////////
// WinFileCreator
bool WinFileCreator::Create(TGenFunc )
{
return false;
}
///////////////////////////////////////////////////////////////////////////////
// MappedWinFileCreator
bool MappedWinFileCreator::Create(TGenFunc )
{
return false;
}