Ejemplo n.º 1
0
void __fastcall TDesignFrm::btAddSubHeadClick(TObject *Sender)
{
    String  key = vleHeadDef->Keys[vleHeadDef->Row];
    if(key == "")
    {
        ShowMessage("请先选择封包头!");
        return;
    }

    String  fileName;
    if(InputQuery("输入文件名(不加后缀)", "输入文件名(不加后缀)", fileName))
    {
        if(fileName == "")
            return;

        if(fileName.Pos("."))
            fileName = LeftString(fileName, ".");
        fileName += ".eggxp";

        WorkSpace	*  selWorkSpace = m_WorkSpaceManager->CreateNewWorkSpace();
        selWorkSpace->InitWorkSpace(m_WorkSpaceManager->GetFilePath(),
                    fileName, key);
        selWorkSpace->SaveToFile();
        m_WorkSpaceManager->ReloadWorkSpacePack();
        WorkspaceToGUI();
    }
}
Ejemplo n.º 2
0
//---------------------------------------------------------------------------
void __fastcall TForm1::CodeBtnClick(TObject *Sender)
{
  TCode Work;
  String S = "";
  // ask for code
  if (InputQuery("Usage Code Entry", "Enter the code", S)) {
    TIniFile* Ini = new TIniFile("ONGUARD.INI");
    try {
      // store the usage code in the ini file if it looks OK
      if (HexToBuffer(S, &Work, sizeof(Work))) {
        // save the value
        Ini->WriteString("Codes", "UsageCode", S);
        CodeLbl->Caption = S;

        // tell the code component to test the new code, reporting the results
        OgUsageCode1->CheckCode(true);
      }
    }
    catch (...) {
    	delete Ini;
      Ini = 0;
    }
		delete Ini;
  }
}
Ejemplo n.º 3
0
void __fastcall TMDIChild::actGoToNumExecute(TObject *Sender)
{
    String num;
    int value = 0;
    if(InputQuery("输入要转到的记录(10进制, 从0开始)", "转到记录位置", num))
    {
        value = num.ToIntDef(0);
        if(value == 0)
            return;

        int pos = m_HexEditor->SelStart;
        int curNum = 0;

        ClearListHistory();

        while(pos < m_HexEditor->DataSize)
        {
            if(curNum >= num)
                break;
            m_ParseListHistory.push(pos);
            m_ParseTree->UnPackData(pos);
            pos += m_ParseTree->GetSize();
            curNum++;
        }
        edtCurParseCount->Value = curNum;
        m_HexEditor->SelStart = pos;
        ParseData();
    }
}
Ejemplo n.º 4
0
void __fastcall TMDIChild::actColorAppendExecute(TObject *Sender)
{
    if(m_ColorAppender.GetEnableAppend())
    {
        actColorAppend->Checked = false;
        m_ColorAppender.SetEnableAppend(false);
        m_HexEditor->Repaint();
        return;
    }

    String num;
    num = "5";
    int value = 0;
    if(InputQuery("颜色扩展", "输入扩展结构体数目(10进制, 0表示所有)", num))
    {
        value = num.ToIntDef(-1);
        if(value == -1)
            return;

        char	*pointer = m_HexEditor->GetFastPointer(0, m_HexEditor->DataSize);
        m_ColorAppender.AppendColor(pointer, m_HexEditor->DataSize,
                                    m_HexEditor->SelStart, m_ParseTree, value);

        actColorAppend->Checked = true;
        m_ColorAppender.SetEnableAppend(true);
        m_HexEditor->Repaint();
    }
}
Ejemplo n.º 5
0
void __fastcall TMDIChild::actSaveFileExecute(TObject *Sender)
{
    if(m_ActiveFileStruct == NULL)
        return;

    m_ActiveFileStruct->GetMemory()->Clear();
    m_HexEditor->SaveToStream(m_ActiveFileStruct->GetMemory());

    String fileName = m_WorkSpace->GetFileName();

    if(fileName == "")
    {
        if(InputQuery("输入文件名(不要加后缀)", "输入保存的文件名(不要加后缀)", fileName))
        {
            if(fileName.Pos("."))
                fileName = LeftString(fileName, ".");
            fileName += ".eggxp";
            m_WorkSpace->SetFileName(fileName);
        }
        else
            return;
    }

    //保存工作区
//	if(m_WorkSpace->GetPath() == "")
//	{
    if(NeedSaveReq)
        NeedSaveReq();
//	}

    if(m_WorkSpace->GetComment() == "" && m_HexEditor->DataSize >= 2)
    {
        //自动生成注释
        if(m_WorkSpace->GetComment() == "")
        {
            char	*pointer = m_HexEditor->GetFastPointer(0, m_HexEditor->DataSize);
            String comment = BinToStr(pointer, 2);
            m_WorkSpace->SetComment(comment);
            if(RefreshWorkSpaceReq)
                RefreshWorkSpaceReq();
        }
    }

    if(m_WorkSpace->IsNewFile())
    {
        if(m_WorkSpace->GetPath() == "")
            return;
        m_WorkSpace->SaveToFile(fileName);
    }
    else
    {
        m_WorkSpace->SaveToFile();
    }

    DoSetTabCaption();
    m_HexEditor->Modified = false;
    m_bTreeModify = false;
    CheckModify();
}
Ejemplo n.º 6
0
wxString InputBox(wxString const & aCaption, wxString const & APrompt,
  wxString const & ADefault)
{
	wxString Value = ADefault;
	if (InputQuery(aCaption, APrompt, false, Value) == false)
		return ADefault;
	else
		return Value;
}
void __fastcall TForm1::editgridEllipsClick(TObject *Sender, int aCol,
      int aRow, AnsiString &S)
{
 char buf[32];
 TPoint pt;
 pt.x = aCol;
 pt.y = aRow;
 wvsprintf(buf,"Edit (%d:%d)",&pt);
 InputQuery(buf,"Cell value",S);
}
Ejemplo n.º 8
0
//---------------------------------------------------------------------------
void __fastcall TViewForm::TabSize1Click(TObject *Sender)
{
  String S = Viewer1->TabSize;
  if (InputQuery("Tab Size", "Enter Tab Size", S))
    try {
      Viewer1->TabSize = (Word)S.ToInt();
    }
    catch (...) {
      return;
    }
}
Ejemplo n.º 9
0
//---------------------------------------------------------------------------
void __fastcall TForm1::Add1Click(TObject *Sender)
{
  TMemoryStream* FromStream;
  AnsiString FN;
  FromStream = new TMemoryStream;
  Memo1->Lines->SaveToStream(FromStream);
  if (InputQuery("Streams", "Give it a filename", FN)) {
    Caption = FN;
    AbZipKit1->AddFromStream(FN, FromStream);
  }
  delete(FromStream);
}
void __fastcall TTimelineMainForm::Move1Click(TObject *Sender)
{
  AnsiString S;

  if( TimeLine1->Selected != NULL )
  {
    S = DateToStr(TimeLine1->Selected->Date);
    if( InputQuery("Move item", "Move to new date:", S) )
    {
      TimeLine1->Selected->Date = StrToDate(S);
    }
  }
}
Ejemplo n.º 11
0
//---------------------------------------------------------------------------
void __fastcall TPreferencesF::Sheet_NewClick(TObject *Sender)
{
    AnsiString S1="New";
    if (!InputQuery(_T("New sheet"), _T("Enter name of new sheet"), S1))
        return;

    Prefs->Create(Sheet, Ztring().From_Local(S1.c_str()));
    ComboBox_Update(Sheet_Sel, Sheet);

    //Selecting and edit
    Sheet_Sel->ItemIndex=Prefs->FilesList[Sheet].Find(Ztring().From_Local(S1.c_str()));
    Sheet_EditClick(Sender);
}
Ejemplo n.º 12
0
//---------------------------------------------------------------------------
void __fastcall TPreferencesF::Custom_NewClick(TObject *Sender)
{
    AnsiString S1=_T("New");
    if (!InputQuery(_T("New Output"), _T("Enter name of new Output"), S1))
        return;

    Prefs->Create(Custom, Ztring().From_Local(S1.c_str()));
    ComboBox_Update(Custom_Sel, Custom);

    //Selecting and edit
    Custom_Sel->ItemIndex=Prefs->FilesList[Custom].Find(Ztring().From_Local(S1.c_str()));
    Custom_EditClick(Sender);
}
Ejemplo n.º 13
0
void __fastcall TfrmCase::btnLocalitateClick(TObject *Sender)
{
UnicodeString loc;
if (InputQuery("Adaugare localitate", "Introduceti localitatea:", loc) == true){

	insertQuery->DatabaseName=frmMain->Database->DatabaseName;
	insertQuery->InsertSQL->Text = "INSERT INTO localitati \
		(den, judet) VALUES ( '"  + loc +
		"', (SELECT id from judete where den = '" + txtJudet->Text +  "'))" ;
	insertQuery->ExecSQL(ukInsert);
	txtJudetChange(Sender);
	txtLocalitate->ItemIndex=txtLocalitate->Items->IndexOf(loc);
}
void __fastcall TTimelineMainForm::Changecaption1Click(TObject *Sender)
{
 AnsiString S;

  if( TimeLine1->Selected != NULL)
  {
    S = TimeLine1->Selected->Caption;
    if( InputQuery("Change caption", "Change caption to:", S) )
    {
      TimeLine1->Selected->Caption = S;
    }
  }

}
Ejemplo n.º 15
0
//---------------------------------------------------------------------------
void __fastcall TPreferencesF::Language_NewClick(TObject *Sender)
{
    AnsiString S1="New";
    if (!InputQuery(_T("New language"), _T("Enter name of new language"), S1))
        return;

    Prefs->Create(Language, Ztring().From_Local(S1.c_str()));
    ComboBox_Update(General_Language_Sel, Language);
    ComboBox_Update(Language_Sel, Language);

    //Selecting and edit
    Language_Sel->ItemIndex=Prefs->FilesList[Language].Find(Ztring().From_Local(S1.c_str()));
    Language_EditClick(Sender);
}
void __fastcall TViewBandedDemoMainForm::miCreateBandClick(
      TObject *Sender)
{
  String BandCaption;
  if(InputQuery("Create band", "Specify a caption of the band", BandCaption))
    if(GetBandByCaption(BandCaption) != NULL)
       MessageDlg("Band with this caption already exists", mtWarning, TMsgDlgButtons() << mbOK, 0);
    else{
      TcxGridBand *ABand = btvItems->Bands->Add();
      ABand->Caption = BandCaption;
      TcxGridBandViewInfo *ABandViewInfo = 
        btvItems->ViewInfo->HeaderViewInfo->BandsViewInfo->Items[ABand->VisibleIndex];
      btvItems->Controller->LeftPos = ABandViewInfo->Bounds.Right;
    }  
}
Ejemplo n.º 17
0
void __fastcall TSQLiteForm::btnAddClick(TObject *Sender) {
	String TaskName;
	try {
		if ((InputQuery("Enter New Task", "Task", TaskName)) &&
			(!(Trim(TaskName) == ""))) {
			SQLQueryInsert->ParamByName("TaskName")->AsString = TaskName;
			SQLQueryInsert->ExecSQL();
			SQLDataSetTask->Refresh();
			LinkFillControlToField1->BindList->FillList();
		}
	}
	catch (Exception &e) {
		ShowMessage(e.Message);
	}
}
Ejemplo n.º 18
0
void __fastcall TACalInfoBox::AutoJXClick(TObject *Sender)
{
	double R, MRO;

	if( (Calc(R, AnsiString(EditSWRZ->Text).c_str()) == TRUE) && (R > 0.0) ){
		UnicodeString MTZ = R < 50 ? "50" : StrDbl(R*2);     //ja7ude 1.0
		if( InputQuery("MMANA", "整合目標のZを入力", MTZ) == TRUE ){
			if( (Calc(MRO, AnsiString(MTZ).c_str()) == TRUE) && (MRO > R) ){
				EditSWRJX->Text = StrDbl(-(sqrt((MRO/R)-1) * R));
			}
            else {
				EditSWRJX->Text = (MRO == R) ? "0":"";
            }
	    }
    }
}
Ejemplo n.º 19
0
void __fastcall TBandedDemoMainForm::miAddBandClick(TObject *Sender)
{
/* remove/add the closing slash on this line to disable/enable the following code */

  String ABandCaption;
  if (InputQuery("Create band", "Specify a caption of the band", ABandCaption))
    if (GetBandByCaption(ABandCaption) != NULL)
       MessageDlg("Band with this caption already exists", mtWarning, TMsgDlgButtons()<<mbOK, 0);
    else {
      TcxTreeListBand *ABand = cxDBTreeList->Bands->Add();
      ABand->Caption->Text = ABandCaption;
      ABand->Caption->AlignHorz = taCenter;
    }

//*/
}
Ejemplo n.º 20
0
void __fastcall TMDIChild::actDoXorExecute(TObject *Sender)
{
    //异或
    String key;
    if(InputQuery("输入Key", "输入Key", key) == false)
        return;

    int keyInt = key.ToIntDef(0);

    for(int i=0; i<m_HexEditor->DataSize; i++)
    {
        m_HexEditor->Data[i] = m_HexEditor->Data[i] ^ keyInt;
    }

    CheckModify();
    ParseData();
}
void __fastcall TTimelineMainForm::TimeLine1DragDrop(TObject *Sender,
      TObject *Source, int X, int Y)
{
  AnsiString S;

  if( (Sender == Source) && (TimeLine1->Selected != NULL ) )
  {
    S = DateToStr(TimeLine1->DateAtPos(X));

    if( InputQuery("Confirm move", Format("Move \"%s\" to new date:", OPENARRAY(TVarRec, (TimeLine1->Selected->Caption) ) ), S ) )
    {
      TimeLine1->Selected->Date  = StrToDate(S);
      TimeLine1->Selected->Level = TimeLine1->LevelAtPos(Y);
    }
  }

}
void __fastcall TTimelineMainForm::TimeLine1ItemMoved(TObject *Sender,
      TJvTimeItem *Item, TDateTime &NewStartDate, int &NewLevel)
{
 AnsiString S;

  if( TimeLine1->Dragging() )
  {
     return;
  }

  S = DateToStr(NewStartDate);
  if( !InputQuery("Confirm move", Format("Move \"%s\" to new date:", OPENARRAY(TVarRec ,(Item->Caption) ) ), S) )
  {
     NewStartDate = Item->Date;
     NewLevel     = Item->Level;
  }
}
Ejemplo n.º 23
0
//---------------------------------------------------------------------------
void __fastcall TForm1::OgUsageCode2Checked(TObject *Sender, TCodeStatus Status)
{
  String S;
  TCode Code;
  switch (Status) {
    case ogValidCode : {
    	Label1->Caption = "Available Runs: "
                       + String((int)OgUsageCode2->GetValue());
      return;
    }
    case ogRunCountUsed : S = "No more runs allowed\r\n"
                              "    Register NOW    "; break;
    case ogInvalidCode  : {
      if (!FileExists(TheDir + "Usage2.INI")) {
        S = "";
        if (InputQuery("Call Vendor NOW", "Code", S)) {
          if (HexToBuffer(S, &Code, sizeof(Code))) {
            IniFile = new TIniFile(TheDir + "Usage2.ini");
            try {
              IniFile->WriteString("Codes", "Uses", S);
            }
            catch (...) {
              delete IniFile;
              IniFile = 0;
            }
            delete IniFile;
            OgUsageCode2->CheckCode(true);
            return;
          }
          else
            S = "Invalid Code entered";
        }
        else
          S = "No Code entered";
      }
      else
        S = "Invalid Code";
     	break;
    }
    case ogCodeExpired  : S = "Trial Run period expired\r\n"
                              "      Register NOW      ";
  }
  ShowMessage(S);
  Application->Terminate();
}
Ejemplo n.º 24
0
//---------------------------------------------------------------------------
void __fastcall TViewForm::GotoLine1Click(TObject *Sender)
{
  String S;
  TOvcTextPos GoPos;

  S = "";
  char buff[30];
  sprintf(buff, "Enter Line Number (1 to %d)", Viewer1->LineCount);
  if (InputQuery("Go to Line Number", buff, S))
    try {
      GoPos.Line = S.ToInt() - 1;
    }
    catch (...) {
      return;
    }
    GoPos.Col = 0;
    Viewer1->CaretActualPos = GoPos;
}
Ejemplo n.º 25
0
//---------------------------------------------------------------------------
void __fastcall TFormMenu::ImageStartTestClick(TObject *Sender)
{
//  //Ask name
  String username_Vcl = "";
  const bool inputGiven = InputQuery(
    "Hometrainer2",
    "Please enter your full name",
    username_Vcl);
  if (!inputGiven) return;

  const std::string username = username_Vcl.c_str();

  SaveDialog1->FileName = String(username.c_str()) + ".txt";
  if (!SaveDialog1->Execute()) return;
  const std::string path = GetPath(SaveDialog1->FileName.c_str());
  const std::string filename = path + "\\" + username + ".txt";


  assert(m_questions.empty() == false);
  boost::shared_ptr<TFormMain> f(new TFormMain(0,m_questions,true,m_key,username,filename));
  f->ShowModal();
}
Ejemplo n.º 26
0
void __fastcall TDesignFrm::btAddHeadDefClick(TObject *Sender)
{
    String  key;
    if(InputQuery("输入标识头(2个字节以内)", "输入标识头(2个字节以内)", key))
    {
        if(key == "")
            return;
        key = key.SubString(1, 2);

        for(int i=0; i<m_WorkSpaceManager->GetWorkSpacePacks()->GetWorkPacks()->Count(); i++)
        {
            if(key == m_WorkSpaceManager->GetWorkSpacePacks()->GetWorkPacks()->At(i)->m_Head)
            {
                ShowMessage(FormatStr("已经有头定义 : %s", key));
                return;
            }
        }

        vleHeadDef->InsertRow(key, "", true);
        vleHeadDef->Row = vleHeadDef->RowCount-1;
        btAddSubHeadClick(Sender);
        SaveAndRefreshClickHead();
    }
}
Ejemplo n.º 27
0
void __fastcall TFormMain::FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift)
{
  TRect R = RectNormalize(&Selection);
  unsigned tx = MAX(ListView->ItemIndex,0);

  //ShowMessage(Key);
  switch (Key)
  {
    case 221: {APPLY(cell->bot += 64) Key = 1; break;}
    case 219: {APPLY(cell->bot -= 64) Key = 1; break;}
    //case  36: {APPLY(cell->mid += 64) Key = 1; break;}
    //case  35: {APPLY(cell->mid -= 64) Key = 1; break;}
    case 'P': {APPLY(cell->top += 64) Key = 1; break;}
    case 'O': {APPLY(cell->top -= 64) Key = 1; break;}
    case 'L': {APPLY(cell->swi ^= CELL_SWI_LIGHT) Key = 1; break;}

    case  45: {if(tc)tx=(tx-1)%YETI_TEXTURE_MAX;APPLY(cell->btx=tx);Key=1;break;}
    case  46: {if(tc)tx=(tx+1)%YETI_TEXTURE_MAX;APPLY(cell->btx=tx);Key=1;break;}
    case  36: {if(tc)tx=(tx-1)%YETI_TEXTURE_MAX;APPLY(cell->wtx=tx);Key=1;break;}
    case  35: {if(tc)tx=(tx+1)%YETI_TEXTURE_MAX;APPLY(cell->wtx=tx);Key=1;break;}
    case  33: {if(tc)tx=(tx-1)%YETI_TEXTURE_MAX;APPLY(cell->ttx=tx);Key=1;break;}
    case  34: {if(tc)tx=(tx+1)%YETI_TEXTURE_MAX;APPLY(cell->ttx=tx);Key=1;break;}

    case 'F': {APPLY(cell_block(cell, true )); Key = 1; break;}
    case 'G': {APPLY(cell_block(cell, false)); Key = 1; break;}
    case 'E':
    {
      String Value = yeti->cells[R.top][R.left].ent;
      if (InputQuery("", "Enter Entity ID (0..255):", Value))
      {
        int ent = Value.ToIntDef(0);
        APPLY(cell->ent = ent);
        Key = 1;
      }
      break;
    }
    case  VK_LEFT     : {yeti->keyboard.left  = true; Key = 0; break;}
    case  VK_UP       : {yeti->keyboard.up    = true; Key = 0; break;}
    case  VK_RIGHT    : {yeti->keyboard.right = true; Key = 0; break;}
    case  VK_DOWN     : {yeti->keyboard.down  = true; Key = 0; break;}
    case  VK_CONTROL  : {yeti->keyboard.a     = true; Key = 0; break;}
    case  ' '         : {yeti->keyboard.b     = true; Key = 0; break;}
    case  'A'         : {yeti->keyboard.l     = true; Key = 0; break;}
    case  'Z'         : {yeti->keyboard.r     = true; Key = 0; break;}

    default:
    {
      //ShowMessage(Key);
    }
  }
  
  if (Key == 1)
  {
    Key = 0;
    yeti_default_lighting(yeti);
    PaintBoxPaint(PaintBox);
    FormPreview->TimerTimer(FormPreview->Timer);
    Modified = true;
    ListView->ItemIndex = tx;
    ListView->Selected->MakeVisible(False);
    tc = true;
  }
}
Ejemplo n.º 28
0
void			TMDIChild::ChangeNodeName(ParseTreeNode * curParseTree, bool needRefresh, int changeType)
{
    ClassData	*	curClass = GetCurParseClass();
    if(curClass == NULL)
        return;

    String showName;
    if(changeType == 0)
    {
        showName = "输入新名称";
    }
    else
    {
        showName = "输入新注释";
    }

    String name;
    int haveResult = 0;
    if(curParseTree == NULL)
    {
        //选择的是结构体
        if(changeType==0)
        {
            name = curClass->GetName();
        }
        else
        {
            name = curClass->GetComment();
        }
        if(InputQuery(showName, showName, name))
        {
            haveResult = 1;
            if(changeType==0)
            {
                curClass->SetName(name);
            }
            else
            {
                curClass->SetComment(name);
            }
        }
    }
    else
    {
        //选择的是变量
        String curName;
        if(changeType==0)
        {
            curName = curParseTree->GetClassMember()->GetName();
        }
        else
        {
            curName = curParseTree->GetClassMember()->GetComment();
        }

        if(curName.Pos("["))
        {
            //是数组中的一个
            ParseTreeNode * parent = curParseTree->GetParent();
            ChangeNodeName(parent, false);
            parent->SetExNodeName();
            haveResult = 1;
        }
        else
        {
            ClassMember * curModifyMember = NULL;
            for(int i=0; i<curClass->GetMemberDataCount(); i++)
            {
                if((IClassMember *)curClass->GetMemberData(i) == curParseTree->GetClassMember())
                {
                    curModifyMember = curClass->GetMemberByIndex(i);
                }
            }
            if(curModifyMember)
            {
                if(changeType==0)
                {
                    name = curModifyMember->GetName();
                }
                else
                {
                    name = curModifyMember->GetComment();
                }
                if(InputQuery(showName, showName, name))
                {
                    haveResult = 1;
                    if(changeType==0)
                    {
                        curModifyMember->SetName(name);
                    }
                    else
                    {
                        curModifyMember->SetComment(name);
                    }
                    curParseTree->SetExNodeName();
                }
            }
        }
    }

    if(haveResult && needRefresh)
    {
        RefreshAllClassView();
        m_ParseTree->RefreshViewText();
    }
}
Ejemplo n.º 29
0
void __fastcall TMDIChild::actWriteExecute(TObject *Sender)
{
    if(tvParseTree->Selected == NULL)
        return;

    ParseTreeNode	*	curParseTree = (ParseTreeNode	*)tvParseTree->Selected->Data;

    if(curParseTree == NULL)
    {
        return;
    }

    ClassData	*	curClass = GetCurParseClass();
    if(curClass == NULL)
        return;

    tagSelRect	selRect;
    if(GetTreeSelRect(selRect) == false)
        return;

    String  type = curParseTree->GetClassMember()->GetType();
    if(IsNormalType(type) == false)
    {
        ShowMessage("只能改变普通变量的值");
        return;
    }

    String  value = curParseTree->GetParseResult();
    if(InputQuery("输入值", "输入值", value) == false)
        return;

//    m_HexEditor->BeginUpdate();
    char	*pointer = m_HexEditor->GetFastPointer(0, m_HexEditor->DataSize);
    int dataSize = m_HexEditor->DataSize;
    int pos = selRect.SelStart;
    int nodeSize = m_ParseEngine->GetSize(type, pointer, dataSize, pos);
    int childCount = curParseTree->GetClassMember()->GetArrayVar().ToIntDef(0);

    int curSize = 0;
    for(int i=0; i<m_ParseTree->GetParseTreeNodeCount(); i++)
    {
        ParseTreeNode	* curTreeNode = m_ParseTree->GetParseTreeNode(i);
        if(curTreeNode == curParseTree)
            break;

        int curChildCount = curTreeNode->GetClassMember()->GetArrayVar().ToIntDef(0);
        if(curChildCount == 0)
            curChildCount = 1;
        curSize += curChildCount * m_ParseEngine->GetSize(
                       curTreeNode->GetClassMember()->GetType(), pointer, dataSize, pos);
    }

    pos = m_LastPos + curSize;
    if(childCount == 0)
        childCount = 1;
    nodeSize *= childCount;


    //插入数据
    if(pos + nodeSize > dataSize)
    {
        String  buffer;
        buffer.SetLength(pos + nodeSize - dataSize);
        memset(buffer.c_str(), '\0', buffer.Length());
        m_HexEditor->InsertBuffer(AnsiString(buffer).c_str(), buffer.Length(), selRect.SelStart, "insert", false);
    }


    pointer = m_HexEditor->GetFastPointer(0, m_HexEditor->DataSize);
//	String  setEmpty;
//	setEmpty.SetLength(nodeSize);
//    int oldPos = pos;
//	WriteBuf(pointer, oldPos, setEmpty.c_str(), setEmpty.Length());

    if(type == "char")
    {
        WriteBuf(pointer, pos, value.c_str(), value.Length());
    }
    else
    {
        int iResult = value.ToIntDef(0);
        WriteBuf(pointer, pos, &iResult, sizeof(iResult));
    }
    m_HexEditor->SelStart = m_LastPos;
    ParseData(false);
//    m_HexEditor->EndUpdate();
}
Ejemplo n.º 30
0
void __fastcall TFormMenu::ImageLoadTestClick(TObject *Sender)
{
  //Ask for file
  if (!OpenDialog->Execute()) return;

  //Ask for key
  String userInput = "0";
  const bool inputGiven = InputQuery(
    "Hometrainer 2", //The caption of the InputBox
    "What is the encryption key?",
    userInput);

  if (!inputGiven) return;

  const int key_user = userInput.ToInt();

  boost::shared_ptr<TStringList> s(new TStringList);
  s->LoadFromFile(OpenDialog->FileName);

  const std::string path = GetPath(OpenDialog->FileName.c_str());

  if (s->Count == 0)
  {
    MessageDlg("File is empty and cannot be used",
      mtError,
      TMsgDlgButtons() << mbOK,
      0);
    return;
  }
  if (s->Count == 1)
  {
    MessageDlg("File has only one line and thus cannot be used",
      mtError,
      TMsgDlgButtons() << mbOK,
      0);
    return;
  }

  //Deencrypt file
  {
    //Need of new TStringList, because TStringList::operator[]()
    //does not seem to support writing, use TStringList::Add() instead
    boost::shared_ptr<TStringList> s_new(new TStringList);

    Encranger e(key_user);
    const int sz = s->Count;
    for (int i=0; i!=sz; ++i)
    {
      const String s1 = s->operator [](i).c_str();
      const String s2 = e.Deencrypt(s1.c_str()).c_str();
      s_new->Add(s2);
    }
    //Overwrite old TStringList
    s = s_new;
  }

  if (s->Count > 1 && s->operator [](0) != signature)
  {
    //ShowMessage(s->operator [](0));
    MessageDlg("Incorrect key given, therefore test is not loaded.",
      mtError,
      TMsgDlgButtons() << mbOK,
      0);
    return;
  }

  //Parsing the questions
  m_questions.clear();
  assert(m_questions.empty() == true);

  const int sz = s->Count;
  for (int i=1; i!=sz; ++i) //1, because first line is signature
  {
    const std::string str_to_split_original = s->operator [](i).c_str();
    if (str_to_split_original.empty() == true) continue;

    //Replace \, by {comma}
    const std::string str_to_split = ReplaceAll(str_to_split_original,"\\,","{comma}");

    const std::string debug_output = "MyDebug:" + str_to_split;
    OutputDebugString(debug_output.c_str());
    const std::vector<std::string> v_original = SeperateString(str_to_split,",");

    //Replace {comma} by a comma for each std::string in v
    const std::vector<std::string> v = ReplaceAll(v_original,"{comma}",",");

    if (v.empty()==true) continue;

    const std::string& filename = path + '\\' + v[0];
    const std::string& question = v[1];
    const std::string& answer   = v[2];
    const std::vector<std::string> false_answers(&v[3],v.end());

    if (false_answers.empty())
    {
      //Open question
      const std::vector<std::string> answers(SeperateString(answer,"/"));
      boost::shared_ptr<Question> q(
        new OpenQuestion(filename,question,answers));
      m_questions.push_back(q);
    }
    else
    {
      //Multiple choice question
      boost::shared_ptr<Question> q(
        new MultipleChoiceQuestion(filename,question,answer,false_answers));
      m_questions.push_back(q);
    }
  }


  if (m_questions.empty() == false)
  {
    m_key = key_user;
    ImageStartTest->Visible = true;
  }
}