Initial commit
This commit is contained in:
@@ -0,0 +1,261 @@
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#include <vcl.h>
|
||||
#pragma hdrstop
|
||||
|
||||
#include "GlobalUnit.h"
|
||||
#include "ProgressThreadUnit.h";
|
||||
#include "StylesUpProgressFormUnit.h"
|
||||
|
||||
#define OPERATION_MM_SAVE 1
|
||||
#define OPERATION_MM_LOAD 2
|
||||
#define OPERATION_PROJ_LOAD 3
|
||||
#define OPERATION_PROJ_SAVE 4
|
||||
#define OPERATION_USER_LOGIN 5
|
||||
#define OPERATION_USER_VERIFY 6
|
||||
#define OPERATION_USER_PURCHASE 7
|
||||
#define OPERATION_STYLE_UPLOAD 8
|
||||
// ---------------------------------------------------------------------------
|
||||
#pragma package(smart_init)
|
||||
#pragma resource "*.dfm"
|
||||
TStylesUpProgressForm *StylesUpProgressForm;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
__fastcall TStylesUpProgressForm::TStylesUpProgressForm(TComponent* Owner)
|
||||
: TForm(Owner) {
|
||||
|
||||
m_nPos = 0;
|
||||
m_iUpLoadFlag = -1;
|
||||
m_nNextMinPos = 0;
|
||||
m_nNextMaxPos = m_nMaxPos = 100;
|
||||
m_iOperation = m_iOperationResult = 0;
|
||||
|
||||
m_pThread = new TProgressThread(true, this);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
void __fastcall TStylesUpProgressForm::OnCancelClick(TObject *Sender) {
|
||||
|
||||
if (m_iOperation == OPERATION_STYLE_UPLOAD) {
|
||||
m_iOperationResult = mrCancel;
|
||||
|
||||
WaitForSingleObject(m_hProcessEvent, INFINITE);
|
||||
|
||||
m_pThread->Terminate();
|
||||
f_CS_CancelOperation();
|
||||
|
||||
ModalResult = mrCancel;
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
void __fastcall TStylesUpProgressForm::TimerProc(TObject* Sender) {
|
||||
m_nPos += 2;
|
||||
|
||||
/*
|
||||
if( m_nPos>=m_nMaxPos ){
|
||||
m_nPos -= m_nMaxPos;
|
||||
}
|
||||
*/
|
||||
if (m_nPos >= m_pgProgBar->Max) {
|
||||
m_nPos = 0;
|
||||
}
|
||||
|
||||
m_pgProgBar->Position = m_nPos;
|
||||
m_pgProgBar->Invalidate();
|
||||
}
|
||||
|
||||
void __fastcall TStylesUpProgressForm::WMNCHitTest(TWMNCHitTest &Msg) {
|
||||
TForm::Dispatch(&Msg);
|
||||
|
||||
if (Msg.Result == HTCLIENT && Msg.YPos < Top + 24 && Msg.XPos < Left + 274)
|
||||
Msg.Result = HTCAPTION;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
void __fastcall TStylesUpProgressForm::UMOperateFailed(TMessage &Message) {
|
||||
// m_pThread->Terminate();
|
||||
// ModalResult = Message.WParam;
|
||||
}
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
void __fastcall TStylesUpProgressForm::UMOperatePercent(TMessage &Message)
|
||||
{
|
||||
if( m_iOperationResult==0 ){
|
||||
m_nPos = m_nNextMinPos + Message.WParam *
|
||||
(m_nNextMaxPos - m_nNextMinPos) / 100;
|
||||
lbPrctStyle->Caption = IntToStr(m_nPos) + L"%";
|
||||
m_pgProgBar->Position = m_nPos;
|
||||
}
|
||||
}
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
void __fastcall TStylesUpProgressForm::UMOperateComplete(TMessage &Message)
|
||||
{
|
||||
if( m_iOperationResult==0 ){
|
||||
if( Message.WParam==1 ){
|
||||
m_pgProgBar->Position = 100;
|
||||
lbPrctStyle->Caption = L"100%";
|
||||
|
||||
m_iUpLoadFlag = 1;
|
||||
m_iOperationResult = mrOk;
|
||||
|
||||
m_pThread->Terminate();
|
||||
ModalResult = mrOk;
|
||||
}
|
||||
else{
|
||||
lbPrctStyle->Caption = L"100%";
|
||||
m_pgProgBar->Position = 100;
|
||||
}
|
||||
}
|
||||
}
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
void __fastcall TStylesUpProgressForm::UMOperateNextRange(TMessage &Message) {
|
||||
m_nNextMinPos = Message.WParam * m_nMaxPos / 100;
|
||||
m_nNextMaxPos = (Message.LParam == 0 ? m_nMaxPos :
|
||||
Message.LParam * m_nMaxPos / 100);
|
||||
}
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
int __fastcall TStylesUpProgressForm::Styles_Upload(vector<TDEFSTYLEINFO>vcDefStyleInfo)
|
||||
{
|
||||
m_iOperation = OPERATION_STYLE_UPLOAD;
|
||||
m_hProcessEvent = CreateEvent(NULL, FALSE, TRUE, NULL);
|
||||
|
||||
this->Caption = L"正在上传...";
|
||||
// m_pTimer->Enabled = true;
|
||||
m_pThread->Start();
|
||||
|
||||
m_pgProgTotalBar->Max = vcDefStyleInfo.size() * 100;
|
||||
m_pgProgTotalBar->Min = 0;
|
||||
|
||||
if (m_vcDefStylesInfo.size())
|
||||
m_vcDefStylesInfo.clear();
|
||||
|
||||
for( int i=0; i<vcDefStyleInfo.size(); i++ )
|
||||
m_vcDefStylesInfo.push_back( vcDefStyleInfo[i] );
|
||||
|
||||
return ShowModal();
|
||||
}
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
void __fastcall TStylesUpProgressForm::Operation() {
|
||||
|
||||
switch (m_iOperation) {
|
||||
case OPERATION_STYLE_UPLOAD: {
|
||||
// Ñ»·ÉÏ´«
|
||||
wchar_t strCaption[1000];
|
||||
for (int i = 0; i < m_vcDefStylesInfo.size(); i++) {
|
||||
// Begin to Recombin Style File
|
||||
|
||||
TDEFSTYLEINFO defStyleTmp;
|
||||
defStyleTmp = m_vcDefStylesInfo[i];
|
||||
|
||||
String strFileName = ExtractFileName(defStyleTmp.strFileName);
|
||||
wcscpy( strCaption, strFileName.c_str() );
|
||||
|
||||
PostMessage( Handle, MSG_UPLOAD_STATE, 0, (LPARAM)strCaption );
|
||||
|
||||
WaitForSingleObject(m_hProcessEvent, INFINITE);
|
||||
|
||||
int iTmpo = 0, iTmpSig = 0;
|
||||
int iRet = f_CM_RecombineFiles( defStyleTmp.idStyle,
|
||||
((AnsiString)defStyleTmp.strFileName).c_str(),
|
||||
&iTmpo, &iTmpSig);
|
||||
defStyleTmp.tStyleInfo.detail.iTempo = iTmpo;
|
||||
defStyleTmp.tStyleInfo.detail.iTimesignature = iTmpSig;
|
||||
|
||||
SetEvent( m_hProcessEvent );
|
||||
|
||||
if( m_iOperationResult==0 && iRet==0 ){
|
||||
TMAKESTYLEINFO* pStyleInfo = &(defStyleTmp.tStyleInfo);
|
||||
|
||||
char strGBName[80];
|
||||
strcpy( strGBName, pStyleInfo->detail.strStyleName );
|
||||
|
||||
string strTmp = GBToUTF8(pStyleInfo->detail.strStyleName).c_str();
|
||||
memcpy(pStyleInfo->detail.strStyleName, strTmp.c_str(),strTmp.length());
|
||||
|
||||
strTmp = GBToUTF8(pStyleInfo->detail.strDescription).c_str();
|
||||
memcpy(pStyleInfo->detail.strDescription, strTmp.c_str(), strTmp.length());
|
||||
|
||||
strTmp = GBToUTF8(pStyleInfo->detail.strAuthor).c_str();
|
||||
memcpy(pStyleInfo->detail.strAuthor,strTmp.c_str(),strTmp.length());
|
||||
|
||||
pStyleInfo->detail.idAuthor = g_infoUser.accountInfo.ID;
|
||||
|
||||
DebugPrint("正在生成");
|
||||
int iFileLen = 1000000;
|
||||
BYTE* buff = new BYTE[iFileLen];
|
||||
int ret = f_CM_MakeStyle( defStyleTmp.idStyle, pStyleInfo, iFileLen, buff);
|
||||
|
||||
if (ret != 0) {
|
||||
char msg[160];
|
||||
sprintf( msg, "%s\n生成错误 errcode=%d", strGBName, ret );
|
||||
ShowMessage(msg);
|
||||
}
|
||||
else{
|
||||
// Get the current combine style file
|
||||
m_iCurStyleIndex = i;
|
||||
|
||||
String str = IntToStr(m_iCurStyleIndex) + L"/" +
|
||||
IntToStr(int(m_vcDefStylesInfo.size()));
|
||||
wcscpy( strCaption, str.c_str() );
|
||||
PostMessage( Handle, MSG_UPLOAD_STATE, 1, (LPARAM)strCaption );
|
||||
|
||||
m_iOperationResult =
|
||||
f_CS_UploadStyle( e_ST_Origin, g_infoUser.accountInfo.ID,
|
||||
iFileLen, buff, Handle);
|
||||
|
||||
DebugPrint("上传成功");
|
||||
}
|
||||
|
||||
delete buff;
|
||||
}
|
||||
}
|
||||
|
||||
PostMessage(Handle, MSG_OPERATE_COMPLETE, 1, 0);
|
||||
} break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void __fastcall TStylesUpProgressForm::UMUploadState(TMessage &Message)
|
||||
{
|
||||
if( m_iOperationResult==0 ){
|
||||
int iState = Message.WParam;
|
||||
wchar_t* strCaption = (wchar_t*)Message.LParam;
|
||||
|
||||
if( iState==0 ){
|
||||
DebugPrint("正在合成");
|
||||
lbProg->Caption = L"正在合成:";
|
||||
lbStyleName->Caption = strCaption;
|
||||
lbPrctStyle->Caption = L"0%";
|
||||
m_pgProgBar->Position = 0;
|
||||
}
|
||||
else{
|
||||
DebugPrint("正在上传");
|
||||
lbProg->Caption = L"正在上传:";
|
||||
lbPrctStyles->Caption = strCaption;
|
||||
m_pgProgTotalBar->Position = m_iCurStyleIndex * 100;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void __fastcall TStylesUpProgressForm::FormClose(TObject *Sender,
|
||||
TCloseAction &Action)
|
||||
{
|
||||
/* if (m_iOperation == OPERATION_STYLE_UPLOAD) {
|
||||
f_CS_CancelOperation();
|
||||
m_pThread->Terminate();
|
||||
if (m_iUpLoadFlag != 1)
|
||||
m_iOperationResult = mrCancel;
|
||||
ModalResult = mrCancel;
|
||||
}
|
||||
*/
|
||||
}
|
||||
// ---------------------------------------------------------------------------
|
||||
Reference in New Issue
Block a user