Automatic updating

Automatic updating

Postby driessen » Fri Apr 30, 2010 11:52 am

Hello,

On a regular base, I put updates of my application on my website. An update always contains 2 files.

I want to build a function in my application which checks if an update is available on my website. If an update is available, the user has to get a message to tell him/her to update.

Does anyone have any idea how I can check in FWH if an update is available on a website ?

Thank you very much in advance for any idea.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.02 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc77
User avatar
driessen
 
Posts: 1399
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Automatic updating

Postby anserkk » Fri Apr 30, 2010 12:02 pm

Dear Mr. Michel,

1.Each time your program is run, it should check with your FTP site whether a new exe is available or not. This can be File's date Time.
2. If the exe in FTP is the latest, means there is an update. Now inform the user about this and get the confirmation from the user whether to download the new exe or not.
3. If the user prefer to download the update, then establish FTP connection and download the exe from the site and save it with a different name.
4. Once the download is finished, you should quit the currently running app.
5. Rename the newly downloaded app to your actual App.Exe name, run the app. (This process can be done with another app in your app folder)

Regards
Anser
User avatar
anserkk
 
Posts: 1331
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: Automatic updating

Postby Otto » Fri Apr 30, 2010 1:42 pm

Hello Michel,
this is how I do it:
Regards,
Otto

Code: Select all  Expand view
if  Memoread(cAppPath + "\ini\update.txt") = lookforupdate("http://www.test.at/update.txt")
      //msginfo("keine Änderungen")
else
      msginfo( Memoread(cAppPath + "\ini\update.txt") )
endif
       




Code: Select all  Expand view

   
function lookforupdate(cUrl)
  local cAppPath     := cFilePath( GetModuleFileName( GetInstance( ) ) )
  local cPageContent := "Error: " + cUrl + " not found or timed out."
  local oConn

  //IF Upper(Left(cUrl,4))="HTTP"
  //   cUrl:="http://"+cUrl
  //ENDIF
 
 
  TRY
   oConn := TipClientHttp():New(TURL():New(cUrl))
   oConn:nConnTimeout := 20000
   IF oConn:Open(cURL)
      cPageContent := oConn:ReadAll()
      oConn:Close()
   ENDIF
  CATCH
   cPageContent:="Error opening " + cUrl
  END


  MemoWrit(cAppPath + "\ini\update.txt" ,cPageContent)

  WritePProString( "SETUPDATEN" ,"DOWNLOAD", dtoc( date() ), "INI\update.ini" )


RETURN cPageContent


//================================================================================
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6133
Joined: Fri Oct 07, 2005 7:07 pm

Re: Automatic updating

Postby mgsoft » Fri Apr 30, 2010 2:14 pm

Hi,

Master Gabriel Maimó created a solution to update via FTP. See at http://bielsys.blogspot.com/

(actualización automática de aplicaciones).

It is an excelent work done by him.

Regards :D
Saludos,

Eduardo
User avatar
mgsoft
 
Posts: 422
Joined: Mon Aug 17, 2009 12:18 pm
Location: España

Re: Automatic updating

Postby TimStone » Fri Apr 30, 2010 2:20 pm

Michael,

I do it a bit differently. I created a separate program which runs on the server all of the time. Here is how it works:

1) The program, when started, will check my server to see if an update exists AND if the client is authorized to receive it. If so, the program downloads the update file ( created as a zip ) and then unpacks it. This overwrites a "server" file that is rarely open ( just used for maintenance ), and a "client" file. The program also does a backup of all files to a USB drive, and does some timed submissions. This program runs all the time in the background, and if that machine is shut down, the shortcut is in the startup folder so it will run again when the "server" is turned back on. Backups are daily ( afer midnight ), and other submissions are on their scheduled basis. The program will cycle every six hours, so it does this 4 times a day. If an update is brought to the machine, it is then logged in.

2) When starting the "client" program, it checks to see if the current running program is less then the version on the local server. If it is, then it will copy the newer .exe to the local machine, and then start the program. My shortcut actually points to a separate program which does the checking and copy before running the actual client .exe.

If anyone wants details, I will be happy to post them.
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2909
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: Automatic updating

Postby driessen » Fri Apr 30, 2010 3:09 pm

Thank you guys, for your answers.

Otto's suggestion works perfectly.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.02 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc77
User avatar
driessen
 
Posts: 1399
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Automatic updating

Postby MdaSolution » Fri Apr 30, 2010 3:51 pm

mgsoft
the test of biel not run on xharbour
FWH .. BC582.. xharbour
User avatar
MdaSolution
 
Posts: 401
Joined: Tue Jan 05, 2010 2:33 pm

Re: Automatic updating

Postby George » Fri Apr 30, 2010 6:33 pm

Biel's program run perfect under xHarbour and xBuilder. Please use the following code:
Code: Select all  Expand view

///// FUNCIONES PARA CONVERIR HORA A SEGUNDOS, Y VICEVERSA
// Nota: me comentan que al compilar con xHarbour falta la función HB_IsChar, simplemente sustituir HB_ISCHAR( cTime ) por ValType(cTime)=='C'.
//---------------------------------
STATIC FUNCTION  TIMETOSEC( cTime )
local nSec := 0, nLen, i, aLim, aMod, nInd, n
if cTime == NIL
   nSec := seconds()
