예제 #1
0
 public void GetTheTotalDataExecute(object sender)
 {
     DisplayRootRegistry.ShowPresentation(new TheTotalDataViewModel());
     if (sender is Window)
     {
         (sender as Window).Close();
     }
 }
예제 #2
0
 public void BackExecute(object sender)
 {
     DisplayRootRegistry.ShowPresentation(new MainViewModel());
     if (sender is Window)
     {
         (sender as Window).Close();
     }
 }
예제 #3
0
 public void GetDataByCountryExecute(object sender)
 {
     DisplayRootRegistry.ShowPresentation(TheByCountry);
     OpenByCountryEvent?.Invoke(Country);
     if (sender is Window)
     {
         (sender as Window).Close();
     }
 }
예제 #4
0
        protected override void OnStartup(StartupEventArgs e)
        {
            try
            {
                var args = Environment.GetCommandLineArgs();
                Constant.PidLauncher = int.Parse(args[1]);
            }
            catch (Exception)
            {
                MessageBox.Show(Constant.ErrorOnStartUpdater);
                Shutdown();
                return;
            }

            var proc = new ProcessHelper();

            if (!File.Exists(CommonConstant.FileSettingsLauncher))
            {
                MessageBox.Show(CommonConstant.NotFoundFileSettings);
                Shutdown();
                return;
            }

            var token = proc.GetPublicKeyTokenFromAssembly(Assembly.GetCallingAssembly());

            if (string.IsNullOrEmpty(token))
            {
                MessageBox.Show(Constant.CrashUpdater);
                Shutdown();
                return;
            }

            var mut = new Mutex(true, token, out _instance);

            if (!_instance)
            {
                MessageBox.Show(Constant.AlreadyStartUpdater);
                Shutdown();
            }


            base.OnStartup(e);

            _mainWindowViewModel = new DataMainViewModel();

            displayRootRegistry.ShowPresentation(_mainWindowViewModel, false);
        }
예제 #5
0
        private async void RequestData(DisplayRootRegistry displayRootRegistry, DataUpdaterViewModel dataUpdater)
        {
            var net          = new Net();
            var dataLauncher = new LauncherInfoSerializer();
            var proc         = new ProcessHelper();

            var settingHelp = new SettingHelper();
            LauncherSettingLastSerializer lastSettingLauncher = null;


            try
            {
                lastSettingLauncher  = settingHelp.Read <LauncherSettingLastSerializer>(CommonConstant.KeySettings, CommonConstant.FileSettingsLauncher);
                dataLauncher.version = lastSettingLauncher.Info.Version;
            }
            catch (Exception ex)
            {
                if (ex is DirectoryNotFoundException || ex is FileNotFoundException)
                {
                    MessageBox.Show(CommonConstant.NotFoundFileSettings);
                }
                else
                {
                    MessageBox.Show(CommonConstant.ErrorReadOrWriteSettings);
                }
                proc.CloseProcess(Constant.PidLauncher);
                Application.Current.Shutdown();
                return;
            }



            var programLauncher = await net.RequestAsync(Constant.UrlUpdaterLauncherCheckVersion, Net.Post, dataLauncher);

            if (programLauncher.detail != null)
            {
                MessageBox.Show(ErrorParser.Parse(programLauncher.detail));
                return;
            }

            if (!programLauncher.is_updated)
            {
                var message = MessageBox.Show(Constant.DescriptionMessBoxUpdate, "Обновление", MessageBoxButton.OKCancel);
                if (message == MessageBoxResult.Cancel)
                {
                    return;
                }


                _dataMainViewModel.TimerUpdater.Stop();

                displayRootRegistry.ShowPresentation(dataUpdater);

                programLauncher = await net.RequestAsync <LauncherInfoSerializer>(
                    Constant.UrlUpdaterLauncherInfo,
                    Net.Post,
                    null,
                    null,
                    null,
                    (s, e) =>
                {
                    dataUpdater.ProgressValue = (e.BytesReceived * 100 / e.TotalBytesToReceive);
                });

                if (programLauncher.detail != null)
                {
                    displayRootRegistry.HidePresentation(dataUpdater);
                    MessageBox.Show(ErrorParser.Parse(programLauncher.detail));
                    return;
                }

                var cryptBytesLauncher = Convert.FromBase64String(programLauncher.data);


                if (Hash.Sha256Bytes(cryptBytesLauncher) == programLauncher.hash)
                {
                    var crypt = new Crypt(Encoding.UTF8.GetBytes(CommonConstant.Key));
                    crypt.RemoveAndSetIv(ref cryptBytesLauncher);

                    var bytesLauncher = crypt.Decode(cryptBytesLauncher);


                    proc.CloseProcess(Constant.PidLauncher);


                    var zip = new ArchiveHelper();

                    var bytesLauncherSetting = zip.Extract(bytesLauncher, programLauncher.hash, Path.GetTempPath());



                    settingHelp.RemoveProgram(@".\", false);

                    settingHelp.RemoveDumps <SettingLastSerializer, IRemoveData>(lastSettingLauncher.Info);



                    settingHelp.CopyFilesProgram(Path.GetTempPath() + programLauncher.hash, ".\\");

                    var getLauncherSetting = settingHelp.Read <LauncherSettingSerializer>(bytesLauncherSetting, CommonConstant.KeySettings);



                    settingHelp.RewriteLastToNewSettingsLauncher(getLauncherSetting, lastSettingLauncher, CommonConstant.KeySettings, CommonConstant.FileSettingsLauncher);

                    displayRootRegistry.HidePresentation(dataUpdater);


                    try
                    {
                        proc.StartProcess(getLauncherSetting.Info.StartApp, new string[1] {
                            programLauncher.hash
                        });
                    }
                    catch (System.ComponentModel.Win32Exception)
                    {
                        MessageBox.Show(Constant.NotFoundStartAppLauncher);
                    }

                    Application.Current.Shutdown();
                    return;
                }
                else
                {
                    MessageBox.Show(Constant.NoHashEqual);
                }


                displayRootRegistry.HidePresentation(dataUpdater);

                _dataMainViewModel.TimerUpdater.Start();
            }
        }
예제 #6
0
 public override void CloseExecute(object sender)
 {
     DisplayRootRegistry.ShowPresentation(new MainViewModel());
     base.CloseExecute(sender);
 }
예제 #7
0
        private void RunProgramLogic()
        {
            mainVM = new MainViewModel();

            DisplayRootRegistry.ShowPresentation(mainVM);
        }
 protected override void OnStartup(StartupEventArgs e)
 {
     base.OnStartup(e);
     mainVM = new MainViewModel(context, displayRootRegistry);
     displayRootRegistry.ShowPresentation(mainVM);
 }