Пример #1
0
        public ShellViewModel(IKernel kernel, MainManager mainManager, MetroDialogService metroDialogService, FlyoutSettingsViewModel flyoutSettings)
        {
            _kernel = kernel;
            var checkedForUpdate = false;

            MainManager        = mainManager;
            MetroDialogService = metroDialogService;

            DisplayName     = "Artemis";
            ActiveIcon      = "../Resources/logo-disabled.ico";
            GeneralSettings = SettingsProvider.Load <GeneralSettings>();
            Flyouts         = new BindableCollection <FlyoutBaseViewModel>
            {
                flyoutSettings
            };

            MainManager.EnabledChanged += (sender, args) =>
            {
                Enabled = args.Enabled;
                // Check for updates once if auto update is enabled and the window is shown
                if (GeneralSettings.AutoUpdate && !checkedForUpdate && CanHideWindow)
                {
                    checkedForUpdate = true;
                    Updater.CheckForUpdate(MetroDialogService);
                }
            };


            // This gets updated automatically but during startup lets quickly preset it
            Enabled = GeneralSettings.Suspended;
        }
Пример #2
0
        /// <summary>
        ///     Checks to see if a new version is available on GitHub asks the user to see changes and download
        /// </summary>
        /// <param name="dialogService">The dialog service to use for progress and result dialogs</param>
        /// <returns></returns>
        public static async Task <bool?> CheckForUpdate(MetroDialogService dialogService)
        {
            // Check GitHub for a new version
            var jsonClient = new WebClient();

            // GitHub trips if we don't add a user agent
            jsonClient.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");

            // Random number to get around cache issues
            var    rand = new Random(DateTime.Now.Millisecond);
            string json;

            try
            {
                json = await jsonClient.DownloadStringTaskAsync("https://api.github.com/repos/SpoinkyNL/Artemis/releases/latest?random=" + rand.Next());
            }
            catch (Exception e)
            {
                Logger.Warn(e, "Update check failed.");
                return(null);
            }

            var release        = JObject.Parse(json);
            var releaseVersion = Version.Parse(release["tag_name"].Value <string>());
            var currentVersion = Assembly.GetExecutingAssembly().GetName().Version;

            if (releaseVersion > currentVersion)
            {
                await Execute.OnUIThreadAsync(async() => await ShowChanges(dialogService, release));

                return(true);
            }

            return(false);
        }
Пример #3
0
 public ProfileEditorModel(WindowService windowService, MetroDialogService dialogService, DeviceManager deviceManager, LuaManager luaManager)
 {
     _windowService = windowService;
     _dialogService = dialogService;
     _deviceManager = deviceManager;
     _luaManager    = luaManager;
 }
Пример #4
0
        public static async Task <Action> CheckForUpdate(MetroDialogService dialogService)
        {
            Logger.Info("Checking for updates - Current version: 1.1.3");
            if (!General.Default.CheckForUpdates)
            {
                return(null);
            }

            var newRelease = IsUpdateAvailable();

            if (newRelease == null)
            {
                Logger.Info("No update found.");
                return(null);
            }

            Logger.Info("Found new version - {0}.", newRelease["tag_name"].Value <string>());
            var viewUpdate = await
                             dialogService.ShowQuestionMessageBox("ApplyProperties available",
                                                                  $"A new version of Artemis is available, version {newRelease["tag_name"].Value<string>()}.\n" +
                                                                  "Do you wish to view the update on GitHub now?\n\n" +
                                                                  "Note: You can disable update notifications in the settings menu");

            if (viewUpdate.Value)
            {
                Process.Start(new ProcessStartInfo(newRelease["html_url"].Value <string>()));
            }

            return(null);
        }
