Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[EO]Autoupdater in frmMenu


Mitus
 Share

Recommended Posts

(1/10) easy :P

**Credits**
_Eclipse Origins - Autoupdater
Created by: Robin Perris
Website: freemmorpgmaker.com_

**Requeriment**
_unrar.dll in you client folder_

**Client-Side**

Requeriment Components
Go menu project in VB and components or Ctrl+T
Add components MSINET.OCX
Microsoft Internet Transfer Control 6.0(SP6)

**1* –-------- Create**

Create new Module and named "modUnrar"
And Add in new module
```
Option Explicit

Private Const ERAR_END_ARCHIVE As Byte = 10
Private Const ERAR_NO_MEMORY As Byte = 11
Private Const ERAR_BAD_DATA As Byte = 12
Private Const ERAR_BAD_ARCHIVE As Byte = 13
Private Const ERAR_UNKNOWN_FORMAT As Byte = 14
Private Const ERAR_EOPEN As Byte = 15
Private Const ERAR_ECREATE As Byte = 16
Private Const ERAR_ECLOSE As Byte = 17
Private Const ERAR_EREAD As Byte = 18
Private Const ERAR_EWRITE As Byte = 19
Private Const ERAR_SMALL_BUF As Byte = 20

Private Const RAR_OM_LIST As Byte = 0
Private Const RAR_OM_EXTRACT As Byte = 1

Private Const RAR_SKIP As Byte = 0
Private Const RAR_TEST As Byte = 1
Private Const RAR_EXTRACT As Byte = 2

Private Const RAR_VOL_ASK As Byte = 0
Private Const RAR_VOL_NOTIFY As Byte = 1

Public Enum RarOperations
    OP_EXTRACT = 0
    OP_TEST
    OP_LIST
End Enum

Private Type RARHeaderData
    ArcName As String * 260
    FileName As String * 260
    Flags As Long
    PackSize As Long
    UnpSize As Long
    HostOS As Long
    FileCRC As Long
    FileTime As Long
    UnpVer As Long
    Method As Long
    FileAttr As Long
    CmtBuf As String
    CmtBufSize As Long
    CmtSize As Long
    CmtState As Long
End Type

Private Type RAROpenArchiveData
    ArcName As String
    OpenMode As Long
    OpenResult As Long
    CmtBuf As String
    CmtBufSize As Long
    CmtSize As Long
    CmtState As Long
End Type

Private Declare Function RAROpenArchive Lib "unrar.dll" (ByRef ArchiveData As

RAROpenArchiveData) As Long
Private Declare Function RARCloseArchive Lib "unrar.dll" (ByVal hArcData As Long) As Long
Private Declare Function RARReadHeader Lib "unrar.dll" (ByVal hArcData As Long, ByRef

HeaderData As RARHeaderData) As Long
Private Declare Function RARProcessFile Lib "unrar.dll" (ByVal hArcData As Long, ByVal

Operation As Long, ByVal DestPath As String, ByVal DestName As String) As Long
Private Declare Sub RARSetChangeVolProc Lib "unrar.dll" (ByVal hArcData As Long, ByVal Mode

As Long)
Private Declare Sub RARSetPassword Lib "unrar.dll" (ByVal hArcData As Long, ByVal Password

As String)

Public Sub RARExecute(ByVal Mode As RarOperations, ByVal RarFile As String, Optional ByVal

Password As String)
    ' Description:-
    ' Extract file(s) from RAR archive.
    ' Parameters:-
    ' Mode = Operation to perform on RAR Archive
    ' RARFile = RAR Archive filename
    ' sPassword = Password (Optional)
    Dim lHandle As Long
    Dim iStatus As Integer
    Dim uRAR As RAROpenArchiveData
    Dim uHeader As RARHeaderData
    Dim sStat As String, Ret As Long

    uRAR.ArcName = RarFile
    uRAR.CmtBuf = Space(16384)
    uRAR.CmtBufSize = 16384

    If Mode = OP_LIST Then
        uRAR.OpenMode = RAR_OM_LIST
    Else
        uRAR.OpenMode = RAR_OM_EXTRACT
    End If

    lHandle = RAROpenArchive(uRAR)
    If uRAR.OpenResult <> 0 Then
        Kill RarFile
        OpenError uRAR.OpenResult, RarFile
    End If

    If Password <> "" Then RARSetPassword lHandle, Password

    If (uRAR.CmtState = 1) Then MsgBox uRAR.CmtBuf, vbApplicationModal + vbInformation,

"Comment"

    iStatus = RARReadHeader(lHandle, uHeader)

    Do Until iStatus <> 0
        sStat = Left(uHeader.FileName, InStr(1, uHeader.FileName, vbNullChar) - 1)
        Select Case Mode
        Case RarOperations.OP_EXTRACT
            Ret = RARProcessFile(lHandle, RAR_EXTRACT, "", uHeader.FileName)
        Case RarOperations.OP_TEST
            Ret = RARProcessFile(lHandle, RAR_TEST, "", uHeader.FileName)
        Case RarOperations.OP_LIST
            Ret = RARProcessFile(lHandle, RAR_SKIP, "", "")
        End Select

        If Ret = 0 Then
            ProcessError Ret
        End If

        iStatus = RARReadHeader(lHandle, uHeader)
    Loop

    If iStatus = ERAR_BAD_DATA Then
        MsgBox "File header broken", vbCritical
        DestroyUpdater
    End If

    RARCloseArchive lHandle
End Sub

' Error handling
Private Sub OpenError(ErroNum As Long, ArcName As String)
Dim erro As String

    Select Case ErroNum
        Case ERAR_NO_MEMORY
            erro = "Not enough memory"
            GoTo errorbox
        Case ERAR_EOPEN:
            erro = "Cannot open " & ArcName
            GoTo errorbox
        Case ERAR_BAD_ARCHIVE:
            erro = ArcName & " is not RAR archive"
            GoTo errorbox
        Case ERAR_BAD_DATA:
            erro = ArcName & ": archive header broken"
            GoTo errorbox
    End Select

    Exit Sub

errorbox:
    MsgBox erro, vbCritical
    DestroyUpdater
End Sub

Private Sub ProcessError(ErroNum As Long)
Dim erro As String

    Select Case ErroNum
        Case ERAR_UNKNOWN_FORMAT
            erro = "Unknown archive format"
            GoTo errorbox
        Case ERAR_BAD_ARCHIVE:
            erro = "Bad volume"
            GoTo errorbox
        Case ERAR_ECREATE:
            erro = "File create error"
            GoTo errorbox
        Case ERAR_EOPEN:
            erro = "Volume open error"
            GoTo errorbox
        Case ERAR_ECLOSE:
            erro = "File close error"
            GoTo errorbox
        Case ERAR_EREAD:
            erro = "Read error"
            GoTo errorbox
        Case ERAR_EWRITE:
            erro = "Write error"
            GoTo errorbox
        Case ERAR_BAD_DATA:
            erro = "CRC error"
            GoTo errorbox
    End Select

    Exit Sub

errorbox:
    MsgBox erro, vbCritical
    DestroyUpdater
End Sub

```
**2* –-------- In modGeneral**

