Exemplo n.º 1
0
//---------------------------------------------------------------------------
// удалим временные DBF файлы, если они есть
void __fastcall TfrmSignsReports::DeleteTempDBFFile(TADOCommand *DbfCommand, String DBFPath,String DBFName)
{
TSearchRec sr;
if(FindFirst(DBFPath+"\\"+DBFName+".dbf", 0, sr) == 0)
    {
    DbfCommand->CommandText = "drop table "+DBFName;
    DbfCommand->Execute();
    }
}
Exemplo n.º 2
0
int __fastcall TFileInfo::Size() {
	TSearchRec sr;
	int filesize = -1;
	if (FindFirst(ToString(), faAnyFile, sr) == 0) {
		filesize = sr.Size;
	}
	FindClose(sr);
	return filesize;
}
Exemplo n.º 3
0
RBITER
RbBeginIter (RBTREE tree, RBKEY low, RBKEY high)
{
	RBITER rbit = (RBITER)SafeMalloc(sizeof(*rbit));
	rbit->rbtree = tree;
	rbit->low = low;
	rbit->high = high;
	rbit->next = FindFirst(tree, low);
	return rbit;
}
Exemplo n.º 4
0
CBuilding *CGameWorld::IntersectBuilding(vec2 Pos0, vec2 Pos1, float Radius, vec2& NewPos, CEntity *pNotThis)
{
	// Find other players
	float ClosestLen = distance(Pos0, Pos1) * 100.0f;
	vec2 LineDir = normalize(Pos1-Pos0);
	CBuilding *pClosest = 0;

	CBuilding *pBuilding = (CBuilding *)FindFirst(ENTTYPE_BUILDING);
	for(; pBuilding; pBuilding = (CBuilding *)pBuilding->TypeNext())
 	{
		if(pBuilding == pNotThis)
			continue;

		vec2 Dir = normalize(Pos1-Pos0);
		vec2 Pos[4] = {
				vec2(pBuilding->m_Pos.x - pBuilding->m_Width/2, pBuilding->m_Pos.y + 16),
				vec2(pBuilding->m_Pos.x - pBuilding->m_Width/2, pBuilding->m_Pos.y - pBuilding->m_Height + 16),
				vec2(pBuilding->m_Pos.x + pBuilding->m_Width/2, pBuilding->m_Pos.y - pBuilding->m_Height + 16),
				vec2(pBuilding->m_Pos.x + pBuilding->m_Width/2, pBuilding->m_Pos.y + 16)
		};

		vec2 Col[4] = {vec2(100000.0f, 100000.0f), vec2(100000.0f, 100000.0f), vec2(100000.0f, 100000.0f), vec2(100000.0f, 100000.0f)};
		
		bool Hit = false;
		for(int i = 0; i < 4; i++)
		{
			if(Intersect(Pos0, Pos1, Pos[i], Pos[(i+1) % 4], &Col[i]))
				Hit = true;
		}

		if(Hit)
		{
			vec2 CCol = Col[0];

			float Len = distance(CCol, Pos0);
			for(int i = 1; i < 4; i++)
			{
				if(distance(Col[i], Pos0) < Len)
				{
					CCol = Col[i];
					Len = distance(CCol, Pos0);
				}
			}

			if(Len < ClosestLen)
			{
				NewPos = CCol;
				ClosestLen = Len;
				pClosest = pBuilding;
			}
		}
	}

	return pClosest;
}
Exemplo n.º 5
0
BString&
BString::ReplaceFirst(const char* replaceThis, const char* withThis)
{
	if (!replaceThis || !withThis || FindFirst(replaceThis) < 0)
		return *this;

	if (_MakeWritable() != B_OK)
		return *this;

	return _DoReplace(replaceThis, withThis, 1, 0, KEEP_CASE);
}
Exemplo n.º 6
0
Object * List::FindFirst(Object *search)
{
    ListNode *p;
    Object *ob = FindFirst(&p);
    while(ob != NULL)
    {
        if(ob->Compare(search)==0)
            return ob;
    }
    return NULL;
}
Exemplo n.º 7
0
BString&
BString::RemoveAll(const char* string)
{
	if (!string || Length() == 0 || FindFirst(string) < 0)
		return *this;

	if (_MakeWritable() != B_OK)
		return *this;

	return _DoReplace(string, "", REPLACE_ALL, 0, KEEP_CASE);
}
Exemplo n.º 8
0
// ---------------------------------------------------------------------------
// Loading Susie Plug-in
void __fastcall TForm1::SPI_LoadPlugin(String path) {
	TSearchRec sr;
	if (FindFirst(TPath::Combine(path, L"*.spi"), 0, sr) == 0) {
		do {
			hSPI->Add((TObject *) LoadLibrary(TPath::Combine(path, sr.Name).w_str()));
		}
		while (!FindNext(sr));
		// FindClose(sr);
	}
	FindClose(sr);
}
Exemplo n.º 9
0
void __fastcall TForm1::AbrirButtonClick(TObject *Sender)
{
    ListBox1->Items->Clear();

    OpenDialog1->Filter = "Dicom files (*.dcm)|*.dcm";

    AnsiString FileName;
    AnsiString FileDir;

    if(OpenDialog1->Execute())
    {
        FileName = OpenDialog1->FileName ;
        FileDir = ExtractFileDir(FileName);
        FileDirLabel->Caption = FileDir;
    }
    else return;

    TSearchRec sr;

    if (FindFirst(FileDir+"\\*.*", faAnyFile, sr) == 0)
    {
        do
        {   ListBox1->Items->Add(sr.Name);
        } while (FindNext(sr) == 0);
        FindClose(sr);
    }

    CountLabel->Caption = AnsiString(ListBox1->Items->Count-2) + " Files";

    ProgressBar1->Max = ListBox1->Items->Count-2;
    AnsiString ExecProgPath;
    AnsiString FileName_Path;
    AnsiString DestinyFolder;
    char Quote = '"';

    for(int i=2; i<ListBox1->Items->Count; i++)
    {
        FileName = FileDir + "\\" + ListBox1->Items->Strings[i];
        FileName_Path = ExtractFileName(FileName);
        DestinyFolder = DirectoryListBox1->Directory;

        ExecProgPath = "D:\\Estudios\\DCMTKBIN\\dcmdjpeg.exe "
                       +  AnsiQuotedStr(FileName, Quote) +
                       + " "
                       +  AnsiQuotedStr(DestinyFolder + "\\" + FileName_Path, Quote);

        WinExec(ExecProgPath.c_str() ,  SW_HIDE);
        ProgramLabel->Caption =  ExecProgPath;
        ProgressBar1->Position++;
    }

    ProgressBar1->Position = 0;
}
Exemplo n.º 10
0
//---------------------------------------------------------------------------
void __fastcall TRelDirSearchForm::GetFileList(AnsiString path, int baselen)
{
	TSearchRec r;
	int done;

	done=FindFirst(path + "*.*" ,faAnyFile, r);
	try
	{
		while(!done)
		{
			if(r.FindData.cFileName[0]!='.')
			{
				if(! (r.Attr & faDirectory))
				{
					// a file
					AnsiString name = AnsiString(path.c_str()+ baselen) +
						r.FindData.cFileName;
					FileList->Add(name);
					CurrentLabel->Caption = name;
					AnsiString fileext = ExtractFileExt(r.FindData.cFileName);
					ExtList->Add(fileext);

					// message processing
					Application->ProcessMessages();
					if(Aborted)
					{
						throw EAbort("Aborted");  // raise an aborting exception
					}
				}
				else
				{
					// a directory
					if(r.Name != "." && r.Name != ".." &&
						!(r.Name == "CVS" &&
							FileExists(path + AnsiString("CVS\\Repository"))))
								// ignoring CVS meta-data directory
					{
						GetFileList(path  + r.FindData.cFileName+
							AnsiString("\\"), baselen);
					}
				}
			}
			done=FindNext(r);
		}
	}
	catch(Exception &e)
	{
		FindClose(r);
		throw Exception(e);
	}
	FindClose(r);
}
Exemplo n.º 11
0
// удаляет ненужные файлы из текущего каталога и его подкаталогов
void __fastcall Clear(void)
{

   TSearchRec SearchRec; // информация о файле или каталоге

   cDir = GetCurrentDir()+"\\";

   if ( FindFirst("*.*", faArchive,SearchRec) == 0)
       do {
            // проверим расширение файла
            int p = SearchRec.Name.Pos(".");
            FileExt = SearchRec.Name.SubString(p+1,MAX_PATH);
            if ( ( FileExt[1] == '~') || ( FileExt == "obj" ) ||
                 ( FileExt == "tds" ) )
            {
                  Form1->Memo1->Lines->Add(cDir+SearchRec.Name);
                  DeleteFile(SearchRec.Name);
                  n++;
            }
        }
        while ( FindNext(SearchRec) == 0);

       // обработка подкаталогов текущего каталога
       if ( FindFirst("*", faDirectory, SearchRec) == 0)
          do
              if ((SearchRec.Attr & faDirectory) == SearchRec.Attr )
              {
                    // каталоги ".." и "." тоже каталоги,
                    // но в них входить не надо !!!
                    if (( SearchRec.Name != "." ) && (SearchRec.Name != ".."))
                    {
                         ChDir(SearchRec.Name); // войти в подкаталог
                         Clear();               // очистить каталог
                         ChDir("..");           // выйти из каталога

                    };
               }
          while ( FindNext(SearchRec) == 0 );
}
Exemplo n.º 12
0
BString&
BString::ReplaceAll(const char* replaceThis, const char* withThis,
	int32 fromOffset)
{
	if (!replaceThis || !withThis || FindFirst(replaceThis) < 0)
		return *this;

	if (_MakeWritable() != B_OK)
		return *this;

	return _DoReplace(replaceThis, withThis, REPLACE_ALL,
		min_clamp0(fromOffset, Length()), KEEP_CASE);
}
Exemplo n.º 13
0
void FileFind::GetFiles(StringVector &list)  // get all files.
{

	std::string str;
  if ( FindFirst(str) )
  {
    list.push_back(str);
    while ( FindNext(str) )
    {
      list.push_back(str);
    }
  }
}
Exemplo n.º 14
0
 //FindAll
 size_t DirSearch::FileSys::FindAll( const STRING& pattern, std::vector< STRING >& fileNames )
 {
     fileNames.clear();
     if ( FindFirst( pattern ) )
     {
         fileNames.push_back( GetFileName() );
         while ( FindNext() )
         {
             fileNames.push_back( GetFileName() );
         }
         FindClose();
     }
     return fileNames.size();
 }