Пример #5
0
        /// <summary>
        ///     Checks to see if the program has updated and shows a dialog if so.
        /// </summary>
        /// <param name="dialogService">The dialog service to use for progress and result dialogs</param>
        /// <returns></returns>
        public static async void CheckChangelog(MetroDialogService dialogService)
        {
            var settings       = SettingsProvider.Load <GeneralSettings>();
            var currentVersion = Assembly.GetExecutingAssembly().GetName().Version;

            if ((settings.LastRanVersion != null) && (currentVersion > settings.LastRanVersion))
            {
                Logger.Info("Updated from {0} to {1}, showing changelog.", settings.LastRanVersion, currentVersion);

                // Ask the user whether he/she wants to see what's new
                var showChanges = await dialogService.
                                  ShowQuestionMessageBox("New version installed",
                                                         $"Artemis has recently updated from version {settings.LastRanVersion} to {currentVersion}. \n" +
                                                         "Would you like to see what's new?");

                // If user wants to see changelog, show it to them
                if ((showChanges != null) && showChanges.Value)
                {
                    await ShowChanges(dialogService, currentVersion);
                }
            }

            settings.LastRanVersion = currentVersion;
            settings.Save();
        }
Пример #6
0
        public Dota2Model(DeviceManager deviceManager, LuaManager luaManager, MetroDialogService dialogService,
                          GameStateWebServer gameStateWebServer) : base(deviceManager, luaManager)
        {
            _gameStateWebServer = gameStateWebServer;
            _dialogService      = dialogService;

            Settings  = SettingsProvider.Load <Dota2Settings>();
            DataModel = new Dota2DataModel();
            ProcessNames.Add("dota2");

            FindGameDir();
            PlaceConfigFile();
        }
Пример #7
0
        public CounterStrikeModel(DeviceManager deviceManager, LuaManager luaManager, MetroDialogService dialogService,
                                  GameStateWebServer gameStateWebServer) : base(deviceManager, luaManager)
        {
            _gameStateWebServer = gameStateWebServer;
            _dialogService      = dialogService;

            Settings  = SettingsProvider.Load <CounterStrikeSettings>();
            DataModel = new CounterStrikeDataModel();
            ProcessNames.Add("csgo");

            FindGameDir();
            PlaceConfigFile();
        }
Пример #8
0
        public EurotruckSimulator2Model(DeviceManager deviceManager, LuaManager luaManager,
                                        MetroDialogService dialogService) : base(deviceManager, luaManager)
        {
            _dialogService = dialogService;

            Settings  = SettingsProvider.Load <EurotruckSimulator2Settings>();
            DataModel = new EurotruckSimulator2DataModel();
            ProcessNames.Add("eurotrucks2");
            ProcessNames.Add("amtrucks");

            FindEts2GameDir();
            FindAtsGameDir();
        }
Пример #9
0
        public OverwatchModel(DeviceManager deviceManager, LuaManager luaManager, PipeServer pipeServer,
                              MetroDialogService dialogService, DebugViewModel debugViewModel) : base(deviceManager, luaManager)
        {
            _pipeServer     = pipeServer;
            _dialogService  = dialogService;
            _debugViewModel = debugViewModel;

            Settings  = SettingsProvider.Load <OverwatchSettings>();
            DataModel = new OverwatchDataModel();
            ProcessNames.Add("Overwatch");

            LoadOverwatchCharacters();
            FindOverwatch();
        }
Пример #10
0
        public UnrealTournamentModel(DeviceManager deviceManager, LuaManager luaManager, PipeServer pipeServer,
                                     MetroDialogService dialogService) : base(deviceManager, luaManager)
        {
            _pipeServer    = pipeServer;
            _dialogService = dialogService;

            Settings  = SettingsProvider.Load <UnrealTournamentSettings>();
            DataModel = new UnrealTournamentDataModel();
            ProcessNames.Add("UE4-Win64-Shipping");

            _killTimer          = new Timer(3500);
            _killTimer.Elapsed += KillTimerOnElapsed;

            FindGame();
        }
