Page 1 of 1

Automatic updating

PostPosted: Fri Apr 30, 2010 11:52 am
by driessen
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.

Re: Automatic updating

PostPosted: Fri Apr 30, 2010 12:02 pm
by anserkk
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

Re: Automatic updating

PostPosted: Fri Apr 30, 2010 1:42 pm
by Otto
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


//================================================================================

Re: Automatic updating

PostPosted: Fri Apr 30, 2010 2:14 pm
by mgsoft
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

Re: Automatic updating

PostPosted: Fri Apr 30, 2010 2:20 pm
by TimStone
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.

Re: Automatic updating

PostPosted: Fri Apr 30, 2010 3:09 pm
by driessen
Thank you guys, for your answers.

Otto's suggestion works perfectly.

Re: Automatic updating

PostPosted: Fri Apr 30, 2010 3:51 pm
by MdaSolution
mgsoft
the test of biel not run on xharbour

Re: Automatic updating

PostPosted: Fri Apr 30, 2010 6:33 pm
by George
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

Re: Automatic updating

PostPosted: Mon May 03, 2010 3:37 pm
by MdaSolution
Good george can you post the sample complete please?
And How I can make If I must go out from a proxy ?

Re: Automatic updating

PostPosted: Tue May 04, 2010 4:05 pm
by George
Please refer to:
Gabriel Maimó at http://bielsys.blogspot.com/ For further explanation.

He is the person that developed this program.

Regards,


George