         title   Startup
         .586
         .model flat, stdcall
            option   casemap: none

            include  L:\AsmEdit\include\windows.inc
            include  user32.inc
            include  kernel32.inc
            include  gdi32.inc
            include  imagehlp.inc
            include  shell32.inc
            include  advapi32.inc

     include  L:\AsmEdit\include\DSPMACRO.asm

         includelib  user32.lib
         includelib  kernel32.lib
         includelib  gdi32.lib
         includelib  imagehlp.lib
         includelib  shell32.lib
         includelib  advapi32.lib

WndProc         PROTO  :DWORD, :DWORD, :DWORD, :DWORD
FindRep         PROTO  :DWORD, :DWORD

.data
RichEdit       db  'RichEdit20A',0
RichEdDLL      db  'RICHED20.DLL',0
ListboxClass   db  'listbox',0

AppName        db  'Setup',0

szRedit        db  'Software\EW Software\AsmEdit V5\',0
szREGSZ        db  'REG_SZ',0
rDEFr          db  '[Default Root Dir]',0
rDEFb          db  '[Default Bin Dir.]',0
rDEFp          db  '[Default Proj Dir]',0
rDEFi          db  '[Default Inc Dir.]',0
rDEFs          db  '[Default Back Dir]',0
rDEFh          db  '[Win32 Help Dir..]',0

szSetup        db  'Setup',0
szBin          db  'Bin\',0
szLib          db  'lib\',0
szBak          db  'Backup\',0
szInc          db  'include\',0
szPgm          db  'Programs\',0
szPro          db  'Projects\',0
szAdd          db  'Addins\',0
szPoi          db  'Pointers\',0
szPoiUser      db  'PointUser\Pointers01\',0
szReg          db  'Registry\',0

szData         db  '.data',0
szCode         db  '.code',0
szCp           db  '/Cp',0
szI            db  ' /I ',0
szRc           db  '\rc ',0
szWindows      db  ':WINDOWS',0
szIncP         db  '\Include',0
szLibP         db  '\Lib ',0
szLibPath      db  '/LIBPATH:',0
szIncNS        db  'Include',0
szLibNS        db  'Lib ',0

szPgmP         db  'Updating The Program Paths',0
szProP         db  'Updating The Project Paths',0
szAddP         db  'Updating The Addin Paths',0
szPoiP         db  'Updating The Pointer Paths',0

szWininc       db  'Windows.inc',0
szDSPMACRO     db  'DSPMACRO.asm',0
szdebuginc     db  'debug.inc',0
szdebuglib     db  'debug.lib',0

szIncWin       db  '\Include\windows.inc',0 ;wow32.inc
szMasm32       db  'Masm32',0
szFile         db  'wow32.inc',0
szWin32hlp     db  'Win32.hlp',0
szMasm32V1     db  'Masm32V1',0
szIncludeR     db  '#include',0
szInclude      db  'include',0
szLibrary      db  'includelib',0

szFile01       db  'windows',0
szFile02       db  'user32',0
szFile03       db  'kernel32',0
szFile04       db  'comctl32',0
szFile05       db  'comdlg32',0
szFile06       db  'gdi32',0
szFile07       db  'advapi32',0
szFile08       db  'shell32',0
szFile09       db  'tapi32',0
szFile10       db  'ole32',0
szFile11       db  'winmm',0
szFile12       db  'winspool',0
szFile13       db  'version',0
szFile14       db  'imagehlp',0
szFile15       db  'wsock32',0
szFile16       db  'oleaut32',0
szFile17       db  'resource',0
szFile18       db  'masm32',0

szFileArray    dd  szFile01,szFile02,szFile03,szFile04,szFile05,szFile06,szFile07,
                   szFile08,szFile09,szFile10,szFile11,szFile12,szFile13,szFile14,
                   szFile15,szFile16,szFile17,szFile18


szNULL         db  ' ',0
szLess         db  '<',0
szBackS        db  '\',0
szEnd          db  '*.*',0
szDir          db  'C:\*.*',0
szR1           db  'R1=',0
szA1           db  'A1=',0
szL1           db  'L1=',0
szCR           db  0dh,0
szCRLF         db  0dh,0ah,0
szPPPP         db  'PPPP',0

szBat          db  'CD \Masm32V1\Programs\AsmEdit\', 0Dh,0Ah
               db  'PPPP\BIN\rc /I PPPP\Include AsmEdit.rc', 0Dh,0Ah
               db  'PPPP\BIN\ml /c /coff /Cp /I PPPP\Include AsmEdit.asm MRUFiles.asm Treeview.asm Listview.asm MenuMaint.asm', 0Dh,0Ah
               db  'PPPP\BIN\link /SUBSYSTEM:WINDOWS /LIBPATH:PPPP\Lib AsmEdit.obj MRUFiles.obj Treeview.obj Listview.obj MenuMaint.obj AsmEdit.res', 0Dh,0Ah
               db  'CD \Masm32V1\',0
szAsmEdit      db  'AsmEdit\AsmEdit.bat',0

szError1       db  'The RICHED20.DLL was not found!',0

szMsg1         db  'You Must Run The Setup Program'
               db  0Dh,0Ah
               db  0Dh,0Ah
               db  'From The AsmEdit Root Directory.',0

szMsg2         db  'Windows.inc Is Already Present !'
               db  0Dh,0Ah
               db  0Dh,0Ah
               db  'Do You Wish To Replace It ?'
               db  0Dh,0Ah
               db  0Dh,0Ah
               db  'If you select No the paths will', 0Dh,0Ah
               db  'still be updated.',0

szMsg3         db  '      The File Has Been Copied Successfully'
               db  0Dh,0Ah
               db  'And The Paths For AsmEdit Have Been Updated !'
               db  0Dh,0Ah
               db  0Dh,0Ah
               db  "                        HAVE A NICE DAY !",0

szMsg4         db  '                         No File Was Copied'
               db  0Dh,0Ah
               db  'And The Paths For AsmEdit Have Been Updated !'
               db  0Dh,0Ah
               db  0Dh,0Ah
               db  "                        HAVE A NICE DAY !",0

szMsg5         db  'The Copy Was NOT Successfull !'
               db  0Dh,0Ah
               db  0Dh,0Ah
               db  'You Will Have To Copy The File Manually',0

szStatus1      db  'Checking if file has been copied',0
szStatus2      db  'Searching for Win32 Help',0
szStatus3      db  'Searching for MASM32',0
szStatus4      db  'Copying the Include files',0
szStatus5      db  'Copying the Bin files',0
szStatus6      db  'Copying the Lib files',0
szStatus7      db  'Updating the path names',0

;szFixFind      db  'L:\MASM32V1\PROGRAMS\AsmEdit\windows.inc',0
;szFixUpdate    db  'L:\MASM32V1\PROGRAMS\AsmEdit\include\windows.inc',0
;szFixFind      db  'L:\MASM32V1\PROGRAMS\AsmEdit\DSPMACRO.asm',0
;szFixUpdate    db  'L:\MASM32V1\PROGRAMS\AsmEdit\include\DSPMACRO.asm',0


DriveLetter    db  'C:\',0
DriveArray     db  30  dup(?)

Lev            dd  0
lpType         dd  0
lpcbData       dd  0
lpdwDisp       dd  0
PoiCnt         dd  8

.data?
szFind         db  20  dup(?)
szBuff4        db  256 dup(?)
HutchDir       db  256 dup(?)
hSubDir        dd  32  dup(?)
PathLen        dd  32  dup(?)

hInst          dd  ?
hREdDll        dd  ?
hREdit         dd  ?
hListbox       dd  ?
fpMem          dd  ?
hpMem          dd  ?
hFile          dd  ?
BytesRead      dd  ?
hOper          dd  ?
hStat          dd  ?
AddPath        dd  ?

Test4          dd  ?

.code

start:
      INVOKE     GetModuleHandle, NULL
         mov     hInst, eax

;        call     InitCommonControls          ; Initialize the common ctrl lib
      INVOKE     LoadLibrary, addr RichEdDLL ; Load the Riched20.dll
         mov     hREdDll, eax
      .if !eax
         INVOKE     MessageBox, NULL, addr szError1, addr szSetup, MB_OK or MB_ICONERROR
            jmp     NoGo
      .endif

;---------- [Call the dialog box stored in resource file] ----------
      INVOKE     DialogBoxParam, hInst, addr AppName, 0, addr WndProc, 0
      INVOKE     FreeLibrary, hREdDll
      INVOKE     ExitProcess, eax

