Discussion in 'Programming Chat & Support' started by EriX920, July 22, 2008.

  1. EriX920

    EriX920 FS Administrator

    I need someone to write me a fast and clean way of updating my app.

    Heres what I wrote in a minute, I just have so much shit to write for my app I can't do it all.

        Private Sub autoup()
                My.Computer.Network.DownloadFile("", "version.txt")
            Catch ex As Exception
                Exit Sub
            End Try
            Dim vrspth As String = "version.txt"
            Dim vrs As String
            Dim objReader As StreamReader
            objReader = New StreamReader(vrspth)
            vrs = objReader.ReadToEnd()
            If My.Application.Info.Version.ToString < vrs.ToString Then
                MsgBox("Updated available!")
                ' Do update, maybe call a secondary app to start, close this app
                ' delete old copy or rename and download new and then start it.
            End If
        End Sub
  2. WorldWarIII

    WorldWarIII Guest

    Simple and effective. I have made many different auto-updates all with different ways of checking for updates and getting them each time lol.
  3. EriX920

    EriX920 FS Administrator

    Well I meant like doing what did, download and check the text file. Not like checking system time, having it show a progress bar / download speed etc..
  4. Hackless

    Hackless #define Hackless "FS Coder"

    Well, I use another executable for updating the application, so the main app checks for updates then sends the update query for the updater then closes, the updater waits for it to exit then it downloads the updates. I may send ya teh source....


    See if this helps:
  5. EriX920

    EriX920 FS Administrator

    First link is exactly what I meant by too complicated.

    I can just close the program by:

    Private Sub kill(Byval proc As String)
            Dim inst As Process
            Dim klpc As Process() = Process.GetProcessesByName(proc)
            For Each inst In klpc
    End Sub
    So that isn't a problem. I've ran into a really annoying bug in my server so i'm trying to fix that. If you want to build onto that, please do ;).
  6. CioNide

    CioNide FS Member

    Very nice guys!
  7. adz0rd

    adz0rd New Member

    Hi could anyone help with a auto updater, ive tried all the codes found on the internet but none seem to work, my version .txt is Here but it doesnt seem to work, i made a if statment saying if that file has a length less than 7 then it should come up with an error, so it always comes up with an error, what i want is a form which says the current program version (label1.text) and the most updated version (label2.text) and if label1 is less that label2 it would download then close the current program, rename the old program move the new one into that dir and then delete the old one

    when i try the original code from that guy i get no error but a debug error which doesnt say what it is or how to fix
  8. Binary

    Binary Member

  9. oldfart

    oldfart Member

    Hi guys,

    I may post the auto updater part of my YASAMM it does the following:-

    1. YASAMM contacts the HTTP Update Server (written in PHP on Apache)
    2. HTTP Server responds with the current version
    3. If version is out of date YASAMM asks the user whether to update or not
    4. If update is accepted then YASAMM does a slow HTTP download :rolleyes: from the server using "PRIMITIVE" requests and stores the block in an internal buffer
    5. YASAMM then loads update file to "temp" folder on disk, it also loads it's internal launcher to "temp" folder and launches it.
    6. The launcher waits until YASAMM has terminated and then deletes YASAMM, renames the update file and copies it to the original folder
    7. The Launcher then launches the new YASAMM and exits
    8. The updated YASAMM starts

    YASAM is about 2.5 MB and totally self contained so the above scenario works well for it but may not be suitable for others - although the Launcher may be.

    This is all in Win32 C++ - I was considering posting this in snippets and listening to any suggested improvements.


    The notes below may be a bit cryptic but I hope they convey enough information to make sense ..

    Notes: Usage parameters (primitives)
    -d => delete file
    -r => rename file (from to)
    -c => copy (from to)
    -e => execute (exe + command line + parameters fed to exe)

    //		Notes:
    //	vnetcafeupdater -d file_a.txt -r file_b.txt file_e.txt -c file_c.txt test_out/file.c -e "" "dir test_out"
    //  ------------------------------------------------------------------------
    Interface Header

    //	-------------------------------------------------------------
    //		Defines & Typedefs
    //	-------------------------------------------------------------
    #define	GLOBAL
    #define	LOCAL	static
    #define	UPD_PARAM_COPY		"-C"
    #define	UPD_PARAM_DELETE	"-D"
    #define	UPD_PARAM_EXECUTE	"-E"
    #define	UPD_PARAM_MKDIR		"-MD"
    #define	UPD_PARAM_RENAME	"-R"
    #define	UPD_PARAM_RMDIR		"-RD"
    #define	CMD_COPY			"C"
    #define	CMD_DELETE			"D"
    #define	CMD_EXECUTE			"E"
    #define	CMD_MKDIR			"MD"
    #define	CMD_RENAME			"R"
    #define	CMD_RMDIR			"RD"
    //	-------------------------------------------------------------
    And invocation

    //	**************************************************************************
    //	**                                                                      **
    //	**                                                                      **
    //	**                                                                      **
    //	**      Name:  UTILITY FUNCTIONS                                        **
    //	**                                                                      **
    //	**      Description:                                                    **
    //	**                                                                      **
    //	**                                                                      **
    //	**      Parameters:                                                     **
    //	**                                                                      **
    //	**                                                                      **
    //	**		Returns:                                                        **
    //	**                                                                      **
    //	**                                                                      **
    //	**                                                                      **
    //	**                                                                      **
    //	**************************************************************************
    void CUpdateViaHttp::LaunchUpdate()
    	CFile	tFile;
    	DWORD	dwLastError;
    	BOOL	fRC	= FALSE;
    	CString	csCommandLine;
    	char	*pszTempName	= NULL;
    	pszTempName	= _tempnam((char *)(LPCTSTR) m_csLoaderBaseDir, m_csFname );
    	//	--->	--------------------------	<---
    	//	--->	Validate call to tempnam()	<---
    	//	--->	--------------------------	<---
    	if	( pszTempName != NULL )
    //		_splitpath( pszTempName, 
    //					szDrive,
    //					szDir,
    //					szFname,
    //					szExt );
    //		csApplicationDir	= szDrive;
    //		csApplicationDir	+= szDir;
    		//	Save the temp file name
    		m_csTempPath	= pszTempName;
    		//	--->	---------------	<---
    		//	--->	Load the loader	<---
    		//	--->	---------------	<---
    		fRC	= CreateLoaderFile( LOADER_FILENAME );
    		if	( fRC == TRUE )
    			//	--->	---------------------------------	<---	
    			//	--->	Copy from internal to Destination	<---
    			//	--->	---------------------------------	<---
    			fRC	= tFile.Open( pszTempName, CFile::modeCreate | CFile::modeWrite | CFile::shareExclusive | CFile::typeBinary );
    			if	( fRC )
    				tFile.Write( m_pabClientDownloadFileData, m_dwClientDownloadFileSize );
    				//fRC	= TRUE;
    				//	Temp Files is loaded - Now create 
    				//					  loader  -D xx -R sr dn -E ex cl
    				csCommandLine.Format( "\"%s\" %s \"%s\" %s \"%s\" \"%s\" %s \"%s\" %s",
    					UPD_PARAM_DELETE, m_csClientFullPathName,
    					UPD_PARAM_RENAME, m_csTempPath, m_csClientFullPathName,
    					UPD_PARAM_EXECUTE, m_csClientFullPathName, "\"\"" );
    				//	Create Loader Command Line
    				fRC	= LaunchLoader( (char *)(LPCTSTR)m_csLoaderFilePath, 
    									(char *)(LPCTSTR)csCommandLine,
    									(char *)(LPCTSTR)m_csLoaderBaseDir );
    				if	( fRC == TRUE )
    					//	Launch is successful
    					PostMessageToParent( ExitNow, 0 );
    					PostQuitMessage( 0 );
    					unlink( pszTempName );
    //				}
    #				ifdef	LOG_ENABLE
    //				else
    //				{
    					//dwLastError	= GetLastError();
    					ON_LOG_ERROR( va_string( " ** Launch Loader FAILS\n" ));
    //				}
    #				endif	//ifdef	LOG_ENABLE
    #			ifdef	LOG_ENABLE
    				dwLastError	= GetLastError();
    				ON_LOG_ERROR( va_string( " ** Create Temp File FAILS (%ld)\n", dwLastError ));
    #			endif	//ifdef	LOG_ENABLE
    #		ifdef	LOG_ENABLE
    			dwLastError	= GetLastError();
    			ON_LOG_ERROR( va_string( " ** CreateLoaderFile FAILS (%ld)\n", dwLastError ));
    #		endif	//ifdef	LOG_ENABLE
    #	ifdef	LOG_ENABLE
    		dwLastError	= GetLastError();
    		ON_LOG_ERROR( va_string( " ** Create Temp Name fails (%ld)\n", dwLastError ));
    //	ON_LOG_FUNCTION( va_string( "<-- CUpdateClient::UpdateClient( %s, %p, %ld )\n", pszApplicationPath, pbDownloadBuffer, dwDownloadSize));
    #	endif	//ifdef	LOG_ENABLE
    //	return	fRC;

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice