Author Topic: Network share/ script  (Read 6037 times)

0 Members and 1 Guest are viewing this topic.

Bryco

  • Water Moccasin
  • Posts: 1883
Network share/ script
« on: August 11, 2009, 04:52:41 PM »
the info http://www.theswamp.org/index.php?topic=9250.0 works.
But if I am updating the dll all the time, I have the same problem as vba. You cant change it while someone has cad open.
I have heard mention of a script to check on the latest version then copy the dll (if reqd.) locally to each computer. How would I go about doing that?

mcarson

  • Guest
Re: Network share/ script
« Reply #1 on: September 17, 2009, 05:17:24 PM »
In my past experience developing an addon for AutoCAD 2008 used by over 200 users I used a combination of the following:

  • A network share containing the latest updates required
  • A text/ini file that contained the updated version number
  • DFS (Distributed File System) to coordinate the shared data across the WLAN
  • A program that performed the update on startup of the relevant computers or on demand
  • Various other registry checks, file version checks as well as checksum stuff etc

I had also attempted to replace the file when it was loaded, however AutoCAD places a lock on the file and this is impossible.

Without knowing your exact situation I cannot post all the code, however the following 'Sync' code that performs the
necessary checking migh help you: (The code has been modified somewhat from something online - thanx to them)

Code: [Select]
Imports System.IO

