Example #1
1
// fires an event when a file, or files are dropped onto the application.
void __fastcall TForm1::WMDropFiles(TWMDropFiles &message)
{ AnsiString FileName;
  FileName.SetLength(MAX_PATH);
  FileName.SetLength(DragQueryFile((HDROP)message.Drop, 0,FileName.c_str(), MAX_PATH));

  if(UpperCase(ExtractFileExt(FileName)) == ".BMP")
  {   bmp->LoadFromFile(FileName) ;
      img->Picture->Bitmap->Assign(bmp) ;
  } else if(UpperCase(ExtractFileExt(FileName)) == ".JPG")
         {   TJPEGImage * jpeg = new TJPEGImage();
             jpeg->LoadFromFile(FileName);
             jpeg->DIBNeeded();   
             bmp->Assign(jpeg);
             img->Picture->Bitmap->Assign(bmp) ;
             delete jpeg;
         }
  preview->frmSelect->Position = 0 ;
  outType->ItemIndex = 1 ;
  if(preview->Visible) updatePreview();
  int l = bmp->Width, h = bmp->Height ;
  transType->ItemIndex = 0 ;
  //preview->TransparentColor = 0 ;
  // auto compute frame number and frameset way
   if(l < 142 || h < 142)
    {  
       int s ; int yyop ; int *v=&h, *vh=&l ;
       if(l > h*2) { v=&l ; vh=&h ; vertical=0 ; } // horizontal frameset
       else vertical = 1 ;
       flipWay->Checked = !vertical ;
       s = *vh + 3 ;
       do { yyop = (*v)/s ; } while(s && yyop*s-- != *v) ; ++s ;
       if(s < 4)
       {  frmNb->Text = 1 ;
          sprintf(msg,"frames of %i*%i",l,h) ;
          LabelSize->Caption = msg ; fsx = l ; fsy = h ;
       }
       else {nb = yyop ; fsx = s ; fsy = *vh ;
             frmNb->Text = yyop ;
             sprintf(msg,"frames of %i*%i",s,*vh) ;
             LabelSize->Caption = msg ;
       }
    } else { frmNb->Text = 1 ;
             sprintf(msg,"frames of %i*%i",l,h) ;
             LabelSize->Caption = msg ;
             nb=1 ;
           }
  preview->ClientHeight = h ;
  preview->ClientWidth  = l + (nb > 1)*15 ;
  preview->Caption      = FileName + " (" + nb + ")" ;
  fname = FileName ;
  outTypeChange((TObject*)42) ;
  Form1->Button1->Enabled = 1 ;
  Form1->Height = 304 ;
  Form1->StatusBar->Visible = 1 ;
  // tell the OS that you're finished...
  DragFinish((HDROP) message.Drop);
}
Example #2
0
//---------------------------------------------------------------------------
void __fastcall TTableForm::SpeedButton3Click(TObject *Sender)
{
	Form1->m_Descr.Clear();
   AnsiString str =  ChangeFileExt(Form1->m_strFileName, ".xml");
   Form1->m_Descr.SaveXML(str.c_str());
	Form1->FImage1->Init(Form1->m_strFileName, NULL);
    Form1->FImage1->BestFit();
    this->ListView1->Clear();
}
Example #3
0
void WriteToLog(String S) {
	HANDLE LogFile;
	String LogPath;
	String LogFileName;
	DWORD dwSize;
	AnsiString SS;
	TDateTime DateTime;
	LPDWORD NumberOfBytesWritten = new DWORD;

	try { // except
		DateTime = Now();

		LogPath = ExtractFilePath(Application->ExeName) + LoadStr(IDS_LOG_PATH);
		if (!DirectoryExists(LogPath))
			CreateDir(LogPath);

		LogFileName = IncludeTrailingPathDelimiter(LogPath) +
			ChangeFileExt(ExtractFileName(Application->ExeName),
			LoadStr(IDS_LOG_EXT));

		LogFile = CreateFile(LogFileName.w_str(), GENERIC_READ, FILE_SHARE_READ,
			NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);

		dwSize = 0;
		if (LogFile != INVALID_HANDLE_VALUE) {
			dwSize = GetFileSize(LogFile, NULL);
			CloseHandle(LogFile);
		}

		if (dwSize > MaxLogSize) {
			String NewFileName = IncludeTrailingPathDelimiter(LogPath) +
				OnlyFileName(Application->ExeName) + SPACE + FormatDateTime
				(LoadStr(IDS_DATETIME_FORMAT_FILENAME), DateTime) +
				LoadStr(IDS_LOG_EXT);
			MoveFile(LogFileName.w_str(), NewFileName.w_str());
		}

		LogFile = CreateFile(LogFileName.w_str(), GENERIC_WRITE,
			FILE_SHARE_READ, NULL, OPEN_ALWAYS,
			FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_COMPRESSED, 0);

		if (LogFile != INVALID_HANDLE_VALUE) {
			SS = AnsiString(FormatDateTime(LoadStr(IDS_DATETIME_FORMAT_LOG),
				DateTime) + "; " + AnsiReplaceStr(S, sLineBreak, SPACE) +
				sLineBreak);

			if (SetFilePointer(LogFile, 0, NULL,
				FILE_END) != INVALID_SET_FILE_POINTER)
				WriteFile(LogFile, SS.c_str(), SS.Length(),
				NumberOfBytesWritten, NULL);

			CloseHandle(LogFile);
		}
	}
	catch (...) {
	}
}
Example #4
0
//---------------------------------------------------------------------------
void __fastcall TTableForm::SpeedButton2Click(TObject *Sender)
{
   Form1->m_Descr.DeleteDetectedItem(Form1->SelectedIndex);
   AnsiString str =  ChangeFileExt(Form1->m_strFileName, ".xml");
   Form1->m_Descr.SaveXML(str.c_str());
   Form1->FImage1->Init(Form1->m_strFileName, NULL);
   Form1->FImage1->BestFit();
   ListView1->DeleteSelected();
}
Example #5
0
__fastcall TFrmAlarmDetailList::TFrmAlarmDetailList(TComponent* Owner)
	: TForm(Owner)
{        
	_nOldErrCode = 0;
	_nTableIndex = 0;

	AnsiString szQuery = "SELECT * FROM Alarm";

	dbMain.open( AnsiString( g_MainDBPath ).c_str() );
	tblAlarm = dbMain.getTable( szQuery.c_str() );
	_nMaxAlarmCnt = tblAlarm.numRows();

	szQuery = "SELECT * FROM Warning";

	dbMain.open( AnsiString( g_MainDBPath ).c_str() );
	tblWarning = dbMain.getTable( szQuery.c_str() );
	_nMaxAlarmCnt = tblAlarm.numRows();
}
Example #6
0
void __fastcall TForm1::mnuConnectClick(TObject *Sender)
{
    if(lvList->Selected == NULL)
        return;
    AnsiString sCmd;
    sCmd = "mstsc.exe /v:"+ lvList->Selected->SubItems->Strings[1]+
        ":"+lvList->Selected->SubItems->Strings[2];
    WinExec(sCmd.c_str(),SW_SHOW);
}
Example #7
0
void __fastcall TFrmAlarmDetailList::BtnAlarmEditSaveClick(TObject *Sender)
{
	bSaveChkFlag = false;
	SaveErrorDatas(lblAlarmCode->Caption.ToInt());

	AnsiString szQuery = "SELECT * FROM " + g_szDBList[_nTableIndex];
	tblAlarm = dbMain.getTable( szQuery.c_str() );
	_nMaxAlarmCnt = tblAlarm.numRows();
}
Example #8
0
//---------------------------------------------------------------------------
void __fastcall TClientForm::SendButtonClick(TObject *Sender)
{
    AnsiString Buf;

    Buf = DataEdit->Text + "\r\n";
    Socket->Send(Buf.c_str(), Buf.Length());
    DataEdit->Text = "";
    ActiveControl  = DataEdit;
}
Example #9
0
void __fastcall TForm1::mnuFTPClick(TObject *Sender)
{
    if(lvList->Selected == NULL)
        return;
    AnsiString sCmd;
    sCmd = "ftp.exe "+ lvList->Selected->SubItems->Strings[1];
    WinExec(sCmd.c_str(),SW_SHOW);

}
Example #10
0
LPCSTR _GetItem(LPCSTR src, int index, AnsiString& dst, char separator, LPCSTR def, bool trim)
{
    LPCSTR ptr;
    ptr = _SetPos(src, index, separator);
    if (ptr) _CopyVal(ptr, dst, separator);
    else dst = def;
    if (trim) dst = dst.Trim();
    return dst.c_str();
}
Example #11
0
bool TMeasurementColorHistory::Edit(AnsiString& strId, AnsiString& strValue)
{
	TiXmlElement* e = Find(strId);
	if (e)
	{
		e->SetAttribute("descr", strValue.c_str());
	}
	return true;
}
void __fastcall TfrmMainFormServer::DeltaCopyHelp1Click(TObject *Sender)
{
    AnsiString helpFileName = ExtractFilePath(Application->ExeName) + "\\DeltaCopy.chm";

    ShellExecute(Handle,
                 "open",
                 helpFileName.c_str(),
                 NULL, NULL, SW_SHOWDEFAULT);    
}
Example #13
0
AnsiString CFolderHelper::GetObjectName(const AnsiString& full_name, AnsiString& dest)
{
    for (int i=full_name.Length(); i>=1; i--)
    	if (full_name[i]=='\\'){
        	dest=full_name.SubString(i+1,full_name.Length());
            break;
        }
    return dest.c_str();
}
Example #14
0
void TItemList::LoadSelection(TFormStorage* storage)
{
	last_selected_items.clear();
    int cnt 			= storage->ReadInteger("sel_cnt",0);
    for (int k=0; k<cnt;k++){
    	AnsiString tmp = storage->ReadString(AnsiString().sprintf("sel%d",k),"");
        if (!tmp.IsEmpty())last_selected_items.push_back(tmp.c_str());
    }
}
Example #15
0
bool __fastcall TEntryForm::InValidChar(AnsiString label, TEditPlus *edit)
{
  if (edit->Text.Length() > 0)
    return false;
  AnsiString msg = "The field "+label+" contains the value '"+edit->Text+"'."
                  +" This is invalid for a non null char field.";
  Application->MessageBox(msg.c_str(), "Invalid Char", ID_OK);
  return true;
}
Example #16
0
void __fastcall TMainForm::BookComboBoxDrawItem(TWinControl *Control, int Index,
      TRect &Rect, TOwnerDrawState State)
{
	TComboBox *c = (TComboBox*)Control;
	TRect rect, r;
	AnsiString s;
	HDC dc;
	HFONT font1, font2;
	HGDIOBJ old;
	TBook *b;

	b = (TBook*)(c->Items->Objects[Index]);
	r = rect = Rect;
//	dc = GetDC(Control->Handle);
	c->Canvas->FillRect(rect);

	dc = c->Canvas->Handle;
	font1 = CreateFontA(Font->Height, 0, 0, 0, 0, 0u, 0u, 0u, RUSSIAN_CHARSET, 0u, 0u, 0u, 0u, TEXT("Tahoma"));
	font2 = CreateFontA(Font->Height, 0, 0, 0, 0, 1u, 0u, 0u, RUSSIAN_CHARSET, 0u, 0u, 0u, 0u, TEXT("Tahoma"));
//
	old = SelectObject(dc, font1);
	SetTextColor(dc, 0x00000000);

	rect = r;
	rect.Bottom -= 14;
	rect.left += 2;
//	SetBkMode(dc, TRANSPARENT);
	s = b->BookName;
	DrawTextA(dc, s.c_str(), s.Length(), &rect, DT_LEFT);

	rect = r;
	rect.Top += 14;
	rect.left += 10;
//    rect.bottom -= 2;
	SelectObject(dc, font2);
//	SetTextColor(dc, 0x0000ff00);
	s = b->BookAuthor;
	DrawTextA(dc, s.c_str(), s.Length(), &rect, DT_LEFT);

	SelectObject(dc, old);
//	ReleaseDC(c->Canvas, dc);
	DeleteObject(font1);
	DeleteObject(font2);
}
Example #17
0
//---------------------------------------------------------------------------
void __fastcall TMainForm::LoadFromFile(const AnsiString FileName)
{
  std::ifstream in_file(FileName.c_str());
  if (!in_file)
  {
    ShowError("File cannot be opened!");
    return;
  }
  switch (FileName[FileName.Length()])
  {
    case 'm':
    case 'M':
    in_file >> rows >> cols >> lyrs;
    if (rows > MAX_DIM || cols > MAX_DIM || lyrs > MAX_DIM)
    {
      ShowError(("An array dimension cannot be more than " +
        IntToStr(MAX_DIM)).c_str());
      return;
    }
    pgcProblems->ActivePage = tbsMatrix;
    udwRows->Position = rows;
    udwColumns->Position = cols;
    udwLayers->Position = lyrs;
    udwLayer->Position = 1;
    for (int k = 0; k < lyrs; k++)
      for (int i = 0; i < rows; i++)
        for (int j = 0; j < cols; j++)
          in_file >> a[i][j][k];
    ShowMatrix();
    break;
    case 'l':
    case 'L':
    pgcProblems->ActivePage = tbsStudents;
    std::string tmps;
    StudList->Items->BeginUpdate();
    StudList->Clear();
    for (;;)
    {
      using std::getline;
      getline(in_file, tmps);
      if (!(tmps.length() && in_file)) goto ready;
      TListItem *Item = StudList->Items->Add();
      Item->Caption = tmps.c_str();
      for (int i = 0; i < 8; i++)
      {
        getline(in_file, tmps);
        Item->SubItems->Add(tmps.c_str());
      }
      while (in_file.get() != '\n')
        if (!in_file) goto ready;
    }
    ready:
    StudList->Items->EndUpdate();
    break;
  }
}
Example #18
0
AnsiString __fastcall TFTPFile::GetPort(AnsiString ServerString)
{
  int pos = ServerString.LowerCase().Pos("ftp://");
  if(pos < 1)
    return "";
  ServerString = ServerString.SubString(pos + 6,ServerString.Length() - pos);
  pos = StrLScan(ServerString.c_str(),"@");
  if(pos < 0)
    return "";
  ServerString = ServerString.SubString(pos + 2,ServerString.Length() - pos - 1);
  pos = StrLScan(ServerString.c_str(),":");
  if(pos < 0)
    return "";
  ServerString = ServerString.SubString(pos + 2,ServerString.Length() - pos - 1);
  pos = StrLScan(ServerString.c_str(),"/");
  if(pos < 0)
    return "";
  return ServerString.SubString(1,pos);
}
Example #19
0
//---------------------------------------------------------------------------
void __fastcall TPrnCompareFactoryForm::pd_codePrint(TObject *sender,
      AnsiString &Value)
{
	char strItem[80];
  strcpy(strItem,Value.c_str());
  if(strItem[0]!='\0')
	{
  	Value = strItem+strlen(strItem)-1;
  }
}
Example #20
0
void TClipMaker::SelectClip(CUIClip* clip)
{
	if (sel_clip!=clip){
        AnsiString nm	= clip?*clip->name:"";
        sel_clip		= clip;
        m_ClipList->SelectItem(nm.c_str(),true,false,true);
        RepaintClips	();
        UpdateProperties();
    }
}
Example #21
0
bool __fastcall TFTPFile::GetPasv(AnsiString ServerString)
{
  int pos = ServerString.LowerCase().Pos("ftp://");
  if(pos < 1)
    return false;
  pos = StrLScan(ServerString.c_str(),"|");
  if(pos < 0)
    return false;
  return ServerString.SubString(pos + 2,ServerString.Length() - pos - 1).UpperCase() == "PASV";
}
Example #22
0
void PuttyInitialize()
{
  SaveRandomSeed = true;

  // make sure random generator is initialised, so random_save_seed()
  // in destructor can proceed
  random_ref();

  flags = FLAG_VERBOSE/* | FLAG_SYNCAGENT*/; // verbose log

  sk_init();

  AnsiString VersionString = AnsiString(GetSshVersionString());
  DebugAssert(!VersionString.IsEmpty() && (static_cast<size_t>(VersionString.Length()) < _countof(sshver)));
  strncpy(sshver, VersionString.c_str(), sizeof(sshver));
  AnsiString AppName = AnsiString(GetAppNameString());
  DebugAssert(!AppName.IsEmpty() && (static_cast<size_t>(AppName.Length()) < _countof(appname_)));
  strncpy(appname_, AppName.c_str(), sizeof(appname_));
}
Example #23
0
TPrivateKey * LoadKey(TKeyType KeyType, const UnicodeString & FileName, const UnicodeString & Passphrase)
{
  UTF8String UtfFileName = UTF8String(::ExpandEnvironmentVariables(FileName));
  Filename * KeyFile = filename_from_str(UtfFileName.c_str());
  AnsiString AnsiPassphrase = AnsiString(Passphrase);
  struct ssh2_userkey * Ssh2Key = nullptr;
  const char * ErrorStr = nullptr;

  switch (KeyType)
  {
    case ktSSH2:
      Ssh2Key = ssh2_load_userkey(KeyFile, (char *)AnsiPassphrase.c_str(), &ErrorStr);
      break;

    case ktOpenSSHPEM:
    case ktOpenSSHNew:
    case ktSSHCom:
      Ssh2Key = import_ssh2(KeyFile, KeyType, (char *)AnsiPassphrase.c_str(), &ErrorStr);
      break;

    default:
      DebugFail();
      break;
  }

  Shred(AnsiPassphrase);

  if (Ssh2Key == nullptr)
  {
    UnicodeString Error = UnicodeString(ErrorStr);
    // While theoretically we may get "unable to open key file" and
    // so we should check system error code,
    // we actully never get here unless we call KeyType previously
    // and handle ktUnopenable accordingly.
    throw Exception(Error);
  }
  else if (Ssh2Key == SSH2_WRONG_PASSPHRASE)
  {
    throw Exception(LoadStr(AUTH_TRANSL_WRONG_PASSPHRASE));
  }

  return reinterpret_cast<TPrivateKey *>(Ssh2Key);
}
Example #24
0
// ---------------------------------------------------------------------------
// 检测正则表达式条件是否符合报警
// 0 - 无报警
int TForm1::detectAlert(AnsiString & msg, RegExEntryList& filter) {
	int n;
	for (n = 0; n < filter.size(); n++) {
		regex e(filter[n].exs.c_str());
		if (regex_search(msg.c_str(), e)) {
			return 1;
		}
	}
	return 0;
}
Example #25
0
void SSceneSummary::STextureInfo::FillProp	(PropItemVec& items, LPCSTR main_pref, u32& mem_use)
{
	if (file_name.size()){
        int tex_mem			= info.MemoryUsage(*file_name);
        mem_use				+= tex_mem;
        AnsiString pref		= PrepareKey(AnsiString(main_pref).c_str(),*file_name).c_str();
        PropValue* V=0;
        V=PHelper().CreateChoose(items,PrepareKey(pref.c_str(),"Texture"), 		&file_name, smTexture); V->Owner()->Enable(FALSE);
        PHelper().CreateCaption(items,PrepareKey(pref.c_str(),"Format"),		info.FormatString());
        PHelper().CreateCaption(items,PrepareKey(pref.c_str(),"Size"), 			shared_str().printf("%d x %d x %s",info.width,info.height,info.HasAlpha()?"32b":"24b"));
        PHelper().CreateCaption(items,PrepareKey(pref.c_str(),"Memory Usage"),	shared_str().printf("%d Kb",iFloor(tex_mem/1024)));
        PHelper().CreateCaption(items,PrepareKey(pref.c_str(),"Effective Area"),shared_str().printf("%3.2f m^2",effective_area));
        PHelper().CreateCaption(items,PrepareKey(pref.c_str(),"Pixel Density"),	shared_str().printf("%3.2f p/m",_sqrt((pixel_area*info.width*info.height)/effective_area)));
/*
//. убрал из-за кол-ва > 4096 
        AnsiString tmp 		= "on demand";
        for (objinf_map_it o_it=objects.begin(); o_it!=objects.end(); o_it++){
        	tmp += AnsiString().sprintf("%s%s[%d*%3.2f]",tmp.Length()?"; ":"",o_it->first.c_str(),o_it->second.ref_count,o_it->second.area);
        }
        PHelper().CreateCaption(items,PrepareKey(pref.c_str(),"Objects"), tmp.c_str());
*/
        if (info.flags.is_any(STextureParams::flDiffuseDetail|STextureParams::flBumpDetail)){
            if (0!=info.detail_name.size()){
                V=PHelper().CreateChoose(items,PrepareKey(pref.c_str(),"Detail Texture"),	&info.detail_name,smTexture); 	V->Owner()->Enable(FALSE);
                PHelper().CreateCaption(items,PrepareKey(pref.c_str(), "Detail Scale"),		shared_str().printf("%3.2f",info.detail_scale));
            }else{
                PHelper().CreateCaption(items,PrepareKey(pref.c_str(), "Detail Texture"),	"INVALID");
                ELog.Msg(mtError,"Empty details on texture: '%s'",*file_name);
            }
        }
        if (info.bump_mode==STextureParams::tbmUse){
            if (0!=info.bump_name.size()){
                V=PHelper().CreateChoose(items,PrepareKey(pref.c_str(),"Bump Texture"),		&info.bump_name,smTexture); 	V->Owner()->Enable(FALSE);
            }else{
                PHelper().CreateCaption(items,PrepareKey(pref.c_str(), "Bump Texture"),		"INVALID");    
                ELog.Msg(mtError,"Empty bump on texture: '%s'",*file_name);
            }
        }
        ButtonValue* B 		= PHelper().CreateButton(items,PrepareKey(pref.c_str(),"Highlight Texture"), "Select,Density =,Density +,Clear", 0);
		B->OnBtnClickEvent.bind(this,&SSceneSummary::STextureInfo::OnHighlightClick);
        B->tag 				= (int)(*file_name);
    }
}
Example #26
0
LPCSTR _CopyVal(LPCSTR src, AnsiString& dst, char separator)
{
    LPCSTR p;
    u32 n;
    p = strchr(src, separator);
    n = (p > 0) ? (p - src) : xr_strlen(src);
    dst = src;
    dst = dst.Delete(n + 1, dst.Length());
    return dst.c_str();
}
Example #27
0
// save history to ini-file -------------------------------------------------
void __fastcall TMainWindow::WriteList(TIniFile *ini, AnsiString cat,
    AnsiString key, TStrings *list)
{
    AnsiString s;
    int i;
    
    for (i=0;i<list->Count;i++) {
        ini->WriteString(cat,s.sprintf("%s_%03d",key.c_str(),i),list->Strings[i]);
    }
}
Example #28
0
bool SaveImage(Graphics::TBitmap* picture, AnsiString path, TYPE bit_per_pixel, int flags)
{
	FIBITMAP *image = FreeImage_Allocate(picture->Width, picture->Height, 32);
	if(!image) return false;
	
	picture->PixelFormat = pf32bit;
	
	if(!WriteImage(image, picture))
	{
		FreeImage_Unload(image);
		return false;
	}

	AnsiString ext((((AnsiString)ExtractFileExt(path))).UpperCase());

	if (ext == ".BMP")
	{
		if(FreeImage_Save(FIF_BMP, BitrateConversion(image,bit_per_pixel), path.c_str(), BMP_DEFAULT))
		{
			FreeImage_Unload(image);
			return true;
		}	
	}	
	else if (ext == ".JPG")
	{
		if(FreeImage_Save(FIF_JPEG, FreeImage_ConvertTo24Bits(image), path.c_str(), flags))
		{
			FreeImage_Unload(image);
			return true;
		}
	}		
	else if (ext == ".TIF")
	{
		if(FreeImage_Save(FIF_TIFF, FreeImage_ConvertTo24Bits(image), path.c_str(), TIFF_DEFAULT))
		{
			FreeImage_Unload(image);
			return true;
		}	
	}
		
	FreeImage_Unload(image);
	return false;
}
Example #29
0
//---------------------------------------------------------------------------
void __fastcall TOptDialog::BtnSaveClick(TObject *Sender)
{
	AnsiString file;
	SaveDialog->Title="Save Options";
	SaveDialog->FilterIndex=2;
	if (!SaveDialog->Execute()) return;
	file=SaveDialog->FileName;
	if (!strrchr(file.c_str(),'.')) file=file+".conf";
	SaveOpt(file);
}
Example #30
0
int __fastcall TItemList::GetSelected(RStringVec& items)
{
    for (TElTreeItem* item = tvItems->GetNextSelected(0); item; item = tvItems->GetNextSelected(item)){
        if (item->Hidden)	continue;
    	AnsiString 			nm;
    	FHelper.MakeFullName(item,0,nm);
        items.push_back		(nm.c_str());
    }
    return items.size();
}