Find
```
Public DX7 As New DirectX7  ' Master Object, early binding

```
and add below one line
```
' file host
Private UpdateURL As String

' stores the variables for the version downloaders
Private VersionCount As Long

```
Find "Public Sub Main()" and find
```
' Reset values
    Ping = -1

```
and add below one line
```
If Not FileExists(App.Path & "\Data Files\updaterInfo.ini") Then DestroyUpdater
    UpdateURL = GetVar(App.Path & "\Data Files\updaterInfo.ini", "UPDATER", "updateURL")

```
Next find "Public Function isStringLegal"
and add below of sub
New subs
```

Public Sub DestroyUpdater()
    ' kill temp files
    If FileExists(App.Path & "\tmpUpdate.ini") Then Kill App.Path & "\tmpUpdate.ini"
    ' end updater
    Unload frmMenu
    End
End Sub

Public Sub Update()
Dim CurVersion As Long
Dim FileName As String
Dim I As Long

    AddProgress "Connecting to server..."

    ' get the file which contains the info of updated files
    DownloadFile UpdateURL & "/update.ini", App.Path & "\tmpUpdate.ini"

    AddProgress "Connected to server!"
    AddProgress "Retrieving version information."

    ' read the version count
    VersionCount = GetVar(App.Path & "\tmpUpdate.ini", "FILES", "Versions")

    ' check if we've got a current client version saved
    If FileExists(App.Path & "\Data Files\version.ini") Then
        CurVersion = GetVar(App.Path & "\Data Files\version.ini", "UPDATER", "CurVersion")
    Else
        CurVersion = 0
    End If

    ' are we up to date?
    If CurVersion < VersionCount Then
        ' make sure it's not 0!
        If CurVersion = 0 Then CurVersion = 1
        ' loop around, download and unrar each update
        For I = CurVersion To VersionCount
            ' let them know!
            AddProgress "Downloading version " & I & "."
            FileName = "version" & I & ".rar"
            ' set the download going through inet
            DownloadFile UpdateURL & "/" & FileName, App.Path & "\" & FileName
            ' us the unrar.dll to extract data
            RARExecute OP_EXTRACT, FileName
            ' kill the temp update file
            Kill App.Path & "\" & FileName
            ' update the current version
            PutVar App.Path & "\Data Files\version.ini", "UPDATER", "CurVersion", Str(I)
            ' let them know!
            AddProgress "Version " & I & " installed."
        Next
        ' let them know the update has finished
        AddProgress ""
        AddProgress "Update Complete!"
        AddProgress "You can now exit the updater.", False
        AddProgress ""
    Else
        ' they're at the correct version, or perhaps higher!
        AddProgress ""
        AddProgress "You are completely up to date!"
        AddProgress "You can now exit the updater.", False
        AddProgress ""
        frmMenu.cmdEnter.Visible = True
    End If

End Sub

Public Sub AddProgress(ByVal sProgress As String, Optional ByVal newline As Boolean = True)
    ' add a string to the textbox on the form
    frmMenu.txtProgress.text = frmMenu.txtProgress.text & sProgress
    If newline = True Then frmMenu.txtProgress.text = frmMenu.txtProgress.text & vbNewLine
End Sub

Private Sub DownloadFile(ByVal URL As String, ByVal FileName As String)
    Dim fileBytes() As Byte
    Dim fileNum As Integer

    On Error GoTo DownloadError

    ' download data to byte array
    fileBytes() = frmMenu.inetDownload.OpenURL(URL, icByteArray)

    fileNum = FreeFile
    Open FileName For Binary Access Write As #fileNum
        ' dump the byte array as binary
        Put #fileNum, , fileBytes()
    Close #fileNum

    Exit Sub

DownloadError:
    MsgBox Err.Description
End Sub

```
**3* –-------- modDatabase**

