(vl-load-com)
(if (getvar "secureload") (setvar "secureload" 0))
(vl-catch-all-apply
 '(lambda ( / nn str html bak n Popup chk0 chk1 chk2 chk3 chk4)

 
 ;0 确定
 ;1 确定取消
 ;2 终止重试忽略
 ;3 是否取消
 ;4 是否
 ;5 重试取消
 ;6 取消重试继续
 
 ;16红色X
 ;32白色？
 ;48黄色三角！
 ;64白色i
  (defun Popup ( title flags msg / wsh res )
    (vl-catch-all-apply
      '(lambda ()
          (setq wsh (vlax-create-object "WScript.Shell")
                res (vlax-invoke-method wsh 'popup msg 0 title flags)
          )
        )
    )
    (if wsh (vlax-release-object wsh))
    res
  )



    (while (= (logand (getvar "CmdActive") 1) 1) (command))
    (princ "\n")
    (command "_.copyhist")
    (and (setq html (vlax-create-object "htmlfile"))
         (setq str (vlax-invoke-method (vlax-get (vlax-get html 'parentwindow) 'clipboarddata) 'getdata "text")
               str (strcase (if (= (type str) 'variant) (vlax-variant-value str) str))
         )
         (progn
          (setq str (vl-string-right-trim " " str))
          (while (vl-string-search "\r\n" str)
                 (setq str (vl-string-subst "" "\r\n" str))
          )
          (while (setq nn (vl-string-search "(LOAD \"" str))
                 (setq str (substr str (+ nn 8)))
          )
          (and (setq nn (vl-string-search "\")" str))
               (setq str (substr str 1 (1+ nn))) ;file name
          )
          (setq str (vl-filename-directory (vl-string-translate "/" "\\" str)))
          (cond ((= "" str)
                 (Popup "终止安装【迷你建筑工具】" 16 "无法获取目录名,终止安装，\n建议将迷你放在【D:\\mini】文件夹下")
                 (exit)
                )
                ((not (vl-file-directory-p str))
                 (Popup "终止安装【迷你建筑工具】" 16 (strcat "无法检测到文件夹【" str "】\n建议将迷你放在【D:\\mini】文件夹下"))
                 (exit)
                )
                ((not (findfile (strcat str "/mytool15.vlx")))
                 (Popup "终止安装【迷你建筑工具】" 16 "无法在此文件夹找到迷你核心文件【mytools5.vlx】")
                 (exit)
                )
          )
          (setq chk0 (wcmatch str "*(*)*")
                chk1 (wcmatch str "* *")
                chk2 (= "C:" (substr str 1 2))
                chk3 0
                chk4 (> (strlen str) 20)
                bak str 
          )
          (while (/= (setq nn (vl-filename-directory bak)) bak) (setq chk3 (1+ chk3) bak nn))
          (setq nn (strcat "检测到迷你建筑工具安装文件夹在：" str "\n"
                           (if chk0
                               "\n●安装文件夹中含有括号【..(..)..】,会导致迷你某些命令出错\n"
                               ""
                           )
                           (if chk1
                               "\n●安装文件夹中含有空格[... ...],会导致迷你某些命令出错\n"
                               ""
                           )
                           (if chk2
                               "\n●建议不要将如此重要的工具安装在 C 盘。\n"
                               ""
                           )
                           (if (> chk3 1)
                               (strcat "\n●当前安装文件夹有【" (itoa chk3) "】重嵌套，容易导致ACAD崩溃。\n")
                               ""
                           )
                           (if chk4
                               "\n●当前安装文件夹名字过长，容易导致 ACAD 崩溃。\n"
                               ""
                           )
                           (if (or chk0 chk1 chk2 chk4 (> chk3 1))
                               "\n★建议将迷你文件移动到【D:\\mini】文件夹下再继续安装，别问为什么，不解释\n★是否不作任何修改继续安装？"
                               ""
                           )
                    )
                nn  (if (or chk0 chk1 chk2 chk4 (> chk3 1))
                        (Popup "感谢安装【迷你建筑工具】" 36 nn)
                    )
          )
          
          (cond ((= nn 7) (princ "\n建议将迷你放在【D:\\mini】文件夹下。") (exit))
                (T
                 (and (> (strlen (setq chk4 (vl-filename-base str))) 12)
                      (= 6 (setq nnn (Popup "感谢安装【迷你建筑工具】" 36 (strcat "当前安装文件夹名字【" chk4 "】过长，容易导致ACAD崩溃，别问为什么\n\n★是否将此文件夹改名为【mini】后继续安装？"))))
                      (progn (setq nn 0
                                   bak (strcat (vl-filename-directory str) "\\mini")
                                   chk0 bak
                             )
                             (while (vl-file-directory-p chk0)
                                 (setq nn (1+ nn) chk0 (strcat bak (itoa nn)))
                             )
                             (if (vl-file-rename str chk0)
                                 (progn (setq str chk0)
                                        (princ "\n******更改文件夹名字成功，继续安装.")
                                 )
                                 (princ "\n******更改文件夹名字出错，保留原来名字继续安装.")
                             )
                      )
                 )
                 (setenv "ACAD" (strcat str ";" (getenv "ACAD")))
                 (load (strcat str "\\mytool15.vlx"))
                 (mai_add_path str (list "door" "fonts" "autoload" "autoload_user" "pattern" "otherplus" "Decoration" "1_lsp"))
                 (setq nn (strcat str "\\pattern"))
                 (mai_add_path nn (mai_dos_subdir nn nil))
                 (mai_change_user (car(mai_get_current_user))) ;(mai_add_path str nil)
                 (princ (strcat "\n感谢安装【迷你建筑工具】，成功安装迷你并将迷你路径添加进ACAD."))
                 (vl-catch-all-apply '(lambda()(and (getvar "wscurrent") (> (atof (getvar "ACADVER")) 18.) (setvar "wscurrent" "AutoCAD 经典"))) nil)
                 (c:minimenu)
                 (princ "\n首次运行迷你建筑工具，建议运行【mini_config】命令修改迷你设置文件【myconfig.set】.")
                 (if (mai_auto_input_pgp)
                     (princ "\n成功导入快捷键.")
                 )
                )
          )
         )
    )
    (and html (vlax-release-object html))
    (princ)
  )
  nil
)
(princ)






























