// This code is part of VDF GUIdance // Visit us @ http://www.vdf-guidance.com // e-Mail us @ info@vdf-guidance.com // VDF GUIdance is a mutual project of // Frank Vandervelpen - Vandervelpen Systems and // Wil van Antwerpen - Antwise Solutions // All software source code should be used <> without any warranty. // // // *** Windows 32bit file handling wrapper class *** // #IFNDEF Is$WebApp Use File_Dlg.pkg // Contains OpenDialog class definition Use cvFileDialogs.pkg Use windows.pkg #ENDIF Use Seq_chnl.pkg Use Dll.pkg #IF (!@ < 200) Use vWin32fhA.pkg // WinAPI ANSI legacy interface #ELSE Use vWin32fhW.pkg // WinAPI Unicode version #ENDIF // // Gets the string from the right of the last sStopChar in sFrom // If sStopChar has no occurences in the string an empty string is // returned. Function StringFromRightOfChar Global String sFrom String sStopChar Returns String String sRetVal String sChar Integer iLength Integer iPos Boolean bStopChar Move "" to sRetval Move (Length(sFrom)) to iLength If ((iLength>0) And (Pos(sStopChar,sFrom) <> 0)) Begin Move iLength to iPos Move (False) to bStopChar While Not bStopChar Move (Mid(sFrom,1,iPos)) to sChar Decrement iPos If ((sChar=sStopChar) Or (iPos<1)) Begin Move (True) to bStopChar End Else Begin Move (sChar+sRetVal) to sRetVal End Loop End Function_Return sRetVal End_Function // Pre: sFileName contains the complete path of the file. // Post: returns the complete path of the file. // This function is inspired on function SEQ_ExtractPathFromFileName of Sture Andersen. Function ParseFolderName Global String sFileName Returns String String sFile String sFolderName String sDirSep // this is "\" for windows, or "/" for unix Move "" to sFolderName Move (SysConf(SYSCONF_DIR_SEPARATOR)) to sDirSep If sDirSep In sFileName Begin Move (StringFromRightOfChar(sFileName,sDirSep)) to sFile Move (Left(sFileName,Length(sFileName)-Length(sFile))) to sFolderName End Else If ":" In sFileName Begin Move (StringFromRightOfChar(sFileName,":")) to sFile Move (Replace(sFile,sFileName,"")) to sFolderName End Function_Return sFolderName End_Function // Pre: sFileName contains the complete path of the file. // post: The returned filename has it's path removed, but will have a extension Function ParseFileName Global String sFileName Returns String String sFolderName String sDirSep // this is "\" for windows, or "/" for unix Move (sysconf(SYSCONF_DIR_SEPARATOR)) to sDirSep Get ParseFolderName sFileName to sFolderName If (sFolderName <> "") Begin Move (Replace(sFolderName,sFileName,"")) to sFileName End Move (Replace(sDirSep,sFileName,"")) to sFileName Function_Return sFilename End_Function // Pre: sFileName may contain the complete path of the file. // or contain multiple dots in the filename, so temp.gif.bak will // return "bak" as the extension and not "gif" // Post: returns the extension only, this extension can be a valid unixlike extension // such as "html" or "java" Function ParseFileExtension Global String sFileName Returns String String sFileExtension Get ParseFileName sFileName to sFileName // takes care of corner case with path containing a ".". eg. c:\frank.cheng\hello Get StringFromRightOfChar sFileName "." to sFileExtension Function_Return sFileExtension End_Function Define CS_DDE_ERR_UNKNOWN_LINE2 For ".\n" Function DDE_Error_To_String Integer iErrorID Returns String String sMessage Case Begin Case (iErrorID = vERROR_FILE_NOT_FOUND) Move CS_DDE_ERR_FILE_NOT_FOUND to sMessage Case Break Case (iErrorID = vERROR_PATH_NOT_FOUND) Move CS_DDE_ERR_PATH_NOT_FOUND to sMessage Case Break Case (iErrorID = vERROR_BAD_FORMAT) Move CS_DDE_ERR_BAD_FORMAT to sMessage Case Break Case (iErrorID = vSE_ERR_ACCESSDENIED) Move CS_DDE_ERR_ACCESSDENIED to sMessage Case Break Case (iErrorID = vSE_ERR_ASSOCINCOMPLETE) Move CS_DDE_ERR_ASSOCINCOMPLETE to sMessage Case Break Case (iErrorID = vSE_ERR_DDEBUSY) Move CS_DDE_ERR_DDEBUSY to sMessage Case Break Case (iErrorID = vSE_ERR_DDEFAIL) Move CS_DDE_ERR_DDEFAIL to sMessage Case Break Case (iErrorID = vSE_ERR_DDETIMEOUT) Move CS_DDE_ERR_DDETIMEOUT to sMessage Case Break Case (iErrorID = vSE_ERR_DLLNOTFOUND) Move CS_DDE_ERR_DLLNOTFOUND to sMessage Case Break Case (iErrorID = vSE_ERR_NOASSOC) Move CS_DDE_ERR_NOASSOC to sMessage Case Break Case ((iErrorID = vSE_ERR_OOM) Or (iErrorID = 0)) Move CS_DDE_ERR_OOM to sMessage Case Break Case (iErrorID = vSE_ERR_PNF) Move CS_DDE_ERR_PNF to sMessage Case Break Case (iErrorID = vSE_ERR_SHARE) Move CS_DDE_ERR_SHARE to sMessage Case Break Case Else Move CS_DDE_ERR_UNKNOWN_LINE1 to sMessage Move (sMessage*Trim(iErrorID)*CS_DDE_ERR_UNKNOWN_LINE2) to sMessage Case Break Case End Function_Return sMessage End_Function Procedure vDDE_Error_Handler Integer iErrorID String sMessage Get DDE_Error_To_String iErrorID to sMessage Append sMessage CS_DDE_ERR_HANDL_PAKTC // "Press a key to continue..." Send Stop_Box sMessage CS_DDE_ERR_HANDL_CAPTION End_Procedure // This function informs the user that he entered a yet unknown folder and // asks if he/she wants to create the folder (Yes/No) // Choice: "Yes" - this creates the folder // if successful, the function returns false // else it will be true. // Choice: "No" - returns TRUE, This allows the programmer to take action // For example: to stop a save // Precondition: A foldername must be entered. We do not check for empty paths // This function returns a non-zero value if the folder isn't created afterwards Function vVerifyNewFolder Global String sFolderName Returns Integer Integer bIsNotValid Integer iUsers_Choice String sMessage If (vFolderExists(sFolderName) Eq 0) Begin Move "The folder '" to sMessage Append sMessage sFolderName Append sMessage "' does not yet exist,\n" Append sMessage "Do you want to create it now?" Get YesNo_Box sMessage "Confirm" MB_DefButton1 to iUsers_Choice Case Begin Case (iUsers_Choice = MBR_Yes) Move (vCreateDirectory(sFolderName)) to bIsNotValid If bIsNotValid Begin Move "An error occurred while trying to create folder '" to sMessage Append sMessage sFolderName "'.\n\n" Send Info_Box sMessage "Info" End Case Break Case (iUsers_Choice = MBR_No) Move dfTrue to bIsNotValid // Cancel the save Case Break Case End End Function_Return bIsNotValid End_Function // **WvA // Formats a foldername by first trimming it and after that by sticking a // directory separator (/\) to the end if it doesn't have one there already. // The folder may contain a drive letter or UNC encoding. Function vFolderFormat Global String sFolderName Returns String String sDirSep Move (sysconf(SYSCONF_DIR_SEPARATOR)) to sDirSep // normally \ (backslash) Move (Trim(sFolderName)) to sFolderName If (Right(sFolderName,1)<>sDirSep) Begin Move (sFolderName+sDirSep) to sFolderName End Function_Return sFolderName End_Function // // Gets the parent path of the currently supplied path // Returns "" when we are at the root folder. // Function vParentPath Global String sPath Returns String String sStrip sDirSep Move (SysConf(SYSCONF_DIR_SEPARATOR)) to sDirSep Move (Trim(sPath)) to sPath If (Right(sPath,1) = sDirSep) Begin Move (Left(sPath,Length(sPath)-1)) to sPath End If (Pos(sDirSep, sPath)) Begin Move (StringFromRightOfChar(sPath, sDirSep)) to sStrip Move (Left(sPath,Length(sPath)-Length(sStrip))) to sPath End Else Begin Move "" to sPath End Function_Return sPath End_Function