Esempio n. 1
0
        /// <summary>
        /// Creates new instance of WurmApiManager.
        /// All WurmApi services are thread safe and independent of execution context (i.e. synchronization context, async handling).
        /// Always call Dispose on the Manager, before closing app or dropping the instance. This will ensure proper cleanup and internal cache consistency.
        /// Not calling Dispose without terminating hosting process, may result in resource leaks.
        /// </summary>
        /// <param name="creationOptions">
        /// Optional configurable parameters of the WurmApi.
        /// </param>
        public static IWurmApi Create(WurmApiCreationOptions creationOptions = null)
        {
            if (creationOptions == null)
            {
                creationOptions = new WurmApiCreationOptions();
            }

            if (creationOptions.DataDirPath == null)
            {
                creationOptions.DataDirPath = "WurmApi";
            }
            if (!Path.IsPathRooted(creationOptions.DataDirPath))
            {
                var codebase = typeof(WurmApiFactory).Assembly.GetAssemblyDllDirectoryAbsolutePath();
                creationOptions.DataDirPath = Path.Combine(codebase, creationOptions.DataDirPath);
            }
            if (creationOptions.WurmApiLogger == null)
            {
                creationOptions.WurmApiLogger = new WurmApiLoggerStub();
            }
            if (creationOptions.WurmClientInstallDirectory == null)
            {
                creationOptions.WurmClientInstallDirectory = WurmClientInstallDirectory.AutoDetect();
            }
            if (creationOptions.WurmApiConfig == null)
            {
                creationOptions.WurmApiConfig = new WurmApiConfig();
            }
            return(new WurmApiManager(new WurmApiDataDirectory(creationOptions.DataDirPath, true),
                                      creationOptions.WurmClientInstallDirectory,
                                      creationOptions.WurmApiLogger,
                                      creationOptions.WurmApiEventMarshaller,
                                      creationOptions.WurmApiConfig));
        }
Esempio n. 2
0
        public WurmApiSetupForm([CanBeNull] string currentWurmInstallDirectory, bool wurmUnlimitedMode)
        {
            this.wurmUnlimitedMode = wurmUnlimitedMode;

            InitializeComponent();

            wurmOnlineClientDirPath.Text = currentWurmInstallDirectory ?? string.Empty;
            if (wurmOnlineClientDirPath.Text.IsNullOrEmpty() && !wurmUnlimitedMode)
            {
                try
                {
                    var dirPath = WurmClientInstallDirectory.AutoDetect();
                    wurmOnlineClientDirPath.Text = dirPath.FullPath;
                }
                catch (WurmGameClientInstallDirectoryValidationException exception)
                {
                    autodetectFailedLabel2.Visible = true;
                    autodetectFailedLabel2.Text    = "Failed to autodetect Wurm game client installation directory. Please choose manually."
                                                     + Environment.NewLine
                                                     + exception.Message;
                }
            }
        }