Module Sync
  Const NB_SECOND_SLACK As Integer = 15

   Sub sync(ByVal src As String, ByVal dst As String)
      Dim srcDir As New DirectoryInfo(src)
      Dim dstDir As New DirectoryInfo(dst)

      If srcDir.Exists = False Then
         Console.WriteLine("Source directory does not exist.")
         Environment.ExitCode = 1
      Else
         sync(srcDir, dstDir)
      End If
   End Sub

   Sub sync(ByVal srcDir As DirectoryInfo, ByVal dstdir As DirectoryInfo)
      'Dim nbFileCopied As Integer
      'Dim nbFileDeleted As Integer
      Dim DstDirFullName As String = dstdir.FullName

      Console.WriteLine("[" & DstDirFullName & "]")
    If dstdir.Exists = False Then
      dstdir.Create()
    End If

      ' Read from hard disk the directory for source and destination
    Dim srcFiles As FileSystemInfo() = srcDir.GetFileSystemInfos
    Dim dstFiles As FileSystemInfo() = dstdir.GetFileSystemInfos

    Dim dstDict As IDictionary = New Specialized.HybridDictionary

    ' put the the destination list in a dictionary to speed up
    For Each fd As FileSystemInfo In dstFiles
      dstDict(fd.Name) = fd
    Next

    ' parse all the source files
    For Each fs As FileSystemInfo In srcFiles
      If TypeOf fs Is FileInfo Then
        Dim found As Boolean = False
        Dim differentDate As Boolean = False
        Dim fd As FileSystemInfo = Nothing

        If dstDict.Contains(fs.Name) Then
          found = True
          fd = DirectCast(dstDict(fs.Name), FileSystemInfo)
          Dim timeDiff As Double = fd.LastWriteTimeUtc.Subtract(fs.LastWriteTimeUtc).TotalSeconds
          If timeDiff < 0 Or timeDiff > NB_SECOND_SLACK Then
            ' We give NB_SECOND_SLACK seconds slack for the file to be copied to the destination
            ' Looks like the datetime last write is the datetime of the source plus duration
            ' of copy
            differentDate = True
          End If

          dstDict.Remove(fs.Name)
        End If
        If found = False Or differentDate Then
          Try
            Console.WriteLine("sync " & fs.Name)
            If found AndAlso (fd.Attributes And FileAttributes.ReadOnly) <> 0 Then
              fd.Attributes = fd.Attributes And Not FileAttributes.ReadOnly
            End If
            DirectCast(fs, FileInfo).CopyTo(DstDirFullName & "\" & fs.Name, True)
          Catch ex As Exception
            Console.WriteLine(">> Error " & ex.Message)
          End Try
        Else
          'Console.WriteLine("not modified " & fs.Name)
        End If
      ElseIf TypeOf fs Is DirectoryInfo Then
        sync(DirectCast(fs, DirectoryInfo), _
            New DirectoryInfo(DstDirFullName & "\" & fs.Name))
        dstDict.Remove(fs.Name)
      End If
    Next

    For Each de As DictionaryEntry In dstDict
      If TypeOf de.Value Is FileInfo Then
        Dim fd As FileInfo = DirectCast(de.Value, FileInfo)
        Try
          Console.WriteLine("delete " & fd.Name)
          If (fd.Attributes And FileAttributes.ReadOnly) <> 0 Then
            fd.Attributes = fd.Attributes And Not FileAttributes.ReadOnly
          End If
          fd.Delete()
        Catch ex As Exception
          Console.WriteLine(">> Error " & ex.Message)
        End Try
      ElseIf TypeOf de.Value Is DirectoryInfo Then
        Dim dd As DirectoryInfo = DirectCast(de.Value, DirectoryInfo)
        If dd.Exists Then ' still
          delTree(dd)
        End If
      End If
    Next
   End Sub

  Private Sub delTree(ByVal dstDir As DirectoryInfo)
    Try
      For Each fd As FileSystemInfo In dstDir.GetFileSystemInfos
        If TypeOf fd Is FileInfo Then
          Try
            Console.WriteLine("delete " & fd.Name)
            DirectCast(fd, FileInfo).Delete()
          Catch ex As Exception
            Console.WriteLine(">> Error " & ex.Message)
          End Try
        ElseIf TypeOf fd Is DirectoryInfo Then
          delTree(DirectCast(fd, DirectoryInfo))
        End If

      Next
      Console.WriteLine("delete [" & dstDir.Name & "]")
      dstDir.Delete()
    Catch ex As Exception
      Console.WriteLine(">> Error " & ex.Message)
    End Try
  End Sub

End Module


You could reduce this code somewhat, to just check for the version number: I'll post the code later. (I may post the full solution later...)

If you are updating the dll all the time, is it being tested before release to the usergroup?



Bryco

  • Water Moccasin
  • Posts: 1883
Re: Network share/ script
« Reply #2 on: September 17, 2009, 06:17:26 PM »
This looks great, thanks.
It's going to take me a little while to soak up as I haven't used ini files and DFS;
I'm off to google that now

Chumplybum

  • Newt
  • Posts: 97
Re: Network share/ script
« Reply #3 on: September 17, 2009, 07:24:39 PM »
i use a loading dll, which checks the network for an updated dll (using the timestamp) against the files on the users machine. The process is as follows...

1. an msi installs the loading dll on the users machine, registers the dll for demand loading and adds 2 other registry keys... one for the network location and one for the local computer install location
2. on autocad startup, the loading dll gets loaded into cad and runs the check, comparing the network files against the local machine files
3. if a change is found the new file gets copied to the local machine and loaded, if not then the local copy gets loaded
4. any changes required of the loading dll get updated via a new msi package


HTH

cheers, Mark

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Network share/ script
« Reply #4 on: September 17, 2009, 08:25:16 PM »
Did you buy a programme to make the msi file?

Chumplybum

  • Newt
  • Posts: 97
Re: Network share/ script
« Reply #5 on: September 17, 2009, 09:12:39 PM »
no, i use WiX (Windows Installer XML) which intergrates into visual studio (not sure about express editions)... http://wix.sourceforge.net/

you can also use the setup / deployment template that comes with visual studio, using this one to do the type of installation i mentioned should be fine... its a little easier to use, but lacks the flexibility of the WiX toolset

MickD

  • King Gator
  • Posts: 3637
  • (x-in)->[process]->(y-out) ... simples!
Re: Network share/ script
« Reply #6 on: September 17, 2009, 10:06:20 PM »
I was going to suggest something similar to Chumply's method but use a batch file which is call in the shortcut to start acad.

Basically the shortcut runs the bat file to check for updated files on the repository and copies them over if newer, then start acad.
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien

mcarson

  • Guest
Re: Network share/ script
« Reply #7 on: September 18, 2009, 03:34:22 AM »
i use a loading dll, which checks the network for an updated dll (using the timestamp) against the files on the users machine. The process is as follows...

1. an msi installs the loading dll on the users machine, registers the dll for demand loading and adds 2 other registry keys... one for the network location and one for the local computer install location
2. on autocad startup, the loading dll gets loaded into cad and runs the check, comparing the network files against the local machine files
3. if a change is found the new file gets copied to the local machine and loaded, if not then the local copy gets loaded
4. any changes required of the loading dll get updated via a new msi package


HTH

cheers, Mark

Excellent! Never thought of this way. Seems to answer all the questions I have had. One question though: With my program, I sync'd more than
the standard assemblies; I checked the versions, datetimes and checksums of over 15000 support files, including templates, block libraries etc.
It may be too much of a performance hit on AutoCAD startup to check this many. Do you do this?


Glenn R

  • Guest
Re: Network share/ script
« Reply #8 on: September 18, 2009, 09:30:46 AM »
I had the IT dept add a call to a VB script, under my control, from their network login script. This script executed a ROBOCOPY command to copy only files that were updated from the network to the local machine and anything else I needed to do.

Mick's idea is a good one if you can't get the IT dept to play ball. Just use a call to ROBOCOPY in that and you're done.

Glenn R

  • Guest
Re: Network share/ script
« Reply #9 on: September 18, 2009, 09:37:17 AM »
Forgot to mention that I also used the script to 'merge' registry entries for the demandloading of the .net dll's as well.

If you're interested I can post it after I remove the names to protect the innocent (me) ;)

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Network share/ script
« Reply #10 on: September 18, 2009, 01:25:16 PM »
Forgot to mention that I also used the script to 'merge' registry entries for the demandloading of the .net dll's as well.
I am as that is my next task to start looking at seting up
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Network share/ script
« Reply #11 on: September 18, 2009, 01:27:23 PM »
As I dont have a lot of files, I use a batch file that copies all the files locally when the user boots the machine.  While not everyone boots daily, at least they update weekly.
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

Glenn R

  • Guest
Re: Network share/ script
« Reply #12 on: September 18, 2009, 03:11:45 PM »
Duh,

This is a very stripped down version of the script, but it gives the relevant command strings etc.

Code: [Select]
Option Explicit

Dim pWshShell
Dim iVersion


' Call the entrypoint
Main

'----------------------------------------------------------------------
Sub Main

    On Error Resume Next
   
    ' Create our main objects to get everything else from
    Set pWshShell = CreateObject("WScript.Shell")

    ' Setup AutoCAD customisations if the user needs them
    DeployAcadFiles 2006

End Sub


Sub DeployAcadFiles(iVersion)
    On Error Resume Next
    Select Case iVersion
        Case 2006
            pWshShell.Run "regedit.exe /s ""\\SERVERNAME\ShareName\SomeFolder\ACAD 2006 CAD dll.reg""", 0, false
            pWshShell.Run "\\SERVERNAME\ShareName\SomeFolder\Robocopy.exe ""\\SERVERNAME\ShareName\SomeFolder\CAD 2006"" ""C:\SomeLocalFolder\SomeCompanyCAD\2006"" /E /PURGE /LOG:""\\SERVERNAME\ShareName\Deployment Logs\Deploy_%COMPUTERNAME%.log"" /R:0 /W:0", 0, false
    End Select
End Sub

For the .reg file, on my dev box, you export the relevant keys for all your .dll's, then combine then into a single .reg file. If you ever need to remove a .dll quickly, from memory, you just precede the hive you're adding with a minus ( - ) and ask the use to log off/on and the reg keys will be removed.

It's late and dinner here, but if you have any questions, post away and I will get to them when I get a chance on the weekend.

Cheers,

Glenn R

  • Guest
Re: Network share/ script
« Reply #13 on: September 18, 2009, 03:46:47 PM »
You could also use xcopy with these switches:

xcopy /D /E /C /R /Y

Consult the commandline help for xcopy to get the exact description of the switches. Either robocopy or xcopy will work well.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Network share/ script
« Reply #14 on: September 18, 2009, 04:00:59 PM »
You could also use xcopy with these switches:

xcopy /D /E /C /R /Y

Consult the commandline help for xcopy to get the exact description of the switches. Either robocopy or xcopy will work well.

That's exactly what I do....xcopy and switches make network life simple  :-)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC