private void UpdateAppsAndUrls()
        {
            if (isUpdateAppsUrls)
            {
                return;
            }

            try
            {
                isUpdateAppsUrls = true;
                var allApps         = AppInfoFactory.GetVisibleAppsInfo();
                var appInfoComparer = new AppInfoComparer();

                var apps = allApps
                           .Where(a => string.IsNullOrEmpty(a.Domain))
                           .Except(OpenedApps, appInfoComparer)
                           .ToArray();

                var urls = AddMainDomain(allApps.Where(a => !string.IsNullOrEmpty(a.Domain)))
                           .Distinct(appInfoComparer)
                           .Except(OpenedForegroundUrls, appInfoComparer)
                           .ToArray();

                Application.Current.Dispatcher.Invoke(() =>
                {
                    OpenedApps.Add(apps);
                    OpenedForegroundUrls.Add(urls);
                });
            }
            finally
            {
                isUpdateAppsUrls = false;
            }
        }
示例#2
0
        public static void Setup()
        {
            Logger.Debug("Trying to set up AppInfoFactory given path: {0}", FullPath);

            AppInfoFactory appInfoFactory = GetFactory(FullPath);

            CreateInstance(appInfoFactory);
        }
示例#3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Startup"/> class.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <param name="env">The hosting environment.</param>
        public Startup(IConfiguration configuration, IHostingEnvironment env)
        {
            Configuration      = configuration;
            HostingEnvironment = env;
            AppInfo            = new AppInfoFactory().Create(typeof(Program));
            Serializer         = new DefaultJsonSerializer();

            Configuration.GetSection("ApiOptions").Bind(ApiOptions);
        }
        async Task HandleInputActionAsync(string deviceId, IInputAlgorithm inputAlgorithm)
        {
            try
            {
                await inputAlgorithm.InputAsync(new[] { deviceId });
            }
            catch (OtpNotFoundException ex)
            {
                await _metaMessenger.Publish(new ShowWarningNotificationMessage(ex.Message, notificationId : _activeDevice.Device?.Mac));

                WriteLine(ex.Message, LogErrorSeverity.Warning);
            }
            catch (AccountException ex) when(ex is LoginNotFoundException || ex is PasswordNotFoundException)
            {
                if (_appSettingsManager.Settings.UseSimplifiedUI)
                {
                    await _metaMessenger.Publish(new ShowWarningNotificationMessage(ex.Message, notificationId : _activeDevice.Device?.Mac));

                    WriteLine(ex.Message, LogErrorSeverity.Warning);
                }
                else if (_appSettingsManager.Settings.AutoCreateAccountIfNotFound)
                {
                    await OnAddNewAccount(deviceId);
                }
                else
                {
                    var appInfo = AppInfoFactory.GetCurrentAppInfo();
                    WriteLine(ex.Message, LogErrorSeverity.Warning);
                    var createNewAccount = await _windowsManager.ShowAccountNotFoundAsync(ex.Message);

                    if (createNewAccount)
                    {
                        await OnAddNewAccount(deviceId, appInfo);
                    }
                }
            }
            catch (FieldNotSecureException) // Assume that precondition failed because field is not secure
            {
                string message = TranslationSource.Instance["Exception.FieldNotSecure"];
                await _metaMessenger.Publish(new ShowWarningNotificationMessage(message, notificationId : _activeDevice.Device?.Mac));

                WriteLine(message, LogErrorSeverity.Warning);
            }
            catch (AuthEndedUnexpectedlyException)
            {
                var message = TranslationSource.Instance["Exception.AuthEndedUnexpectedly"];
                await _metaMessenger.Publish(new ShowWarningNotificationMessage(message, notificationId : _activeDevice.Device?.Mac));

                WriteLine(message, LogErrorSeverity.Warning);
            }
        }