NoGo:
      INVOKE     ExitProcess, 0


;________________________________________________________________________________
WndProc proc  uses ebx esi edi hWnd:DWORD, uMsg, wParam, lParam
LOCAL    FindData:WIN32_FIND_DATA
LOCAL    ShFileOp:SHFILEOPSTRUCT
LOCAL    ft:FINDTEXT
LOCAL    cr:CHARRANGE
LOCAL    tr:TEXTRANGE
LOCAL    hReg:DWORD, Dirs, DirI, DirB, DirL, Cnt, Step, hFind, hFindS, sw1, h431, Cnt2
LOCAL    NoCopy:DWORD, AsmDirOn, NewOn, SameDir, EndPos, SavMax, RcOn, Incr
LOCAL    CurDir[256]:BYTE, szBuff0[256]:BYTE, szBuff1[256]:BYTE, szBuff2[256]:BYTE
LOCAL    szBuff3[256]:BYTE, szWork[256]:BYTE, szPath[256]:BYTE, szExt[6]:BYTE
LOCAL    AsmEditDir[256]:BYTE, DriveLet:BYTE, FileName[32]:BYTE

      .if uMsg == WM_INITDIALOG
         INVOKE     LoadIcon, 0, IDI_APPLICATION
         INVOKE     SendMessage, hWnd, WM_SETICON, 1, eax

         INVOKE     CreateWindowEx, 0, addr ListboxClass, 0,\
                    WS_CHILD or WS_BORDER or WS_VSCROLL or\
                    LBS_HASSTRINGS or LBS_NOINTEGRALHEIGHT or LBS_NOTIFY or LBS_SORT,\
                    100, 100, 100, 100, hWnd, 89, hInst, 0
            mov     hListbox, eax

            and     AddPath, 0
         INVOKE     SendDlgItemMessage, hWnd, 201, BM_SETCHECK, BST_CHECKED, 0

         INVOKE     GetDlgItem, hWnd, 431
            mov     h431, eax
         INVOKE     SetFocus, h431

         INVOKE     GetDlgItem, hWnd, 104
            mov     hOper, eax
         INVOKE     GetDlgItem, hWnd, 105
            mov     hStat, eax

;---------- [Find available drives] ----------
         INVOKE     GetLogicalDrives
            mov     ebx, eax
            shr     ebx, 2                             ; Skip test for drives A: & B:
            xor     edx, edx
         .while (ebx > 0)
               shr     ebx, 1
              push     edx
              push     ebx
            INVOKE     GetDriveType, addr DriveLetter  ; Get type of drive
               pop     ebx
               pop     edx
   
;---------- [If FIXED drive add the letter to the array] ----------
            .if eax == DRIVE_FIXED
                  mov     al, byte ptr DriveLetter
                  mov     DriveArray[edx], al
                  inc     edx
            .endif
               inc     DriveLetter
         .endw
            mov     DriveArray[edx], 0
            jmp     Ret0


      .elseif uMsg == WM_CLOSE
            jmp     GetOut

      .elseif uMsg == WM_COMMAND
         .if wParam == 102
               jmp     PressOn
         .elseif wParam == 103
               jmp     GetOut
         .elseif wParam == 201 || wParam == 202
            INVOKE     SetFocus, h431
            INVOKE     IsDlgButtonChecked, hWnd, 202
            .if eax
                  mov     AddPath, 1
            .endif
         .else
               jmp     Ret0
         .endif
      .endif
         jmp     Ret0

PressOn:
         and     NoCopy, 0
         and     SameDir, 0
      INVOKE     LoadCursor, NULL, IDC_WAIT
      INVOKE     SetCursor, eax

      INVOKE     RegCreateKeyEx, HKEY_CURRENT_USER, addr szRedit, 0, addr szREGSZ, 0,\
                 KEY_WRITE or KEY_READ, 0, addr hReg, addr lpdwDisp

         mov     byte ptr szBuff0, 0
         mov     lpcbData, 250
      INVOKE     RegQueryValueEx, hReg, addr rDEFr, 0, addr lpType, addr szBuff0, addr lpcbData
      .if szBuff0 == ' ' || !szBuff0

      .endif

      INVOKE     GetCurrentDirectory, lengthof CurDir, addr CurDir

;---------- [Make sure Setup is run from the AsmEdit root dir] ----------
      INVOKE     lstrlen, addr CurDir
         sub     eax, 5
         mov     ecx, dword ptr AppName
      .if ecx == dword ptr CurDir[eax] && byte ptr CurDir[eax+4] == 'p'
         INVOKE     MessageBox, hWnd, addr szMsg1, addr AppName, MB_OK or MB_ICONSTOP or MB_SYSTEMMODAL
            jmp     GetOut
      .endif

      INVOKE     SetWindowText, hOper, addr szStatus1

      INVOKE     lstrcpy, addr szPath, addr CurDir+3
      INVOKE     lstrcpy, addr AsmEditDir, addr CurDir
      INVOKE     lstrcat, addr AsmEditDir, addr szBackS

      INVOKE     lstrcpy, addr szBuff1, addr CurDir
      INVOKE     lstrcat, addr szBuff1, addr szBackS
      INVOKE     lstrcmpi, addr szBuff0, addr szBuff1
      .if !eax
            mov     SameDir, 1
      .endif

      INVOKE     lstrcpy, addr szBuff0, addr szBuff1
      INVOKE     lstrlen, addr szBuff0
         mov     lpcbData, eax
      INVOKE     RegSetValueEx, hReg, addr rDEFr, 0, REG_SZ, addr szBuff0, lpcbData

      INVOKE     lstrcpy, addr szBuff2, addr szBuff1
      INVOKE     lstrcat, addr szBuff2, addr szBak
      INVOKE     lstrlen, addr szBuff2
         mov     lpcbData, eax
      INVOKE     RegSetValueEx, hReg, addr rDEFs, 0, REG_SZ, addr szBuff2, lpcbData

      INVOKE     lstrcpy, addr szBuff2, addr szBuff1
      INVOKE     lstrcat, addr szBuff2, addr szBin
      INVOKE     lstrlen, addr szBuff2
         mov     lpcbData, eax
      INVOKE     RegSetValueEx, hReg, addr rDEFb, 0, REG_SZ, addr szBuff2, lpcbData

      INVOKE     lstrcpy, addr szBuff2, addr szBuff1
      INVOKE     lstrcat, addr szBuff2, addr szPro
      INVOKE     lstrlen, addr szBuff2
         mov     lpcbData, eax
      INVOKE     RegSetValueEx, hReg, addr rDEFp, 0, REG_SZ, addr szBuff2, lpcbData

      INVOKE     lstrcpy, addr szBuff2, addr szBuff1
      INVOKE     lstrcat, addr szBuff2, addr szInc
      INVOKE     lstrlen, addr szBuff2
         mov     lpcbData, eax
      INVOKE     RegSetValueEx, hReg, addr rDEFi, 0, REG_SZ, addr szBuff2, lpcbData

;---------- [Search for Win32 Help] ----------
      INVOKE     SetWindowText, hOper, addr szStatus2
      INVOKE     lstrlen, addr DriveArray
         mov     Dirs, eax
         mov     Cnt, 0

GetDirH:
      .if !Dirs
            jmp     NoGo4
      .endif
         mov     eax, Cnt
         mov     bl, DriveArray[eax]
         mov     szDir, bl
         inc     Cnt
         dec     Dirs
      INVOKE     lstrcpyn, addr szBuff0, addr szDir, 4
      INVOKE     SetWindowText, hStat, addr szBuff0
      INVOKE     UpdateWindow, hStat
      INVOKE     SearchTreeForFile, addr szBuff0, addr szWin32hlp, addr szBuff2
      .if eax
         INVOKE     lstrlen, addr szBuff2
            mov     lpcbData, eax
         INVOKE     RegSetValueEx, hReg, addr rDEFh, 0, REG_SZ, addr szBuff2, lpcbData
      .else
            jmp     GetDirH
      .endif

NoGo4:
      INVOKE     RegCloseKey, hReg
         mov     NewOn, 1
      INVOKE     lstrcpy, addr szBuff0, addr CurDir
      INVOKE     lstrcat, addr szBuff0, addr szIncWin
      INVOKE     FindFirstFile, addr szBuff0, addr FindData
      .if eax == -1
            jmp     FindFile
      .else
         INVOKE     FindClose, eax
            and     NewOn, 0
         INVOKE     MessageBox, NULL, addr szMsg2, addr szSetup, MB_YESNO
         .if eax == IDNO
