public void Execute(IJobExecutionContext context)
 {
     using (IGameCleaner gameCleaner = new GameCleaner())
     {
         gameCleaner.Clean();
     }
 }
Esempio n. 2
0
        private async void Wind_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                if (Settings.ExperimentalFunctions == null)
                {
                    MessageBoxResult result = MessageBox.Show(Res.ExperimentalFeaturesText.Replace(@"\n", "\n"),
                                                              Res.ExperimentalFeatures, MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No);

                    if (result == MessageBoxResult.Yes)
                    {
                        Settings.ExperimentalFunctions = true;
                    }
                    else
                    {
                        Settings.ExperimentalFunctions = false;
                    }
                    Settings.Save();
                }
            }
            catch (Exception er) { Logger.Error("ExpFunc", er); }

            Mods.Init();

            if (ExperimentalFunctions.HasExperimentalFunctions())
            {
                if (!Mods.ExistMod("SkyMPCore"))
                {
                    MessageBox.Show("All files will be reinstalled", "Attention",
                                    MessageBoxButton.OK, MessageBoxImage.Exclamation, MessageBoxResult.OK);
                    GameCleaner.Clear();
                }

                await CheckGameNew();
            }
            else
            {
                await CheckGameOld();
            }

            SetBackgroundServerList();
            FillServerList();
            Authorization_SignIn();
        }
    void Awake()
    {
        // ===>> Singleton

        //Check if instance already exists
        if (p_instance == null)
        {
            //if not, set instance to this
            p_instance = this;
        }
        //If instance already exists and it's not this:
        else if (p_instance != this)
        {
            //Then destroy this. This enforces our singleton pattern, meaning there can only ever be one instance of a GameManager.
            Destroy(gameObject);
        }
        //Sets this to not be destroyed when reloading scene
        // DontDestroyOnLoad(gameObject);   par nécessaire ici car déja fait par script __DDOL sur l'objet _EGO_app qui recueille tous les mgr
    }
        //TODO: Переработать
        private bool HandleCmdArgs()
        {
            string[] args = Environment.GetCommandLineArgs();
            if (args.Length > 1)
            {
                bool eUpdate = false;
                int  trying  = 0;
                try
                {
                    switch (args[1])
                    {
                    case EndUpdate:
                        eUpdate = true;
                        Thread.Sleep(500);
                        try
                        {
                            if (File.Exists($"{args[2]}.update.exe"))
                            {
                                File.SetAttributes($"{args[2]}.update.exe", FileAttributes.Normal);
                                File.Delete($"{args[2]}.update.exe");
                            }
                        }
                        catch (IOException io)
                        //фикс ошибки занятого файла, он должен освободится через какое то время
                        {
                            trying++;
                            if (trying < 5)
                            {
                                goto case EndUpdate;
                            }
                            else
                            {
                                throw new TimeoutException("Timeout \"EndUpdate\"", io);
                            }
                        }
                        break;

                    case BeginUpdate:
                        Thread.Sleep(500);
                        try
                        {
                            File.Copy(EnvParams.PathToFile, $"{args[2]}.exe", true);
                            File.SetAttributes($"{args[2]}.exe", FileAttributes.Normal);
                        }
                        catch (IOException io)
                        //фикс ошибки занятого файла, он должен освободится через какое то время
                        {
                            trying++;
                            if (trying < 5)
                            {
                                goto case BeginUpdate;
                            }
                            else
                            {
                                throw new TimeoutException("Timeout \"BeginUpdate\"", io);
                            }
                        }
                        Process.Start($"{args[2]}.exe", $"{EndUpdate} {args[2]}");
                        goto default;

                    case "recovery":
                        RecoveryWindow rw = new RecoveryWindow();
                        rw.ShowDialog();
                        break;

                    case "repair":
                        Settings.Reset();
                        break;

                    case "repair-client":
                        try
                        {
                            ModVersion.Reset();
                        }
                        catch (Exception e) { MessageBox.Show($"{e.Message}", $"{Res.Error}"); }
                        goto default;

                    case "clear-client":
                        try
                        {
                            Mods.Init();
                            Mods.DisableAll(true).Wait();
                            GameCleaner.Clear();
                        }
                        catch (Exception e) { MessageBox.Show($"{e.Message}", $"{Res.Error}"); }
                        goto default;

                    case "clear-full-client":
                        try
                        {
                            Mods.Init();
                            Mods.DisableAll(true).Wait();
                            GameCleaner.Clear(true);
                        }
                        catch (Exception e) { MessageBox.Show($"{e.Message}", $"{Res.Error}"); }
                        goto default;

                    default:
                        ExitApp();
                        return(false);
                    }
                }
                catch (UnauthorizedAccessException e)
                {
                    if (!eUpdate)
                    {
                        MessageBox.Show($"{Res.ErrorEndSelfUpdate}\n{e.Message}", $"{Res.Error}");
                        return(false);
                    }
                }
                catch (Exception e)
                {
                    Logger.Error("HandleCmdArgs", e);
                    return(false);
                }
            }
            return(true);
        }