elseif ValType(cTime)=='C'  //HB_ISCHAR( cTime )
   nLen := len( cTime )
   if ( nLen + 1 ) % 3 == 0 .and. nLen <= 11
      nInd := 1
      aLim := { 24, 60, 60, 100 }
      aMod := { 3600, 60, 1, 1/100 }
      for i := 1 to nLen step 3
         if isdigit( substr( cTime, i,     1 ) ) .and. ;
            isdigit( substr( cTime, i + 1, 1 ) ) .and. ;
            ( i == nLen - 1 .or. substr( cTime, i + 2, 1 ) == ":" ) .and. ;
            ( n := val( substr( cTime, i, 2 ) ) ) < aLim[ nInd ]
            nSec += n * aMod[ nInd ]
         else
            nSec := 0
            exit
         endif
         ++nInd
      next
   endif
endif
return round( nSec, 2) /* round FL val to be sure that you can compare it */

#pragma BEGINDUMP
#include <Windows.h>
//#include <mapiwin.h>
#include <hbApi.h>
                     //nTime 1=Last Update, 2=Last Acces, 3=Creation, defecto last update
HB_FUNC( FILETIMES ) // params cFileName, nTime --> { nYear, nMonth, nDay, nHour, nMin, nSec }
{
   LPSTR cFileName = hb_parc( 1 ) ;
   int nTime       = ( ISNUM( 2 ) ? hb_parni( 2 ) :  1 ) ; // defaults to 1

   FILETIME ftCreate, ftAccess, ftWrite ;
   SYSTEMTIME stTime ;
   BOOL bRet ;
   HANDLE hFile = CreateFile( cFileName, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0 ) ;

   if( ! hFile )
      return ;

   GetFileTime( (HANDLE) hFile, &ftCreate, &ftAccess, &ftWrite ) ;

   switch( nTime )
   {
      case 1 : // last update
         FileTimeToSystemTime( &ftWrite, &stTime ) ;
         break ;
      case 2 : // last access
         FileTimeToSystemTime( &ftAccess, &stTime ) ;
         break ;
      case 3 : // creation
         FileTimeToSystemTime( &ftCreate, &stTime ) ;
         break ;
      default : // last update
         FileTimeToSystemTime( &ftWrite, &stTime ) ;
         break ;
   }

   SystemTimeToTzSpecificLocalTime( NULL, &stTime, &stTime ) ;
   CloseHandle( hFile ) ;
   hb_reta( 6 ) ;
   hb_storni( stTime.wYear,   -1, 1 ) ;
   hb_storni( stTime.wMonth,  -1, 2 ) ;
   hb_storni( stTime.wDay,    -1, 3 ) ;
   hb_storni( stTime.wHour,   -1, 4 ) ;
   hb_storni( stTime.wMinute, -1, 5 ) ;
   hb_storni( stTime.wSecond, -1, 6 ) ;
}

#define FA_RDONLY           1   /* R */
#define FA_HIDDEN           2   /* H */
#define FA_SYSTEM           4   /* S */
#define FA_LABEL            8   /* V */
#define FA_DIREC           16   /* D */
#define FA_ARCH            32   /* A */
#define FA_NORMAL           0
HB_FUNC(_FILESIZE)

   {
   LPCTSTR szFile;
   DWORD dwFlags=FILE_ATTRIBUTE_ARCHIVE;
   HANDLE hFind;
   WIN32_FIND_DATA  hFilesFind;
      int iAttr;
      if (hb_pcount() >=1){
         szFile=hb_parc(1);
         if (ISNUM(2))      {
            iAttr=hb_parnl(2);
         }
         else{
         iAttr=63;
         }
            if( iAttr & FA_RDONLY )
               dwFlags |= FILE_ATTRIBUTE_READONLY;

            if( iAttr & FA_HIDDEN )
               dwFlags |= FILE_ATTRIBUTE_HIDDEN;

            if( iAttr & FA_SYSTEM )
               dwFlags |= FILE_ATTRIBUTE_SYSTEM;
            if( iAttr & FA_NORMAL )
               dwFlags |=    FILE_ATTRIBUTE_NORMAL;

            hFind = FindFirstFile(szFile,&hFilesFind);
                  if (hFind != INVALID_HANDLE_VALUE){
                      if (dwFlags & hFilesFind.dwFileAttributes) {
                         if(hFilesFind.nFileSizeHigh>0)
                              hb_retnl((hFilesFind.nFileSizeHigh*MAXDWORD)+hFilesFind.nFileSizeLow);
                         else
                              hb_retnl(hFilesFind.nFileSizeLow);
                       }
                   else
                           hb_retnl(-1);
                     }

         }
}

#pragma ENDDUMP

 


Regards

George
George
 
Posts: 725
Joined: Tue Oct 18, 2005 6:49 pm

Re: Automatic updating

Postby MdaSolution » Mon May 03, 2010 3:37 pm

Good george can you post the sample complete please?
And How I can make If I must go out from a proxy ?
FWH .. BC582.. xharbour
User avatar
MdaSolution
 
Posts: 401
Joined: Tue Jan 05, 2010 2:33 pm

Re: Automatic updating

Postby George » Tue May 04, 2010 4:05 pm

Please refer to:
Gabriel Maimó at http://bielsys.blogspot.com/ For further explanation.

He is the person that developed this program.

Regards,


George
George
 
Posts: 725
Joined: Tue Oct 18, 2005 6:49 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 140 guests