Find "Public Function FileExist"

And add below sub
new sub
```
Public Function FileExists(ByVal FileName As String, Optional RAW As Boolean = False) As

Boolean
      If LenB(Dir(FileName)) > 0 Then FileExists = True
End Function

```OBS: Need add new Public FUnction FileExist**"S"** not use "Public Function FileExist"

Next

**4* –-------- frmMenu**
in frmMenu find
```
Dim AlignText As Integer

    Me.Show

```
and add below one line
```
    AddProgress "Welcome to the Eclipse Origins autoupdater."
    AddProgress "Press 'Connect' to update your client."
    AddProgress ""
    ' call the update sub
    Update

```
in frmMenu below sub Form_Load
Add below sub, new sub
```
Private Sub cmdEnter_Click()
    picUpdate.Visible = False
End Sub

```

**5* –-------- frmMainGame**

In frmMainGame, find "Private Sub imgExit_Click()"

in sub find
```
txtChat.text = vbNullString

```
and add below one line
```
frmMenu.picUpdate.Visible = False

```

**6* –-------- Edit frmMenu**

Now here is ghaphics
you modifique for you preferences

1 - Create new PictureBox, full size of frmMenu or not you prefence
and give name "picUpdate"

2 - In new PictureBox, create textBox
and give name "txtProgress"
in properties of textbox change
* Locked for True
* Multiline for True
* ScrollBars for 2 - Vertical

3 - In new PictureBox, create Inet 'you new component
and give name "inetDownload"

4 - In new PictureBox, create CommandButton
and give name "cmdEnter"

**7* –-------- INI Files**

In folder "\Data Files" create a ini file name "updaterInfo"

And add
```
[UPDATER]
updateURL= http://yousite/update

```

**Server-Side**

Now is for you site or folder

Create in folder update ini file name "update"
And add
```
[FILES]
versions=1
version1=version1.rar

```
**Exemple**
_[FILES]
versions=3
version1=version1.rar
version2=version2.rar
version3=version3.rar
etc._

–-------------------------------

**Now is Done :D**

SORRY ME ENGLISH NOT IS GOOD :S
Link to comment
Share on other sites

Umm… how is this supposed to update if the changes you made are within the client's source? To update, would it not have to extract the new client over the old one, therefore deleting the old one? How can it continue the update if it's been deleted?
Link to comment
Share on other sites

  • 3 weeks later...
I've modified robin's updater into my game, as seperate program. If you lauch the client, it first checks lauches the updater, if there is no update, it lets you in the game, by clicking a button on the updater. You cannot play until you've updated.

Besides, this DOESN'T work, because it will not let you overwrite your client.exe as the program is running.
Link to comment
Share on other sites

  • 1 month later...
@Robin:

> This won't let you update the actual executable though. >_>

That's exactly the reason why i removed the Unrar process from my updater and made a standalone "Unrar - "patch installer" application so that the client + updater and all the other rest can be patched without a problem.
Link to comment
Share on other sites

@Aramyth:

> @Robin:
>
> > This won't let you update the actual executable though. >_>
>
> That's exactly the reason why I removed the Unrar process from my updater and made a standalone "Unrar - "patch installer" application so that the client + updater and all the other rest can be patched without a problem.

Post a tutorial on it then ;D
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...