FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Automatic updating
Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM
Automatic updating
Posted: 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. 25.12 - Harbour 3.2.0 (May 2025) - xHarbour Builder (January 2020) - Bcc773

Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Re: Automatic updating
Posted: 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

Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: Automatic updating
Posted: Fri Apr 30, 2010 01:42 PM
Hello Michel,
this is how I do it:
Regards,
Otto

Code (fw): Select all Collapse
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 (fw): Select all Collapse
   
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


//================================================================================
Posts: 422
Joined: Mon Aug 17, 2009 12:18 PM
Re: Automatic updating
Posted: Fri Apr 30, 2010 02: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
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: Automatic updating
Posted: Fri Apr 30, 2010 02: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
Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM
Re: Automatic updating
Posted: Fri Apr 30, 2010 03: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. 25.12 - Harbour 3.2.0 (May 2025) - xHarbour Builder (January 2020) - Bcc773

Posts: 401
Joined: Tue Jan 05, 2010 02:33 PM
Re: Automatic updating
Posted: Fri Apr 30, 2010 03:51 PM

mgsoft
the test of biel not run on xharbour

FWH .. BC582.. xharbour
Posts: 729
Joined: Tue Oct 18, 2005 06:49 PM
Re: Automatic updating
Posted: Fri Apr 30, 2010 06:33 PM
Biel's program run perfect under xHarbour and xBuilder. Please use the following code:
Code (fw): Select all Collapse
///// 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
Posts: 401
Joined: Tue Jan 05, 2010 02:33 PM
Re: Automatic updating
Posted: Mon May 03, 2010 03: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
Posts: 729
Joined: Tue Oct 18, 2005 06:49 PM
Re: Automatic updating
Posted: Tue May 04, 2010 04: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

Continue the discussion