├── driveclear ├── stdafx.h ├── ReadMe.txt ├── SM3Tool.cpp ├── SM3Tool.h ├── stdafx.cpp ├── driveclear.h ├── driveclear.rc ├── driveclear.aps ├── driveclear.cpp ├── driveclearDlg.h ├── driveclear.vcproj ├── res │ ├── driveclear.ICO │ └── driveclear.rc2 ├── driveclear.vcxproj.user ├── resource.h ├── driveclear.vcproj.epc-PC.Administrator.user ├── driveclear.vcproj.EPC-SOFT.Administrator.user ├── driveclear.vcproj.MICROSOFTCHINA.Administrator.user ├── driveclear.vcproj.A53D0688C2DE417.Administrator.user ├── driveclear.vcxproj.filters ├── driveclear.vcxproj └── driveclearDlg.cpp └── 磁盘毁尸灭迹.sln /driveclear/stdafx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/epcsoft/driveclear/HEAD/driveclear/stdafx.h -------------------------------------------------------------------------------- /driveclear/ReadMe.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/epcsoft/driveclear/HEAD/driveclear/ReadMe.txt -------------------------------------------------------------------------------- /driveclear/SM3Tool.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/epcsoft/driveclear/HEAD/driveclear/SM3Tool.cpp -------------------------------------------------------------------------------- /driveclear/SM3Tool.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/epcsoft/driveclear/HEAD/driveclear/SM3Tool.h -------------------------------------------------------------------------------- /driveclear/stdafx.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/epcsoft/driveclear/HEAD/driveclear/stdafx.cpp -------------------------------------------------------------------------------- /driveclear/driveclear.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/epcsoft/driveclear/HEAD/driveclear/driveclear.h -------------------------------------------------------------------------------- /driveclear/driveclear.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/epcsoft/driveclear/HEAD/driveclear/driveclear.rc -------------------------------------------------------------------------------- /driveclear/driveclear.aps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/epcsoft/driveclear/HEAD/driveclear/driveclear.aps -------------------------------------------------------------------------------- /driveclear/driveclear.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/epcsoft/driveclear/HEAD/driveclear/driveclear.cpp -------------------------------------------------------------------------------- /driveclear/driveclearDlg.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/epcsoft/driveclear/HEAD/driveclear/driveclearDlg.h -------------------------------------------------------------------------------- /driveclear/driveclear.vcproj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/epcsoft/driveclear/HEAD/driveclear/driveclear.vcproj -------------------------------------------------------------------------------- /driveclear/res/driveclear.ICO: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/epcsoft/driveclear/HEAD/driveclear/res/driveclear.ICO -------------------------------------------------------------------------------- /driveclear/res/driveclear.rc2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/epcsoft/driveclear/HEAD/driveclear/res/driveclear.rc2 -------------------------------------------------------------------------------- /driveclear/driveclear.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /磁盘毁尸灭迹.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "磁盘毁尸灭迹", "driveclear\driveclear.vcxproj", "{67639E06-72E2-4B05-A44F-08343F1EA3B3}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {67639E06-72E2-4B05-A44F-08343F1EA3B3}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {67639E06-72E2-4B05-A44F-08343F1EA3B3}.Debug|Win32.Build.0 = Debug|Win32 16 | {67639E06-72E2-4B05-A44F-08343F1EA3B3}.Release|Win32.ActiveCfg = Release|Win32 17 | {67639E06-72E2-4B05-A44F-08343F1EA3B3}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /driveclear/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by driveclear.rc 4 | // 5 | #define IDM_ABOUTBOX 0x0010 6 | #define IDD_ABOUTBOX 100 7 | #define IDS_ABOUTBOX 101 8 | #define IDD_DRIVECLEAR_DIALOG 102 9 | #define IDR_MAINFRAME 128 10 | #define IDC_COMBO1 1000 11 | #define IDC_EDIT1 1001 12 | #define IDC_CHECK1 1002 13 | #define IDC_PROGRESS1 1003 14 | #define IDC_EDIT2 1004 15 | #define IDC_EDIT3 1005 16 | #define IDC_EDIT4 1006 17 | #define IDC_EDIT5 1007 18 | #define IDC_BUTTON1 1008 19 | #define IDC_BUTTON2 1009 20 | #define IDSTART 1010 21 | 22 | // Next default values for new objects 23 | // 24 | #ifdef APSTUDIO_INVOKED 25 | #ifndef APSTUDIO_READONLY_SYMBOLS 26 | #define _APS_NEXT_RESOURCE_VALUE 129 27 | #define _APS_NEXT_COMMAND_VALUE 32771 28 | #define _APS_NEXT_CONTROL_VALUE 1011 29 | #define _APS_NEXT_SYMED_VALUE 101 30 | #endif 31 | #endif 32 | -------------------------------------------------------------------------------- /driveclear/driveclear.vcproj.epc-PC.Administrator.user: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 11 | 35 | 36 | 39 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /driveclear/driveclear.vcproj.EPC-SOFT.Administrator.user: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 11 | 35 | 36 | 39 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /driveclear/driveclear.vcproj.MICROSOFTCHINA.Administrator.user: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 11 | 35 | 36 | 39 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /driveclear/driveclear.vcproj.A53D0688C2DE417.Administrator.user: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 11 | 35 | 36 | 39 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /driveclear/driveclear.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav 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 | -------------------------------------------------------------------------------- /driveclear/driveclear.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | 磁盘毁尸灭迹 15 | {67639E06-72E2-4B05-A44F-08343F1EA3B3} 16 | driveclear 17 | MFCProj 18 | 8.1 19 | 20 | 21 | 22 | Application 23 | v140 24 | Static 25 | MultiByte 26 | true 27 | 28 | 29 | Application 30 | v140 31 | Static 32 | MultiByte 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | <_ProjectFileVersion>14.0.25431.1 46 | 47 | 48 | ..\bin 49 | ..\temp\$(ProjectName)\$(Configuration)\ 50 | true 51 | 52 | 53 | ..\bin 54 | ..\temp\$(ProjectName)\$(Configuration)\ 55 | false 56 | 57 | 58 | 59 | _DEBUG;%(PreprocessorDefinitions) 60 | false 61 | false 62 | 63 | 64 | Disabled 65 | WIN32;_WINDOWS;_CRT_SECURE_NO_WARNINGS;_DEBUG;%(PreprocessorDefinitions) 66 | true 67 | EnableFastChecks 68 | MultiThreadedDebug 69 | Use 70 | Level3 71 | EditAndContinue 72 | 73 | 74 | _DEBUG;%(PreprocessorDefinitions) 75 | 0x0804 76 | $(IntDir);%(AdditionalIncludeDirectories) 77 | 78 | 79 | true 80 | Windows 81 | MachineX86 82 | winmm.lib 83 | 84 | 85 | 86 | 87 | NDEBUG;%(PreprocessorDefinitions) 88 | false 89 | false 90 | 91 | 92 | WIN32;_WINDOWS;_CRT_SECURE_NO_WARNINGS;NDEBUG;%(PreprocessorDefinitions) 93 | false 94 | MultiThreaded 95 | Use 96 | Level3 97 | None 98 | 99 | 100 | NDEBUG;%(PreprocessorDefinitions) 101 | 0x0804 102 | $(IntDir);%(AdditionalIncludeDirectories) 103 | 104 | 105 | true 106 | Windows 107 | true 108 | true 109 | MachineX86 110 | winmm.lib 111 | RequireAdministrator 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | Create 120 | Create 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | -------------------------------------------------------------------------------- /driveclear/driveclearDlg.cpp: -------------------------------------------------------------------------------- 1 | // driveclearDlg.cpp : 实现文件 2 | // 3 | 4 | #include "stdafx.h" 5 | #include "driveclear.h" 6 | #include "driveclearDlg.h" 7 | #include "SM3Tool.h" 8 | #define BUFFERLEN 16777216 9 | bool isdoing=false; 10 | ULONGLONG spacecanuse; 11 | LPCTSTR localdrive=new TCHAR[16]; 12 | 13 | #ifdef _DEBUG 14 | #define new DEBUG_NEW 15 | #endif 16 | 17 | 18 | // 用于应用程序“关于”菜单项的 CAboutDlg 对话框 19 | 20 | class CAboutDlg : public CDialog 21 | { 22 | public: 23 | CAboutDlg(); 24 | 25 | // 对话框数据 26 | enum { IDD = IDD_ABOUTBOX }; 27 | 28 | protected: 29 | virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 30 | 31 | // 实现 32 | protected: 33 | DECLARE_MESSAGE_MAP() 34 | }; 35 | 36 | CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) 37 | { 38 | } 39 | 40 | void CAboutDlg::DoDataExchange(CDataExchange* pDX) 41 | { 42 | CDialog::DoDataExchange(pDX); 43 | } 44 | 45 | BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) 46 | END_MESSAGE_MAP() 47 | 48 | 49 | // CdriveclearDlg 对话框 50 | 51 | 52 | 53 | 54 | CdriveclearDlg::CdriveclearDlg(CWnd* pParent /*=NULL*/) 55 | : CDialog(CdriveclearDlg::IDD, pParent) 56 | { 57 | m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); 58 | } 59 | 60 | void CdriveclearDlg::appendInfo(const char* str) 61 | { 62 | struct tm *pTime; 63 | time_t ctTime; time(&ctTime); 64 | pTime = localtime(&ctTime); 65 | char tmpTime[128]; 66 | strftime(tmpTime, 128, "[%H:%M:%S]", pTime); 67 | CString instr; 68 | GetDlgItemText(IDC_EDIT5, instr); 69 | instr = CString(tmpTime)+str +CString("\r\n")+ instr; 70 | SetDlgItemText(IDC_EDIT5, instr); 71 | } 72 | 73 | void CdriveclearDlg::DoDataExchange(CDataExchange* pDX) 74 | { 75 | CDialog::DoDataExchange(pDX); 76 | DDX_Control(pDX, IDC_CHECK1, m_capcheck); 77 | } 78 | 79 | void CdriveclearDlg::showInfo() 80 | { 81 | SetDlgItemText(IDC_EDIT5, _T("原理:\r\n 本软件通过覆盖磁盘可用空间来达到彻底清除曾经删除的文件.\r\n\r\n作用:\r\n 可以彻底清除磁盘曾经储存但被移动、修改、删除的痕迹,这样就可以不必担心以前删除了的文件被他人使用 磁盘恢复软件 恢复了.\r\n\r\n常识:\r\n 一般常规方式删除(比如清空回收站或SHIFT+DELETE,以及在windows下的格式化)只是清除文件在文件系统中的索引位置,而文件的实体还是保存在磁盘扇区里的,所以所谓 磁盘恢复软件 依然能够恢复你已删除了的文件,只有完全清除文件在磁盘物理扇区上所占用的每一个区块才算彻底删除,所谓的 文件粉碎软件 就是这个原理.")); 82 | 83 | } 84 | 85 | BEGIN_MESSAGE_MAP(CdriveclearDlg, CDialog) 86 | ON_WM_SYSCOMMAND() 87 | ON_WM_PAINT() 88 | ON_WM_QUERYDRAGICON() 89 | ON_WM_CLOSE() 90 | ON_WM_DEVICECHANGE() 91 | //}}AFX_MSG_MAP 92 | ON_CBN_SELCHANGE(IDC_COMBO1, &CdriveclearDlg::OnCbnSelchangeCombo1) 93 | //ON_BN_CLICKED(IDCANCEL, &CdriveclearDlg::OnBnClickedCancel) 94 | ON_BN_CLICKED(IDC_BUTTON1, &CdriveclearDlg::OnBnClickedButton1) 95 | ON_BN_CLICKED(IDC_BUTTON2, &CdriveclearDlg::OnBnClickedButton2) 96 | ON_BN_CLICKED(IDSTART, &CdriveclearDlg::OnBnClickedStart) 97 | END_MESSAGE_MAP() 98 | CString zxcstr(float zvalue) 99 | { 100 | CString zxstr; 101 | zxstr.Format(_T("%.2f MB"),zvalue); 102 | return zxstr; 103 | } 104 | 105 | 106 | ULONGLONG CdriveclearDlg::getDiskSpaceRemain(const char *path) 107 | { 108 | BOOL flag; 109 | ULARGE_INTEGER clu, sec, freeclu; 110 | char myvolname[128] = { 0 }; 111 | char myfilesys[128] = { 0 }; 112 | char txtbuf[256] = { 0 }; 113 | char rootPath[MAX_PATH] = {0}; 114 | strcpy(rootPath,path); 115 | rootPath[3] = 0; 116 | flag = GetVolumeInformation(rootPath, myvolname, 128, NULL, NULL, NULL, myfilesys, 128); 117 | if (flag != 0) 118 | { 119 | wsprintf(txtbuf, _T("%s, %s"), myvolname, myfilesys); 120 | //MessageBox(hwnd,txtbuf,rootpath,MB_OK); 121 | SetDlgItemText(IDC_EDIT1, txtbuf); 122 | //CEdit *pxl=(CEdit *) GetDlgItem(hwnd,IDC_EDIT1); 123 | //pxl->SetWindowText(txtbuf); 124 | 125 | GetDiskFreeSpaceEx(rootPath, (PULARGE_INTEGER)&clu, (PULARGE_INTEGER)&sec, (PULARGE_INTEGER)&freeclu); 126 | return freeclu.QuadPart; 127 | } 128 | return 0; 129 | } 130 | 131 | 132 | 133 | void CdriveclearDlg::getdiskinfo(LPCTSTR rootpath) 134 | { 135 | BOOL flag; 136 | ULARGE_INTEGER clu,sec,freeclu; 137 | char myvolname[128] = {0}; 138 | char myfilesys[128] = {0}; 139 | char txtbuf[256] = {0}; 140 | flag= GetVolumeInformation(rootpath,myvolname,128,NULL,NULL,NULL,myfilesys,128); 141 | if(flag!=0) 142 | { 143 | wsprintf(txtbuf,_T("%s, %s"),myvolname,myfilesys); 144 | //MessageBox(hwnd,txtbuf,rootpath,MB_OK); 145 | SetDlgItemText(IDC_EDIT1,txtbuf); 146 | //CEdit *pxl=(CEdit *) GetDlgItem(hwnd,IDC_EDIT1); 147 | //pxl->SetWindowText(txtbuf); 148 | 149 | GetDiskFreeSpaceEx(rootpath,(PULARGE_INTEGER)&clu,(PULARGE_INTEGER)&sec,(PULARGE_INTEGER)&freeclu); 150 | //wsprintf(txtbuf,_T("%s/%s"),(long)freeclu,(long)sec); 151 | SetDlgItemText(IDC_EDIT2,zxcstr((float)freeclu.QuadPart/1024/1024)); 152 | //localdrive=rootpath; 153 | StringCbCopy((STRSAFE_LPSTR)localdrive,16,rootpath); 154 | spacecanuse=freeclu.QuadPart; 155 | } 156 | else refreshdskinfo(); 157 | } 158 | void CdriveclearDlg::refreshdskinfo(){ 159 | bool first=true; 160 | CComboBox *pxl = (CComboBox *) GetDlgItem(IDC_COMBO1); 161 | unsigned char r; 162 | //LPTSTR szBuffer=new TCHAR[1024]; 163 | char testbuf[16] = {0}; 164 | pxl->ResetContent(); 165 | for(r='A';r<='Z';r++){ 166 | //testbuf[0]=r; 167 | sprintf(testbuf,"%c:\\",r); 168 | 169 | if(GetVolumeInformation((LPCTSTR)testbuf,NULL,NULL,NULL,NULL,NULL,NULL,NULL)!=0){ 170 | //MessageBox((LPCTSTR)testbuf,NULL,MB_OK); 171 | pxl->InsertString(-1,(LPCTSTR )testbuf); 172 | if(first){getdiskinfo(testbuf);first=false;} 173 | } 174 | 175 | } 176 | pxl->SetCurSel(0); 177 | 178 | } 179 | // CdriveclearDlg 消息处理程序 180 | 181 | BOOL CdriveclearDlg::OnInitDialog() 182 | { 183 | 184 | CDialog::OnInitDialog(); 185 | 186 | // 将“关于...”菜单项添加到系统菜单中。 187 | 188 | // IDM_ABOUTBOX 必须在系统命令范围内。 189 | ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); 190 | ASSERT(IDM_ABOUTBOX < 0xF000); 191 | 192 | CMenu* pSysMenu = GetSystemMenu(FALSE); 193 | if (pSysMenu != NULL) 194 | { 195 | CString strAboutMenu; 196 | strAboutMenu.LoadString(IDS_ABOUTBOX); 197 | if (!strAboutMenu.IsEmpty()) 198 | { 199 | pSysMenu->AppendMenu(MF_SEPARATOR); 200 | pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); 201 | } 202 | } 203 | 204 | // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动 205 | // 执行此操作 206 | SetIcon(m_hIcon, TRUE); // 设置大图标 207 | SetIcon(m_hIcon, FALSE); // 设置小图标 208 | HANDLE hMutex = CreateMutex(NULL, FALSE, _T("driverclear")); 209 | if (hMutex != NULL) 210 | { 211 | if (GetLastError() == ERROR_ALREADY_EXISTS) 212 | { 213 | MessageBox("磁盘填充器已经在运行了","提示",MB_OK | MB_ICONINFORMATION); 214 | //关闭互斥对象,退出程序 215 | CloseHandle(hMutex); 216 | exit (0); 217 | } else 218 | { 219 | //MessageBox(NULL,TEXT("第一次运行这个程序。"),TEXT("OnlyOne"),MB_OK | MB_ICONINFORMATION); 220 | } 221 | } 222 | //ShowWindow(SW_SHOW); 223 | // TODO: 在此添加额外的初始化代码 224 | 225 | showInfo(); 226 | //创建互斥对象 227 | srand(time(NULL)); 228 | m_capcheck.SetCheck(BST_CHECKED); 229 | refreshdskinfo(); 230 | return TRUE; // 除非将焦点设置到控件,否则返回 TRUE 231 | } 232 | 233 | void CdriveclearDlg::OnSysCommand(UINT nID, LPARAM lParam) 234 | { 235 | if ((nID & 0xFFF0) == IDM_ABOUTBOX) 236 | { 237 | CAboutDlg dlgAbout; 238 | dlgAbout.DoModal(); 239 | } 240 | else 241 | { 242 | CDialog::OnSysCommand(nID, lParam); 243 | } 244 | } 245 | 246 | // 如果向对话框添加最小化按钮,则需要下面的代码 247 | // 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序, 248 | // 这将由框架自动完成。 249 | 250 | void CdriveclearDlg::OnPaint() 251 | { 252 | if (IsIconic()) 253 | { 254 | CPaintDC dc(this); // 用于绘制的设备上下文 255 | 256 | SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0); 257 | 258 | // 使图标在工作矩形中居中 259 | int cxIcon = GetSystemMetrics(SM_CXICON); 260 | int cyIcon = GetSystemMetrics(SM_CYICON); 261 | CRect rect; 262 | GetClientRect(&rect); 263 | int x = (rect.Width() - cxIcon + 1) / 2; 264 | int y = (rect.Height() - cyIcon + 1) / 2; 265 | 266 | // 绘制图标 267 | dc.DrawIcon(x, y, m_hIcon); 268 | } 269 | else 270 | { 271 | CDialog::OnPaint(); 272 | } 273 | } 274 | 275 | //当用户拖动最小化窗口时系统调用此函数取得光标显示。 276 | // 277 | HCURSOR CdriveclearDlg::OnQueryDragIcon() 278 | { 279 | return static_cast(m_hIcon); 280 | } 281 | 282 | BOOL CdriveclearDlg::OnDeviceChange(UINT nEventType, DWORD_PTR dwData) 283 | { 284 | if (!isdoing) 285 | { 286 | refreshdskinfo(); 287 | } 288 | return CDialog::OnDeviceChange(nEventType, dwData); 289 | } 290 | 291 | void randomBuff(char* buffer,int len) 292 | { 293 | int blocksize = 23333; 294 | if (blocksize > len) 295 | { 296 | blocksize = len; 297 | } 298 | for (int r = 0; r < blocksize; r++) 299 | { 300 | buffer[r] = rand() % 255; 301 | } 302 | for (int r = 1; r < len/ blocksize; r++) 303 | { 304 | memcpy(buffer+r*blocksize,buffer,blocksize); 305 | } 306 | } 307 | unsigned int getCurrentTime() 308 | { 309 | #ifndef WIN32 310 | struct timeval tv; 311 | gettimeofday(&tv, NULL); 312 | return tv.tv_sec * 1000 + tv.tv_usec / 1000; 313 | #else 314 | unsigned int current = (unsigned int)(timeGetTime()); 315 | return current; 316 | #endif 317 | } 318 | 319 | HANDLE dealFileCreation(std::vector& vecTestFile, CdriveclearDlg *dlg,CString &path,GM_TestFile &singlefile) 320 | { 321 | char txtbuf[MAX_PATH] = {0}; 322 | sprintf(txtbuf, "temp_%u.tmp", vecTestFile.size()); 323 | path = localdrive + CString(txtbuf); 324 | dlg->appendInfo(CString("创建文件:" + path)); 325 | HANDLE hfile = CreateFile(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_FLAG_NO_BUFFERING, NULL); 326 | if (hfile == INVALID_HANDLE_VALUE) 327 | { 328 | dlg->appendInfo("无法创建文件,介质只读或没有权限"); 329 | CloseHandle(hfile); 330 | return NULL; 331 | } 332 | singlefile.filename = path; 333 | singlefile.vecSM3Hash.clear(); 334 | return hfile; 335 | } 336 | 337 | void WINAPI erasing (PVOID pParam) 338 | { 339 | HANDLE hfile=NULL; 340 | ULARGE_INTEGER a1,a2,a3; 341 | unsigned long n; 342 | SYSTEMTIME sys; 343 | unsigned int nowtime; 344 | unsigned int countst,counten; 345 | CString path=localdrive; 346 | ULONGLONG validSpace = spacecanuse; 347 | char* buf=new char [BUFFERLEN]; 348 | char txtbuf[256] = {0}; 349 | int nErrcount = 0; 350 | BOOL userstop=false; 351 | CdriveclearDlg *dlg = (CdriveclearDlg*)pParam; 352 | if(spacecanuse<=0) 353 | { 354 | dlg->appendInfo("剩余0字节..."); 355 | isdoing=false; 356 | delete[] buf; 357 | return; 358 | } 359 | isdoing = true; 360 | 361 | dlg->GetDlgItem(IDC_BUTTON2)->EnableWindow(FALSE); 362 | dlg->GetDlgItem(IDC_COMBO1)->EnableWindow(FALSE); 363 | dlg->m_capcheck.EnableWindow(FALSE); 364 | dlg->GetDlgItem(IDSTART)->SetWindowText("停止"); 365 | dlg->SendDlgItemMessage(IDC_PROGRESS1,PBM_SETRANGE, 0,MAKELPARAM (0,100)); 366 | GetSystemTime(&sys); 367 | nowtime=getCurrentTime(); 368 | dlg->appendInfo("准备填充..."); 369 | std::vector vecTestFile; 370 | GM_TestFile singlefile; 371 | while (1) 372 | { 373 | if (hfile == NULL) 374 | { 375 | hfile = dealFileCreation(vecTestFile, dlg, path, singlefile); 376 | if (hfile == NULL) 377 | { 378 | isdoing = false; 379 | delete[] buf; 380 | return; 381 | } 382 | } 383 | randomBuff(buf, BUFFERLEN); 384 | countst = getCurrentTime(); 385 | n = 0; 386 | if (!WriteFile(hfile, buf, BUFFERLEN, &n, NULL)) 387 | { 388 | if (validSpace < BUFFERLEN) 389 | { 390 | sprintf(txtbuf, "收尾...%llu KB", validSpace / 1024); 391 | dlg->appendInfo(txtbuf); 392 | if (!WriteFile(hfile, buf, validSpace, &n, NULL) && n == validSpace) 393 | { 394 | dlg->appendInfo("收尾失败!请不要操作测试分区!"); 395 | break; 396 | } 397 | 398 | } 399 | else 400 | { 401 | nErrcount++; 402 | if (nErrcount > 10) 403 | { 404 | dlg->appendInfo("错误过多,检测中断!"); 405 | userstop = true; 406 | break; 407 | } 408 | sprintf(txtbuf, "文件写入错误!位置:%llu MB", validSpace / 1024 / 1024); 409 | dlg->appendInfo(txtbuf); 410 | } 411 | } 412 | counten = getCurrentTime() - countst; 413 | if (validSpace < n) 414 | { 415 | validSpace = 0; 416 | } 417 | else 418 | { 419 | validSpace -= n; 420 | } 421 | sprintf(txtbuf, "%llu MB", validSpace / 1024 / 1024); 422 | dlg->SetDlgItemText(IDC_EDIT3, txtbuf); 423 | if (isdoing == false) 424 | { 425 | dlg->appendInfo("用户终止!"); 426 | userstop = true; 427 | break; 428 | } 429 | if (dlg->m_capcheck.GetCheck() == BST_CHECKED&&n > 0) 430 | { 431 | GM_SM3Hash sm3hash; 432 | SM3Tool sm3; 433 | sm3.sm3((unsigned char*)buf, (int)n, sm3hash.sm3hash); 434 | sm3hash.len = n; 435 | singlefile.vecSM3Hash.push_back(sm3hash); 436 | } 437 | if (n == 0) 438 | { 439 | if (singlefile.vecSM3Hash.size()> 0) 440 | { 441 | vecTestFile.push_back(singlefile); 442 | CloseHandle(hfile); 443 | hfile = NULL; 444 | } 445 | } 446 | else 447 | if (singlefile.vecSM3Hash.size() >=100) 448 | { 449 | vecTestFile.push_back(singlefile); 450 | CloseHandle(hfile); 451 | hfile = NULL; 452 | } 453 | GetSystemTime(&sys); 454 | unsigned int delta = getCurrentTime() - nowtime; 455 | if(delta>1000) 456 | { 457 | nowtime = getCurrentTime(); 458 | dlg->SendDlgItemMessage(IDC_PROGRESS1, PBM_SETPOS, (WPARAM)((spacecanuse- validSpace) * 100 / spacecanuse), 0); 459 | if(counten==0) 460 | sprintf(txtbuf,"-"); 461 | else 462 | { 463 | sprintf(txtbuf, "%.2f MB/S", (float)BUFFERLEN *1000.0f / (float)counten / 1024.0f / 1024.0f); 464 | } 465 | dlg->SetDlgItemText(IDC_EDIT4,txtbuf); 466 | } 467 | if (validSpace == 0) 468 | { 469 | break; 470 | } 471 | } 472 | 473 | CloseHandle(hfile); 474 | vecTestFile.push_back(singlefile); 475 | if (dlg->m_capcheck.GetCheck() == BST_CHECKED&&!userstop) 476 | { 477 | 478 | for (int i = 0; i < vecTestFile.size(); i++) 479 | { 480 | if (userstop) 481 | { 482 | break; 483 | } 484 | GM_TestFile & testFile = vecTestFile[i]; 485 | hfile = CreateFile(testFile.filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, NULL); 486 | if (hfile == INVALID_HANDLE_VALUE) 487 | { 488 | dlg->appendInfo(CString("无法读取文件:" + testFile.filename + ",介质损坏!")); 489 | CloseHandle(hfile); 490 | } 491 | else 492 | { 493 | dlg->appendInfo(CString("校验文件:" + testFile.filename)); 494 | } 495 | for (int r = 0; r < testFile.vecSM3Hash.size(); r++) 496 | { 497 | countst = getCurrentTime(); 498 | if (ReadFile(hfile, buf, BUFFERLEN, &n, NULL) == 0) 499 | { 500 | dlg->appendInfo("读取错误!数据意外终止!"); 501 | userstop = true; 502 | break; 503 | } 504 | counten = getCurrentTime() - countst; 505 | if (isdoing == false) 506 | { 507 | dlg->appendInfo("用户终止!"); 508 | userstop = true; 509 | break; 510 | } 511 | unsigned char sm3hash[32] = { 0 }; 512 | SM3Tool sm3; 513 | sm3.sm3((unsigned char*)buf, (int)n, sm3hash); 514 | if (memcmp(sm3hash, testFile.vecSM3Hash[r].sm3hash, 32) != 0) 515 | { 516 | nErrcount++; 517 | sprintf(txtbuf, "%s文件检测到%d个错误,位置:%llu MB", testFile.filename.GetBuffer(),nErrcount, (ULONGLONG)r*BUFFERLEN / 1024 / 1024); 518 | dlg->appendInfo(txtbuf); 519 | if (nErrcount > 10) 520 | { 521 | dlg->appendInfo("错误过多,检测中断!"); 522 | userstop = true; 523 | break; 524 | } 525 | } 526 | else 527 | { 528 | validSpace += testFile.vecSM3Hash[r].len; 529 | } 530 | sprintf(txtbuf, "%llu MB", (spacecanuse - validSpace) / 1024 / 1024); 531 | dlg->SetDlgItemText(IDC_EDIT3, txtbuf); 532 | dlg->SendDlgItemMessage(IDC_PROGRESS1, PBM_SETPOS, (WPARAM)(validSpace * 100 / spacecanuse), 0); 533 | GetSystemTime(&sys); 534 | unsigned int delta = getCurrentTime() - nowtime; 535 | if (delta > 1000) 536 | { 537 | nowtime = getCurrentTime(); 538 | if (counten == 0) 539 | sprintf(txtbuf, "-"); 540 | else 541 | { 542 | sprintf(txtbuf, "%.2f MB/S", (float)BUFFERLEN *1000.0f / (float)counten / 1024.0f / 1024.0f); 543 | } 544 | dlg->SetDlgItemText(IDC_EDIT4, txtbuf); 545 | } 546 | } 547 | CloseHandle(hfile); 548 | hfile = NULL; 549 | } 550 | if (hfile != NULL) 551 | { 552 | CloseHandle(hfile); 553 | } 554 | } 555 | 556 | dlg->appendInfo("清理数据中..."); 557 | for (int r = 0; r < vecTestFile.size(); r++) 558 | { 559 | DeleteFile(vecTestFile[r].filename); 560 | } 561 | isdoing=false; 562 | dlg->SendDlgItemMessage(IDC_PROGRESS1, PBM_SETPOS, (WPARAM)(100),0); 563 | dlg->SetDlgItemText(IDC_EDIT3,_T("0 MB")); 564 | if (userstop == false) 565 | { 566 | if (dlg->m_capcheck.GetCheck() == BST_CHECKED) 567 | { 568 | if (nErrcount == 0) 569 | { 570 | sprintf(txtbuf, "处理结束!您的磁盘有效容量:%lld MB (%.2lf GB)",validSpace/1024/1024,double(validSpace)/1024.0/1024.0/1024.0); 571 | dlg->appendInfo(txtbuf); 572 | } 573 | else 574 | { 575 | dlg->appendInfo("处理结束!您的磁盘有错误!"); 576 | } 577 | } 578 | else 579 | { 580 | dlg->appendInfo("处理结束!您的磁盘数据已毁尸灭迹!"); 581 | } 582 | } 583 | dlg->GetDlgItem(IDC_BUTTON2)->EnableWindow(TRUE); 584 | dlg->GetDlgItem(IDC_COMBO1)->EnableWindow(TRUE); 585 | dlg->m_capcheck.EnableWindow(TRUE); 586 | dlg->GetDlgItem(IDSTART)->EnableWindow(TRUE); 587 | dlg->GetDlgItem(IDSTART)->SetWindowText("开始"); 588 | delete[] buf; 589 | } 590 | void CdriveclearDlg::OnCbnSelchangeCombo1() 591 | { 592 | // TODO: 在此添加控件通知处理程序代码 593 | CString testbuf; 594 | GetDlgItemText(IDC_COMBO1,testbuf); 595 | getdiskinfo(testbuf); 596 | } 597 | void CdriveclearDlg::OnClose() 598 | { 599 | // TODO: Add your message handler code here and/or call default 600 | if(isdoing)MessageBox(_T("正在处理,请先停止!"),NULL,MB_OK); 601 | else CDialog::OnClose(); 602 | } 603 | 604 | void CdriveclearDlg::OnBnClickedButton1() 605 | { 606 | // TODO: 在此添加控件通知处理程序代码 607 | CAboutDlg dlg; 608 | //dlg.Create(IDD_ABOUTBOX,this); 609 | //dlg.ShowWindow(SW_SHOW); 610 | dlg.DoModal(); 611 | } 612 | 613 | void CdriveclearDlg::OnBnClickedButton2() 614 | { 615 | // TODO: 在此添加控件通知处理程序代码 616 | refreshdskinfo(); 617 | } 618 | 619 | void CdriveclearDlg::OnBnClickedStart() 620 | { 621 | // TODO: 在此添加控件通知处理程序代码 622 | unsigned long ThreadID; 623 | if(!isdoing) 624 | { 625 | getdiskinfo(localdrive); 626 | SetDlgItemText(IDC_EDIT5, ""); 627 | CloseHandle(CreateThread(NULL,NULL,(LPTHREAD_START_ROUTINE)erasing,this,0,&ThreadID)); 628 | } 629 | else { 630 | CWnd *pWnd; 631 | pWnd=GetDlgItem(IDSTART); 632 | pWnd->EnableWindow(FALSE); 633 | isdoing=false; 634 | } 635 | } 636 | --------------------------------------------------------------------------------