Ignore:
Timestamp:
Oct 30, 2009, 4:17:35 PM (16 years ago)
Author:
Herwig Bauernfeind
Message:

GUI-Tools: EVFSGUI Version 2.0 beta3 level code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/guitools-2.0/shared/smbtree.vrs

    r334 r345  
    1414    if ShowHidden = 'SHOWHIDDEN' | ShowHidden = '' then ShowHidden = 0
    1515
    16     say 'detach 'samba.!smbtreeexe' 'debuglevel' 'UserCred' >'samba.!msg
    17     address cmd 'detach 'samba.!smbtreeexe' 'debuglevel' 'UserCred' >'samba.!msg
     16    say 'detach 'samba.!smbtreeexe' -S 'debuglevel' 'UserCred' >'samba.!msg
     17    address cmd 'detach 'samba.!smbtreeexe' -S 'debuglevel' 'UserCred' >'samba.!msg
    1818
    1919    if UserCred = '-N' then UserCred = ''
     
    2121    ok = VRMethod("CN_smbtree", "RemoveRecord", "ALL")
    2222
     23    RefreshMode = "TREE"
    2324    ok = VRSet("CN_smbtree","Enabled", 0)
    2425    ok = VRset("TM_RefreshTreeDisplay","Enabled",1)
     
    3233    if stat <> "READY:" then return
    3334
     35    if UserCred = 'USERCRED' | UserCred = '' | UserCred = '--user=%' then do
     36        UserCred = '-N'
     37    end
     38
    3439    if ShowHidden = 'SHOWHIDDEN' | ShowHidden = '' then ShowHidden = 0
    3540
     
    5863        Header = c2x(left(smbtreeline.sl,3))
    5964        select
    60             when Header = "09095C" then do /* share */
     65            when Header = "09095C" then do /* share - obsolete, we do that differently now see below! */
    6166                smbtreeline.sl = strip(smbtreeline.sl,,'09'x)
    6267                parse var smbtreeline.sl '\\'machine'\'share '09'x comment
     
    7277                    if pos("$", share) > 0 then ok = VRMethod( "CN_smbtree", "SetRecordAttr", smbtree.!share, "Visible", ShowHidden)
    7378                end
    74             end
     79            end /* end of obsolete share code */
    7580            when Header = "095C5C" then do /* Machine */
    7681                smbtreeline.sl = strip(smbtreeline.sl,,'09'x)
     
    7984                comment = strip(comment)
    8085                if VRGet("CN_smbtree","View") = "IconTree" then parent = smbtree.!workgroup; else parent = ""
    81                 smbtree.!machine = VRMethod( "CN_smbtree", "AddRecord",parent,, machine||'0D0A'x||comment,"#35:PMWP.DLL")
     86                ok = VRSet( "CN_smbtree", "Painting", 1  )
     87                smbtree.!machine = VRMethod( "CN_smbtree", "AddRecord",parent,, machine||'0D0A'x||comment)
     88                /* We make any machine as sleeping initially */
     89                ok = VRMethod('CN_smbtree', 'SetRecordAttr', smbtree.!machine, 'Icon',"#61:PMWP.DLL")
    8290                ok = VRMethod( "CN_smbtree", "SetRecordAttr", smbtree.!machine, "ReadOnly", 1)
    8391                ok = VRMethod( "CN_smbtree", "SetFieldData", smbtree.!machine, NBFH, machine, CommentFH, Comment, WorkGroupFH, CurWG)
     92                ok = VRSet( "CN_smbtree", "Painting", 0  )
    8493                if VRGet("CN_smbtree","View") = "Detail" then do
    8594                    address cmd samba.!nmblookupexe' 'machine' 'debuglevel' -N >'samba.!msg
     
    123132                    end
    124133                end
    125                 ok = VRSet( "CN_smbtree", "Painting", 1  )
    126                 ok = VRSet( "CN_smbtree", "Painting", 0  )
     134                else do
     135                    call _RefreshShares
     136                end
    127137            end
    128138            otherwise do
     
    139149                        ok = VRMethod( "CN_smbtree", "SetRecordAttr", smbtree.!workgroup, "Collapsed", 0)
    140150                        ok = VRMethod( "CN_smbtree", "SetRecordAttr", smbtree.!workgroup, "ReadOnly", 1)
     151                        ok = VRMethod( "CN_smbtree", 'SetRecordAttr', smbtree.!workgroup, "UserData", "WORKGROUP|")
    141152                    end
    142153                    CurWG = smbtreeline.sl
     
    154165return
    155166
    156 /*:VRX         _GuessIcon
     167/*:VRX         _RefreshShares
    157168*/
    158 _GuessIcon: procedure
    159     text = translate(arg(1))
    160     select /* Printer guessing */
    161         when pos('PS3',text)        > 0 then res = '#65:PMWP.DLL'
    162         when pos('PCL5',text)       > 0 then res = '#65:PMWP.DLL'
    163         when pos('PCL6',text)       > 0 then res = '#65:PMWP.DLL'
    164         when pos('PSCRIPT',text)    > 0 then res = '#65:PMWP.DLL'
    165         when pos('POSTSCRIPT',text) > 0 then res = '#65:PMWP.DLL'
    166         when pos('LJ',text)         > 0 then res = '#65:PMWP.DLL'
    167         when pos('LASER',text)      > 0 then res = '#65:PMWP.DLL'
    168         when pos('EPSON',text)      > 0 then res = '#65:PMWP.DLL'
    169         when pos('PRINT',text)      > 0 then res = '#65:PMWP.DLL'
    170         when pos('PRT',text)        > 0 then res = '#65:PMWP.DLL'
    171         when pos('CANON',text)      > 0 then res = '#65:PMWP.DLL'
    172         when pos('MINOLTA',text)    > 0 then res = '#65:PMWP.DLL'
    173         when pos('FAX',text)        > 0 then res = '#65:PMWP.DLL'
    174         when pos('LEXMARK',text)    > 0 then res = '#65:PMWP.DLL'
    175         when pos('IPC$',text)       > 0 then res = '#59:PMWP.DLL'
    176         when pos('GHOSTPDF',text)   > 0 then res = '#65:PMWP.DLL'
    177         when pos('PDF',text)        > 0 & ,
    178              pos('WRI',text)        > 0 then res = '#65:PMWP.DLL'
    179         otherwise res = "#34:PMWP.DLL"
    180     end
    181 return res
     169_RefreshShares:
     170    say "_RefreshShares() started"
     171    RefreshID = RANDOM()
     172    smbshares = TempDir||"smbshares."||machine
     173
     174    say         'detach 'samba.!smbclientexe' -L "'strip(machine)'" 'UserCred' 'debuglevel' 1>'smbshares' 2>NUL'
     175    address cmd 'detach 'samba.!smbclientexe' -L "'strip(machine)'" 'UserCred' 'debuglevel' 1>'smbshares' 2>NUL'
     176
     177    RefreshMode = "SHARE"
     178
     179    ok = VRSet("CN_smbtree","Enabled", 0)
     180    ok = VRset("TM_RefreshTreeDisplay","Enabled",1)
     181return
     182
     183/*:VRX         _AddSharesDisplay
     184*/
     185_AddSharesDisplay: /* New get shares code - uses smbclient output and is much faster */
     186    say "_AddSharesDisplay() started"
     187
     188    ok = SysFileTree(Tempdir||'smbshares.*',smbshare.,'FO')
     189
     190    if smbshare.0 = 0 then do /* we are done, no more files around, cleanup, disable Timer and exit */
     191        RefreshMode = ""
     192        ok = VRSet("CN_smbtree","Enabled", 1)
     193        ok = VRset("TM_RefreshTreeDisplay","Enabled",0)
     194        say "_AddSharesDisplay() completed"
     195        return /* exit here */
     196    end
     197
     198    if UserCred = 'USERCRED' | UserCred = '' | UserCred = '--user=%' then do
     199        UserCred = '-N'
     200    end
     201
     202    if ShowHidden = 'SHOWHIDDEN' | ShowHidden = '' then ShowHidden = 0
     203
     204    do I = 1 to smbshare.0
     205        stat = stream(smbshare.I,'c','open read')
     206        if stat = "READY:" then do /* we found a readable output file */
     207            Machine = VRParseFilename(smbshare.I,'E')
     208            smbtree.!machine = _GetMachinehandle(Machine)
     209
     210            line = linein(smbshare.I)
     211            say line
     212            ok = VRMethod('CN_smbtree', 'SetRecordAttr', smbtree.!machine, 'UserData', "SERVER|"||strip(line))
     213
     214            if left(line, 20) = "session setup failed" then do /* we see an error message */
     215                say left(line, 20)
     216                signal sharecleanup
     217            end
     218
     219            retries = 0
     220            do while(left(line,1) <> '09'x)
     221                line = linein(smbshare.I)
     222                retries = retries + 1
     223                say 'Retry 'retries
     224                if retries >=10 then do /* No valid output - error */
     225                    signal sharecleanup
     226                end
     227            end
     228
     229            /* Skip header */
     230            line = linein(smbshare.I)
     231            line = linein(smbshare.I)
     232
     233            if left(line,5) = "Error" then ok = VRMethod('CN_smbtree', 'SetRecordAttr', smbtree.!machine, 'UserData', "SERVER|"||strip(line))
     234
     235            do while(left(line,1) = '09'x)
     236                parse var line '09'x share type comment
     237                type = translate(strip(type))
     238                comment = strip(comment)
     239
     240                select
     241                    when type = "DISK"    then res = '#34:PMWP.DLL'
     242                    when type = "PRINTER" then res = '#65:PMWP.DLL'
     243                    when type = "IPC"     then res = '#59:PMWP.DLL'
     244                    when type = "DEVICE"  then res = '#84:PMWP.DLL' /* There might be better ones around */
     245                    otherwise res = ''
     246                end
     247
     248                /* Now the machine receives the wakeup icon */
     249                ok = VRMethod('CN_smbtree', 'SetRecordAttr', smbtree.!machine, 'Icon', "#35:PMWP.DLL")
     250                parent = smbtree.!machine
     251                smbtree.!share = VRMethod( "CN_smbtree", "AddRecord",parent,, share||'0D0A'x||comment, res)
     252                ok = VRMethod( "CN_smbtree", "SetRecordAttr", smbtree.!share, "ReadOnly", 1, 'UserData', type"|")
     253                if pos("$", share) > 0 then ok = VRMethod( "CN_smbtree", "SetRecordAttr", smbtree.!share, "Visible", ShowHidden)
     254
     255                /* get next share */
     256                line = linein(smbshare.I)
     257            end
     258sharecleanup:
     259            say "_AddSharesDisplay() cleanup"
     260            ok = stream(smbshare.I,'c','close')
     261            ok = SysFileDelete(smbshare.I)
     262            if ok <> 0 then say 'Failure 'ok' deleting "'smbshare.I'"!'
     263        end
     264    end
     265    say "_AddSharesDisplay() loop finished"
     266return
     267
     268/*:VRX         _GetMachinehandle
     269*/
     270
     271_GetMachinehandle: procedure
     272    Machine = arg(1)
     273    ok = VRMethod("CN_smbtree", "GetRecordList", "All", rh.)
     274
     275    do I = 1 to rh.0
     276
     277        ResName  = VRMethod("CN_smbtree","GetRecordAttr",rh.I,"Caption")
     278
     279        parse var ResName  ResName '0D0A'x .
     280        ResName = strip(ResName)
     281
     282        if Machine = ResName then leave /* we got a matching name */
     283    end 
     284return rh.I
Note: See TracChangeset for help on using the changeset viewer.