示例#5
0
        private static void CreateInstance(AppInfoFactory appInfoFactory)
        {
            if (appInfoFactory != null && !SettingsManager.XmlData.GamePath.IsNullOrWhitespace())
            {
                var directoryInfo = new DirectoryInfo(SettingsManager.XmlData.GamePath);
                Context.Value = appInfoFactory.CreateInfo(directoryInfo);

                Logger.Debug("Found AppInfo.dll. Using AppInfo instance: {0}", Context.Value.AppName);

                return;
            }

            Logger.Error("Cannot find AppInfo.dll. Using default AppInfo instance.");

            Context.Value = DefaultAppInfo;
        }
        async void RefreshAppList()
        {
            try
            {
                Refreshing = true;

                await Task.Run(() =>
                {
                    var apps = AppInfoFactory.GetVisibleAppsInfo();

                    var expandedApps = apps.Select(a => new ExpandedAppInfo(a)).ToList();

                    var urls = new List <ExpandedAppInfo>();

                    foreach (var app in expandedApps)
                    {
                        if (!string.IsNullOrWhiteSpace(app.AppInfo.Domain))
                        {
                            urls.Add(new ExpandedAppInfo(app.AppInfo.Copy()));
                            app.AppInfo.Domain = string.Empty;
                        }
                    }

                    var uniqueApps = expandedApps.GroupBy(x => x.AppInfo.Description).Select(a => a.First()).ToList();

                    uniqueApps.AddRange(urls);

                    App.Current.Dispatcher.Invoke(() =>
                    {
                        Apps.Clear();
                        foreach (var app in uniqueApps)
                        {
                            Apps.Add(app);
                        }
                    });
                });
            }
            finally
            {
                Refreshing = false;
            }
        }
        async Task OnAddNewAccount(string deviceId, AppInfo appInfo = null)
        {
            if (_appSettingsManager.Settings.UseSimplifiedUI)
            {
                throw new ActionNotSupportedException();
            }

            if (appInfo == null)
            {
                appInfo = AppInfoFactory.GetCurrentAppInfo();
            }

            if (appInfo.ProcessName == "HideezClient")
            {
                throw new HideezWindowSelectedException();
            }

            if (_activeDevice.Device.IsLoadingStorage)
            {
                return;
            }

            if (!_activeDevice.Device.IsAuthorized || !_activeDevice.Device.IsStorageLoaded)
            {
                await _activeDevice.Device.InitRemoteAndLoadStorageAsync();
            }

            if (_activeDevice.Device.IsAuthorized && _activeDevice.Device.IsStorageLoaded)
            {
                await _metaMessenger.Publish(new ShowInfoNotificationMessage(string.Format(TranslationSource.Instance["UserAction.Notification.CreatingNewAccount"], appInfo.Title), notificationId : _activeDevice.Device?.Mac));

                await _metaMessenger.Publish(new ShowActivateMainWindowMessage());

                await _metaMessenger.Publish(new OpenPasswordManagerMessage(deviceId));

                await _metaMessenger.Publish(new AddAccountForAppMessage(deviceId, appInfo));
            }
        }
