-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformatthread.cpp
119 lines (105 loc) · 3.31 KB
/
formatthread.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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// ---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "formatthread.h"
#include "vdskapi.h"
#include "main.h"
#include "functions.h"
#pragma package(smart_init)
#include <stdio.h>
extern HANDLE hdisk;
extern TForm1 *Form1;
extern LARGE_INTEGER sizee;
extern unsigned long clstsize;
extern TCriticalSection *cchs;
extern int *diskcolor;
extern double disksize;
extern LPVOID memory;
__fastcall formatthread::formatthread(bool CreateSuspended):TThread(CreateSuspended)
{
}
// ---------------------------------------------------------------------------
void __fastcall formatthread::Execute()
{
NameThreadForDebugging("formatthread");
// ---- Place thread code here ----
Sleep(1000);
// Synchronize(Do);
Do();
}
void __fastcall formatthread::Do(void)
{
// if (!cchs->TryEnter())
// {
// deb("äèñê çàíÿò");
// return;
// }
extern int totreads, totwrites;
extern int numpkt;
int forr = 0, forw = totwrites;
forr = totreads;
forw = 0;
numpkt = 0;
// VdskSetDisk(hdisk, sizee, 2, 32, 512, false, true, true);
if (!diskcolor)
diskcolor = new int[Form1->pb1->Width];
// for (DWORD i = 0;i<Form1->pb1->Width-1;i++)
// diskcolor[i] = (int)clGray;
// deb("îòêëþ÷àåì äèñê ...");
//VdskUnmountDisk(hdisk, 'y');
//deb("äèñê îòêëþ÷¸í.");
char str[233];
DWORD ms = GetTickCount();
for (DWORD i = 0;i<Form1->pb1->Width-1;i++)
diskcolor[i] = (int)clWhite;
if (!disksize)
deb("format no disksize");
extern LONGLONG curdisksize;
// memset(memory, 0x0, curdisksize);
deb("íà÷àëî ôîðìàòèðîâàíèÿ (clstsize=%d,disksize=%.0f)...", clstsize, disksize);
// Application->ProcessMessages();
// Form1->deblog->Visible = false;
int ret = VdskFormatDiskA(hdisk, VDSK_FS_FAT32, "t1", false, (unsigned long)0, OnFormat, NULL);
if (!ret)
{
int err = GetLastError();
if (err == ERROR_NOT_INITIALIZED)
{
deb("!!!!!!!!!! ERROR_NOT_INITIALIZED ");
VdskUnmountDisk(hdisk, 'y');
VdskDeleteDisk(hdisk);
VdskFreeLibrary();
}
else
{
deb("=============\r\n !!! VdskFormatDisk: îøèáêà ïðè ôîðìàòèðîâàíèè\r\n " " %s",
fmterr(err));
}
VdskInitializeLibrary();
// ret = VdskFormatDisk(hdisk, VDSK_FS_FAT32, "temp1", false, clstsize, OnFormat, NULL);
// if (!ret)
// { // cchs->Leave();
// deb("fail restore");
// return;
// }
sprintf(str, "FORMAT FAILED");
Form1->current->Text = str;
}
else
{
ms = GetTickCount()-ms;
deb("============= äèñê îòôîðìàòèðîâàí çà %.2f ñåê.\r\n ×òåíèé: %d Çàïèñåé: %d",
(double)ms/1000.0, totreads-forr, totwrites-forw);
sprintf(str, "FORMAT DONE");
Form1->current->Text = str;
}
// MessageBox(NULL, "format done", NULL, MB_OK);
if (!VdskMountDisk(hdisk, 'y', true))
deb("îøèáêà ïðè ïîäêëþ÷åíèè äèñêà %s", fmterr());
// VdskStartDisk(hdisk, true);
// Form1->deblog->Visible = true;
Application->ProcessMessages();
Form1->OnPaint(0);
Form1->Button3->Enabled = true;
}
// ---------------------------------------------------------------------------