Пример #11
0
        public ShellViewModel(IKernel kernel, IEventAggregator events, BaseViewModel[] viewModels,
                              DeviceManager deviceManager, MetroDialogService dialogService)
        {
            _viewModels    = viewModels;
            _deviceManager = deviceManager;
            _dialogService = dialogService;

            events.Subscribe(this);

            // Setup UI
            DisplayName = "Artemis";
            Flyouts     = new BindableCollection <FlyoutBaseViewModel>
            {
                kernel.Get <FlyoutSettingsViewModel>()
            };
        }
Пример #12
0
        public WoWModel(DeviceManager deviceManager, LuaManager luaManager, WowPacketScanner packetScanner, MetroDialogService dialogService) : base(deviceManager, luaManager)
        {
            Settings  = SettingsProvider.Load <WoWSettings>();
            DataModel = new WoWDataModel();
            ProcessNames.Add("Wow-64");

            _packetScanner = packetScanner;
            _dialogService = dialogService;
            _packetScanner.RaiseDataReceived += (sender, args) => HandleGameData(args.Command, args.Data);

            FindWoW();

            // I simply cannot be sure wether this addon will bring people's accounts in trouble so
            // lets remove it whenever Artemis isn't running the WoW module.
            // (This also means the addon isnt left behind should the user uninstall Artemis.)
            RemoveAddon();
        }
Пример #13
0
        public ProfileEditorViewModel(ProfileEditorModel profileEditorModel, DeviceManager deviceManager,
                                      LoopManager loopManager, ModuleModel moduleModel, MetroDialogService dialogService)
        {
            _deviceManager = deviceManager;
            _loopManager   = loopManager;
            _moduleModel   = moduleModel;
            _dialogService = dialogService;

            ProfileNames       = new ObservableCollection <string>();
            Layers             = new ObservableCollection <LayerModel>();
            ProfileEditorModel = profileEditorModel;
            ShowAll            = true;

            PropertyChanged += EditorStateHandler;
            _deviceManager.OnKeyboardChanged += DeviceManagerOnOnKeyboardChanged;
            _moduleModel.ProfileChanged      += ModuleModelOnProfileChanged;
            LoadProfiles();
        }
Пример #14
0
        public SystemTrayViewModel(IWindowManager windowManager, IEventAggregator events, MetroDialogService dialogService, ShellViewModel shellViewModel,
                                   MainManager mainManager)
        {
            _windowManager    = windowManager;
            _shellViewModel   = shellViewModel;
            _checkedForUpdate = false;

            DialogService = dialogService;
            MainManager   = mainManager;

            events.Subscribe(this);
            MainManager.EnableProgram();

            if (General.Default.ShowOnStartup)
            {
                ShowWindow();
            }
        }
Пример #15
0
        public SystemTrayViewModel(IWindowManager windowManager, MetroDialogService dialogService,
                                   ShellViewModel shellViewModel, MainManager mainManager)
        {
            _windowManager  = windowManager;
            _shellViewModel = shellViewModel;

            DialogService = dialogService;
            MainManager   = mainManager;

            MainManager.EnableProgram();
            MainManager.OnEnabledChangedEvent += MainManagerOnOnEnabledChangedEvent;

            var generalSettings = SettingsProvider.Load <GeneralSettings>();

            Enabled = !generalSettings.Suspended;
            if (generalSettings.ShowOnStartup)
            {
                ShowWindow();
            }
        }
Пример #16
0
        public ShellViewModel(IKernel kernel, MainManager mainManager, MetroDialogService metroDialogService,
                              FlyoutSettingsViewModel flyoutSettings)
        {
            _kernel = kernel;

            MainManager        = mainManager;
            MetroDialogService = metroDialogService;

            DisplayName     = "Artemis";
            GeneralSettings = SettingsProvider.Load <GeneralSettings>();
            Flyouts         = new BindableCollection <FlyoutBaseViewModel>
            {
                flyoutSettings
            };

            MainManager.EnabledChanged += (sender, args) => Enabled = args.Enabled;

            // This gets updated automatically but during startup lets quickly preset it
            Enabled = GeneralSettings.Suspended;
        }
