Author Topic: Findfile + LEGACYCODESEARCH in BricsCAD  (Read 6414 times)

0 Members and 1 Guest are viewing this topic.

PrinceLISPalot

  • Newt
  • Posts: 34
  • perfectionist trapped inside the mind of an idiot.
Findfile + LEGACYCODESEARCH in BricsCAD
« on: August 03, 2022, 05:19:47 AM »
Has anyone else noticed the change in LISP findfile behaviour in recent BricsCAD releases?

With V19 they added LEGACYCODESEARCH system variable, but it had no effect.
With V20 on, BricsCAD has LEGACYCODESEARCH, SECURELOAD, and TRUSTEDPATHS. All of which are now enabled.
It's not that well documented. Mainly discussed here
https://developer.bricsys.com/bricscad/help/en_US/V22/DevRef/index.html?page=source%2FApplicationSecurity.htm

The Lisp Developer Support Package (LDSP) includes some registry snipits in the security folder to change the behaviour back to legacy. This requires Admin access, as these are under the HKEY_LOCAL_MACHINE
https://boa.bricsys.com/applications/a/?lisp-developer-support-package-(ldsp)-a720-al1176

If you're a CAD admin and you want to set TRUSTEDPATHS, then you would need to edit the registry key. As far as I'm aware there is no interface provided to set.

I find the LISP findfile behaviour annoying as it now fails to find files in the current drawing folder. I know they have simply implemented the same functionality as AutoCAD, but I don't get the logic of having a function to find files that doesn't always find files!

I commonly store files in the same folder as the current drawing. These aren't LISP, often just simple text files.

LEGACYCODESEARCH is not offering any protection, as it you can simply build a new search function to get around the limitation. here are a couple of examples that follow legacy behaviour to findfiles.

Code - Auto/Visual Lisp: [Select]
  1. ;LEGACYFINDFILE
  2.  
  3. ; Provides legacy findfile behaviour without the need of setting LEGACYCODESEARCH = 1
  4. ; Searches in the following order:
  5. ; - If a folder path is included with the filename, searches just there.
  6. ; - Current drawing folder.
  7. ; - Start-In folder. This is the folder that the progam has been launched from
  8. ; - Installation folder. Folder that application has been installed in.
  9. ; - Folders listed on search path, normal findfile behaviour
  10.  
  11.  
  12. (defun legacyfindfile (fn / startin dwgfolder installkey installfolder return)
  13.         (setq startin (strcat (vl-string-right-trim "\\." (findfile ".")) "\\")) ; Finds the Start-In folder. BricsCAD returns the "\\." AutoCAD doesn't
  14.         (setq dwgfolder (getvar 'DWGPREFIX)) ; current drawing folder
  15.         ; Retrieve the Installation folder from registry. BricsCAD returns the "\\" AutoCAD doesn't
  16.         (setq installkey (if (= (getvar 'PROGRAM) "BRICSCAD") "InstallDir" "acadlocation")) ; reg key is application specific
  17.         (setq installfolder (strcat (vl-string-right-trim "\\" (vl-registry-read (strcat "HKEY_LOCAL_MACHINE\\" (vlax-product-key)) installkey)) "\\"))
  18.         (cond
  19.       ; GIVEN FOLDER
  20.       ; If the filename includes the path or starts with "."
  21.       ((or (/= (vl-filename-directory fn) "") (= (substr fn 1 1) "."))
  22.                                 (setq return (findfile fn))
  23.                         )
  24.                         ; CURRENT DRAWING FOLDER
  25.                         ; If the drawing has been saved, then search the current dwgfolder for the file
  26.                         ((and (= (getvar 'dwgtitled) 1) (setq return (findfile (strcat dwgfolder fn))))
  27.                          return
  28.                         )
  29.                         ; START-IN FOLDER
  30.                         ; Search the start-in folder for the file.
  31.                         ; This step may not be necessary as normal findfile searches here in anycase.
  32.                         ; However, this does insure that it follows legacy search order
  33.                         ((setq return (findfile (strcat startin fn)))
  34.                          return
  35.                         )
  36.                         ; INSTALL FOLDER
  37.                         ; Search the installation folder for the cad application
  38.                         ; again not necessary as normal findile searches here too
  39.                         ((setq return (findfile (strcat installfolder fn)))
  40.                          return
  41.                         )
  42.       ; SEARCH PATH
  43.       ; Use standard findfile behavior to search the support file search path
  44.                         (T (setq return (findfile fn)))
  45.         )
  46. return
  47. )


Code - Auto/Visual Lisp: [Select]
  1. ; BCADLEGACYFINDFILE
  2. ; Does the same based on a specific list of folders.
  3. ; Requires BricsCAD VLE Extension for it to work in AutoCAD
  4.  
  5. (defun bcadlegacyfindfile (fn / searchfolders installkey flag return)
  6.   (cond
  7.     ; GIVEN FOLDER
  8.     ; If the filename includes the path, or starts with "."
  9.      ((or (/= (vl-filename-directory fn) "") (= (substr fn 1 1) "."))
  10.           (setq return (findfile fn))
  11.      )
  12.      ; SEARCH FOLDERS
  13.      ; Search for the file across our list of searchfolders
  14.     (T
  15.       ; Build search folder list
  16.       ; Current drawing
  17.        (if (= (getvar 'dwgtitled) 1) (setq searchfolders (getvar 'DWGPREFIX)))
  18.        ; Start-in
  19.        (setq searchfolders (strcat searchfolders ";" (findfile ".")))  ; Finds the Start-In folder.
  20.        ; Installation folder.
  21.        (setq installkey (if (= (getvar 'PROGRAM) "BRICSCAD") "InstallDir" "acadlocation"))  ; reg key is application specific
  22.        (setq searchfolders (strcat searchfolders ";" (vl-registry-read (strcat "HKEY_LOCAL_MACHINE\\" (vlax-product-key)) installkey)))
  23.        ;Support file search path
  24.        (setq searchfolders (strcat searchfolders ";" (getenv "ACAD")))
  25.        ;convert to list and clean up path end
  26.        (setq searchfolders (mapcar '(lambda (fol) (strcat (vl-string-right-trim "\\." fol) "\\")) (vle-string-split ";" searchfolders)))
  27.        (setq flag T)
  28.         (while (and flag searchfolders)
  29.           (cond
  30.             ((setq return (findfile (strcat (car searchfolders) fn)))
  31.                    (setq flag nil)
  32.             )
  33.             (T (setq searchfolders (cdr searchfolders) flag T))
  34.           )
  35.         )
  36.     )
  37.   )
  38.   return
  39. )