示例#8
0
        /// <summary>
        /// Cache current input field, AppInfo
        /// Get accounts for AppInfo
        /// Filter accounts by divicessId
        /// Filter accounts by previous cached inputs
        /// Call method NotFoundAccounts if not found any
        /// Input data if found one account
        /// Show window to select one account if found more then one
        /// Save Exception in property Exception if was exception during work the method
        /// </summary>
        /// <param name="devicesId">Devices for find account</param>
        public async Task InputAsync(string[] devicesId)
        {
            if (devicesId == null)
            {
                string message = $"ArgumentNull: {nameof(devicesId)}";
                log.WriteLine(message, LogErrorSeverity.Error);
                Debug.Assert(false, message);
                return;
            }

            if (!devicesId.Any())
            {
                string message = "Vaults id cannot be empty.";
                log.WriteLine(message, LogErrorSeverity.Error);
                Debug.Assert(false, message);
                return;
            }

            if (inputCache.HasCache())
            {
                return;
            }

            try
            {
                await Task.Run(() =>
                {
                    currentAppInfo = AppInfoFactory.GetCurrentAppInfo();
                });

                // Our application window was active during action invocation
                if (currentAppInfo.ProcessName == "HideezClient")
                {
                    throw new HideezWindowSelectedException();
                }

                inputCache.CacheInputField();

                if (await BeforeCondition(devicesId))
                {
                    Account[] accounts = GetAccountsByAppInfoAsync(currentAppInfo, devicesId);
                    accounts = FilterAccounts(accounts, devicesId);

                    if (!accounts.Any()) // No accounts for current application
                    {
                        if (inputCache.HasCache())
                        {
                            await inputCache.SetFocusAsync();
                        }

                        OnAccountNotFoundError(currentAppInfo, devicesId);
                    }
                    else if (accounts.Length == 1) // Single account for current application
                    {
                        try
                        {
                            await InputAsync(accounts.First());
                        }
                        catch (HideezException ex) when(ex.ErrorCode == HideezErrorCode.ChannelNotAuthorized)
                        {
                            log.WriteLine(ex, LogErrorSeverity.Warning);
                            throw new AuthEndedUnexpectedlyException();
                        }
                    }
                    else // Multiple accounts for current application
                    {
                        Account selectedAccount = null;
                        try
                        {
                            selectedAccount = await windowsManager.SelectAccountAsync(accounts, inputCache.WindowHandle);

                            if (selectedAccount != null)
                            {
                                await InputAsync(selectedAccount);
                            }
                            else
                            {
                                log.WriteLine("Account was not selected.");
                            }
                        }
                        catch (HideezException ex) when(ex.ErrorCode == HideezErrorCode.ChannelNotAuthorized)
                        {
                            log.WriteLine(ex, LogErrorSeverity.Warning);
                            if (inputCache.HasCache())
                            {
                                await inputCache.SetFocusAsync();
                            }

                            throw new AuthEndedUnexpectedlyException();
                        }
                        catch (SystemException ex) when(ex is OperationCanceledException || ex is TimeoutException)
                        {
                            if (inputCache.HasCache())
                            {
                                await inputCache.SetFocusAsync();
                            }
                            log.WriteLine(ex, LogErrorSeverity.Information);
                        }
                        catch (Exception ex)
                        {
                            Debug.Assert(false, ex.ToString());
                            log.WriteLine(ex);
                        }
                    }
                }
            }
            finally
            {
                inputCache.ClearInputFieldCache();
                currentAppInfo = null;
            }
        }
