-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwxBupTestRestoreCleanup.cpp
More file actions
101 lines (95 loc) · 3.72 KB
/
wxBupTestRestoreCleanup.cpp
File metadata and controls
101 lines (95 loc) · 3.72 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*-----------------------------------------------------------------
* Name: wxBupTestRestoreCleanup.cpp
* Purpose: cleanout destination directory for clean restart
* Author: A. Wiegert
*
* Copyright:
* Licence: wxWidgets licence
*---------------------------------------------------------------- */
/*----------------------------------------------------------------
* Standard wxWidgets headers
*---------------------------------------------------------------- */
// Note __VISUALC__ is defined by wxWidgets, not by MSVC IDE
// and thus won't be defined until some wxWidgets headers are included
#if defined( _MSC_VER )
# if defined ( _DEBUG )
// this statement NEEDS to go BEFORE all headers
# define _CRTDBG_MAP_ALLOC
# endif
#endif
#include "wxBupPreProcDefsh.h" // needs to be first
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
/* For all others, include the necessary headers
* (this file is usually all you need because it
* includes almost all "standard" wxWidgets headers) */
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
// ------------------------------------------------------------------
#include "wxBupTestRestoreThreadh.h"
// ------------------------------------------------------------------
#if defined(_MSC_VER ) // from Autohotkey-hummer.ahk
// only good for MSVC
// this block needs to AFTER all headers
#include <crtdbg.h>
#ifdef _DEBUG
#ifndef DBG_NEW
#define DBG_NEW new ( _NORMAL_BLOCK , __FILE__ , __LINE__ )
#define new DBG_NEW
#endif
#endif
#endif
// ------------------------------------------------------------------
/**
* This will remove all files and sub directories of the specified directory
*
* All my attempts using the wxWidget classes wxFileName & wxDir were
* way too complicated.
* NOTE: this may or may NOT work on older Win Oses - i.e before Win XP.
*
* wxDir works well, except when we delete directories - possibly
* also if we were to create new ones
*/
#include <string.h>
bool MyRestoreThread::RemoveTestRestoreDirAndFiles( wxString wsDir )
{
int iRes;
wsDir += _T("*");
wchar_t szDir[MAX_PATH+1]; // +1 for the double null terminate
SHFILEOPSTRUCTW fos = {0};
wcsncpy_s(szDir, MAX_PATH, wsDir.c_str(), wsDir.Len() );
int len = lstrlenW(szDir);
szDir[len+1] = 0; // double null terminate for SHFileOperation
// delete the folder and everything inside
fos.wFunc = FO_DELETE;
fos.pFrom = szDir;
fos.fFlags = FOF_NO_UI;
iRes = SHFileOperation( &fos );
/* from the MSDN explanation:
* Return value
* Type: int
* Returns zero if successful; otherwise nonzero. Applications normally
* should simply check for zero or nonzero.
*
* It is good practice to examine the value of the fAnyOperationsAborted
* member of the SHFILEOPSTRUCT. SHFileOperation can return 0 for success
* if the user cancels the operation. If you do not check fAnyOperationsAborted
* as well as the return value, you cannot know that the function accomplished
* the full task you asked of it and you might proceed under incorrect assumptions.
*
* Do not use GetLastError with the return values of this function.
*
* To examine the nonzero values for troubleshooting purposes, they largely
* map to those defined in Winerror.h. However, several of its possible return
* values are based on pre-Win32 error codes, which in some cases overlap
* the later Winerror.h values without matching their meaning. Those particular
* values are detailed here, and for these specific values only these meanings
* should be accepted over the Winerror.h codes.
*/
return( iRes == 0 );
}
// ------------------------------- eof ------------------------------