コード例 #1
0
        public Bootstrapper()
        {
            HandleExceptions(() =>
            {
                System.Windows.Forms.Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
                System.Windows.Forms.Application.EnableVisualStyles();
                Regex.CacheSize = 1000;

                var executingAssemblyName = this.GetType().Assembly.GetName();

                consoleArgs = new ConsoleArgs(executingAssemblyName.Name);
                kernel.Bind <IConsoleArgs>().ToConstant(consoleArgs);

                var dataDirectory = new WurmAssistantDataDirectory(consoleArgs);
                kernel.Bind <IWurmAssistantDataDirectory, WurmAssistantDataDirectory>()
                .ToConstant(dataDirectory);

                var pluginsDir = new DirectoryInfo(Path.Combine(dataDirectory.DirectoryPath, "Plugins"));
                pluginManager  = new PluginManager(pluginsDir);
                pluginManager.EnablePlugins();
                kernel.Bind <PluginManager>().ToConstant(pluginManager);

                Initialize();
            });
        }
コード例 #2
0
        /// <summary>
        /// Prepares data directory and obtains exclusive lock for the directory.
        /// </summary>
        /// <param name="consoleArgs"></param>
        /// <exception cref="LockFailedException"></exception>
        public WurmAssistantDataDirectory(IConsoleArgs consoleArgs)
        {
            string dataDirPath;

            if (consoleArgs.UseRelativeDataDir)
            {
                var finder          = new LauncherDirFinder();
                var launcherBinPath = finder.TryFindLauncherParentDirPath();
                if (launcherBinPath != null)
                {
                    dataDirPath = consoleArgs.WurmUnlimitedMode
                        ? Path.Combine(launcherBinPath, "data-wa-u")
                        : Path.Combine(launcherBinPath, "data-wa-o");
                }
                else
                {
                    dataDirPath = consoleArgs.WurmUnlimitedMode
                        ? Path.Combine(GetType().Assembly.CodeBaseLocalPath(), "data-wa-u")
                        : Path.Combine(GetType().Assembly.CodeBaseLocalPath(), "data-wa-o");
                }
            }
            else
            {
                dataDirPath = consoleArgs.WurmUnlimitedMode
                    ? AppPaths.WurmAssistantUnlimited.DataDir.FullPath
                    : AppPaths.WurmAssistant3.DataDir.FullPath;
            }

            dataDir = new DirectoryInfo(dataDirPath);
            if (!dataDir.Exists)
            {
                dataDir.Create();
            }
            Lock();
        }
コード例 #3
0
        public MainViewModel(
            [NotNull] MainDataContext dataContext,
            [NotNull] ISystemTrayContextMenu trayMenu,
            [NotNull] IConsoleArgs consoleArgs,
            [NotNull] IWaVersionInfoProvider waVersionInfoProvider,
            [NotNull] MainForm mainForm)
        {
            if (dataContext == null)
            {
                throw new ArgumentNullException(nameof(dataContext));
            }
            if (trayMenu == null)
            {
                throw new ArgumentNullException(nameof(trayMenu));
            }
            if (consoleArgs == null)
            {
                throw new ArgumentNullException(nameof(consoleArgs));
            }
            if (waVersionInfoProvider == null)
            {
                throw new ArgumentNullException(nameof(waVersionInfoProvider));
            }
            if (mainForm == null)
            {
                throw new ArgumentNullException(nameof(mainForm));
            }
            this.DataContext           = dataContext;
            this.trayMenu              = trayMenu;
            this.consoleArgs           = consoleArgs;
            this.waVersionInfoProvider = waVersionInfoProvider;
            this.mainForm              = mainForm;

            trayMenu.ShowMainWindowClicked    += ShowRestore;
            trayMenu.ExitWurmAssistantClicked += (sender, eventArgs) => this.TryClose();

            savedNonMinimizedWindowState = WindowState.Normal;

            if (consoleArgs.WurmUnlimitedMode)
            {
                WindowTitle = "Aldur's Wurm Assistant Unlimited";
                Icon        = Resources.WurmAssistantUnlimitedIcon.ToImageSource();
            }
            else
            {
                WindowTitle = "Aldur's Wurm Assistant";
                Icon        = Resources.WurmAssistantIcon.ToImageSource();
            }

            WindowTitle += string.Format(" ({0})", waVersionInfoProvider.Get());

            mainForm.Dock   = DockStyle.Fill;
            WinFormsContent = new WindowsFormsHost()
            {
                Child = mainForm,
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment   = VerticalAlignment.Stretch
            };
        }