Пример #17
0
        public ProfileEditorViewModel(IEventAggregator events, MainManager mainManager, EffectModel gameModel,
                                      ProfileViewModel profileViewModel, MetroDialogService dialogService, string lastProfile,
                                      ILayerEditorVmFactory layerEditorVmFactory)
        {
            _mainManager          = mainManager;
            _gameModel            = gameModel;
            _layerEditorVmFactory = layerEditorVmFactory;

            Profiles         = new BindableCollection <ProfileModel>();
            Layers           = new BindableCollection <LayerModel>();
            ProfileViewModel = profileViewModel;
            DialogService    = dialogService;
            LastProfile      = lastProfile;

            events.Subscribe(this);

            ProfileViewModel.PropertyChanged += PropertyChangeHandler;
            PropertyChanged += PropertyChangeHandler;
            LoadProfiles();
        }
Пример #18
0
        public FlyoutSettingsViewModel(MainManager mainManager, ILogger logger, WindowService windowService, MetroDialogService metroDialogService)
        {
            _logger             = logger;
            _windowService      = windowService;
            _metroDialogService = metroDialogService;

            MainManager     = mainManager;
            Header          = "Settings";
            Position        = Position.Right;
            GeneralSettings = SettingsProvider.Load <GeneralSettings>();

            LogLevels = new BindableCollection <string>();
            LogLevels.AddRange(LogLevel.AllLoggingLevels.Select(l => l.Name));

            ActiveWindowDetections = new BindableCollection <ActiveWindowDetectionType>(Enum.GetValues(typeof(ActiveWindowDetectionType)).Cast <ActiveWindowDetectionType>());

            PropertyChanged            += KeyboardUpdater;
            mainManager.EnabledChanged += MainManagerEnabledChanged;
            mainManager.ModuleManager.EffectChanged += EffectManagerEffectChanged;
        }
Пример #19
0
        /// <summary>
        ///     Fetches all releases from GitHub, looks up the current release and shows the changelog
        /// </summary>
        /// <param name="dialogService">The dialog service to use for progress and result dialogs</param>
        /// <param name="version">The version to fetch the changelog for</param>
        /// <returns></returns>
        private static async Task ShowChanges(MetroDialogService dialogService, Version version)
        {
            var progressDialog = await dialogService.ShowProgressDialog("Changelog", "Fetching release data from GitHub..");

            progressDialog.SetIndeterminate();

            var jsonClient = new WebClient();

            // GitHub trips if we don't add a user agent
            jsonClient.Headers.Add("user-agent",
                                   "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");

            // Random number to get around cache issues
            var rand = new Random(DateTime.Now.Millisecond);
            var json = await jsonClient.DownloadStringTaskAsync(
                "https://api.github.com/repos/SpoinkyNL/Artemis/releases?random=" + rand.Next());

            // Get a list of releases
            var releases = JsonConvert.DeserializeObject <JArray>(json);
            var release  = releases.FirstOrDefault(r => r["tag_name"].Value <string>() == version.ToString());

            try
            {
                await progressDialog.CloseAsync();
            }
            catch (InvalidOperationException)
            {
                // Occurs when main window is closed before finished
            }

            if (release != null)
            {
                dialogService.ShowMarkdownDialog(release["name"].Value <string>(), release["body"].Value <string>());
            }
            else
            {
                dialogService.ShowMessageBox("Couldn't fetch release",
                                             "Sorry, Artemis was unable to fetch the release data off of GitHub.\n" +
                                             "If you'd like, you can always find out the latest changes on the GitHub page accessible from the options menu");
            }
        }
Пример #20
0
        private void CheckDuplicateInstances()
        {
            if (_checked)
            {
                return;
            }
            _checked = true;

            bool aIsNewInstance;

            Mutex = new Mutex(true, "ArtemisMutex", out aIsNewInstance);
            if (aIsNewInstance)
            {
                return;
            }

            MetroDialogService.ShowMessageBox("Multiple instances found",
                                              "It looks like there are multiple running instances of Artemis. " +
                                              "This can cause issues, especially with CS:GO and Dota2. " +
                                              "If so, please make sure Artemis isn't already running");
        }
        public ProfileEditorViewModel(ProfileEditorModel profileEditorModel, DeviceManager deviceManager, LoopManager loopManager, LuaManager luaManager, ModuleModel moduleModel, MetroDialogService dialogService)
        {
            _deviceManager       = deviceManager;
            _loopManager         = loopManager;
            _moduleModel         = moduleModel;
            _dialogService       = dialogService;
            _copyKeybind         = new KeybindModel("copy", new HotKey(Key.C, ModifierKeys.Control), PressType.Down, LayerToClipboard);
            _pasteKeybind        = new KeybindModel("paste", new HotKey(Key.V, ModifierKeys.Control), PressType.Up, ClipboardToLayer);
            _placeholderKeyboard = KeyboardPreview = ImageUtilities.BitmapToBitmapImage(Resources.none);
            ProfileNames         = new ObservableCollection <string>();
            Layers             = new ObservableCollection <LayerModel>();
            ProfileEditorModel = profileEditorModel;
            LuaManager         = luaManager;
            ShowAll            = true;

            PropertyChanged += EditorStateHandler;
            _deviceManager.OnKeyboardChanged += DeviceManagerOnOnKeyboardChanged;
            _moduleModel.ProfileChanged      += ModuleModelOnProfileChanged;

            LoadProfiles();
        }
Пример #22
0
        public async void DismissEmployee()
        {
            var dialog = new MetroDialogService();
            await dialog.Show("Werknemer non-actief zetten",
                              "Weet u zeker dat u " + SelectedEmployee.Name + " op non-actief wilt zetten?");

            if (dialog.IsAffirmative != true)
            {
                return;
            }
            SelectedEmployee.DismissalDate = DateTime.Now;

            if (!_repository.Update(SelectedEmployee))
            {
                return;
            }

            Employees.Remove(SelectedEmployee);

            RaisePropertyChanged("Employees");
        }
Пример #23
0
        private async void CheckKeyboardState()
        {
            var dialog = await MetroDialogService.ShowProgressDialog("Enabling keyboard",
                                                                     "Artemis is still busy trying to enable your last used keyboard. " +
                                                                     "Please wait while the process completes");

            dialog.SetIndeterminate();

            while (MainManager.DeviceManager.ChangingKeyboard)
            {
                await Task.Delay(1000);
            }

            try
            {
                await dialog.CloseAsync();
            }
            catch (InvalidOperationException)
            {
                // Occurs when window is closed again, can't find a proper check for this
            }
        }
Пример #24
0
        public ProfileEditorViewModel(MainManager mainManager, EffectModel gameModel, ProfileViewModel profileViewModel,
                                      MetroDialogService dialogService, string lastProfile, ILayerEditorVmFactory layerEditorVmFactory)
        {
            _mainManager          = mainManager;
            _gameModel            = gameModel;
            _layerEditorVmFactory = layerEditorVmFactory;

            Profiles         = new BindableCollection <ProfileModel>();
            Layers           = new BindableCollection <LayerModel>();
            ProfileViewModel = profileViewModel;
            DialogService    = dialogService;
            LastProfile      = lastProfile;

            PropertyChanged += EditorStateHandler;
            ProfileViewModel.PropertyChanged += LayerSelectedHandler;
            mainManager.DeviceManager.OnKeyboardChangedEvent += DeviceManagerOnOnKeyboardChangedEvent;

            _saveTimer          = new Timer(5000);
            _saveTimer.Elapsed += ProfileSaveHandler;

            LoadProfiles();
        }
Пример #25
0
 public WowPacketScanner(ILogger logger, MetroDialogService dialogService)
 {
     _dialogService = dialogService;
     Logger         = logger;
 }
Пример #26
0
        /// <summary>
        ///     Shows the changes for the given release and offers to download it
        /// </summary>
        /// <param name="dialogService">The dialog service to use for progress and result dialogs</param>
        /// <param name="release">The release to show and offer the download for</param>
        /// <returns></returns>
        private static async Task ShowChanges(MetroDialogService dialogService, JObject release)
        {
            var settings = new MetroDialogSettings
            {
                AffirmativeButtonText = "Download & install",
                NegativeButtonText    = "Ask again later"
            };

            var update = await dialogService.ShowMarkdownDialog(release["name"].Value <string>(), release["body"].Value <string>(), settings);

            if (update == null || (bool)!update)
            {
                return;
            }

            // Show a process dialog
            var dialog = await dialogService.ShowProgressDialog("Applying update", "The new update is being downloaded right now...");

            dialog.SetIndeterminate();
            // Download the release file, it's the one starting with "artemis-setup"
            var releaseFile = release["assets"].Children().FirstOrDefault(c => c["name"].Value <string>().StartsWith("artemis-setup") &&
                                                                          c["name"].Value <string>().EndsWith(".msi"));

            // If there's no matching release it means whoever published the new version f****d up, can't do much about that
            if (releaseFile == null)
            {
                await dialog.CloseAsync();

                dialogService.ShowMessageBox("Applying update failed", "Couldn't find the update file. Please install the latest version manually, sorry!");
                return;
            }

            var downloadClient = new WebClient();

            downloadClient.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
            Task <byte[]> download;

            try
            {
                download = downloadClient.DownloadDataTaskAsync(releaseFile["browser_download_url"].Value <string>());
            }
            catch (Exception e)
            {
                dialogService.ShowMessageBox("Applying update failed", "We ran into an issue downloaidng the update: \n\n" + e.Message);
                Logger.Warn(e, "Update check failed.");
                return;
            }
            downloadClient.DownloadProgressChanged += (sender, args) =>
            {
                dialog.SetMessage("The new update is being downloaded right now...\n\n" +
                                  $"Progress: {ConvertBytesToMegabytes(args.BytesReceived)} MB/{ConvertBytesToMegabytes(args.TotalBytesToReceive)} MB");
                dialog.SetProgress(args.ProgressPercentage / 100.0);
            };
            var setupBytes = await download;

            dialog.SetMessage("Installing the new update...");
            dialog.SetIndeterminate();

            // Ensure the update folder exists
            var artemisFolder = AppDomain.CurrentDomain.BaseDirectory.Substring(0, AppDomain.CurrentDomain.BaseDirectory.Length - 1);
            var updateFolder  = GeneralHelpers.DataFolder + "updates";
            var updatePath    = updateFolder + "\\" + releaseFile["name"].Value <string>();

            if (!Directory.Exists(updateFolder))
            {
                Directory.CreateDirectory(updateFolder);
            }

            // Store the bytes
            File.WriteAllBytes(updatePath, setupBytes);
            // Create a bat file that'll take care of the installation (Artemis gets shut down during install) the bat file will
            // carry forth our legacy (read that in an heroic tone)
            var updateScript = "ECHO OFF\r\n" +
                               "CLS\r\n" +
                               $"\"{updatePath}\" /passive\r\n" +
                               $"cd \"{artemisFolder}\"\r\n" +
                               "start Artemis.exe --show";

            File.WriteAllText(updateFolder + "\\updateScript.bat", updateScript);
            var psi = new ProcessStartInfo
            {
                FileName = updateFolder + "\\updateScript.bat",
                Verb     = "runas"
            };

            var process = new System.Diagnostics.Process {
                StartInfo = psi
            };

            process.Start();
            process.WaitForExit();
        }