Exemplo n.º 15
0
BString&
BString::IReplace(const char* replaceThis, const char* withThis,
	int32 maxReplaceCount, int32 fromOffset)
{
	if (!replaceThis || !withThis || maxReplaceCount <= 0
		|| FindFirst(replaceThis) < 0)
		return *this;

	if (_MakeWritable() != B_OK)
		return *this;

	return _DoReplace(replaceThis, withThis, maxReplaceCount,
		min_clamp0(fromOffset, Length()), IGNORE_CASE);
}
Exemplo n.º 16
0
HANDLE CFindChangeNotification::FindFirst(LPCWSTR pathName, bool watchSubtree, DWORD notifyFilter)
{
  if (!g_IsNT)
    return FindFirst(UnicodeStringToMultiByte(pathName, GetCurrentCodePage()), watchSubtree, notifyFilter);
  _handle = ::FindFirstChangeNotificationW(pathName, BoolToBOOL(watchSubtree), notifyFilter);
  #ifdef WIN_LONG_PATH
  if (!IsHandleAllocated())
  {
    UString longPath;
    if (GetLongPath(pathName, longPath))
      _handle = ::FindFirstChangeNotificationW(longPath, BoolToBOOL(watchSubtree), notifyFilter);
  }
  #endif
  return _handle;
}
Exemplo n.º 17
0
XBOOL XFileFinder::GetFileTime(XPCTSTR strFile, XTime &time, XU8 ts)
{
    if(!FindFirst(strFile)) return XFALSE;
	switch(ts)
	{
	default:
	case XTM_CREATE:
		 time.SetTime(ftCreationTime);break;
	case XTM_ACCESS:
		 time.SetTime(ftLastAccessTime);break;
	case XTM_MODIFY:
		 time.SetTime(ftLastWriteTime);break;
	}
	return XTRUE;
}
Exemplo n.º 18
0
void GetAllFileNames(String path,std::list<String> &ret)
{
	TSearchRec rec;
	int attr = 0;
	int r = FindFirst(path,attr,rec);
	while(r==0)
	{
		if(rec.Name!="." && rec.Name!="..")
		{
			String name = ChangeFileExt(rec.Name,"");
			ret.push_back(name);
		}
		r = FindNext(rec);
	}
	FindClose(rec);
}
Exemplo n.º 19
0
AnsiString  __fastcall TMainForm::GetList()
{
   TSearchRec sr;
   AnsiString s;
   AnsiString result;
sFilePattern = ExtractFileDir(ParamStr(0)) + "\\images\\*.bmp";
s = "";
if (FindFirst(sFilePattern,faAnyFile,sr) == 0)
    {
    s = sr.Name;
    while (FindNext(sr) == 0 )
        {s = s + "," + sr.Name;
        }
    }
result = s;
return result;
}
Exemplo n.º 20
0
void __fastcall TForm1::FindFile(TMenuItem *parent, String path) {
	TSearchRec sr;

	if (FindFirst(TPath::Combine(path, "*.*"), faAnyFile, sr) == 0) {
		do {
			if (sr.Name == "." || sr.Name == "..")
				continue;
			TMenuItem *item = AddMenu(parent, sr, TPath::Combine(path, sr.Name));
			if (sr.Attr & faDirectory && chbSubDirectory->Checked) {
				FindFile(item, TPath::Combine(path, sr.Name));
			}
		}
		while (!FindNext(sr));
	}

	FindClose(sr);
}
Exemplo n.º 21
0
static void b_ls(int argc, char **argv) {
    /* arquivos ocultos, pastas, sistema */
    unsigned int atributos = ATTR_ARCHIVE | ATTR_HIDDEN | ATTR_DIRECTORY | ATTR_SYSTEM;
    int i = 0;
    SearchRec busca;

    (void) argc;
    (void) argv;

    /* procura todos os arquivos, pastas... */
    if (!FindFirst("*.*", atributos, &busca)) {
        printf("\r\n%02u - %03lu  %s", i++, busca.filesize, busca.filename);
        while (!FindNext(&busca)) {
            printf("\r\n%02i - %03lu  %s", i++, busca.filesize, busca.filename);
        }
    }
}
Exemplo n.º 22
0
//---------------------------------------------------------------------------
void __fastcall TfrmMacros::LoadMacroses(void)
{
String Folder=ExtractFilePath(Application->ExeName)+"Macroses\\";
TSearchRec sr;
if (!FindFirst(Folder+"*.mcr",faAnyFile,sr))
    {
    do
        {
        TMacros *Macros=new TMacros;
        Macros->LoadFromFile(Folder+sr.Name);
        FMacrosList->Add(Macros);
        listMacroses->Items->AddObject(Macros->MacrosName,Macros);
        }
    while (!FindNext(sr));
    FindClose(sr);
    }
}
Exemplo n.º 23
0
/************************************************************************
Function: void MonitorDriveMedia( void )

Precondition: None

Overview: This function calls the background tasks necessary to support
          USB Host operation.  Upon initial insertion of the media, it
          initializes the file system support and reads the volume label.
          Upon removal of the media, the volume label is marked invalid.

Input: None

Output: None
*************************************************************************/
void MonitorDriveMedia(void)
{
    BYTE        mediaPresentNow;
    BYTE        mountTries;
    SearchRec   searchRecord;

        #if defined ENABLE_USB_MSD_DEMO

    // Call to USBTasks() is assumed to be done in the main. If not you can
    // call it here.
    //USBTasks();	
    mediaPresentNow = USBHostMSDSCSIMediaDetect();
        #elif defined ENABLE_SD_MSD_DEMO
    mediaPresentNow = MDD_MediaDetect();
        #endif
    if(mediaPresentNow != mediaPresent)
    {
        if(mediaPresentNow)
        {
            mountTries = 10;
            while(!FSInit() && mountTries--);
            if(!mountTries)
            {
                //UART2PrintString("APP: Could not mount media\r\n");
                mediaPresent = FALSE;
            }
            else
            {
                mediaPresent = TRUE;

                // Find the volume label.  We need to do this here while we are at the
                // root directory.
                if(!FindFirst("*.*", ATTR_VOLUME, &searchRecord))
                {
                    strcpy(volume.label, searchRecord.filename);
                    volume.valid = TRUE;
                }
            }
        }
        else
        {
            mediaPresent = FALSE;
            volume.valid = FALSE;
        }
    }
}
Exemplo n.º 24
0
//===========================================================================
void __fastcall GetFolderList( AnsiString Directory, TStringList *DirList )
{
	TSearchRec srEntry;
    try {
        // Because we're looking for files and directories, the first two entries will be "." and "..", which we want to skip
        if ( FindFirst(Directory + "\\*.*", faDirectory | faArchive, srEntry) == 0 && FindNext(srEntry) == 0 )
        {
            while ( FindNext(srEntry) == 0 )
            {
                if ( srEntry.Attr == faDirectory  )
                    DirList->Add( Directory + "\\" + srEntry.Name );
            }  
        }  
    }
    __finally {
    	FindClose( srEntry );
    }  
}  
Exemplo n.º 25
0
			bool CFindFile::FindFirst(LPCWSTR wildcard, CFileInfoW &fileInfo)
			{
				if (!Close())
					return false;
				CFileInfo fileInfo0;
				AString Awildcard = UnicodeStringToMultiByte(wildcard, CP_ACP);
				bool bret = FindFirst((LPCSTR)Awildcard, fileInfo0);
				if (bret)
				{
     fileInfo.Attrib = fileInfo0.Attrib;
     fileInfo.CTime = fileInfo0.CTime;
     fileInfo.ATime = fileInfo0.ATime;
     fileInfo.MTime = fileInfo0.MTime;
     fileInfo.Size = fileInfo0.Size;
     fileInfo.IsDevice = fileInfo0.IsDevice;
     fileInfo.Name = GetUnicodeString(fileInfo0.Name, CP_ACP);
				}
				return bret;
			}
_reentrant RETCODE Fast_Playlist_GetLFN(INT iEntryType,INT pEntry,INT* pName){
	_packed BYTE sFileSpec[SFN_LENGTH];
	Finddata finddata;
	int find_handle ;
	int iDirHandle;
	int i;
	WORD iStrLen;
	RETCODE	rtn = PLAYLIST_TRACK_NOT_FOUND;

	sFileSpec[0] = 0;
	packed_strcpy((_packed BYTE *)pName,g_CurrentSongName);
	iStrLen= packed_strlen((_packed BYTE *)pName);
	while(iStrLen--)
	{
	    if(packed_get((_packed BYTE *)pName,iStrLen)=='/')
		{
	        for (i = 0; i < SFN_LENGTH; i++)
				packed_set(sFileSpec,i,packed_get((_packed BYTE *)pName,iStrLen+1+i));
			packed_set((_packed BYTE *)pName,iStrLen+1,0);
			break;
		}
	}

	Chdir((_packed char *)pName);
	iDirHandle = GetCWDHandle();
	_memset(&finddata,0,sizeof(finddata));
	finddata.device = 0;
	finddata.startrecord = 0;//start at the 0th record.
	find_handle = FindFirst(&finddata,(_packed char*) sFileSpec);
	if( find_handle > 0 )
	{
		g_FileKey = finddata.Key;
		song_info.g_songFastKey=g_FileKey;
        packed_strcpy((_packed BYTE *)g_shortname, (_packed BYTE *)finddata.name);

		if (ConstructLongFileName(iDirHandle, finddata.startrecord - 1, pName ) > 0)
			rtn = PLAYLIST_SUCCESS;
		Fclose(iDirHandle);
		Fclose(find_handle);
	}

	return rtn;
}
Exemplo n.º 27
0
int
RbTraverseUp (RBTREE tree, RBKEY low, RBKEY high, void *param, TraverseFuncType TraverseFunc)
{
	RBNODE nil=tree->nil;
	RBNODE lastBest=nil;
	int rtn=1;

	/* Find starting location */
	lastBest = FindFirst(tree, low);

	/* Now traverse, watching for ending location */
	while ( (lastBest != nil) && (0 <= TreeCompare(tree, high, lastBest->key))) {

		rtn = (*TraverseFunc)(lastBest->key, lastBest->info, param);
		if (!rtn) return rtn;
		lastBest=RbTreeSuccessor(tree,lastBest);
	}
	return rtn;
}
Exemplo n.º 28
0
std::list<class CCharacter *> CGameWorld::IntersectedCharacters(vec2 Pos0, vec2 Pos1, float Radius, class CEntity *pNotThis)
{
	std::list< CCharacter * > listOfChars;

	CCharacter *pChr = (CCharacter *)FindFirst(CGameWorld::ENTTYPE_CHARACTER);
	for(; pChr; pChr = (CCharacter *)pChr->TypeNext())
 	{
		if(pChr == pNotThis)
			continue;

		vec2 IntersectPos = closest_point_on_line(Pos0, Pos1, pChr->m_Pos);
		float Len = distance(pChr->m_Pos, IntersectPos);
		if(Len < pChr->m_ProximityRadius+Radius)
		{
			pChr->m_Intersection = IntersectPos;
			listOfChars.push_back(pChr);
		}
	}
	return listOfChars;
}
Exemplo n.º 29
0
bool __fastcall TfrmSignsReports::DeleteFileDialog(String Path,String FName)
{
bool Res=true;
TSearchRec sr;
if (FindFirst(Path+FName, 0, sr) == 0)
    {
    if (Application->MessageBox(String("Файл с именем "+FName+" уже существует. Вы хотите переписать его?").c_str(),"Предупреждение",MB_YESNO)==ID_YES)
        {
        if (!DeleteFile(Path+FName))
            {
            ShowMessage("Файл "+FName+" не может быть удален. Возможно файл занят другим приложением");
            Res=false;
            }
        }
    else
        Res=false;
    }

return Res;
}
Exemplo n.º 30
0
//++ ------------------------------------------------------------------------------------
// Details: Splits string into array of strings using delimiter. However the string is
//          also considered for text surrounded by quotes. Text with quotes including the
//          delimiter is treated as a whole. If multiple delimiter are found in sequence
//          then they are not added to the list of splits. Quotes that are embedded in
//          the string as string formatted quotes are ignored (proceeded by a '\\') i.e.
//          "\"MI GDB local C++.cpp\":88".
// Type:    Method.
// Args:    vData       - (R) String data to be split up.
//          vDelimiter  - (R) Delimiter char or text.
//          vwVecSplits - (W) Container of splits found in string data.
// Return:  size_t - Number of splits found in the string data.
// Throws:  None.
//--
size_t
CMIUtilString::SplitConsiderQuotes(const CMIUtilString &vDelimiter, VecString_t &vwVecSplits) const
{
    vwVecSplits.clear();

    if (this->empty() || vDelimiter.empty())
        return 0;

    const size_t nLen(length());
    size_t nOffset(0);
    do
    {
        // Find first occurrence which doesn't match to the delimiter
        const size_t nSectionPos(FindFirstNot(vDelimiter, nOffset));
        if (nSectionPos == std::string::npos)
            break;

        // Find next occurrence of the delimiter after (quoted) section
        const bool bSkipQuotedText(true);
        bool bUnmatchedQuote(false);
        size_t nNextDelimiterPos(FindFirst(vDelimiter, bSkipQuotedText, bUnmatchedQuote, nSectionPos));
        if (bUnmatchedQuote)
        {
            vwVecSplits.clear();
            return 0;
        }
        if (nNextDelimiterPos == std::string::npos)
            nNextDelimiterPos = nLen;

        // Extract string between delimiters
        const size_t nSectionLen(nNextDelimiterPos - nSectionPos);
        const std::string strSection(substr(nSectionPos, nSectionLen));
        vwVecSplits.push_back(strSection.c_str());

        // Next
        nOffset = nNextDelimiterPos + 1;
    }
    while (nOffset < nLen);

    return vwVecSplits.size();
}