Deploying an update via stroage/SD card

cdurbin

Member
Joined
Dec 21, 2005
Messages
20
Location
Kentucky
Programming Experience
10+
I am posting this because I had such a time finding the information I needed. If I am doing anything stupid here, let me know. The following code allows an update to be distributed via a SD or Storage card for a home grown application. The app is in a folder on the card (CCCLARK). Autorun is used. It must reside in the appropriate folder based on the processor type(In this case folder name 2577 on the card) for it to function properly.

I was having problems with recognizing if the card was inserted or not. Solved that by adding a module(main1) subroutine(main) call to pick up the "install"/"Uninstall" parm passed when autorun executes(built-in to autorun call). My users are not very "computer Literate" so we have the many messages.

I also had problems with displaying my "waitcursor". I solved that by instanciating frm in my module("Dim frm As New AutoLoad") and then doing a "frm.show" in the module.

As you can see, I am learning as I go...

I home that this helps someone somewhere...

VB.NET:
Imports System.io
Imports System.Diagnostics
Imports Microsoft.VisualBasic
Imports System.Threading.Thread
Imports System.Runtime.InteropServices
Imports System.windows.Forms
Public Module main1
    Dim Loc As String
    Dim App_Path As String
    Dim frm As New AutoLoad
    Dim Memory As String
    Public Sub Main(ByVal args() As String)
        frm.Show()
        If (args(0) <> "uninstall") Then

             Dim response As MsgBoxResult

            MsgBox("READ ALL OF THIS MESSAGE BEFORE TAKING ANY ACTION!!!  " _
& "If you have not reset this device, please remove the card and reset the device before you continue.  " _
& "After the device resets, insert the card and tap 'OK' to this message.", MsgBoxStyle.OkCancel)
            response = MsgBox("Do you want to update? You will get a message when the update completes!", MsgBoxStyle.OkCancel)
            If response = MsgBoxResult.Ok Then   ' User chose Yes.
                ' Perform some action.
                Try
                    Cursor.Current = Cursors.WaitCursor
                Catch ex As Exception
                    MsgBox(ex.ToString, MsgBoxStyle.OkOnly)
                End Try

                Memory = "\SD Card\"
                If File.Exists(Memory & "CCClark\Update.txt") = True Then
                    Try
                        File.Copy(Memory & "CCClark\*.*", "\Program Files\CCClark\*.*", True)
                        MsgBox("Update Complete!  Please remove the card!", MsgBoxStyle.OkOnly)
                    Catch ex As Exception
                        MsgBox("Error occurred during SD update.  Try Again!   Please remove the card!" + ex.ToString, MsgBoxStyle.OkOnly)
                    End Try

                End If
                Memory = "\Storage Card\"
                If File.Exists(Memory & "CCClark\Update.txt") = True Then
                    Try
                        loadwin1("exe", "\CCClark\", "\Program Files\CCClark\")
                        loadwin1("dll", "\CCClark\", "\Program Files\CCClark\")
                        loadwin1("bmp", "\CCClark\", "\Program Files\CCClark\")
                        loadwin1("ico", "\CCClark\", "\Program Files\CCClark\")
                        loadwin1("tlb", "\CCClark\", "\Program Files\CCClark\")
                        Try
                            IO.Directory.CreateDirectory("\Program Files\CCClark\My Project")
                        Catch
                        End Try

                        loadwin1("ico", "\CCClark\My Project\", "\Program Files\CCClark\My Project\")
                        loadwin1("bmp", "\CCClark\My Project\", "\Program Files\CCClark\My Project\")
                        loadwin1("gif", "\CCClark\My Project\", "\Program Files\CCClark\My Project\")

                        MsgBox("Update Complete!  Please remove the card!", MsgBoxStyle.OkOnly)
                    Catch ex As Exception
                        MsgBox(ex.ToString, MsgBoxStyle.OkOnly)
                        MsgBox("Update Failed!  You must try again after resetting device!  Please remove the card!", MsgBoxStyle.OkOnly)
                    End Try
                End If
            Else
                MsgBox("Update Cancelled!  No changes occurred.  Please remove the card!", MsgBoxStyle.OkOnly)
            End If
        End If
        Cursor.Current = Cursors.Default
        Cursor.Hide()
        Application.Exit()
    End Sub
    Public Sub loadwin1(ByVal type As String, ByVal folder As String, ByVal tofolder As String)
        Dim strfiles() As String
        Dim textname As String
        Dim MyA() As String
        Dim x As Integer
        Dim txtlocdata As String
        If IO.Directory.Exists("\SD Card") = True Then
            txtlocdata = "\SD Card"
        ElseIf IO.Directory.Exists("\Storage Card") = True Then
            txtlocdata = "\Storage Card"
        Else
            txtlocdata = "\Storage Card"
        End If

        strfiles = System.IO.Directory.GetFiles(txtlocdata & folder, "*." & type)

        Try
            For Each textname In strfiles
                MyA = textname.Split(CChar("\"))
                x = MyA.Length - 1
                Try
                    File.Copy(textname, tofolder & MyA(x), True)
                Catch ex As Exception
                End Try
            Next
        Catch ex As Exception
        End Try

    End Sub
End Module

Public Class AutoLoad
    Inherits System.Windows.Forms.Form
    Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        MyBase.Dispose(disposing)
    End Sub

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Private Sub InitializeComponent()
        Me.MainMenu1 = New System.Windows.Forms.MainMenu
        '
        'AutoRun
        '
        Me.ClientSize = New System.Drawing.Size(240, 268)
        Me.Menu = Me.MainMenu1
        Me.Text = "Form1"

    End Sub

#End Region
 
    

End Class
 
Last edited by a moderator:
Back
Top