1 //---------------------------------------------------------------------------
6 #include "thOpenSource.h"
10 #include <inifiles.hpp>
12 #pragma package(smart_init)
13 //---------------------------------------------------------------------------
15 // Important: Methods and properties of objects in VCL can only be
16 // used in a method called using Synchronize, for example:
18 // Synchronize(UpdateCaption);
20 // where UpdateCaption could look like:
22 // void __fastcall thOpenFile::UpdateCaption()
24 // Form1->Caption = "Updated in a thread";
26 //---------------------------------------------------------------------------
28 __fastcall
thOpenFile::thOpenFile(bool CreateSuspended
)
29 : TThread(CreateSuspended
)
33 //---------------------------------------------------------------------------
34 void __fastcall
thOpenFile::Execute()
36 //---- Place thread code here ----
38 // FrmMain->LoadAndModify(FrmMain->OpenDialog1->FileName.c_str());
39 // FrmMain->OpenOk=true;
47 //---------------------------------------------------------------------------
48 void __fastcall
thOpenFile::RunOpen()
50 LoadAndModify(FrmMain
->OpenDialog1
->FileName
.c_str());
54 void thOpenFile::ReadAndModifyFromBuff(char *pBuff
, DWORD dwSize
, const char* pszFileName
)
56 char szErrorMsg
[MAX_PATH
];
57 char szNewFileName
[MAX_PATH
];
63 if('WDBC' != TAG(*p
.dw
))
65 _snprintf(szErrorMsg
, 512, "[%s]Not Wow's dbc file!", pszFileName
);
66 ShowMessage(szErrorMsg
);
71 DWORD dwRows
, dwCols
, dwRowLen
, dwTextLen
;
77 FrmMain
->sgEdit
->RowCount
= dwRows
+1;
78 FrmMain
->sgEdit
->ColCount
= dwCols
+1;
80 for(int i
=0; i
<FrmMain
->sgEdit
->RowCount
; i
++){
81 FrmMain
->sgEdit
->Cells
[0][i
]=IntToStr(i
);
82 if(Terminated
) return;
85 AnsiString iniSetFile
=ExtractFilePath(Application
->ExeName
)+"BcdEditer.ini";
86 AnsiString SectionName
=ExtractFileName(FrmMain
->CurrentOpenFile
);
88 ini
= new TIniFile( iniSetFile
);
89 for(int j
=0; j
<FrmMain
->sgEdit
->ColCount
; j
++){
90 FrmMain
->sgEdit
->Cells
[j
][0]= ini
->ReadString(SectionName
,"ColTitle"+IntToStr(j
),IntToStr(j
));
91 //sgEdit->Cells[j][0]=IntToStr(j);
92 ColType
[j
]=ini
->ReadInteger(SectionName
,"ColType"+IntToStr(j
),0);
93 if(Terminated
) return;
97 //int *ColType = new int[dwCols];
99 DWORD dwTextStartPos
= dwRows
*dwRowLen
+20;
100 char* pTextPtr
= pBuff
+ dwTextStartPos
;
101 char pszTemp
[MAX_PATH
];
105 BOOL
* pbString
= new BOOL
[dwRows
*dwCols
];
109 ini
= new TIniFile( iniSetFile
);
111 for(i
=0; i
<dwRows
; i
++)
113 for(j
=0; j
<dwCols
; j
++)
116 if(Terminated
) return;
119 memcpy(&fTemp
, &newTmp
, 4);
122 FrmMain
->sgEdit
->Cells
[j
+1][i
+1]=IntToStr(lTemp
);
125 //ColType= ini->ReadInteger(SectionName,"ColType"+IntToStr(j),0);
127 switch (ColType
[j
+1])
130 FrmMain
->sgEdit
->Cells
[j
+1][i
+1]=IntToStr(lTemp
);
133 FrmMain
->sgEdit
->Cells
[j
+1][i
+1]=FloatToStr(fTemp
);
135 case 2: //Îı¾ Îı¾ÀàÐÍÖ»ÄÜ¿´£¬²»Äܱà¼
136 if(dwTextStartPos
+ lTemp
< dwSize
){
137 pTextPtr
= pBuff
+ dwTextStartPos
+ lTemp
;
138 FrmMain
->sgEdit
->Cells
[j
+1][i
+1]=pTextPtr
;
140 FrmMain
->sgEdit
->Cells
[j
+1][i
+1]="¸ÃÁв»ÊÇÎı¾";
144 FrmMain
->sgEdit
->Cells
[j
+1][i
+1]=IntToStr(lTemp
);
157 void thOpenFile::LoadAndModify(const char * pszFileName
)
160 hFile
= CreateFile(pszFileName
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
, 0, NULL
);
161 if(hFile
== INVALID_HANDLE_VALUE
)return;
163 DWORD r
= 0, nFileSize
= 0;
164 nFileSize
= GetFileSize(hFile
, NULL
);
165 char* pTmpBuf
= new char[nFileSize
];
171 ReadFile(hFile
, pTmpBuf
, nFileSize
, &r
, NULL
);
173 FrmMain
->CurrentOpenFile
=pszFileName
;
174 FrmMain
->btSave
->Enabled
=true;
176 ReadAndModifyFromBuff(pTmpBuf
, nFileSize
, pszFileName
);
178 //SAFE_DELETE_ARRAY(pTmpBuf);