MCPcopy Create free account
hub / github.com/ariccio/altWinDirStat / CeCopyFileToDevice

Function CeCopyFileToDevice

Reference code/osImageTool/RemoteDevice.cpp:207–286  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

205}
206
207bool CeCopyFileToDevice(const string& srcfile, const string& dstfile)
208{
209 WIN32_FIND_DATA wfd;
210 HANDLE hFind = FindFirstFile( srcfile.c_str(), &wfd);
211 if (INVALID_HANDLE_VALUE == hFind)
212 {
213 g_err.Set("Source/host file does not exist\n");
214 return false;
215 }
216 FindClose( hFind);
217
218 if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
219 {
220 g_err.Set("Source/host file specifies a directory\n");
221 return false;
222 }
223
224 string dstname= dstfile;
225
226 DWORD dwAttr = CeGetFileAttributes( ToWString(dstname).c_str());
227 if (0xFFFFFFFF != dwAttr)
228 {
229 if (dwAttr & FILE_ATTRIBUTE_DIRECTORY)
230 {
231 dstname += "\\";
232 dstname += wfd.cFileName;
233 }
234 else
235 {
236 g_err.Set("File already exists.\n");
237 return false;
238 }
239 }
240
241 HANDLE hSrc = CreateFile( srcfile.c_str(), GENERIC_READ, FILE_SHARE_READ,
242 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
243 if (INVALID_HANDLE_VALUE == hSrc)
244 {
245 g_err.Set("Unable to open source/host file");
246 return false;
247 }
248
249 HANDLE hDest = CeCreateFile( ToWString(dstname).c_str(), GENERIC_WRITE, FILE_SHARE_READ,
250 NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
251 if (INVALID_HANDLE_VALUE == hDest )
252 {
253 g_err.Set("Unable to open WinCE file");
254 return false;
255 }
256
257 debug("Copying %hs to WCE:%ls\n", srcfile.c_str(), ToWString(dstname).c_str());
258
259 ByteVector buffer; buffer.resize(32768);
260
261 DWORD dwNumRead;
262 do
263 {
264 if (ReadFile( hSrc, vectorptr(buffer), (DWORD)buffer.size(), &dwNumRead, NULL))

Callers 1

CheckITSDllMethod · 0.85

Calls 5

ToWStringFunction · 0.85
debugFunction · 0.85
SetMethod · 0.45
resizeMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected