//**************************************************************************************** //* FindFile.Pkg //* //* //* Inhalt: //* Wenn man mit den Direct_Input "DIR:..." Command Verzeichnisse nach Dateien durch- //* sucht, gibt es Probleme mit den Umlauten, die nicht nur auf den Ansi Zeichensatz //* zurueckzufuehren sind! //* Mit der Windows API hauts aber gut hin! //* //* //* Michael Kurz 05.08.2000 //**************************************************************************************** //**************************************************************************************** //* Class: cDirList //* //* Description: //* Reads Files from a directory and displays them. The visualisation object is //* based on a grid and displays the file with icon and filename. //* //* Usage: //* Object oDirList is a cDirList //* send AddFileListSrc "C:\Eigene Dateien\*.INI" // Reads this files //* send AddFileListSrc "C:\Eigene Dateien\*.BMP" // ... //* ... //* //* set Location to ... //* set Size to ... //* //* set piColumns to ... // number of columns (std.: 1) //* send SingleLineState True //* set piNoTextState to True // Display no text! //* //* // Put your Action here.. //* Procedure onFileChosen string sFile date dDat string sTime //* Forward send onFileChosen string sFile date dDat string sTime // Standard Action: Open/ Save as behavier! //* End_Procedure //* End_Object //* //* //**************************************************************************************** // **WvA: 18-03-03 A minor change in the names has been introduced to prevent compilererrors // under VDF8 and up. This includes WinFindFirstFile, WinFindNextFile and WinFindClose // These functions are changed into: Win32FindFirstFile, Win32FindNextFile and Win32FindClose #Replace QSO_Cancel 0 #Replace QSO_Save 1 #Replace QSO_Open 2 External_Function FindFirstFileA "FindFirstFileA" Kernel32.DLL Pointer pFile Pointer pFindData Returns Handle External_Function FindNextFileA "FindNextFileA" Kernel32.DLL Handle hFind Pointer pFindData Returns Handle External_Function FindCloseA "FindClose" Kernel32.DLL Handle hFind Returns Integer TYPE WIN32_FIND_DATA Field WIN32_FIND_DATA.dwFileAttributes as DWORD Field WIN32_FIND_DATA.ftCreationTime as Char 8 // FileTime=2 DWORD Field WIN32_FIND_DATA.ftLastAccessTime as Char 8 // FileTime=2 DWORD Field WIN32_FIND_DATA.ftLastWriteTime as Char 8 // FileTime=2 DWORD Field WIN32_FIND_DATA.nFileSizeHigh as DWORD Field WIN32_FIND_DATA.nFileSizeLow as DWORD Field WIN32_FIND_DATA.dwReserved0 as DWORD Field WIN32_FIND_DATA.dwReserved1 as DWORD Field WIN32_FIND_DATA.cFileName as Char 260 Field WIN32_FIND_DATA.cAlternateFileName as Char 100 // normale nur 14 aber zur Sicherheit, falls die 260 von vorher nicht reichen! END_TYPE // da diese Laenge von MAX_PATH bestimmt wird, und ich keine Crash riskieren will, // weil in nicht erlaubte Speicherbereiche schreibt! //Use FileInfo.pkg Use mFiles.pkg Use VdfBase.pkg // VDF12+ //Class cSystemTime Is a Message // Procedure Construct_Object // Forward Send Construct_Object // Property Integer wYear PUBLIC 0 // Property Integer wMonth PUBLIC 0 // Property Integer wDayOfWeek PUBLIC 0 // Property Integer wDay PUBLIC 0 // Property Integer wHour PUBLIC 0 // Property Integer wMinute PUBLIC 0 // Property Integer wSecond PUBLIC 0 // Property Integer wMilliseconds PUBLIC 0 // End_Procedure // // Procedure Fill String sBuff // Local Integer iWert // GetBuff From sBuff at SYSTEMTIME.wYear To iWert // Set wYear To iWert // GetBuff From sBuff at SYSTEMTIME.wMonth To iWert // Set wMonth To iWert // GetBuff From sBuff at SYSTEMTIME.wDayOfWeek To iWert // Set wDayOfWeek To iWert // GetBuff From sBuff at SYSTEMTIME.wDay To iWert // Set wDay To iWert // GetBuff From sBuff at SYSTEMTIME.wHour To iWert // Set wHour To iWert // GetBuff From sBuff at SYSTEMTIME.wMinute To iWert // Set wMinute To iWert // GetBuff From sBuff at SYSTEMTIME.wSecond To iWert // Set wSecond To iWert // GetBuff From sBuff at SYSTEMTIME.wMilliseconds To iWert // Set wMilliseconds To iWert // End_Procedure // // Procedure FillFileTime String sTime // Move (FileTimeToSystemTime(sTime)) To sTime // Send Fill sTime // End_Procedure // // Transfers Data from one to another Object! // Procedure TransferData Integer iID // Set wYear Of iID To (wYear(Self)) // Set wMonth Of iID To (wMonth(Self)) // Set wDayOfWeek Of iID To (wDayOfWeek(Self)) // Set wDay Of iID To (wDay(Self)) // Set wHour Of iID To (wHour(Self)) // Set wMinute Of iID To (wMinute(Self)) // Set wSecond Of iID To (wSecond(Self)) // Set wMilliSeconds Of iID To (wMilliSeconds(Self)) // End_Procedure // // Function GetDatum Returns Date // Local String sRet // Append sRet (wDay(Self)) "." (wMonth(Self)) "." (wYear(Self)) // Function_Return sRet // End_Function // Function GetZeit Returns String // Local String sRet // Append sRet (wHour(Self)) ":" (wMinute(Self)) ":" (wSecond(Self)) // Function_Return sRet // End_Function //End_Class Class cFileFindData Is a Message Procedure Construct_Object Property Handle phFileFindHandle PUBLIC -1 Property Integer piFileAttributes PUBLIC 0 Property Integer piFileSizeHigh PUBLIC 0 Property Integer piFileSizeLow PUBLIC 0 // ... Property String psFileName PUBLIC "" Property String psAlternateFileName PUBLIC "" Property String psSearchPath PUBLIC "" // Object oCreationTime Is a cSystemTime // End_Object // Object oLastAccessTime Is a cSystemTime // End_Object // Object oLastWriteTime Is a cSystemTime // End_Object End_Procedure Procedure Fill String sData String sTmp Integer iTmp iOID Move Self To iOID // GetBuff_String From sData at WIN32_FIND_DATA.ftCreationTime To sTmp // Daten Eintragen.... // Send FillFileTime To (oCreationTime(Self)) sTmp // GetBuff_String From sData at WIN32_FIND_DATA.ftLastAccessTime To sTmp // Send FillFileTime To (oLastAccessTime(Self)) sTmp // GetBuff_String From sData at WIN32_FIND_DATA.ftLastWriteTime To sTmp // Send FillFileTime To (oLastWriteTime(Self)) sTmp GetBuff From sData at WIN32_FIND_DATA.nFileSizeHigh To iTmp Set piFileSizeHigh Of iOID To iTmp GetBuff From sData at WIN32_FIND_DATA.nFileSizeLow To iTmp Set piFileSizeLow Of iOID To iTmp GetBuff_String From sData at WIN32_FIND_DATA.cFileName To sTmp Set psFileName Of iOID To (ToOem(CString(sTmp))) GetBuff_String From sData at WIN32_FIND_DATA.cAlternateFileName To sTmp Set psAlternateFileName Of iOID To (ToOem(CString(sTmp))) End_Procedure Function GetSizeStr Returns String Integer Is Get piFileSizeLow To Is If Is Ge 10000 Begin Function_Return (Append(Is/1000," K")) End Else Begin Function_Return (Append(Is, " Byte")) End End_Function // Returns PAth and File... Function FullFileName Returns String String sRet Append sRet (psSearchPath(Self)) "\" (psFileName(Self)) Function_Return sRet End_Function // Creates a FileInfostring containing FileName, FileSize and LastWriteTime! Function FileInfoStr Returns String String sRet Append sRet (psFileName(Self)) " (" (GetSizeStr(Self)) ")" Function_Return sRet End_Function // Is it a Directory? Function isDir Returns Integer String sFile Get psFileName To sFile If (Trim(sFile)) Eq ".." Function_Return 1 If (Trim(sFile)) Eq "." Function_Return 1 Function_Return 0 End_Function // Sets the Data of iID to the Data of the current Object! Procedure TransferData Integer iID Set piFileAttributes Of iID To (piFileAttributes(Self)) Set piFileSizeHigh Of iID To (piFileSizeHigh(Self)) Set piFileSizeLow Of iID To (piFileSizeLow(Self)) Set psFileName Of iID To (psFileName(Self)) Set psAlternateFileName Of iID To (psAlternateFileName(Self)) Set psSearchPath Of iID To (psSearchPath(Self)) End_Procedure // Duplicates an Object and Fills it... Function DuplicateObject Returns Integer Integer iID Object oFileFindData Is a cFileFindData Move Self To iID End_Object Send TransferData iID Function_Return iID End_Function End_Class Function Win32FindFirstFile Global String sFile Returns Integer Integer iRet iOID Pointer pData pFile String sData Move (ToAnsi(sFile)) To sFile Append sFile (Character(0)) Zerotype WIN32_FIND_DATA To sData GetAddress Of sData To pData GetAddress Of sFile To pFile Move (FindFirstFileA(pFile,pData)) To iRet If iRet Gt 0 Begin Object oFileFindData Is a cFileFindData // Object erzeugen... Move Self To iOID End_Object Set phFileFindHandle Of iOID To iRet Set psSearchPath Of iOID To (PathFromPath(sFile)) Send Fill To iOID sData End Function_Return iOID End_Function Function Win32FindNextFile GLOBAL Integer iOID Returns Integer Integer iRet Handle hH Pointer pData String sData Zerotype WIN32_FIND_DATA To sData GetAddress Of sData To pData If Not iOID Function_Return -1 Get phFileFindHandle Of iOID To hH Move (FindNextFileA(hH,pData)) To iRet Send Fill To iOID sData // Soll auch setzen wenn leer! Function_Return iRet End_Function Function Win32FindClose Global Integer iOID Returns Integer Handle hH Integer iRet If Not iOID Function_Return -1 Get phFileFindHandle Of iOID To hH // FindHandle holen If hH Move (FindCloseA(hH)) To iRet // freigeben wenn gueltig Send Destroy_Object To iOID // Object freigeben! Function_Return iRet // Freigabe OK? End_Function // // Returns the correct case sensitivity for a filename. If you test for the existence // of a file using Get_File_Path then the filename itself will keep the case you give // it. Opening files that way and editing them, can change the case and some // code source tools don't like that. // Pre: The filename must exist // Function FileNameOnDisk String sFileName Returns String Integer hoId iRet String sRealName Move (Win32FindFirstFile(sFileName)) To hoId If hoId Begin Get FullFileName Of hoID To sRealName // Move (Win32FindNextFile(hoId)) To iRet // If iRet send iMsg hoId Move (Win32FindClose(hoId)) To iRet End Function_Return sRealName End_Function // FileNameOnDisk