示例#9
0
        public LaunchManager()
        {
            //the following is needed on linux... the current directory must be the Mono executable, which is bad.
            Environment.CurrentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            try
            {
                FormIcon = Icon.FromHandle(Resources.IconSmall.GetHicon());
                if (File.Exists(_pathLogFile))
                {
                    File.Delete(_pathLogFile);
                }
                XmlPreferences prefs = new XmlPreferences();
                try
                {
                    prefs = _prefsSerializer.Deserialize(_pathPrefsFile, new XmlPreferences());
                }
                catch (Exception ex)
                {
                    Command_Display_Error("Read preferences file", _pathPrefsFile, ex, "Special preferences will be reset");
                }
                Preferences = prefs;
                Logger      =
                    new LoggerConfiguration().WriteTo.File(_pathLogFile, LogEventLevel.Verbose).MinimumLevel.Is(Preferences.MinimumEventLevel).CreateLogger();

                var settings = new XmlSettings();
                var history  = new XmlHistory();
                ;
                try
                {
                    history = _historySerializer.Deserialize(_pathHistoryXml, new XmlHistory());
                }
                catch (Exception ex)
                {
                    Command_Display_Error("Load patching history", _pathHistoryXml, ex,
                                          "If the launcher was terminated unexpectedly last time, it may not be able to recover.");
                }

                try
                {
                    settings = _settingsSerializer.Deserialize(_pathSettings, new XmlSettings());
                }
                catch (Exception ex)
                {
                    Command_Display_Error("Read settings file", _pathSettings, ex, "Patch list and other settings will be reset.");
                }

#if DEBUG
                settings.BaseFolder = @"D:\Program Files (x86)\GOG Galaxy\Games\Pillars of Eternity II Deadfire";
                settings.ModFolder  = @"D:\Program Files (x86)\GOG Galaxy\Games\Pillars of Eternity II Deadfire\Mods";
#endif

                // Folder dialog
                string folderDialogReason = null;
                if (settings.BaseFolder == null)
                {
                    folderDialogReason = "(no game folder has been specified)";
                }
                else if (!Directory.Exists(settings.BaseFolder))
                {
                    folderDialogReason = "(the previous game folder does not exist)";
                }

                if (folderDialogReason != null)
                {
                    if (!Command_SetGameFolder_Dialog(folderDialogReason))
                    {
                        Command_ExitApplication();
                    }
                }
                else
                {
                    BaseFolder = settings.BaseFolder;
                }

                // Mod dialog
                string modFolderDialogReason = null;
                if (settings.ModFolder == null)
                {
                    modFolderDialogReason = "(no mod folder has been specified)";
                }
                else if (!Directory.Exists(settings.ModFolder))
                {
                    modFolderDialogReason = "(the previous mod folder does not exist)";
                }

                if (modFolderDialogReason != null)
                {
                    if (!Command_SetModFolder_Dialog(modFolderDialogReason))
                    {
                        Command_ExitApplication();
                    }
                }
                else
                {
                    ModFolder = settings.ModFolder;
                }

                _home = new guiHome(this)
                {
                    Icon = FormIcon
                };
                var defaultAppInfo = new AppInfo()
                {
                    AppName = "No AppInfo.dll",
                };

                AppInfoFactory gameInfoFactory = File.Exists(_pathGameInfoAssembly) ? PatchingHelper.LoadAppInfoFactory(_pathGameInfoAssembly) : null;
                AppInfo            = gameInfoFactory?.CreateInfo(new DirectoryInfo(BaseFolder)) ?? defaultAppInfo;
                AppInfo.AppVersion = AppInfo.AppVersion ?? "version??";
                var icon = TryOpenIcon(AppInfo.IconLocation) ?? _home.Icon.ToBitmap();
                ProgramIcon  = icon;
                Instructions = new DisposingBindingList <PatchInstruction>();
                var instructions = new List <XmlInstruction>();

                foreach (var xmlPatch in settings.Instructions)
                {
                    try
                    {
                        Command_Direct_AddPatch(xmlPatch.PatchPath, xmlPatch.IsEnabled);
                    }
                    catch
                    {
                        instructions.Add(xmlPatch);
                    }
                }
                var patchList = instructions.Select(x => x.PatchPath).Join(Environment.NewLine);
                if (patchList.Length > 0)
                {
                    Command_Display_Error("Load patches on startup.", patchList);
                }
                try
                {
                    PatchingHelper.RestorePatchedFiles(AppInfo, history.Files);
                }
                catch (Exception ex)
                {
                    Command_Display_Error("Restore files", ex: ex);
                }

                _home.Closed += (sender, args) => Command_ExitApplication();
                _icon         = new NotifyIcon
                {
                    Icon        = FormIcon,
                    Visible     = false,
                    Text        = "Patchwork Launcher",
                    ContextMenu = new ContextMenu
                    {
                        MenuItems =
                        {
                            new MenuItem("Quit", (o, e) => Command_ExitApplication())
                        }
                    }
                };
                File.Delete(_pathHistoryXml);
            }
            catch (Exception ex)
            {
                Command_Display_Error("Launch the application", ex: ex, message: "The application will now exit.");
                Command_ExitApplication();
            }
        }