//---------------------------------------------------------------------
		// Constructor()
        //---------------------------------------------------------------------
        public frmVersion()
        {
            //
            InitializeComponent();

            //
            lblCVds30LoaderGUI.Text = frmDS30Loader.verGUI.ToString();
            lblCVds30Loader.Text = clsds30Loader.strVersion;

            //
            objLatestVersionInfo = new clsLatestVersionInfo();
            CheckLatestVersion();
        }// Constructor()
Exemple #2
0
        //---------------------------------------------------------------------
        // Constructor()
        //---------------------------------------------------------------------
        public frmVersion()
        {
            //
            InitializeComponent();

            //
            lblCVds30LoaderGUI.Text = frmDS30Loader.verGUI.ToString();
            lblCVds30Loader.Text    = clsds30Loader.strVersion;

            //
            objLatestVersionInfo = new clsLatestVersionInfo();
            CheckLatestVersion();
        }// Constructor()
        }// CheckLatestVersion()


        //---------------------------------------------------------------------
		// DownloadLatestPackage()
		// Description:
		//---------------------------------------------------------------------
		static public void DownloadLatestPackage( clsLatestVersionInfo objLatestVersionInfo )
		{	
            System.Diagnostics.Process.Start( objLatestVersionInfo.urlLatestPackage );
        }// DownloadLatestPackage()
        }// TermUpdateButtons()

 
        //---------------------------------------------------------------------
		// UpdateGUI()
		// Description:
		//---------------------------------------------------------------------
		static public bool UpdateGUI( clsLatestVersionInfo objLatestVersionInfo )
		{	
            // Download file
            try {
                WebClient Client = new WebClient ();
                Client.DownloadFile( objLatestVersionInfo.urlds30Loader_dll, "ds30 loader.dll.new");
                Client.DownloadFile( objLatestVersionInfo.urlds30LoaderGUI_exe, "ds30 loader GUI.exe.new");
            } catch {
                MessageBox.Show( "Download failed. Update aborted.", "Update", MessageBoxButtons.OK, MessageBoxIcon.Exclamation );
                return false;
            }

            // Create bat-file
            TextWriter tw = new StreamWriter("update.bat");
            tw.WriteLine( "@echo off" );
            tw.WriteLine( "echo Wait for the application to close. Then press any key to continue update." );
            tw.WriteLine( "echo Press CTRL+C to abort." );
            tw.WriteLine( "pause" );
            tw.WriteLine( "del \"ds30 loader.dll\"" );
            tw.WriteLine( "del \"ds30 loader GUI.exe\"" );
            tw.WriteLine( "ren \"ds30 loader.dll.new\" \"ds30 loader.dll\"" );
            tw.WriteLine( "ren \"ds30 loader GUI.exe.new\" \"ds30 loader GUI.exe\"" );
            tw.WriteLine( "start \"\" \"ds30 loader gui.exe\"" );
            tw.Close();

            // Start bat
            try {
                System.Diagnostics.ProcessStartInfo a = new System.Diagnostics.ProcessStartInfo();
                a.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
                a.FileName = "update.bat";
                a.WorkingDirectory = Path.GetDirectoryName( Application.ExecutablePath );
                System.Diagnostics.Process objUpdateProcess = System.Diagnostics.Process.Start( a );                    
            } catch {
                MessageBox.Show( "Update failed.", "Update", MessageBoxButtons.OK, MessageBoxIcon.Exclamation );
                return false;
            }

            // Close application
            Application.Exit();

            return true;
        }// UpdateGUI()
        }//Abort()
	
				
        //---------------------------------------------------------------------
		// CheckLatestVersion()
		//---------------------------------------------------------------------
		public void CheckLatestVersion()		
        {
            //
            clsLatestVersionInfo objLatestVersionInfo = new clsLatestVersionInfo();
            if ( objLatestVersionInfo.CheckLatestVersion() == false ) return;

            //
            string strMsgBoxTitle = "Check for latest version";


            //-----------------------------------------------------------------
            // New version?
            //-----------------------------------------------------------------   
            if ( new Version(clsds30Loader.strVersion) < objLatestVersionInfo.lvds30Loader || verGUI < objLatestVersionInfo.lvds30LoaderGUI ) {  
                // Message
                string strMessage = string.Empty;
                if ( objLatestVersionInfo.latestVersionInfo != string.Empty ) {
                    strMessage = "Info: " + objLatestVersionInfo.latestVersionInfo + Environment.NewLine;
                }


                //-------------------------------------------------------------
                // Update or download is not allowed
                //-------------------------------------------------------------
                if ( objLatestVersionInfo.allowUpdate == false && objLatestVersionInfo.allowDownload == false ) {
                    string strQuestion = 
                        "A new version is available" + Environment.NewLine + 
                        strMessage + Environment.NewLine +
                        "Do you want to visit the homepage?"
                    ;  
                    DialogResult dgrDownload = MessageBox.Show( strQuestion, strMsgBoxTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question );
                    if ( dgrDownload == DialogResult.Yes ) {  
                        frmDS30Loader.VisitHomepage();
                    }   
             

                //-------------------------------------------------------------
                // Download allowed
                //-------------------------------------------------------------
                } else if ( objLatestVersionInfo.allowDownload == true ) {
                    string strQuestion = 
                        "A new version is available" + Environment.NewLine + 
                        strMessage + Environment.NewLine +
                        "Do you want to download the new package?"
                        
                    ;  
                    DialogResult dgrDownload = MessageBox.Show( strQuestion, strMsgBoxTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question );               
                    if ( dgrDownload == DialogResult.Yes ) {  
                         DownloadLatestPackage( objLatestVersionInfo ); 
                    } 
                

                //-------------------------------------------------------------
                // Auto update allowed
                //-------------------------------------------------------------
                } else if ( objLatestVersionInfo.allowUpdate == true ) {
                    string strQuestion = 
                        "A new version is available" + Environment.NewLine + 
                        strMessage + Environment.NewLine +
                        "Do you want to update to the new version?"
                    ;  
                    DialogResult dgrAutoUpdate = MessageBox.Show( strQuestion, strMsgBoxTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2 );
                    
                    if ( dgrAutoUpdate == DialogResult.Yes ) { 
                        UpdateGUI( objLatestVersionInfo );
                    }  
                }
            }
        }// CheckLatestVersion()