-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakeFATThread.cpp
139 lines (118 loc) · 3.59 KB
/
MakeFATThread.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// ---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "MakeFATThread.h"
#include "CacheThread.h"
#include "main.h"
#include "vdskapi.h"
#include <vector>
#include "functions.h"
#pragma package(smart_init)
#include <algorithm>
using namespace std;
extern ULONG totcachsize;
extern vector<CACHE>cache;
extern TCriticalSection *ccs;
extern TEvent *cev;
extern int unsaved;
#pragma package(smart_init)
extern char loadfile[128];
extern LONGLONG disksize;
extern LPVOID memory;
extern HANDLE hdisk;
extern LARGE_INTEGER sizee;
// ---------------------------------------------------------------------------
// Important: Methods and properties of objects in VCL can only be
// used in a method called using Synchronize, for example:
//
// Synchronize(&UpdateCaption);
//
// where UpdateCaption could look like:
//
// void __fastcall MakeFAT::UpdateCaption()
// {
// Form1->Caption = "Updated in a thread";
// }
// ---------------------------------------------------------------------------
__fastcall MakeFAT::MakeFAT(bool CreateSuspended):TThread(CreateSuspended)
{
}
// ---------------------------------------------------------------------------
void __fastcall MakeFAT::Execute()
{
NameThreadForDebugging("MakeFAT");
// ---- Place thread code here ----
// Synchronize(Do);
Do();
}
extern unsigned char fb[];
void __fastcall MakeFAT::Do(void)
{
// od->Execute(NULL);
FILE *x;
char fn[128];
// disksize = (double)atoi(deunicode(Form1->Edit1->Text.c_str(), fn, sizeof(fn)))*1024*1024;
//
// if (memory)
// {
// delete[]memory;
// memory = NULL;
// }
//
// memory = new char[disksize];
//
// if (!disksize || !memory)
// {
// deb("no disksize %.0f, mem %x", disksize,memory);
// return;
// }
// deunicode(od->FileName.c_str(), fn, sizeof(fn));
strcpy(fn, loadfile);
x = fopen(fn, "rb");
if (!x)
{
deb("no file %s\r\n \r\n", loadfile);
return;
}
fseek(x, 0, SEEK_END);
unsigned long sz = ftell(x);
fseek(x, 0, SEEK_SET);
if(!sz||sz>55*1024*1024)
sz=55*1024*1024;
extern double maxquad;
maxquad=sz;
deb(" çàãðæàåì ôàéë %s %lu áàéò (%lu mb)\r\n \r\n", loadfile, sz, sz/1024/1024);
// Application->ProcessMessages();
// char *pp = new char[sz];
extern LONGLONG curdisksize;
if (memory)
HeapFree(GetProcessHeap(), 0, memory);
curdisksize = (LONGLONG)sz;
memory = HeapAlloc(GetProcessHeap(), 0, curdisksize);
disksize = curdisksize;
if (!memory)
deb("failed alloc mem");
else
deb("mem %lu OK",curdisksize);
SIZE_T rd = fread(memory, 1, (unsigned int)curdisksize, x);
deb("fread %u mb", (unsigned)rd/1024/1024);
// disksize = sz;
// memory = new char[sz];
// sz = sz>disksize?disksize:sz;
// sz = fread(memory, 1, sz, x);
// deb("memcpy %d bytes to disksize=%.0f @%p from %p", sz, disksize,memory,pp);
// memcpy(memory, pp, disksize);
// delete[]pp;
// deb("çàãðóæåíî %d áàéò @ %p (%d Ìá) ÑRC=0x%04x\r\n disksize=%.0f\r\n", sz, memory,
// sz/1024/1024, checksum((unsigned short*)memory, (int)disksize), disksize);
fclose(x);
deb("%s çàãðóæåí", loadfile);
extern FAT32BOOT fat32boot;
memcpy(&fat32boot, memory, sizeof(fat32boot));
Application->ProcessMessages();
// Form1->Button9Click(NULL);
// VdskSetDisk(hdisk, sizee, 2, 32, 512, false, true, true);
// if (Form1->Button1->Enabled)
// Form1->Button1Click(NULL);
}
// ---------------------------------------------------------------------------