コード例 #4
0
 public WurmAssistantConfig([NotNull] IConsoleArgs consoleArgs)
 {
     if (consoleArgs == null)
     {
         throw new ArgumentNullException(nameof(consoleArgs));
     }
     this.consoleArgs = consoleArgs;
 }
コード例 #5
0
ファイル: TrayMenu.cs プロジェクト: tiba666/WurmAssistant3
        public TrayMenu(IConsoleArgs consoleArgs)
        {
            contextMenuStrip = new ContextMenuStrip();
            notifyIcon       = new NotifyIcon
            {
                BalloonTipText   = "I\'ll be here if you need me!",
                BalloonTipTitle  = "Aldur's Wurm Assistant 3",
                ContextMenuStrip = contextMenuStrip,
                Icon             = Resources.WurmAssistantIcon,
                Text             = "Aldur's Wurm Assistant 3",
                Visible          = true
            };

            if (consoleArgs.WurmUnlimitedMode)
            {
                notifyIcon.BalloonTipTitle = "Aldur's Wurm Assistant 3 Unlimited";
                notifyIcon.Text            = "Aldur's Wurm Assistant 3 Unlimited";
                notifyIcon.Icon            = Resources.WurmAssistantUnlimitedIcon;
            }

            notifyIcon.MouseClick += (sender, args) =>
            {
                if (args.Button == MouseButtons.Left)
                {
                    OnShowMainWindowClicked();
                }
                else if (args.Button == MouseButtons.Right)
                {
                    contextMenuStrip.Show();
                }
            };

            var tsmi = new ToolStripMenuItem()
            {
                Text = "Show Main Window"
            };

            tsmi.Click += (sender, args) => OnShowMainWindowClicked();
            contextMenuStrip.Items.Add(tsmi);
            contextMenuStrip.Items.Add(new ToolStripSeparator());
            contextMenuStrip.Items.Add(new ToolStripSeparator());
            var tsmi2 = new ToolStripMenuItem()
            {
                Text = "Exit"
            };

            tsmi2.Click += (sender, args) => OnExitWurmAssistantClicked();
            contextMenuStrip.Items.Add(tsmi2);
        }
コード例 #6
0
ファイル: MainForm.cs プロジェクト: tiba666/WurmAssistant3
        public MainForm(
            [NotNull] IConsoleArgs consoleArgs,
            [NotNull] CombinedLogsUserControl combinedLogsUserControl,
            [NotNull] MainMenuUserControl mainMenuUserControl,
            [NotNull] IFeaturesManager featuresManager,
            [NotNull] INewsViewModelFactory newsViewModelFactory,
            [NotNull] ITelemetry telemetry)
        {
            if (consoleArgs == null)
            {
                throw new ArgumentNullException(nameof(consoleArgs));
            }
            if (combinedLogsUserControl == null)
            {
                throw new ArgumentNullException(nameof(combinedLogsUserControl));
            }
            if (mainMenuUserControl == null)
            {
                throw new ArgumentNullException(nameof(mainMenuUserControl));
            }
            if (featuresManager == null)
            {
                throw new ArgumentNullException(nameof(featuresManager));
            }
            if (newsViewModelFactory == null)
            {
                throw new ArgumentNullException(nameof(newsViewModelFactory));
            }
            if (telemetry == null)
            {
                throw new ArgumentNullException(nameof(telemetry));
            }
            this.combinedLogsUserControl = combinedLogsUserControl;
            this.mainMenuUserControl     = mainMenuUserControl;
            this.featuresManager         = featuresManager;
            this.telemetry = telemetry;

            InitializeComponent();
        }