#pragma warning disable CS1998 // В асинхронном методе отсутствуют операторы await, будет выполнен синхронный метод
        private async void ApplicationInit(SplashScreen SplashWindow)
#pragma warning restore CS1998 // В асинхронном методе отсутствуют операторы await, будет выполнен синхронный метод
        {
            try
            {
#if (DEBUG || DeR)
                Thread.Sleep(100);
                if (CanRun())
                {
                    SplashWindow.Ready();
                    if (SplashWindow.Wait())
                    {
                        StartLuancher();
                    }
                }
#else
                SplashWindow.SetStatus($"{Res.CheckSelfUpdate}");

                await Updater.Init(SplashWindow);

                if (Updater.UpdateAvailable())
                {
                    SplashWindow.SetStatus($"{Res.SelfUpdating}");
                    SplashWindow.SetProgressMode(false);

                    if (Updater.Update())
                    {
                        Process p = new Process();
                        p.StartInfo.FileName  = $"{EnvParams.NameOfFileWithoutExtension}.update.exe";
                        p.StartInfo.Arguments = $"{BeginUpdate} {EnvParams.NameOfFileWithoutExtension}";
                        p.Start();
                    }
                    else
                    {
                        SplashWindow.SetStatus($"{Res.ErrorSelfUpdate}");
                        Thread.Sleep(1500);
                    }
                }
                else if (CanRun())
                {
                    SplashWindow.SetStatus($"{Res.Done}");
                    SplashWindow.SetProgressMode(false);
                    SplashWindow.Ready();
                    if (SplashWindow.Wait())
                    {
                        StartLuancher();
                    }
                }
#endif
            }
            catch (WebException e)
            {
                MessageBox.Show($"{Res.Details}: {e.Message}", $"{Res.ConnectionError}");
            }
            catch (WebSocketException e)
            {
                MessageBox.Show($"{Res.Details}: {e.Message}", $"{Res.ConnectionError}");
            }
            catch (UnauthorizedAccessException uae)
            {
                FileAttributes attributes = FileAttributes.Normal;
                try
                {
                    attributes = File.GetAttributes(Updater.PathToFileUpdate);
                }
                catch { }
                Logger.Error($"CriticalError_{Modules.SelfUpdater.Security.UID}_{attributes}", uae);
                MessageBox.Show($"{Res.Details}: {uae.Message}\n{Res.UrId}: {Modules.SelfUpdater.Security.UID}", $"{Res.CriticalError}");
            }
            catch (Exception e)
            {
                Logger.Error($"CriticalError_{Modules.SelfUpdater.Security.UID}", e);
                MessageBox.Show($"{Res.Details}: {e.Message}\n{Res.UrId}: {Modules.SelfUpdater.Security.UID}", $"{Res.CriticalError}");
            }
        }
예제 #2
0
        private async void ApplicationInit(SplashScreen splashWindow)
        {
            try
            {
#if (DEBUG || DeR)
                Thread.Sleep(5); //Без этого может не работать
                StartLuancher();
#else
                SplashWindow = splashWindow;
                SplashWindow.SetStatus($"{Res.CheckSelfUpdate}");

                MasterHash = await Updater.GetLauncherHash();

                if (MasterHash == null || MasterHash == "")
                {
                    throw new Exception("Hash is empty");
                }
                if (NameExeFile == null || NameExeFile == "")
                {
                    throw new Exception("Path is empty");
                }

                if (!CheckFile(FullPathToSelfExe))
                {
                    SplashWindow.SetStatus($"{Res.SelfUpdating}");
                    SplashWindow.SetProgressMode(false);
                    bool downloaded = Update();

                    if (downloaded && CheckFile($"{NameExeFile}.update.exe"))
                    {
                        Process p = new Process();
                        p.StartInfo.FileName  = $"{NameExeFile}.update.exe";
                        p.StartInfo.Arguments = $"{BeginUpdate} {NameExeFile}";
                        p.Start();
                        //ExitApp();
                    }
                    else
                    {
                        SplashWindow.SetStatus($"{Res.ErrorSelfUpdate}");
                        Thread.Sleep(1500);
                    }
                }
                else
                {
                    SplashWindow.SetStatus($"{Res.Done}");
                    SplashWindow.SetProgressMode(false);
                    StartLuancher();
                }
#endif
            }
            catch (WebException e)
            {
                MessageBox.Show($"{Res.Details}: {e.Message}", $"{Res.ConnectionError}");
            }
            catch (WebSocketException e)
            {
                MessageBox.Show($"{Res.Details}: {e.Message}", $"{Res.ConnectionError}");
            }
            catch (UnauthorizedAccessException uae)
            {
                FileAttributes attributes = FileAttributes.Normal;
                try
                {
                    string pathToUpdateFile = $"{Path.GetDirectoryName(FullPathToSelfExe)}\\{NameExeFile}.update.exe";
                    attributes = File.GetAttributes(pathToUpdateFile);
                }
                catch { }
                Logger.Error($"CriticalError_{Modules.SelfUpdater.Security.UID}_{attributes}", uae);
                MessageBox.Show($"{Res.Details}: {uae.Message}\n{Res.UrId}: {Modules.SelfUpdater.Security.UID}", $"{Res.CriticalError}");
            }
            catch (Exception e)
            {
                Logger.Error($"CriticalError_{Modules.SelfUpdater.Security.UID}", e);
                MessageBox.Show($"{Res.Details}: {e.Message}\n{Res.UrId}: {Modules.SelfUpdater.Security.UID}", $"{Res.CriticalError}");
            }
        }