;            INVOKE     lstrcat, addr CurDir, addr szBackS
               mov     NoCopy, 1
;               jmp     DoSource ;HaveFile
         .endif
      .endif

FindFile:
      INVOKE     SetWindowText, hOper, addr szStatus3

      INVOKE     lstrcpy, addr szBuff0, addr CurDir
      INVOKE     lstrcat, addr szBuff0, addr szBackS

      INVOKE     lstrlen, addr DriveArray
         mov     Dirs, eax
         mov     Cnt, 0

;_______________________________________________________________________
GetDir:
      .if !Dirs
            jmp     AllDone
      .endif
         mov     eax, Cnt
         mov     bl, DriveArray[eax]
         mov     szDir, bl
         inc     Cnt
         dec     Dirs

      INVOKE     lstrcpy, addr szBuff0, addr szDir
      INVOKE     FindFirstFile, addr szBuff0, addr FindData
        test     eax, eax
          js     NoFile
         mov     hFind, eax
         jmp     ChkDir

;_______________________________________________________________________
NextDir:
      INVOKE     FindNextFile, hFind, addr FindData
        test     eax, eax
          jz     GetDir

;_______________________________________________________________________
ChkDir:
      .if (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
         INVOKE     lstrcmpi, addr FindData.cFileName, addr szMasm32
         .if !eax
            INVOKE     lstrlen, addr szBuff0
               sub     eax, 2
            INVOKE     lstrcpyn, addr szBuff2, addr szBuff0, eax
            INVOKE     lstrcat, addr szBuff2, addr FindData.cFileName
            INVOKE     lstrcat, addr szBuff2, addr szBackS
            INVOKE     SearchTreeForFile, addr szBuff2, addr szFile, addr szBuff3

            .if eax
               INVOKE     lstrlen, addr szFile
                  dec     eax
                 push     eax
               INVOKE     lstrlen, addr szBuff3
                  pop     ebx
                  sub     eax, ebx
               INVOKE     lstrcpyn, addr szBuff3, addr szBuff3, eax
            .else
                  jmp     DoMore1
            .endif
               jmp     AllDone
         .else

;_______________________________________________________________________
DoMore1:
            INVOKE     lstrcpyn, addr szBuff1, addr szDir, 4
            INVOKE     lstrcat, addr szBuff1, addr FindData.cFileName
            INVOKE     lstrcat, addr szBuff1, addr szDir+2
               mov     Lev, 0
               jmp     GetSubDir
         .endif
      .endif
            jmp     NextDir

;_______________________________________________________________________
GetSubDir:
      INVOKE     FindFirstFile, addr szBuff1, addr FindData
      .if eax == -1
         .if !Lev
               jmp     NextDir
         .else
               mov     ebx, Lev
               mov     eax, PathLen[ebx*4]
            INVOKE     lstrcpyn, addr szBuff1, addr szBuff1, eax
               dec     Lev
               jmp     GetSubDir
         .endif
      .endif
         mov     ebx, Lev
         mov     hSubDir[ebx*4], eax
         jmp     ChkSubDir

;_______________________________________________________________________
NextSubDir:
         mov     ebx, Lev
      INVOKE     FindNextFile, hSubDir[ebx*4], addr FindData
      .if !eax  ;eax = 0 = failure
            mov     ebx, Lev   
         INVOKE     FindClose, hSubDir[ebx*4]
         .if !Lev
               jmp     NextDir
         .else
               dec     Lev
               mov     ebx, Lev
               mov     eax, PathLen[ebx*4]
               sub     eax, 3
            INVOKE     lstrcpyn, addr szBuff1, addr szBuff1, eax
            INVOKE     lstrcat, addr szBuff1, addr szDir+2
               jmp     NextSubDir
         .endif
      .endif

;_______________________________________________________________________
ChkSubDir:
      .if (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
         INVOKE     lstrcmpi, addr FindData.cFileName, addr szMasm32
         .if !eax
            INVOKE     lstrlen, addr szBuff1
               sub     eax, 2
            INVOKE     lstrcpyn, addr szBuff2, addr szBuff1, eax
            INVOKE     lstrcat, addr szBuff2, addr FindData.cFileName
            INVOKE     lstrcat, addr szBuff2, addr szBackS
            INVOKE     SearchTreeForFile, addr szBuff2, addr szFile, addr szBuff3
            .if eax
               INVOKE     lstrlen, addr szFile
                  dec     eax
                 push     eax
               INVOKE     lstrlen, addr szBuff3
                  pop     ebx
                  sub     eax, ebx
               INVOKE     lstrcpyn, addr szBuff3, addr szBuff3, eax
            .else
                  jmp     DoMore2
            .endif
               mov     ebx, Lev
            INVOKE     FindClose, hSubDir[ebx*4]
               jmp     AllDone
         .else

;_______________________________________________________________________
DoMore2:
            .if byte ptr FindData.cFileName == '.'
                  jmp     NextSubDir
            .endif
            INVOKE     lstrlen, addr szBuff1
               mov     ebx, Lev
               mov     PathLen[ebx*4], eax
               sub     eax, 2
            INVOKE     lstrcpyn, addr szBuff1, addr szBuff1, eax
            INVOKE     lstrcat, addr szBuff1, addr FindData.cFileName
            INVOKE     lstrcat, addr szBuff1, addr szDir+2
               inc     Lev
               jmp     GetSubDir
         .endif
      .endif
         jmp     NextSubDir

;_____________________________________________________________________
AllDone:
         and     sw1, 0
         and     Cnt, 0
         and     DirI, 0
         and     DirB, 0
         and     DirL, 0
         and     fpMem, 0
         and     hpMem, 0

      INVOKE     FindClose, hFind
      INVOKE     lstrcpy, addr szBuff1, addr szBuff2  ; Input Dir    F:\Masm32\
      INVOKE     lstrcpy, addr HutchDir, addr szBuff2 ; Input Dir    F:\Masm32\
      INVOKE     lstrcpy, addr szBuff2, addr CurDir
      INVOKE     lstrcat, addr szBuff2, addr szBackS
      INVOKE     lstrcpy, addr CurDir, addr szBuff2   ; Output Dir   L:\MASM32V1\PROGRAMS\AsmEdit\
      INVOKE     lstrcat, addr szBuff2, addr szBak
   INVOKE     CreateDirectory, addr szBuff2, NULL

      INVOKE     lstrcpy, addr szBuff2, addr CurDir
      INVOKE     lstrcat, addr szBuff2, addr szReg
   INVOKE     CreateDirectory, addr szBuff2, NULL

      INVOKE     RegCreateKeyEx, HKEY_CURRENT_USER, addr szRedit, 0, addr szREGSZ, 0,\
                 KEY_WRITE or KEY_READ, 0, addr hReg, addr lpdwDisp
      INVOKE     lstrlen, addr szBuff1
         mov     lpcbData, eax
      INVOKE     RegSetValueEx, hReg, addr rDEFb, 0, REG_SZ, addr szBuff1, lpcbData
      INVOKE     RegCloseKey, hReg

.if NoCopy
;      and     NoCopy, 0
      jmp     DoSource
.endif

      INVOKE     lstrcpy, addr szBuff2, addr CurDir
      INVOKE     lstrcat, addr szBuff2, addr szInc
   INVOKE     CreateDirectory, addr szBuff2, NULL

      INVOKE     lstrcpy, addr szBuff0, addr CurDir
      INVOKE     lstrcat, addr szBuff0, addr szPro
   INVOKE     CreateDirectory, addr szBuff0, NULL

      INVOKE     SetWindowText, hOper, addr szStatus4

;_______________________________________________________________________
CopyMore:
      INVOKE     lstrlen, addr szBuff2
         inc     eax
         mov     szBuff2[eax], 0     ; Insert additional terminator

      INVOKE     SetCurrentDirectory, addr szBuff3
      INVOKE     lstrcat, addr szBuff3, addr szEnd

;_______________________________________________________________________
GetFirstF:
      INVOKE     FindFirstFile, addr szBuff3, addr FindData
        test     eax, eax
          js     NoFile
         mov     hFind, eax
         inc     Cnt
         jmp     ChkFile

;_______________________________________________________________________
GetNextF:
      INVOKE     FindNextFile, hFind, addr FindData
        test     eax, eax
          jz     CloseIt

;_______________________________________________________________________
ChkFile:
      .if byte ptr FindData.cFileName == '.'
            jmp     GetNextF
      .endif

;_______________________________________________________________________
      INVOKE     lstrlen, addr FindData.cFileName
         inc     eax
         mov     FindData.cFileName[eax], 0  ; Insert additional terminator

;$$$$$$$$$$$$$$$$$$$$$$$$$$$
      .if eax == 12
         .if byte ptr FindData.cFileName == 'W'
               mov     byte ptr FindData.cFileName, 'w'
         .endif
         .if byte ptr FindData.cFileName+3 == 'D'
               mov     byte ptr FindData.cFileName+3, 'd'
         .endif
         .if byte ptr FindData.cFileName+6 == 'S'
               mov     byte ptr FindData.cFileName+6, 's'
         .endif
         .if byte ptr FindData.cFileName+8 == 'I'
               mov     byte ptr FindData.cFileName+8, 'i'
         .endif
;---------- [Only copy Windows.inc] ----------
         .if byte ptr FindData.cFileName == 'w' && byte ptr FindData.cFileName+3 == 'd' &&\
             byte ptr FindData.cFileName+6 == 's' && byte ptr FindData.cFileName+8 == 'i'
         .else
               jmp     GetNextF
         .endif
      .else
            jmp     GetNextF
      .endif
;$$$$$$$$$$$$$$$$$$$$$$$$$$$

      .if sw1
         .if byte ptr FindData.cFileName[eax-4] == 'b'
               mov     byte ptr FindData.cFileName[eax-4], 'B'
         .endif
         .if byte ptr FindData.cFileName[eax-2] == 't'
               mov     byte ptr FindData.cFileName[eax-2], 'T'
         .endif

;---------- [Bypass batch files] ----------
         .if byte ptr FindData.cFileName[eax-4] == 'B' && byte ptr FindData.cFileName[eax-2] == 'T'
               jmp     GetNextF
         .endif
      .endif

         mov     ShFileOp.wFunc, FO_COPY
         mov     ShFileOp.hwnd, 0     ; If 0, then no parent can task switch away
         lea     eax, FindData.cFileName
         mov     ShFileOp.pFrom, eax
         lea     eax, szBuff2
         mov     ShFileOp.pTo, eax
         mov     ShFileOp.fFlags, FOF_SILENT or FOF_NOCONFIRMATION or FOF_NOCONFIRMMKDIR
      INVOKE     SHFileOperation, addr ShFileOp
      .if Cnt == 1
            inc     DirI
      .elseif Cnt == 2
            inc     DirB
      .elseif Cnt == 3
            inc     DirL
      .endif
         jmp     GetNextF

;_______________________________________________________________________
CloseIt:
      INVOKE     FindClose, hFind
      INVOKE     lstrlen, addr szBuff2
         sub     eax, 2
      .if byte ptr szBuff2[eax] == 'e'                   ; e = include
;---------- [Bypass Bin and Lib files] ----------
mov     Cnt, 3
jmp     DoSource
         INVOKE     lstrcpy, addr szBuff3, addr szBuff1  ; Input Dir    F:\Masm32\
         INVOKE     lstrcat, addr szBuff3, addr szBin
         INVOKE     lstrcpy, addr szBuff2, addr CurDir   ; Output Dir   L:\MASM32V1\PROGRAMS\AsmEdit\
         INVOKE     lstrcat, addr szBuff2, addr szBin
   INVOKE     CreateDirectory, addr szBuff2, NULL
            mov     sw1, 1
         INVOKE     SetWindowText, hOper, addr szStatus5
            jmp     CopyMore
      .elseif byte ptr szBuff2[eax] == 'n'               ; n = bin
         INVOKE     lstrcpy, addr szBuff3, addr szBuff1  ; Input Dir    F:\Masm32\
         INVOKE     lstrcat, addr szBuff3, addr szLib
         INVOKE     lstrcpy, addr szBuff2, addr CurDir   ; Output Dir   L:\MASM32V1\PROGRAMS\AsmEdit\
         INVOKE     lstrcat, addr szBuff2, addr szLib
   INVOKE     CreateDirectory, addr szBuff2, NULL
            and     sw1, 0
         INVOKE     SetWindowText, hOper, addr szStatus6
            jmp     CopyMore
      .endif
      .if Cnt == 3 && DirI && DirB && DirL
            jmp     DoSource
      .else

NoFile:
         INVOKE     MessageBox, NULL, addr szMsg5, addr szSetup, MB_OK
      .endif
         jmp     NoMore

DoSource:
; WS_VISIBLE or
      INVOKE     SetWindowText, hOper, addr szStatus7

      INVOKE     CreateWindowEx, 0, addr RichEdit, 0,\
                 WS_POPUP or ES_MULTILINE or\
                 WS_HSCROLL or WS_VSCROLL or ES_SAVESEL or ES_NOHIDESEL,\
                 100, 100, 400, 300, hWnd, 0, hInst, 0
         mov     hREdit, eax
      INVOKE     SendMessage, hREdit, EM_EXLIMITTEXT, 0, 8000000


;---------- [Find and update the include and includelib paths for the support programs] ----------
         mov     Step, 1

LoopStep1:
      INVOKE     lstrcpy, addr szBuff0, addr CurDir
      .if Step == 1
         INVOKE     lstrcat, addr szBuff0, addr szPgm
         INVOKE     SetWindowText, hOper, addr szPgmP
      .elseif Step == 2
         INVOKE     lstrcat, addr szBuff0, addr szPro
         INVOKE     SetWindowText, hOper, addr szProP
      .else
         INVOKE     lstrcat, addr szBuff0, addr szAdd
         INVOKE     SetWindowText, hOper, addr szAddP
      .endif
      INVOKE     lstrcpy, addr szBuff1, addr szBuff0
      INVOKE     SetCurrentDirectory, addr szBuff0
      INVOKE     lstrcat, addr szBuff0, addr szEnd

;_______________________________________________________________________
GetFirstSP:
      INVOKE     FindFirstFile, addr szBuff0, addr FindData
        test     eax, eax
; Do message
          js     CloseItSP ;NoFile
         mov     hFind, eax
         inc     Cnt
         jmp     ChkFileSP

;_______________________________________________________________________
GetNextSP:
      INVOKE     FindNextFile, hFind, addr FindData
        test     eax, eax
          jz     CloseItSP

;_______________________________________________________________________
ChkFileSP:
      .if byte ptr FindData.cFileName == '.'
            jmp     GetNextSP
      .endif
      INVOKE     lstrcpy, addr szBuff2, addr szBuff1
      INVOKE     lstrcat, addr szBuff2, addr FindData.cFileName
   INVOKE     SendMessage, hListbox, LB_ADDSTRING, 0, addr FindData.cFileName
      INVOKE     lstrcat, addr szBuff2, addr szBackS
      INVOKE     lstrcpy, addr szBuff3, addr szBuff2
      INVOKE     lstrcat, addr szBuff2, addr szEnd

;_______________________________________________________________________
GetFirstSub:
      INVOKE     FindFirstFile, addr szBuff2, addr FindData
        test     eax, eax
          js     GetNextSP
         mov     hFindS, eax
         inc     Cnt
         jmp     ChkFileSub

;_______________________________________________________________________
GetNextSub:
      INVOKE     FindNextFile, hFindS, addr FindData
      .if eax == 0
         INVOKE     FindClose, hFindS
            jmp     GetNextSP
      .endif

;_______________________________________________________________________
ChkFileSub:
      .if byte ptr FindData.cFileName == '.'
            jmp     GetNextSub
      .endif

      INVOKE     lstrlen, addr FindData.cFileName
      .while (eax)
            dec     eax
         .if FindData.cFileName[eax] == '.'
            .break
         .endif
      .endw
      .if !eax
            jmp     GetNextSub
      .endif
      INVOKE     lstrcpy, addr szExt, addr FindData.cFileName[eax]

      .if byte ptr szExt+1 >= 'A' && byte ptr szExt+1 <= 'Z'
            add     byte ptr szExt+1, 20h
      .endif
      .if byte ptr szExt+2 >= 'A' && byte ptr szExt+2 <= 'Z'
            add     byte ptr szExt+2, 20h
      .endif
      .if byte ptr szExt+3 >= 'A' && byte ptr szExt+3 <= 'Z'
            add     byte ptr szExt+3, 20h
      .endif

         and     RcOn, 0
      .if byte ptr szExt+1 == 'a' && byte ptr szExt+2 == 's' && byte ptr szExt+3 == 'm' ||\
          byte ptr szExt+1 == 'q' && byte ptr szExt+2 == 'a' ||\
          byte ptr szExt+1 == 'r' && byte ptr szExt+2 == 'c' ||\
          byte ptr szExt+1 == 'i' && byte ptr szExt+2 == 'n' && byte ptr szExt+3 == 'c'
         .if byte ptr szExt+1 == 'r' && byte ptr szExt+2 == 'c'
               mov     RcOn, 1
         .endif
      .else
            jmp     GetNextSub
      .endif

      INVOKE     lstrcpy, addr szWork, addr szBuff3
      INVOKE     lstrcat, addr szWork, addr szCRLF
      INVOKE     lstrcat, addr szWork, addr FindData.cFileName
      INVOKE     lstrcpy, addr szBuff4, addr szBuff3
      INVOKE     lstrcat, addr szBuff4, addr FindData.cFileName
      INVOKE     SetWindowText, hStat, addr szWork
;      INVOKE     UpdateWindow, hStat

        call     ReadIn

      .if eax == -1
; Do message
            jmp     NoMore
      .endif

         mov     EndPos, -1
         mov     ft.chrg.cpMin, 0
         mov     ft.chrg.cpMax, -1
         lea     eax, offset szData
         mov     ft.lpstrText, eax
      INVOKE     SendMessage, hREdit, EM_FINDTEXT, FR_DOWN, addr ft
      .if eax != -1
            mov     EndPos, eax
      .else
            lea     eax, offset szCode
            mov     ft.lpstrText, eax
         INVOKE     SendMessage, hREdit, EM_FINDTEXT, FR_DOWN, addr ft
         .if eax != -1
               mov     EndPos, eax
         .endif
      .endif

;         mov     EndPos, -1
;         mov     ft.chrg.cpMin, 0
;         mov     ft.chrg.cpMax, -1
;         lea     eax, offset szCode
;         mov     ft.lpstrText, eax
;      INVOKE     SendMessage, hREdit, EM_FINDTEXT, FR_DOWN, addr ft
;      .if eax != -1
;            mov     EndPos, eax
;      .endif

         mov     Cnt, 1

LoopStep2:
;   include  F:\masm32\include\advapi32.inc
;includelib  F:\masm32\lib\user32.lib

comment^
.if Step == 2
            mov     ft.chrg.cpMin, 0
            mov     eax, EndPos
            mov     ft.chrg.cpMax, eax
            lea     eax, szFixFind
            mov     ft.lpstrText, eax
         INVOKE     SendMessage, hREdit, EM_FINDTEXT, FR_DOWN, addr ft
         .if eax != -1
               mov     cr.cpMin, eax
               mov     cr.cpMax, eax
            INVOKE     lstrlen, addr szFixFind
               add     cr.cpMax, eax
            INVOKE     SendMessage, hREdit, EM_EXSETSEL, 0, addr cr
            INVOKE     SendMessage, hREdit, EM_REPLACESEL, TRUE, addr szFixUpdate
               jmp     WriteIt
         .endif
.endif
^


      .if Cnt == 1
         INVOKE     lstrcpy, addr szFind, addr szBackS
         INVOKE     lstrcat, addr szFind, addr szInc    ; Include\
      .else
         INVOKE     lstrcpy, addr szFind, addr szBackS
         INVOKE     lstrcat, addr szFind, addr szLib    ; Lib\
      .endif
         mov     ft.chrg.cpMin, 0
         mov     eax, EndPos
         mov     ft.chrg.cpMax, eax
         lea     eax, offset szFind
         mov     ft.lpstrText, eax

FindNext:
      .if AddPath ;|| Cnt == 1 && RcOn
         .if Cnt == 1
            .if !RcOn
               INVOKE     lstrcpy, addr szBuff0, addr szInclude  ; include
            .else
               INVOKE     lstrcpy, addr szBuff0, addr szIncludeR ; #include
            .endif
               and     RcOn, 0
         .else
            INVOKE     lstrcpy, addr szBuff0, addr szLibrary     ; includelib
         .endif
            lea     eax, szBuff0
            mov     ft.lpstrText, eax
         INVOKE     SendMessage, hREdit, EM_FINDTEXT, FR_DOWN or FR_WHOLEWORD, addr ft
         .if eax != -1
               and     AsmDirOn, 0
               and     RcOn, 0
               mov     ft.chrg.cpMin, eax
               mov     cr.cpMin, eax
               mov     tr.chrg.cpMin, eax
               add     eax, 64
               mov     tr.chrg.cpMax, eax
               lea     eax, szWork
               mov     tr.lpstrText, eax
            INVOKE     SendMessage, hREdit, EM_GETTEXTRANGE, 0, addr tr
            INVOKE     lstrlen, addr szBuff0
               mov     ecx, 64
               sub     ecx, eax

;---------- [Check for valid include and includelib statements] ----------
            .if byte ptr szWork[eax] != ' ' && byte ptr szWork[eax] != 09h
                  jmp     Pass2
            .endif

            .while (ecx)
               .if byte ptr szWork[eax] == 0dh
                     xor     ecx, ecx
                  .break
               .endif
               .if byte ptr szWork[eax] == ':' || byte ptr szWork[eax] == '\'
                  .break
               .endif
                  inc     eax
                  dec     ecx
            .endw

            .if ecx
                  lea     eax, offset szFind
                  mov     ft.lpstrText, eax
                  jmp     HavePath
            .endif

            INVOKE     lstrlen, addr szBuff0
               add     cr.cpMin, eax
               mov     ecx, 64
               sub     ecx, eax
            .while (ecx)
               .if byte ptr szWork[eax] != ' ' && byte ptr szWork[eax] != 09h
                  .if byte ptr szWork[eax] == '<' || byte ptr szWork[eax] == '"' ; added " 12-30-2002
                        mov     RcOn, 1
                        inc     eax
                        jmp     ChkValid
                  .else
                        dec     cr.cpMin
                     .if byte ptr szWork[eax] == 'W'
                           mov     byte ptr szWork[eax], 'w'
                     .endif
                     .if byte ptr szWork[eax+3] == 'D'
                           mov     byte ptr szWork[eax+3], 'd'
                     .endif
                     .if byte ptr szWork[eax] == 'D'
                           mov     byte ptr szWork[eax], 'd'
                     .endif
                     .if byte ptr szWork[eax+3] == 'U'
                           mov     byte ptr szWork[eax+3], 'u'
                     .endif

                     .if byte ptr szWork[eax] == 'w' && byte ptr szWork[eax+3] == 'd' ||\
                         byte ptr szWork[eax] == 'D' && byte ptr szWork[eax+3] == 'V' ||\
                         byte ptr szWork[eax] == 'd' && byte ptr szWork[eax+3] == 'u'
                           mov     AsmDirOn, 1

                     .else

;---------- [Check for valid system file] ----------
ChkValid:
                           mov     esi, eax
                           xor     edi, edi
                           mov     ecx, 30
                        .while (ecx)
                           .if byte ptr szWork[esi] != '.'
                                 mov     dl, byte ptr szWork[esi]
                                 mov     byte ptr FileName[edi], dl
                                 inc     edi
                           .else
                              .if byte ptr szWork[esi+1] == 'l' || byte ptr szWork[esi+1] == 'L'
                                    jmp     Pass1
                              .endif
                              .break
                           .endif
                              inc     esi
                              dec     ecx
                        .endw
                           mov     byte ptr FileName[edi], 0

                        .if ecx
                              and     Incr, 0
                              mov     Cnt2, 17
                           .while (Cnt2)
                                 mov     eax, Incr
                                 mov     ecx, szFileArray[eax*4]
                              INVOKE     lstrcmpi, ecx, addr FileName
                              .if !eax             ; Files matched
                                 .break
                              .endif
                                 inc     Incr
                                 dec     Cnt2
                           .endw

                           .if !Cnt2 && !AsmDirOn || !Cnt2 && RcOn
                                 jmp     Pass2     ; Not a valid system name
                           .endif
                        .endif

                     .endif
                  .endif
                  .break
               .endif
                  inc     eax
                  inc     cr.cpMin
                  dec     ecx
            .endw

Pass1:
               mov     eax, cr.cpMin
               inc     eax
               mov     cr.cpMax, eax
            INVOKE     SendMessage, hREdit, EM_EXSETSEL, 0, addr cr
               mov     byte ptr szBuff0, 0
            .if RcOn
               INVOKE     lstrcat, addr szBuff0, addr szLess
            .else
               INVOKE     lstrcat, addr szBuff0, addr szNULL
            .endif
            .if !AsmDirOn
               INVOKE     lstrcat, addr szBuff0, addr HutchDir
            .else
               INVOKE     lstrcat, addr szBuff0, addr AsmEditDir
            .endif
            .if Cnt == 1
               INVOKE     lstrcat, addr szBuff0, addr szInc
            .else
               INVOKE     lstrcat, addr szBuff0, addr szLib
            .endif
            INVOKE     SendMessage, hREdit, EM_REPLACESEL, TRUE, addr szBuff0

Pass2:
            INVOKE     lstrlen, addr szBuff0
               add     ft.chrg.cpMin, eax
            .if EndPos != -1
                  add     ft.chrg.cpMax, eax
            .endif
               jmp     FindNext
         .endif
         .if Cnt == 1
               inc     Cnt
               jmp     LoopStep2
         .endif
            jmp     WriteIt
      .endif

HavePath:
      INVOKE     SendMessage, hREdit, EM_FINDTEXT, FR_DOWN, addr ft
      .if eax != -1
            mov     ft.chrg.cpMin, eax
            mov     ft.chrg.cpMax, eax
            mov     cr.cpMax, eax

;---------- [If you want to remove the paths] ----------
            mov     SavMax, eax
         INVOKE     lstrlen, addr szFind
            dec     eax
            add     cr.cpMax, eax
;-------------------------------------------------------

            and     AsmDirOn, 0
;         .if Cnt == 1
               add     ft.chrg.cpMax, 50
               lea     eax, offset szWininc
               mov     ft.lpstrText, eax
            INVOKE     SendMessage, hREdit, EM_FINDTEXT, FR_DOWN, addr ft
            .if eax != -1
                  mov     AsmDirOn, 1
            .else
                  lea     eax, offset szDSPMACRO
                  mov     ft.lpstrText, eax
               INVOKE     SendMessage, hREdit, EM_FINDTEXT, FR_DOWN, addr ft
               .if eax != -1
                     mov     AsmDirOn, 1
               .else
                     lea     eax, offset szdebuginc
                     mov     ft.lpstrText, eax
                  INVOKE     SendMessage, hREdit, EM_FINDTEXT, FR_DOWN, addr ft
                  .if eax != -1
                        mov     AsmDirOn, 1
                  .else
                        lea     eax, offset szdebuglib
                        mov     ft.lpstrText, eax
                     INVOKE     SendMessage, hREdit, EM_FINDTEXT, FR_DOWN, addr ft
                     .if eax != -1
                           mov     AsmDirOn, 1
                     .endif
                  .endif
               .endif
            .endif
               sub     ft.chrg.cpMax, 50
;         .endif

         .if sdword ptr ft.chrg.cpMax > 100 ;50
               sub     ft.chrg.cpMax, 100 ;50
         .else
               mov     ft.chrg.cpMax, 0
         .endif

;   include  F:\masm32\include\advapi32.inc
;includelib  F:\masm32\lib\user32.lib
         .if Cnt == 1
            INVOKE     lstrcpy, addr szBuff0, addr szInclude ; include
         .else
            INVOKE     lstrcpy, addr szBuff0, addr szLibrary ; includelib
         .endif
            and     RcOn, 0
            lea     eax, szBuff0
            mov     ft.lpstrText, eax
         INVOKE     SendMessage, hREdit, EM_FINDTEXT, 0, addr ft
         .if eax != -1
               mov     ecx, ft.chrg.cpMin
               mov     ft.chrg.cpMax, ecx
               mov     ft.chrg.cpMin, eax

               mov     cr.cpMin, eax
               mov     tr.chrg.cpMin, eax
               add     eax, 20
               mov     tr.chrg.cpMax, eax
               lea     eax, szWork
               mov     tr.lpstrText, eax
            INVOKE     SendMessage, hREdit, EM_GETTEXTRANGE, 0, addr tr
            INVOKE     lstrlen, addr szBuff0
;dec     eax
               add     cr.cpMin, eax
               mov     ecx, 20
               sub     ecx, eax
            .while (ecx)
               .if byte ptr szWork[eax] != ' ' && byte ptr szWork[eax] != 09h
                  .if byte ptr szWork[eax] == '<' || byte ptr szWork[eax] == '"' ; added " 12-30-2002
                        inc     eax
                        inc     cr.cpMin
                        mov     RcOn, 1
                  .endif
                  .break
               .endif
                  inc     eax
                  inc     cr.cpMin
                  dec     ecx
            .endw
               inc     cr.cpMin


;            INVOKE     lstrcpy, addr szBuff0, addr szBackS
;               lea     eax, szBuff0
;               mov     ft.lpstrText, eax
;            INVOKE     SendMessage, hREdit, EM_FINDTEXT, FR_DOWN, addr ft
;            .if eax != -1
;                  inc     eax
;                  mov     cr.cpMin, eax
                  mov     eax, cr.cpMax
                  add     eax, 2
                  mov     ft.chrg.cpMin, eax
                  mov     eax, EndPos
                  mov     ft.chrg.cpMax, eax
                  lea     eax, offset szFind
                  mov     ft.lpstrText, eax

               .if AsmDirOn || AddPath || RcOn
                     mov     eax, SavMax
                     mov     cr.cpMax, eax
               .endif
               .if !AsmDirOn && !AddPath && !RcOn
                     dec     cr.cpMin
               .endif
dec     cr.cpMin
inc     cr.cpMax
add     ft.chrg.cpMin, 3

.if RcOn && !AddPath && !AsmDirOn
      dec     cr.cpMin
      add     cr.cpMax, 8
.endif
               INVOKE     SendMessage, hREdit, EM_EXSETSEL, 0, addr cr
               .if !AsmDirOn
                  .if !RcOn
                     .if !AddPath
;---------- [Remove paths] ----------
                        INVOKE     SendMessage, hREdit, EM_REPLACESEL, TRUE, addr szNULL
;------------------------------------
                     .else
                        INVOKE     SendMessage, hREdit, EM_REPLACESEL, TRUE, addr HutchDir
                     .endif

                  .else
                     .if !AddPath
;---------- [Remove path] ----------
                        INVOKE     SendMessage, hREdit, EM_REPLACESEL, TRUE, addr szLess ;HutchDir ;szLess
;-----------------------------------
                     .else
                        INVOKE     SendMessage, hREdit, EM_REPLACESEL, TRUE, addr HutchDir
                     .endif
                  .endif
               .else
                  INVOKE     SendMessage, hREdit, EM_REPLACESEL, TRUE, addr AsmEditDir
               .endif
                  jmp     FindNext
;            .endif
         .endif
      .endif
      .if Cnt == 1
            inc     Cnt
            jmp     LoopStep2
      .endif

WriteIt:
        call     WriteOut
      .if eax == -1
; Do message
            jmp     NoMore
      .endif
         jmp     GetNextSub

CloseItSP:
      .if hpMem
         INVOKE     GlobalUnlock, fpMem
         INVOKE     GlobalFree, hpMem
      .endif
      INVOKE     FindClose, hFind
      INVOKE     FindClose, hFindS
      .if Step < 3
            inc     Step
            jmp     LoopStep1
      .endif

;---------- [Find and update the root paths for the pointer files] ----------
      INVOKE     lstrcpy, addr szBuff0, addr CurDir
      INVOKE     lstrcat, addr szBuff0, addr szPoi

LoopPoi:
      INVOKE     lstrcpy, addr szBuff1, addr szBuff0
      INVOKE     SetCurrentDirectory, addr szBuff0
      INVOKE     lstrcat, addr szBuff0, addr szEnd
      INVOKE     SetWindowText, hOper, addr szPoiP

;_______________________________________________________________________
GetFirstP:
      INVOKE     FindFirstFile, addr szBuff0, addr FindData
        test     eax, eax
; Do message
          js     CloseItP ;NoFile
         mov     hFind, eax
         jmp     ChkFileP

;_______________________________________________________________________
GetNextP:
      INVOKE     FindNextFile, hFind, addr FindData
        test     eax, eax
          jz     CloseItP

;_______________________________________________________________________
ChkFileP:
      .if byte ptr FindData.cFileName == '.'
            jmp     GetNextP
      .endif

      INVOKE     lstrcpy, addr szWork, addr szBuff1
      INVOKE     lstrcat, addr szWork, addr szCRLF
      INVOKE     lstrcat, addr szWork, addr FindData.cFileName
      INVOKE     SetWindowText, hStat, addr szWork

      INVOKE     lstrcpy, addr szBuff4, addr szBuff1
      INVOKE     lstrcat, addr szBuff4, addr FindData.cFileName

        call     ReadIn
      .if eax == -1
; Do message
            jmp     NoMore
      .endif
         mov     Cnt, 1

LoopStepP:
         mov     ft.chrg.cpMin, 0
         mov     ft.chrg.cpMax, -1
         lea     eax, offset szCR
         mov     ft.lpstrText, eax
      INVOKE     SendMessage, hREdit, EM_FINDTEXT, FR_DOWN, addr ft
      .if eax == -1
            jmp     GetNextP
      .endif
         mov     cr.cpMax, eax
         mov     ft.chrg.cpMin, eax

      .if Cnt == 1
         INVOKE     lstrcpy, addr szFind, addr szBackS
         INVOKE     lstrcat, addr szFind, addr szPgm

      .elseif Cnt == 2
         INVOKE     lstrcpy, addr szFind, addr szBackS
         INVOKE     lstrcat, addr szFind, addr szPro

      .else
         INVOKE     lstrcpy, addr szFind, addr szBackS
         INVOKE     lstrcat, addr szFind, addr szAdd
      .endif
;         mov     ft.chrg.cpMin, 0
         mov     ft.chrg.cpMax, 0 ;-1
         lea     eax, offset szFind
         mov     ft.lpstrText, eax

FindNextP:
      INVOKE     SendMessage, hREdit, EM_FINDTEXT, 0, addr ft
      .if eax != -1
            inc     eax
            mov     cr.cpMax, eax
         INVOKE     lstrcpy, addr szBuff0, addr szBackS
            mov     ft.chrg.cpMin, 0
            mov     ft.chrg.cpMax, -1
            lea     eax, szBuff0
            mov     ft.lpstrText, eax
         INVOKE     SendMessage, hREdit, EM_FINDTEXT, FR_DOWN, addr ft
         .if eax != -1
              push     eax
               inc     eax
               mov     cr.cpMin, eax
               pop     ecx
;               dec     ecx
               sub     ecx, 2
              push     cr.cpMin
              push     cr.cpMax
               mov     cr.cpMin, ecx
               mov     cr.cpMax, eax
            INVOKE     SendMessage, hREdit, EM_EXSETSEL, 0, addr cr
               pop     cr.cpMax
               pop     cr.cpMin
            INVOKE     SendMessage, hREdit, EM_GETSELTEXT, 0, addr szBuff3
               dec     cr.cpMin
            .if byte ptr szBuff3+1 == ':'
                  sub     cr.cpMin, 2
            .endif
            INVOKE     lstrlen, addr FindData.cFileName
               sub     eax, 3
            INVOKE     lstrcpyn, addr szWork, addr FindData.cFileName, eax

;---------- [Check if pointer is part of AsmEdit package] ----------
            INVOKE     SendMessage, hListbox, LB_FINDSTRINGEXACT, -1, addr szWork
            .if eax != LB_ERR
               INVOKE     SendMessage, hREdit, EM_EXSETSEL, 0, addr cr
               INVOKE     SendMessage, hREdit, EM_REPLACESEL, TRUE, addr CurDir
            .endif 
         .endif
      .endif
      .if Cnt < 3
            inc     Cnt
            jmp     LoopStepP
      .endif
         dec     Cnt

FindNextP1:
         inc     Cnt
      .if Cnt == 3
         INVOKE     lstrcpy, addr szFind, addr szR1
      .elseif Cnt == 4
         INVOKE     lstrcpy, addr szFind, addr szA1
      .elseif Cnt == 5
         INVOKE     lstrcpy, addr szFind, addr szL1
      .else
            jmp     WriteProj
      .endif

            mov     ft.chrg.cpMin, 0
            mov     ft.chrg.cpMax, -1
            lea     eax, offset szFind
            mov     ft.lpstrText, eax

         INVOKE     SendMessage, hREdit, EM_FINDTEXT, FR_DOWN, addr ft
         .if eax != -1
               add     eax, 3 ;6
               mov     cr.cpMin, eax
               mov     ft.chrg.cpMin, eax
            INVOKE     lstrcpy, addr szFind, addr szBackS
            INVOKE     lstrcat, addr szFind, addr szBin  ; Bin\
               lea     eax, offset szFind
               mov     ft.lpstrText, eax
            INVOKE     SendMessage, hREdit, EM_FINDTEXT, FR_DOWN, addr ft
            .if eax != -1
                  inc     eax
                  mov     cr.cpMax, eax
               INVOKE     SendMessage, hREdit, EM_EXSETSEL, 0, addr cr
               INVOKE     SendMessage, hREdit, EM_REPLACESEL, TRUE, addr HutchDir ;CurDir

               .if Cnt == 3
                     lea     eax, offset szA1
                     mov     ft.lpstrText, eax
                  INVOKE     SendMessage, hREdit, EM_FINDTEXT, FR_DOWN, addr ft
                  .if eax != -1
                        mov     ft.chrg.cpMax, eax
                  .else
                        jmp     FindNextP1
                  .endif

                     lea     eax, offset szIncNS   ; Include
                     mov     ft.lpstrText, eax
                  INVOKE     SendMessage, hREdit, EM_FINDTEXT, FR_DOWN, addr ft
                    push     eax
                     lea     eax, offset szIncP   ; \Include
                     mov     ft.lpstrText, eax
                  INVOKE     SendMessage, hREdit, EM_FINDTEXT, FR_DOWN, addr ft
                     pop     ecx
                  .if eax != -1 || ecx != -1
                     .if eax != -1
                           inc     eax
                     .else
                           mov     eax, ecx
                     .endif
                        mov     cr.cpMax, eax
                        lea     eax, offset szI
                        mov     ft.lpstrText, eax
                     INVOKE     SendMessage, hREdit, EM_FINDTEXT, FR_DOWN, addr ft
                     .if eax != -1
                           add     eax, 4
                           mov     cr.cpMin, eax
                        INVOKE     SendMessage, hREdit, EM_EXSETSEL, 0, addr cr
                        INVOKE     SendMessage, hREdit, EM_REPLACESEL, TRUE, addr HutchDir
                     .endif

                  .else
                        lea     eax, offset szRc  ; \rc
                        mov     ft.lpstrText, eax
                     INVOKE     SendMessage, hREdit, EM_FINDTEXT, FR_DOWN, addr ft
                     .if eax != -1
                           add     eax, 3
                           mov     cr.cpMin, eax
                           mov     cr.cpMax, eax
                        INVOKE     lstrcpy, addr szWork, addr szI
                        INVOKE     lstrcat, addr szWork, addr HutchDir
                        INVOKE     lstrcat, addr szWork, addr szIncP+1
                        INVOKE     SendMessage, hREdit, EM_EXSETSEL, 0, addr cr
                        INVOKE     SendMessage, hREdit, EM_REPLACESEL, TRUE, addr szWork
                     .endif
                  .endif
               .endif

               .if Cnt == 4
                     lea     eax, offset szIncNS   ; Include
                     mov     ft.lpstrText, eax
                  INVOKE     SendMessage, hREdit, EM_FINDTEXT, FR_DOWN, addr ft
                    push     eax
                     lea     eax, offset szIncP    ; \Include
                     mov     ft.lpstrText, eax
                  INVOKE     SendMessage, hREdit, EM_FINDTEXT, FR_DOWN, addr ft
                     pop     ecx
                  .if eax != -1 || ecx != -1
                     .if eax != -1
                           inc     eax
                     .else
                           mov     eax, ecx
                     .endif
                        mov     cr.cpMax, eax
                        lea     eax, offset szI
                        mov     ft.lpstrText, eax
                     INVOKE     SendMessage, hREdit, EM_FINDTEXT, FR_DOWN, addr ft
                     .if eax != -1
                           add     eax, 4
                           mov     cr.cpMin, eax
                        INVOKE     SendMessage, hREdit, EM_EXSETSEL, 0, addr cr
                        INVOKE     SendMessage, hREdit, EM_REPLACESEL, TRUE, addr HutchDir
                     .endif

                  .else
                        lea     eax, offset szCp
                        mov     ft.lpstrText, eax
                     INVOKE     SendMessage, hREdit, EM_FINDTEXT, FR_DOWN, addr ft
                     .if eax != -1
                           add     eax, 3
                           mov     cr.cpMin, eax
                           mov     cr.cpMax, eax
                        INVOKE     lstrcpy, addr szWork, addr szI
                        INVOKE     lstrcat, addr szWork, addr HutchDir
                        INVOKE     lstrcat, addr szWork, addr szIncP+1
                        INVOKE     SendMessage, hREdit, EM_EXSETSEL, 0, addr cr
                        INVOKE     SendMessage, hREdit, EM_REPLACESEL, TRUE, addr szWork
                     .endif
                  .endif
               .endif

               .if Cnt == 5
                     lea     eax, offset szLibNS  ; Lib
                     mov     ft.lpstrText, eax
                  INVOKE     SendMessage, hREdit, EM_FINDTEXT, FR_DOWN, addr ft
                    push     eax
                     lea     eax, offset szLibP   ; \Lib
                     mov     ft.lpstrText, eax
                  INVOKE     SendMessage, hREdit, EM_FINDTEXT, FR_DOWN, addr ft
                     pop     ecx
                  .if eax != -1 || ecx != -1
                     .if eax != -1
                           inc     eax
                     .else
                           mov     eax, ecx
                     .endif
                        mov     cr.cpMax, eax
                        lea     eax, offset szLibPath
                        mov     ft.lpstrText, eax
                     INVOKE     SendMessage, hREdit, EM_FINDTEXT, FR_DOWN, addr ft
                     .if eax != -1
                           add     eax, 9
                           mov     cr.cpMin, eax
                        INVOKE     SendMessage, hREdit, EM_EXSETSEL, 0, addr cr
                        INVOKE     SendMessage, hREdit, EM_REPLACESEL, TRUE, addr HutchDir
                     .endif

                  .else
                        lea     eax, offset szWindows
                        mov     ft.lpstrText, eax
                     INVOKE     SendMessage, hREdit, EM_FINDTEXT, FR_DOWN, addr ft
                     .if eax != -1
                           add     eax, 9
                           mov     cr.cpMin, eax
                           mov     cr.cpMax, eax
                        INVOKE     lstrcpy, addr szWork, addr szLibPath
                        INVOKE     lstrcat, addr szWork, addr HutchDir
                        INVOKE     lstrcat, addr szWork, addr szLibP+1
                        INVOKE     SendMessage, hREdit, EM_EXSETSEL, 0, addr cr
                        INVOKE     SendMessage, hREdit, EM_REPLACESEL, TRUE, addr szWork
                     .endif
                  .endif
               .endif
                  jmp     FindNextP1
            .endif
         .elseif Cnt < 5
               jmp     FindNextP1
         .endif

WriteProj:
        call     WriteOut
      .if eax == -1
; Do message
            jmp     NoMore
      .endif
         jmp     GetNextP

CloseItP:
      .if hpMem
         INVOKE     GlobalUnlock, fpMem
         INVOKE     GlobalFree, hpMem
      .endif
      INVOKE     FindClose, hFind

;---------- [Do user pointer files] ----------
      .while (PoiCnt)
         INVOKE     lstrcpy, addr szBuff0, addr CurDir
         INVOKE     lstrcat, addr szBuff0, addr szPoiUser
            dec     PoiCnt
            add     byte ptr szPoiUser+19, 1
         INVOKE     GetFileAttributes, addr szBuff0
         .if eax != -1
               jmp     LoopPoi
         .endif
      .endw

      .if !NoCopy
         INVOKE     MessageBox, NULL, addr szMsg3, addr szSetup, MB_OK
      .else
         INVOKE     MessageBox, NULL, addr szMsg4, addr szSetup, MB_OK
      .endif

;---------- [Do the bat file] ----------
      INVOKE     lstrcpy, addr szBuff4, addr CurDir ;$$$$$$$$$$
      INVOKE     lstrcat, addr szBuff4, addr szPgm
      INVOKE     lstrcat, addr szBuff4, addr szAsmEdit

        call     ReadIn
      .if eax == -1
; Do message
            jmp     NoMore
      .endif

         mov     cr.cpMin, 0
         mov     cr.cpMax, -1
      INVOKE     SendMessage, hREdit, EM_EXSETSEL, 0, addr cr
      INVOKE     SendMessage, hREdit, EM_REPLACESEL, TRUE, addr szBat

         mov     ft.chrg.cpMin, 0
         mov     ft.chrg.cpMax, -1
         lea     eax, offset szMasm32V1
         mov     ft.lpstrText, eax

FindNextB:
      INVOKE     SendMessage, hREdit, EM_FINDTEXT, FR_DOWN, addr ft
      .if eax != -1
            mov     cr.cpMin, eax
            add     eax, 8
            mov     cr.cpMax, eax
            mov     ft.chrg.cpMin, eax
         INVOKE     SendMessage, hREdit, EM_EXSETSEL, 0, addr cr
         INVOKE     SendMessage, hREdit, EM_REPLACESEL, TRUE, addr szPath
            jmp     FindNextB
      .endif
      INVOKE     FindRep, addr szPPPP, addr HutchDir

        call     WriteOut
      .if eax == -1
; Do message
            jmp     NoMore
      .endif

NoMore:
      .if hpMem
         INVOKE     GlobalUnlock, fpMem
         INVOKE     GlobalFree, hpMem
      .endif

HaveFile:

GetOut:
      INVOKE     LoadCursor, NULL, IDC_ARROW
      INVOKE     SetCursor, eax
      INVOKE     EndDialog, hWnd, 0

Ret0:
         xor     eax, eax
         ret
WndProc endp

;======================================================
; Find Replace Procedure
;======================================================
FindRep PROC lpInput:DWORD, lpReplace
LOCAL    ft:FINDTEXT
LOCAL    cr:CHARRANGE

         mov     ft.chrg.cpMin, 0
         mov     ft.chrg.cpMax, -1
         mov     eax, lpInput
         mov     ft.lpstrText, eax

FindNext:
      INVOKE     SendMessage, hREdit, EM_FINDTEXT, FR_DOWN, addr ft
      .if eax != -1
            mov     ft.chrg.cpMin, eax
            inc     ft.chrg.cpMin
            mov     cr.cpMin, eax
            mov     cr.cpMax, eax
            add     cr.cpMax, 5
         INVOKE     SendMessage, hREdit, EM_EXSETSEL, 0, addr cr
         INVOKE     SendMessage, hREdit, EM_REPLACESEL, TRUE, lpReplace
            jmp     FindNext
      .endif

         ret
FindRep ENDP

;________________________________________________________________________________
ReadIn proc

;---------- [Read file for selecting text] ----------
      .if hpMem
         INVOKE     GlobalUnlock, fpMem
         INVOKE     GlobalFree, hpMem
      .endif
      INVOKE     CreateFile, addr szBuff4,\
                 GENERIC_READ or GENERIC_WRITE ,\
                 FILE_SHARE_READ or FILE_SHARE_WRITE,\
                 0, OPEN_EXISTING,FILE_ATTRIBUTE_ARCHIVE, 0
      .if eax == -1
; Do message
            jmp     NoMore
      .endif
         mov     hFile, eax
      INVOKE     GlobalAlloc, GMEM_MOVEABLE or GMEM_ZEROINIT, 4000000
         mov     hpMem, eax
      INVOKE     GlobalLock, hpMem
         mov     fpMem, eax
      INVOKE     ReadFile, hFile, fpMem, 4000000, addr BytesRead, NULL
      INVOKE     CloseHandle, hFile
      INVOKE     SendMessage, hREdit, WM_SETTEXT, NULL, fpMem

NoMore:
         ret
ReadIn endp

;________________________________________________________________________________
WriteOut proc

;---------- [Write file] ----------
      INVOKE     SendMessage, hREdit, WM_GETTEXT, 4000000, fpMem

      INVOKE     CreateFile, addr szBuff4,\
                 GENERIC_READ or GENERIC_WRITE ,\
                 FILE_SHARE_READ or FILE_SHARE_WRITE,\
                 NULL, CREATE_ALWAYS,FILE_ATTRIBUTE_ARCHIVE, NULL
      .if eax == -1
; Do message
            jmp     NoMore
      .endif
         mov     hFile, eax
      INVOKE     SendMessage, hREdit, WM_GETTEXTLENGTH, 0, 0
         mov     ecx, eax
      INVOKE     WriteFile, hFile, fpMem, ecx, addr BytesRead, NULL
      INVOKE     CloseHandle, hFile
      INVOKE     GlobalUnlock, fpMem
      INVOKE     GlobalFree, hpMem
         and     hpMem, 0

NoMore:
         ret
WriteOut endp

end start
