2016-09-16 22:14:49 +03:00
using System ;
using System.Collections.Generic ;
using System.IO ;
using System.Linq ;
using System.Text ;
using System.Threading ;
using System.Windows.Forms ;
using VisualPascalABCPlugins ;
using System.Net ;
using System.Reflection ;
2018-02-01 22:33:13 +03:00
using Microsoft.Win32 ;
2016-09-16 22:14:49 +03:00
namespace VisualPascalABC
{
class WorkbenchUpdateService : IWorkbenchUpdateService
{
public WorkbenchUpdateService ( )
{
}
2018-02-01 22:33:13 +03:00
public bool IsDotnet71Installed ( )
{
if ( Environment . OSVersion . Version . Major < 6 )
return true ;
try
{
2018-02-01 22:41:48 +03:00
using ( var key = Registry . LocalMachine . OpenSubKey ( @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full" ) )
2018-02-01 22:33:13 +03:00
{
2019-09-14 19:19:29 +03:00
return key ! = null & & ( ( key . GetValue ( "Version" ) as string ) . StartsWith ( "4.7" ) | | ( key . GetValue ( "Version" ) as string ) . StartsWith ( "4.8" ) ) ;
2018-02-01 22:33:13 +03:00
}
}
catch ( Exception ex )
{
return true ;
}
}
2016-09-16 22:14:49 +03:00
public void CheckForUpdates ( )
{
int status = 1 ; //1 - up to date, 0 - not up to date, -1 error
2017-04-07 22:11:18 +03:00
string newVersion = null ;
string curVersion = null ;
2018-02-01 22:33:13 +03:00
if ( ! IsDotnet71Installed ( ) )
{
if ( MessageBox . Show ( PascalABCCompiler . StringResources . Get ( "VP_MF_DOTNET_AVAILABLE" ) ,
PascalABCCompiler . StringResources . Get ( "VP_MF_DOTNET_UPDATE_CHECK" ) ,
MessageBoxButtons . YesNo ) = = DialogResult . Yes )
{
WorkbenchServiceFactory . OperationsService . AddTabWithUrl ( ".NET Framework" , PascalABCCompiler . StringResources . Get ( "VP_MF_FRAMEWORK_DOWNLOAD_PAGE" ) ) ;
}
}
2016-09-16 22:14:49 +03:00
try
{
WebClient client = new WebClient ( ) ;
2023-02-03 10:49:53 +03:00
newVersion = client . DownloadString ( "https://pascalabc.net/downloads/pabcversion.txt" ) . Trim ( ) ;
2017-04-07 22:11:18 +03:00
curVersion = Assembly . GetExecutingAssembly ( ) . GetName ( ) . Version . ToString ( ) ;
2016-09-16 22:14:49 +03:00
if ( ( new Version ( curVersion ) ) . CompareTo ( new Version ( newVersion ) ) = = - 1 )
status = 0 ;
2019-04-23 22:37:50 +03:00
2016-09-16 22:14:49 +03:00
}
catch
{
status = - 1 ;
}
switch ( status )
{
case 1 :
2017-06-14 08:17:49 +03:00
MessageBox . Show ( PascalABCCompiler . StringResources . Get ( "VP_MF_VERSION_IS_UP_TO_DATE" ) , PascalABCCompiler . StringResources . Get ( "VP_MF_UPDATE_CHECK" ) , MessageBoxButtons . OK ) ;
2016-09-16 22:14:49 +03:00
break ;
case 0 :
2017-04-07 22:11:18 +03:00
if ( MessageBox . Show ( PascalABCCompiler . StringResources . Get ( "VP_MF_UPDATE_AVAILABLE" ) + Environment . NewLine +
string . Format ( PascalABCCompiler . StringResources . Get ( "VP_MF_UPDATE_AVAILABLE_CURRENT_VESION{0}" ) , curVersion ) + Environment . NewLine +
string . Format ( PascalABCCompiler . StringResources . Get ( "VP_MF_UPDATE_AVAILABLE_NEW_VESION{0}" ) , newVersion ) ,
PascalABCCompiler . StringResources . Get ( "VP_MF_UPDATE_CHECK" ) ,
MessageBoxButtons . YesNo ) = = DialogResult . Yes )
2016-09-16 22:14:49 +03:00
{
2019-04-24 21:00:25 +03:00
//System.Diagnostics.Process.Start(PascalABCCompiler.StringResources.Get("VP_MF_PABC_DOWNLOAD_PAGE"));
// SSM 24/04/19 - вернул назад, т.к. обновление закрывало оболочку из-за некорректно написанного асинхронного вызова. Обойдёмся без асинхронного вызова. Слишком много пользователей пострадало.
WorkbenchServiceFactory . OperationsService . AddTabWithUrl ( "PascalABC.NET" , PascalABCCompiler . StringResources . Get ( "VP_MF_PABC_DOWNLOAD_PAGE" ) ) ;
2016-09-16 22:14:49 +03:00
}
break ;
case - 1 :
MessageBox . Show ( PascalABCCompiler . StringResources . Get ( "VP_MF_UPDATE_CHECK_ERROR" ) , PascalABCCompiler . StringResources . Get ( "VP_MF_UPDATE_CHECK" ) , MessageBoxButtons . OK ) ;
break ;
}
}
}
}